:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #fbfcfd;
  --ink: #1d2733;
  --ink-2: #56616e;
  --ink-3: #7d8792;
  --rule: #d6dce3;
  --grid: #e4e8ed;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, .12);
  --loss: #c23b3b;
  --loss-soft: rgba(227, 73, 72, .16);
  --gain-text: #1d5fae;
  --dd: #e34948;
  --pos-cell: 42, 120, 214;
  --neg-cell: 227, 73, 72;
  --field: #ffffff;
  --radius-s: 4px;
  --radius-m: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #11161c;
    --surface: #181e26;
    --ink: #e7ecf1;
    --ink-2: #a6b0bb;
    --ink-3: #87919c;
    --rule: #2c343e;
    --grid: #232a33;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, .18);
    --loss: #ee7a7a;
    --loss-soft: rgba(230, 103, 103, .2);
    --gain-text: #7fb2f0;
    --dd: #e66767;
    --pos-cell: 57, 135, 229;
    --neg-cell: 230, 103, 103;
    --field: #10151b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11161c; --surface: #181e26; --ink: #e7ecf1; --ink-2: #a6b0bb; --ink-3: #87919c; --rule: #2c343e; --grid: #232a33;
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, .18); --loss: #ee7a7a; --loss-soft: rgba(230, 103, 103, .2); --gain-text: #7fb2f0;
  --dd: #e66767; --pos-cell: 57, 135, 229; --neg-cell: 230, 103, 103; --field: #10151b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.55 "IBM Plex Sans KR", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.err { color: var(--loss); white-space: pre-wrap; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px max(16px, calc((100vw - 1120px) / 2)); border-bottom: 1px solid var(--rule); background: var(--surface);
}
.tabs { display: flex; gap: 4px; margin-right: auto; margin-left: 18px; }
.tabs a { padding: 4px 12px; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--surface); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .04em; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.bar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.bar select { padding: 4px 8px; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--field); }
.link { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; }

main { max-width: 1120px; margin: 0 auto; padding: 0 16px 64px; }

/* 질문 문장: 이 화면에서 가장 큰 요소. 입력 칸이 문장 안에 들어 있다 */
.ask { padding: 44px 0 28px; }
.sentence { margin: 0; font-size: clamp(20px, 3.1vw, 30px); font-weight: 500; line-height: 1.7; letter-spacing: -.01em; }
.sentence input {
  font-weight: 600; font-size: inherit; padding: 0 4px 2px; margin: 0 2px;
  border: 0; border-bottom: 2px solid var(--accent); border-radius: 0; background: transparent; color: var(--ink);
}
.sentence input[type="date"] { width: 7.6em; }
.sentence input:hover { background: var(--accent-soft); }
.money-in { white-space: nowrap; font-weight: 600; }
.money-in input { width: 4.4em; }
.answer { margin: 10px 0 0; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
#final { font-size: clamp(44px, 8.4vw, 88px); font-weight: 700; line-height: 1.05; letter-spacing: -.03em; }
#final.loss { color: var(--loss); }
#multiple { font-size: clamp(16px, 2vw, 20px); }
.answer.busy #final { opacity: .35; }
.note { margin: 6px 0 0; min-height: 1.5em; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 22px; font-size: 14px; }
.presets .gap { margin-left: 14px; }
.presets button, .seg button, .btn, .more {
  padding: 5px 11px; border: 1px solid var(--rule); border-radius: 999px; background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); font-size: 14px;
}
.presets button:hover, .seg button:hover, .btn:hover, .more:hover { border-color: var(--accent); }
.presets button[aria-current="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
#yearBtns { display: inline-flex; flex-wrap: wrap; gap: 6px; }

.facts { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-bottom: 28px; }
.facts dl { display: grid; grid-template-columns: repeat(6, 1fr); margin: 0; }
.facts dl > div { padding: 16px 14px 16px 0; }
.facts dl > div + div { border-left: 1px solid var(--rule); padding-left: 14px; }
.facts dt { font-size: 13px; color: var(--ink-2); }
.facts dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; }
.facts dd.small { font-size: 13px; font-weight: 400; }
@media (max-width: 860px) {
  .facts dl { grid-template-columns: repeat(3, 1fr); }
  .facts dl > div:nth-child(4) { border-left: 0; padding-left: 0; }
  .facts dl > div:nth-child(n+4) { border-top: 1px solid var(--rule); }
}
@media (max-width: 520px) {
  .facts dl { grid-template-columns: repeat(2, 1fr); }
  .facts dl > div:nth-child(odd) { border-left: 0; padding-left: 0; }
  .facts dl > div:nth-child(4) { border-left: 1px solid var(--rule); padding-left: 14px; }
  .facts dl > div:nth-child(n+3) { border-top: 1px solid var(--rule); }
}

.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 20px; margin-bottom: 20px; position: relative; }
.panel h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.panel .sub { margin: 18px 0 4px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.seg { display: inline-flex; gap: 4px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions select { padding: 5px 8px; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--field); font-size: 14px; }

.chart { width: 100%; position: relative; touch-action: pan-y; }
.chart.tall { height: 340px; }
.chart.short { height: 130px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--ink-3); font-size: 12px; }
.chart .eq { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .eqfill { fill: var(--accent-soft); }
.chart .base { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .ddline { fill: none; stroke: var(--dd); stroke-width: 1.5; }
.chart .ddfill { fill: var(--loss-soft); }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .dot.red { fill: var(--dd); }
.chart .baselabel { fill: var(--ink-2); font-size: 12px; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-s); padding: 8px 10px; font-size: 13px;
  box-shadow: 0 4px 14px rgba(20, 30, 45, .12);
}
.tip b { font-weight: 600; }

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: right; font-weight: 500; color: var(--ink-2); padding: 6px 7px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
td { text-align: right; padding: 6px 7px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
.grid td.c { min-width: 54px; border: 2px solid var(--surface); border-radius: 0; }
.grid td.year { font-weight: 600; }
.grid td.tot { font-weight: 600; border-left: 1px solid var(--rule); }
.grid td.empty { color: var(--ink-3); }
.neg { color: var(--loss); }
.list tbody tr { cursor: default; }
#strat tbody tr { cursor: pointer; }
#strat tbody tr:hover, #strat tbody tr.on { background: var(--accent-soft); }
.more { display: block; margin: 14px auto 0; }
.lead { margin: 8px 0 2px; font-size: 15px; font-weight: 500; }
.chart.bars { height: auto; margin-top: 8px; }
.bars .zero { stroke: var(--ink-3); stroke-width: 1; }
.bars .bname { fill: var(--ink); font-size: 13px; }
.bars .bval { fill: var(--ink-2); font-size: 12.5px; }
.bars .bp { fill: var(--accent); }
.bars .bn { fill: var(--dd); }
.bars .hit { fill: transparent; }
.bars .brow { cursor: pointer; outline: none; }
.bars .brow:hover .hit, .bars .brow:focus-visible .hit, .bars .brow.on .hit { fill: var(--accent-soft); }
.bars .brow.dim { opacity: .35; }
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 10px; }
.mult { border: 1px solid var(--rule); border-radius: var(--radius-s); padding: 8px 10px 6px; cursor: pointer; background: var(--surface); min-width: 0; }
.mult:hover { border-color: var(--accent); }
.mult.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mult.dim { opacity: .45; }
.mhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; }
.mname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mval { font-weight: 600; white-space: nowrap; }
.msub { font-size: 12px; color: var(--ink-2); }
.mplot { height: 64px; margin-top: 4px; }
.mplot svg { display: block; width: 100%; height: 100%; }
.mplot .z { stroke: var(--ink-3); stroke-dasharray: 3 3; stroke-width: 1; }
.mplot .lp { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.mplot .ln { fill: none; stroke: var(--dd); stroke-width: 1.5; }
.mplot .ap { fill: var(--accent-soft); }
.mplot .an { fill: var(--loss-soft); }
.mplot .cx { stroke: var(--ink-2); stroke-width: 1; }
details.more-table { margin-top: 16px; }
details.more-table summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }
#strat tbody tr.on { background: var(--accent-soft); }
.rules ul { margin: 10px 0 0; padding-left: 20px; max-width: 76ch; }
.rules li { margin: 4px 0; }

@media (max-width: 520px) {
  .multiples { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .mult { padding: 6px 8px 4px; }
  .mhead { flex-direction: column; gap: 0; }
  .msub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ask { padding-top: 28px; }
  .panel { padding: 14px; }
  .chart.tall { height: 260px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* 로그인 */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; }
.login h1 { font-size: 22px; margin: 0 0 18px; display: flex; gap: 8px; align-items: center; }
.login h1 svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.login label { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 6px; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--field); font-size: 16px; }
.login button { margin-top: 14px; width: 100%; padding: 10px; border: 0; border-radius: var(--radius-s); background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 15px; }
