:root {
  --bg: #f4f2ec; --panel: #ffffff; --ink: #1d2024; --sub: #5b6169; --line: #e1ddd3; --soft: #f7f5f0;
  --accent: #2f5bd3; --accent-ink: #ffffff; --accent-soft: #e8eefc;
  --warn-bg: #fff6d6; --warn-line: #e9c44a; --warn-ink: #5e4700;
  --hit: rgba(255, 196, 0, .38); --hit-line: #e0a400;
  --r-event: #2f5bd3; --r-due: #d1495b; --r-pay: #1f8a5b; --r-items: #b7791f; --r-place: #0f7c8c; --r-info: #7a8089; --r-todo: #7b4fc9; --r-period: #2b7bb9;
  --radius: 14px; --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 6px 18px rgba(20, 20, 20, .05);
  --f: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131416; --panel: #1c1e21; --ink: #ececea; --sub: #a3a8ae; --line: #2d3034; --soft: #222428;
    --accent: #7c9dff; --accent-ink: #0e1220; --accent-soft: #1f2a46;
    --warn-bg: #3a3112; --warn-line: #8a7320; --warn-ink: #f4dc8a;
    --hit: rgba(255, 196, 0, .30); --hit-line: #f0b400;
    --r-event: #7c9dff; --r-due: #ff7d8d; --r-pay: #4fd08f; --r-items: #f0b44a; --r-place: #4fc4d4; --r-info: #9aa0a8; --r-todo: #b593ff; --r-period: #6fb6ee;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--f); word-break: keep-all; overflow-wrap: anywhere; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
kbd { font: 600 12px/1 var(--f); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 2px 4px; margin: 0 1px; background: var(--soft); }
[hidden] { display: none !important; }

/* header */
.top { max-width: 1320px; margin: 0 auto; padding: 28px 24px 8px; display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; justify-content: space-between; }
.brand { display: flex; gap: 14px; align-items: center; }
.mark { width: 52px; height: 52px; flex: none; }
.mk-body { fill: var(--panel); stroke: var(--ink); stroke-width: 2.4; }
.mk-head { fill: var(--accent); }
.mk-ring { fill: var(--ink); }
.mk-check { fill: none; stroke: var(--r-pay); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: clamp(24px, 3.2vw, 32px); font-weight: 800; }
.tag { margin: 2px 0 0; color: var(--sub); font-size: 15px; max-width: 46em; }
.status { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px 5px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--r-info); }
.chip b { font-weight: 600; }
.chip em { font-style: normal; color: var(--sub); font-variant-numeric: tabular-nums; }
.chip[data-mode="load"] i { background: var(--r-items); animation: pulse 1.1s ease-in-out infinite; }
.chip[data-mode="ok"] i { background: var(--r-pay); }
.chip[data-mode="off"] i { background: var(--r-due); }
@keyframes pulse { 50% { opacity: .3; } }

/* layout */
main { max-width: 1320px; margin: 0 auto; padding: 12px 24px 8px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
@media (max-width: 999px) { main { grid-template-columns: minmax(0, 1fr); } .top { align-items: flex-start; } }
@media (max-width: 520px) { .top, main, .about, .foot { padding-left: 16px; padding-right: 16px; } .examples > span { flex-basis: 100%; } }
h1, h2, .drop strong, .drop span, .c-title, .group { text-wrap: balance; }
p, li, .w, dd { text-wrap: pretty; }
.nw { white-space: nowrap; }
#viewer-panel:not(.loaded) .tools, #viewer-panel:not(.loaded) .viewer, #viewer-panel:not(.loaded) .units, #viewer-panel:not(.loaded) .legend { display: none; }
#viewer-panel.loaded #viewer-empty { display: none; }
#viewer-empty { margin: 12px 0 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel h2 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: var(--panel); font-size: 14px; font-weight: 700; }
.phead { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 9px 16px; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; min-height: 40px; }
@media (hover: hover) { .btn:hover { filter: brightness(1.06); } .btn.ghost:hover { background: var(--soft); filter: none; } .units li:hover { background: var(--soft); } }
.btn:focus-visible, .drop:focus-visible, .card:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.small { padding: 5px 11px; font-size: 13.5px; min-height: 32px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ex { background: var(--accent-soft); color: var(--ink); border-color: transparent; font-weight: 600; }

/* intake */
.drop { margin-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 30px 16px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; background: var(--soft); transition: border-color .15s, background .15s; }
.drop svg { width: 40px; height: 40px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.drop strong { font-size: 17px; }
.drop span { color: var(--sub); font-size: 14px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.examples > span { font-weight: 600; font-size: 14px; color: var(--sub); margin-right: 2px; }
.fine { color: var(--sub); font-size: 13px; margin: 8px 0 0; }
.textbox textarea { width: 100%; margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--soft); resize: vertical; }
.msg { margin: 10px 0 0; font-size: 14px; min-height: 0; }
.msg:empty { display: none; }
.msg[data-kind="warn"], .msg[data-kind="err"] { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); padding: 8px 12px; border-radius: 10px; }

/* viewer */
.viewer { position: relative; margin-top: 14px; border-radius: 10px; overflow: hidden; background: var(--soft); border: 1px solid var(--line); }
.viewer img { display: block; width: 100%; height: auto; }
.viewer.noimg { display: none; }
.boxes { position: absolute; inset: 0; pointer-events: none; }
/* 줄 상자: 읽은 글자 범위보다 사방 6 px 넓게(글자에 선이 닿지 않게). 평소엔 보이지 않고, 고른 줄만 노란 칠 + 바깥 선 */
.box { position: absolute; border-radius: 4px; transition: background .2s; }
.box.hit { background: var(--hit); }
.scan { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 22, 26, .35); color: #fff; font-weight: 600; }
.scan .bar { position: absolute; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent, #9fb7ff, transparent); animation: sweep 1.6s linear infinite; top: 0; }
.scan span { background: rgba(0, 0, 0, .55); padding: 8px 14px; border-radius: 999px; font-variant-numeric: tabular-nums; }
@keyframes sweep { from { top: 0; } to { top: 100%; } }
@media (prefers-reduced-motion: reduce) { .scan .bar, .chip[data-mode="load"] i { animation: none; } }
.units { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.units li { display: grid; grid-template-columns: 4.6em 2.1em minmax(0, 1fr) auto; column-gap: 8px; align-items: baseline; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14.5px; }
.units .role { justify-self: start; }
.units .slot { justify-self: start; }
.units li.hit { background: var(--hit); }
.units li.dim { opacity: .6; }
.units .t { flex: 1; min-width: 0; }
.role { flex: none; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1.5px solid currentColor; line-height: 1.5; }
.r-event { color: var(--r-event); } .r-due { color: var(--r-due); } .r-pay { color: var(--r-pay); } .r-items { color: var(--r-items); } .r-place { color: var(--r-place); } .r-info { color: var(--r-info); }
.by { flex: none; font-size: 11px; font-weight: 800; padding: 0 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); line-height: 1.6; }
.lowconf { flex: none; font-size: 11px; color: var(--warn-ink); background: var(--warn-bg); border-radius: 5px; padding: 0 6px; }
.legend { color: var(--sub); font-size: 13px; margin: 10px 0 0; }

/* cards */
.doc-title { margin: 10px 0 0; color: var(--sub); font-size: 14.5px; }
.doc-title:empty { display: none; }
.empty { color: var(--sub); font-size: 15px; }
.empty ul { margin: 8px 0 0; padding-left: 1.2em; }
.empty.small { font-size: 14px; margin: 6px 0 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 14px; margin-top: 14px; }
.cards.compact { grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
.card { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 14px 18px; background: var(--panel); cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.card::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--k, var(--r-event)); }
.card[data-kind="due"] { --k: var(--r-due); } .card[data-kind="pay"] { --k: var(--r-pay); } .card[data-kind="todo"] { --k: var(--r-todo); } .card[data-kind="period"] { --k: var(--r-period); }
.card.sel { border-color: var(--hit-line); box-shadow: 0 0 0 2px var(--hit); }
.c-top { display: flex; justify-content: space-between; align-items: center; }
.kind { font-size: 12.5px; font-weight: 800; color: var(--k, var(--r-event)); }
.dday { font-size: 12.5px; font-weight: 700; padding: 1px 9px; border-radius: 999px; background: var(--soft); font-variant-numeric: tabular-nums; }
.dday.soon { background: var(--r-due); color: #fff; }
.dday.now { background: var(--r-pay); color: #fff; }
.dday.past { color: var(--sub); }
.c-title { font-size: 18px; font-weight: 750; line-height: 1.35; }
.c-when { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: pre-wrap; }
.c-fields { margin: 0; display: grid; grid-template-columns: 3.4em minmax(0, 1fr); gap: 2px 12px; font-size: 14.5px; }
.c-fields:empty { display: none; }
.c-fields dt { color: var(--sub); }
.c-fields dd { margin: 0; }
.c-warn:empty { display: none; }
.w { margin: 4px 0 0; padding: 8px 10px; border-radius: 8px; font-size: 13.5px; line-height: 1.5; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.w-amount, .w-relative { background: transparent; color: var(--sub); border: 0; border-left: 3px solid var(--line); border-radius: 0; padding: 2px 0 2px 10px; }
.c-note { margin: 0; font-size: 13px; color: var(--sub); }
.c-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: auto; padding-top: 6px; }
.c-actions .gcal { grid-column: 1 / -1; }
.c-edit { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding: 10px 0 8px; border-top: 1px dashed var(--line); cursor: default; }
.c-edit label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--sub); }
.c-edit input { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: var(--soft); color: var(--ink); font-size: 15px; min-width: 0; }
.c-edit .two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.c-edit input { width: 100%; }

/* saved */
.search { display: flex; gap: 8px; margin-top: 14px; }
.search input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--soft); }
.group { font-size: 15px; margin: 18px 0 0; color: var(--sub); }

/* about + footer */
.about, .foot { max-width: 1320px; margin: 0 auto; padding: 12px 24px; }
.about details { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 20px; }
.about summary { cursor: pointer; font-weight: 700; }
.about .steps { padding-left: 1.3em; max-width: 52em; }
.about p { max-width: 52em; }
.about p { color: var(--sub); font-size: 14.5px; }
.foot { color: var(--sub); font-size: 12.5px; padding-bottom: 40px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: var(--panel); padding: 10px 18px; border-radius: 999px; font-size: 14.5px; transition: .25s; pointer-events: none; max-width: calc(100% - 32px); text-align: center; z-index: 9; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 폰: 아래 덩어리(about·바닥글)도 패널과 같은 좌우 여백 — 위의 기본값보다 뒤에 둔다 */
@media (max-width: 520px) { .about, .foot { padding-left: 16px; padding-right: 16px; } }
.c-edit .hint { margin: -2px 0 0; }
.c-edit .two { align-items: end; }
@media (max-width: 520px) {
  .units li { grid-template-columns: 4em minmax(0, 1fr) auto auto; column-gap: 6px; }
  .units .role { grid-column: 1; } .units .t { grid-column: 2; grid-row: 1; } .units .slot { grid-column: 3; grid-row: 1; } .units .lowconf { grid-column: 4; grid-row: 1; }
  .units .slot:empty { display: none; }
}
.about .s { display: block; }
.about .steps li { margin-bottom: 10px; }
.about .steps li b { display: block; }
.about p:last-child { margin-bottom: 4px; }
