/* ─────────────────────────────────────────── 토큰 */
:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --border: #e4e4e1;
  --border-strong: #d3d3cf;
  --text: #1c1c1a;
  --text-2: #57564f;
  --text-3: #8b8a82;
  --accent: #2f6f6a;
  --a: #3d6b9e;
  --b: #b06a4f;
  --ok: #3f7d5a;
  --warn: #a8762c;
  --bad: #a8524a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 18, .04), 0 1px 8px rgba(20, 20, 18, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161a;
    --surface: #1d1d22;
    --surface-2: #24242a;
    --border: #2e2e35;
    --border-strong: #3c3c45;
    --text: #ececef;
    --text-2: #a9a9b2;
    --text-3: #74747e;
    --accent: #6fb3ac;
    --a: #7aa6d8;
    --b: #d99a7c;
    --ok: #6aae86;
    --warn: #d0a457;
    --bad: #d4837a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #16161a; --surface: #1d1d22; --surface-2: #24242a;
  --border: #2e2e35; --border-strong: #3c3c45;
  --text: #ececef; --text-2: #a9a9b2; --text-3: #74747e;
  --accent: #6fb3ac; --a: #7aa6d8; --b: #d99a7c;
  --ok: #6aae86; --warn: #d0a457; --bad: #d4837a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Segoe UI", "Noto Sans KR", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.35; letter-spacing: -.015em; margin: 0; font-weight: 650; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ─────────────────────────────────────────── 레이아웃 */
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 24px; }

header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.top .wrap { display: flex; align-items: center; gap: 16px; height: 56px; }
.brand { font-weight: 680; letter-spacing: -.02em; font-size: 15px; }
.brand small { color: var(--text-3); font-weight: 450; margin-left: 8px; letter-spacing: 0; }
.top .spacer { flex: 1; }

nav.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--border); }
nav.tabs button {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: 11px 14px; font: inherit; font-size: 14px; color: var(--text-3);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 28px 0 96px; }
section.view { display: none; }
section.view.active { display: block; }

/* ─────────────────────────────────────────── 요소 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card > h3 { font-size: 15px; margin-bottom: 4px; }
.card > .sub { color: var(--text-3); font-size: 13px; margin-bottom: 16px; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { font-size: 12px; color: var(--text-3); letter-spacing: .01em; }
.stat .value { font-size: 26px; font-weight: 660; letter-spacing: -.03em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .foot { font-size: 12px; color: var(--text-3); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-3); font-weight: 550; font-size: 12.5px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }

.scroll-x { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 10.5px; }
.chart .rowlabel { fill: var(--text-2); font-size: 12px; }
.chart .s0 { fill: var(--a); }
.chart .s1 { fill: var(--b); }
.chart .line.s0 { stroke: var(--a); stroke-width: 2; fill: none; }
.chart .line.s1 { stroke: var(--b); stroke-width: 2; fill: none; }
.chart .dot.s0 { fill: var(--a); }
.chart .dot.s1 { fill: var(--b); }
.chart .area.s0 { fill: var(--a); opacity: .1; stroke: none; }
.chart .area.s1 { fill: var(--b); opacity: .1; stroke: none; }
.chart .heat { fill: var(--accent); }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-top: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
.legend .s0 i { background: var(--a); }
.legend .s1 i { background: var(--b); }

.splitbar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.splitbar .seg.s0 { background: var(--a); }
.splitbar .seg.s1 { background: var(--b); }

/* 스코어카드 */
.score { border-left: 3px solid var(--border-strong); }
.score.high { border-left-color: var(--ok); }
.score.mid { border-left-color: var(--warn); }
.score.low { border-left-color: var(--bad); }
.score .head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.score .big { font-size: 24px; font-weight: 660; letter-spacing: -.03em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.score .theory { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.score .bench { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin-top: 12px; }
.score .note { font-size: 13px; color: var(--text-2); margin-top: 10px; }

/* 타임라인 */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 1px; background: var(--border); }
.tl-item { position: relative; padding: 0 0 22px 4px; }
.tl-item::before { content: ''; position: absolute; left: -21px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.tl-date { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tl-label { font-weight: 620; font-size: 14.5px; margin-top: 1px; }
.tl-note { font-size: 13px; color: var(--text-2); }
.tl-quote { margin-top: 7px; font-size: 13.5px; color: var(--text-2); border-left: 2px solid var(--border-strong); padding: 2px 0 2px 11px; white-space: pre-wrap; }
.tl-quote b { color: var(--text); font-weight: 600; }

/* 드롭존 */
.drop {
  border: 1.5px dashed var(--border-strong); border-radius: 12px;
  padding: 40px 24px; text-align: center; color: var(--text-2);
  background: var(--surface); transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.drop strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

button.btn {
  appearance: none; font: inherit; font-size: 14px; cursor: pointer;
  background: var(--text); color: var(--bg); border: 0;
  border-radius: 7px; padding: 8px 15px; font-weight: 550;
}
button.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
button.btn:disabled { opacity: .5; cursor: default; }

input[type="password"], input[type="text"], select {
  font: inherit; font-size: 14px; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); color: var(--text); width: 100%;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 잠금 화면 */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate .box { width: 100%; max-width: 340px; text-align: center; }
.gate h1 { font-size: 20px; margin-bottom: 6px; }
.gate p { color: var(--text-3); font-size: 13.5px; margin: 0 0 22px; }
.gate form { display: flex; flex-direction: column; gap: 10px; }
.gate .err { color: var(--bad); font-size: 13px; min-height: 19px; margin-top: 2px; }

.muted { color: var(--text-3); }
.small { font-size: 13px; }
.pill { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sep { height: 1px; background: var(--border); margin: 20px 0; border: 0; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.gallery figcaption { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }

.empty { text-align: center; color: var(--text-3); padding: 48px 20px; font-size: 14px; }

/* ── 인용 칩 ─────────────────────────────── */
.cite {
  appearance: none; font: inherit; font-size: 12px; cursor: pointer;
  margin-top: 8px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border); line-height: 1.5;
}
.cite::before { content: '↗'; margin-right: 4px; opacity: .6; }
.cite:hover { color: var(--text); border-color: var(--border-strong); }
.row .cite { margin-top: 0; }

/* ── 해석 탭 ─────────────────────────────── */
.seg { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.seg button {
  appearance: none; font: inherit; font-size: 13.5px; cursor: pointer;
  padding: 7px 14px; border-radius: 999px;
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border);
}
.seg button:hover { color: var(--text); }
.seg button[aria-selected="true"] {
  background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 560;
}

.ep-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ep-date { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ep-title { font-size: 17px; margin-top: 2px; letter-spacing: -.02em; }
.ep-body { margin: 12px 0 0; font-size: 14.5px; color: var(--text-2); line-height: 1.75; }
.ep-items { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 4px; }

.mood {
  font-size: 12.5px; white-space: nowrap; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}

.ins-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.ins-item:last-child { border-bottom: 0; padding-bottom: 2px; }
.ins-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ins-cap { font-size: 13.5px; color: var(--text-2); }
.ins-cap b { color: var(--text); font-weight: 620; }
.ins-quote {
  margin-top: 8px; font-size: 13.5px; color: var(--text-2);
  border-left: 2px solid var(--border-strong); padding: 3px 0 3px 11px;
  white-space: pre-wrap; word-break: break-word;
}
.ins-quote b { color: var(--text); font-weight: 600; margin-right: 4px; }

.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-3);
}
.tag.move { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tag.warm { color: var(--b); border-color: color-mix(in srgb, var(--b) 40%, var(--border)); }
.tag.fun { color: var(--a); border-color: color-mix(in srgb, var(--a) 40%, var(--border)); }
.tag.joke { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.tag.date { font-variant-numeric: tabular-nums; }

.dict-item { padding: 16px 0; border-bottom: 1px solid var(--border); }
.dict-item:last-child { border-bottom: 0; }
.dict-term { font-size: 16px; font-weight: 650; letter-spacing: -.02em; }
.dict-date { font-size: 11.5px; color: var(--text-3); font-weight: 450; margin-left: 8px; font-variant-numeric: tabular-nums; }
.dict-origin { font-size: 13.5px; color: var(--text-2); margin-top: 2px; }

/* ── 대화 원문 뷰어 ──────────────────────── */
.chat-days { margin-top: 16px; }
.day { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 8px; overflow: hidden; }
.day-head {
  appearance: none; width: 100%; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 11px 16px; background: none; border: 0; cursor: pointer;
  font: inherit; color: var(--text); text-align: left;
}
.day-head:hover { background: var(--surface-2); }
.day-label { font-weight: 580; font-variant-numeric: tabular-nums; font-size: 14px; }
.day-count { color: var(--text-3); font-size: 12px; }
.day-body { display: none; padding: 6px 16px 18px; border-top: 1px solid var(--border); }
.day.open .day-body { display: block; }
.day.open .day-head { background: var(--surface-2); }

.msg { max-width: 78%; margin: 12px 0; scroll-margin-top: 120px; }
.msg.me { margin-left: auto; text-align: right; }
.msg-meta { font-size: 11px; color: var(--text-3); margin-bottom: 3px; }
.msg-time { margin-left: 6px; font-variant-numeric: tabular-nums; }
.msg-text, .msg-placeholder {
  display: inline-block; max-width: 100%; text-align: left;
  padding: 8px 12px; border-radius: 12px; font-size: 14px;
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); border: 1px solid var(--border);
}
.msg.me .msg-text, .msg.me .msg-placeholder {
  background: color-mix(in srgb, var(--a) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--a) 26%, var(--border));
}
.msg-placeholder { color: var(--text-3); font-style: italic; font-size: 13px; }

.msg.focus .msg-text, .msg.focus .msg-placeholder {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.msg.hit .msg-text { box-shadow: inset 3px 0 0 var(--warn); }

@media (max-width: 560px) { .msg { max-width: 90%; } }


/* 좁은 화면: 헤더의 브랜드·아카이브 선택·버튼이 한 줄에 안 들어가 가로 스크롤이 생긴다 */
@media (max-width: 560px) {
  .wrap { padding: 0 14px; }
  .top .wrap { gap: 8px; }
  .brand small { display: none; }
  #archiveSel { max-width: none; min-width: 0; flex: 1; }
  .card { padding: 16px; }
  .stat .value { font-size: 22px; }
  .score .big { font-size: 20px; }
}
