:root {
  --paper: #f3eee4;
  --surface: #fffdf8;
  --ink: #1c1712;
  --muted: #6d645a;
  --line: #e4dbcd;
  --green: #2c6a4a;
  --green-ink: #f4efe6;
  --green-soft: #e3f0e7;
  --orange: #d4652f;
  --orange-soft: #fbe6d6;
  --red: #b42318;
  --red-soft: #f8e4e1;
  --blue: #355a7c;
  --blue-soft: #e6eef6;
  --gold: #b8922a;
  --gold-soft: #f6edd0;
  --shadow: 0 18px 40px rgba(50, 36, 20, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Pretendard Variable", Pretendard, "Noto Sans KR", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #efe4cf 0%, transparent 55%),
    var(--paper);
  letter-spacing: -0.01em;
}

.pub-banner {
  max-width: 1480px;
  margin: 8px auto 0;
  background: #f6edd0;
  border: 1px solid #e4d4a4;
  color: #6a4e10;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
}
.pub-banner code {
  font-size: 12px;
  background: #fff;
  padding: 1px 6px;
  border-radius: 6px;
}
.skip {
  position: absolute; left: -999px; top: 8px;
}
.skip:focus { left: 8px; background: #fff; padding: 8px 12px; z-index: 20; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px 8px;
  max-width: 1480px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark { color: var(--green); display: flex; }
.brand strong { display: block; font-size: 18px; letter-spacing: -0.03em; }
.brand span { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; background: #efe8db; padding: 4px; border-radius: 999px; }
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; font: inherit; cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--surface); color: var(--ink); font-weight: 650;
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

main { max-width: 1480px; margin: 0 auto; padding: 12px 20px 48px; }
#view-plan {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.composer {
  position: sticky; top: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px 18px;
  box-shadow: var(--shadow);
}
.month-head {
  display: grid; grid-template-columns: 40px 1fr 40px; align-items: center;
}
.month-head h1 { margin: 0; text-align: center; font-size: 22px; letter-spacing: -0.04em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; font-size: 22px; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { border-color: var(--green); color: var(--green); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 10px 2px 14px; }

.cal { display: grid; gap: 4px; }
.cal-hd, .cal-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-hd span {
  text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 6px;
  font-weight: 600;
}
.cal-hd span:nth-child(6), .cal-hd span:nth-child(7) { color: #9a8f84; }
.day {
  position: relative;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  font: inherit;
  cursor: pointer;
  padding: 6px 4px 8px;
  color: var(--ink);
}
.day .n { display: block; font-weight: 650; font-size: 14px; }
.day .tag { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day.pad { visibility: hidden; pointer-events: none; }
.day.weekend { color: #9a8f84; cursor: default; }
.day.weekend .n { font-weight: 500; }
.day.biz:hover { background: var(--green-soft); }
.day.holiday {
  background: var(--red-soft);
  border-color: #f0c8c2;
  color: var(--red);
}
.day.feast:not(.holiday) { background: var(--orange-soft); }
.day.gim:not(.holiday):not(.feast) { background: #f3efe4; }
.day:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.counts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 14px 0; padding: 0;
}
.counts div {
  background: #f7f1e7; border-radius: 12px; padding: 10px 8px; text-align: center;
}
.counts dt { font-size: 11px; color: var(--muted); }
.counts dd { margin: 4px 0 0; font-size: 20px; font-weight: 700; letter-spacing: -0.04em; }

.primary {
  width: 100%;
  border: 0;
  background: var(--orange);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(212, 101, 47, 0.22);
}
.primary:hover { filter: brightness(1.04); }
.primary:disabled { opacity: .55; cursor: wait; box-shadow: none; }
.primary.slim { width: auto; padding: 10px 16px; font-size: 14px; box-shadow: none; }
.fine { font-size: 12px; color: var(--muted); line-height: 1.55; margin: 12px 2px 0; }

.stage {
  min-height: 72vh;
  background: #fff;
  border: 1px solid #bbb;
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.sheet-wrap { overflow-x: auto; }
.sheet {
  background: #fff;
  color: #000;
  font-family: "Malgun Gothic", "맑은 고딕", sans-serif;
  min-width: 980px;
}
.sheet table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.sheet th, .sheet td {
  border: 1px solid #000;
  padding: 2px 4px;
  vertical-align: middle;
}
.sheet .title th {
  background: #92d050;
  font-size: clamp(28px, 4.2vw, 46px);
  font-weight: 800;
  height: 88px;
  letter-spacing: 0.12em;
  border: 2px solid #000;
}
.sheet .wd th, .sheet .hdr td, .sheet .hdr th {
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  border: 2px solid #000;
  height: 26px;
}
.sheet .date th, .sheet .date td {
  background: #ffc000;
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  border: 2px solid #000;
  height: 26px;
}
.sheet .wk {
  width: 48px;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
  border: 2px solid #000;
}
.sheet .menu {
  text-align: center;
  font-size: 11px;
  height: 22px;
  border-left: 2px solid #000;
  border-right: 0;
}
.sheet .menu.side { color: #222; }
.sheet .alg {
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  border-right: 2px solid #000;
  border-left: 0;
  white-space: nowrap;
  overflow: hidden;
}
.sheet tbody tr:last-of-type td,
.sheet tbody tr:last-of-type th {
  border-bottom: 2px solid #000;
}
.sheet .legend td {
  border: 2px solid #000;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
  padding: 12px 10px;
  white-space: normal;
}

.empty, .busy {
  min-height: 62vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 8px; color: var(--muted);
}
.empty h2, .busy strong { color: var(--ink); margin: 8px 0 0; font-size: 22px; letter-spacing: -0.04em; }
.empty p, .busy p { max-width: 420px; line-height: 1.6; margin: 6px 0 0; }
.empty em { font-style: normal; color: var(--orange); font-weight: 650; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--orange);
  animation: spin .8s linear infinite; margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--green); }
}

.hidden, [hidden] { display: none !important; }

.result-bar {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  align-items: center; margin-bottom: 14px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 6px 10px; border-radius: 999px;
  background: var(--green-soft); color: #21553b; font-weight: 600;
}
.chip.warn { background: var(--red-soft); color: var(--red); }
.chip.soft { background: var(--blue-soft); color: var(--blue); }
.chip.gold { background: var(--gold-soft); color: #7a5b12; }

.result-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: flex; background: #efe8db; padding: 3px; border-radius: 999px; }
.seg-btn {
  border: 0; background: transparent; font: inherit; cursor: pointer;
  padding: 7px 12px; border-radius: 999px; color: var(--muted);
}
.seg-btn.on { background: #fff; color: var(--ink); font-weight: 650; }
.download {
  display: inline-flex; align-items: center;
  background: var(--green); color: var(--green-ink); text-decoration: none;
  font-weight: 700; padding: 9px 14px; border-radius: 12px;
}
.download:hover { filter: brightness(1.05); }

.banner {
  background: var(--gold-soft); color: #6a4e10; border-radius: 12px;
  padding: 10px 14px; font-size: 13px; margin-bottom: 14px; line-height: 1.5;
}

.page-head { margin: 8px 4px 22px; max-width: 720px; }
.page-head h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.04em; }
.page-head p { margin: 0; color: var(--muted); line-height: 1.6; }

.rules {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px;
}
.rule {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 16px 14px; box-shadow: var(--shadow);
}
.rule .row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.rule h3 { margin: 0 0 8px; font-size: 16px; letter-spacing: -0.03em; }
.rule p { margin: 0 0 8px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.badge.hard { background: var(--red-soft); color: var(--red); }
.badge.soft { background: var(--gold-soft); color: #7a5b12; }
.badge.scope { background: var(--blue-soft); color: var(--blue); }
.badge.code { background: #efe8db; color: var(--ink); }

.verify-row {
  display: flex; gap: 10px; align-items: end; margin-bottom: 18px;
}
.verify-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.verify-row select {
  font: inherit; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); min-width: 160px;
}
.metrics {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px;
}
.metric {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
}
.metric b { display: block; font-size: 28px; letter-spacing: -0.05em; margin-top: 4px; }
.metric span { color: var(--muted); font-size: 12px; }
.note { margin-top: 16px; color: var(--muted); font-size: 13px; line-height: 1.6; max-width: 640px; }

.tip {
  position: fixed; z-index: 30; max-width: 280px;
  background: #1c1712; color: #f4efe6; font-size: 12px; line-height: 1.5;
  padding: 10px 12px; border-radius: 10px; pointer-events: none;
  box-shadow: 0 12px 30px rgba(0,0,0,.2);
}

@media (max-width: 900px) {
  .top { flex-direction: column; align-items: stretch; padding: 14px 14px 0; }
  .tabs { overflow: auto; }
  main { padding: 12px 12px 40px; }
  #view-plan { grid-template-columns: 1fr; }
  .composer { position: static; }
  .stage { min-height: unset; padding: 16px; }
  .empty, .busy { min-height: 40vh; }
}

@media print {
  .top, .composer, .result-actions, .skip { display: none !important; }
  #view-plan { display: block; }
  .stage { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; }
}
