:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-2: #F7F9FB;
  --ink: #111A27;
  --muted: #5B6778;
  --line: #DDE2E9;
  --up: #D3263A;          /* 한국 관례: 상승·플러스 = 빨강 */
  --down: #1E5BCF;        /* 하락·마이너스 = 파랑 */
  --hot: #FFFFFF;         /* 이격과대 배지 글자 */
  --hot-bg: #B3122B;
  --hot-row: #FDECEE;
  --hot-edge: #B3122B;
  --lead: #1B7A4E;
  --lead-bg: #E2F3EA;
  --lag: #9A5B00;
  --lag-bg: #FBEFD8;
  --seg-on: #111A27;
  --seg-off: #D5DBE3;
  --sans: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0B1119; --surface: #121B27; --surface-2: #0F1721; --ink: #E6EAF0; --muted: #96A1B2; --line: #243246;
    --up: #FF5B69; --down: #5E96FF;
    --hot: #FFFFFF; --hot-bg: #D7263D; --hot-row: #2A1419; --hot-edge: #FF5B69;
    --lead: #52C791; --lead-bg: #11291E; --lag: #F0AE4A; --lag-bg: #2C2111;
    --seg-on: #E6EAF0; --seg-off: #2E3C50;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B1119; --surface: #121B27; --surface-2: #0F1721; --ink: #E6EAF0; --muted: #96A1B2; --line: #243246;
  --up: #FF5B69; --down: #5E96FF;
  --hot: #FFFFFF; --hot-bg: #D7263D; --hot-row: #2A1419; --hot-edge: #FF5B69;
  --lead: #52C791; --lead-bg: #11291E; --lag: #F0AE4A; --lag-bg: #2C2111;
  --seg-on: #E6EAF0; --seg-off: #2E3C50;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.55;
  word-break: keep-all; -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--down); outline-offset: 2px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

.wrap {
  max-width: 1320px; margin: 0 auto;
  padding-inline: 24px;
  padding-block: calc(24px + env(safe-area-inset-top, 0px)) calc(48px + env(safe-area-inset-bottom, 0px));
}
@media (max-width: 480px) { .wrap { padding-inline: 16px; } }

/* 머리 */
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 0; }
.meta div { display: flex; flex-direction: column; }
.meta dt { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
.meta dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 500; }
.meta dd.hot { color: var(--hot-edge); }

/* 도구줄 */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button {
  font: inherit; font-weight: 600; background: none; border: 0; cursor: pointer;
  padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-bottom: 8px; }
.controls select, .controls .dir {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
}
.controls .dir { cursor: pointer; }
.sortpick, .check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.check { cursor: pointer; }

/* 그룹 */
.group { margin-bottom: 28px; }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.group-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.group-head h2 .num { font-weight: 500; }
.group-head .count { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.group-head .hint { font-size: 13px; color: var(--muted); flex-basis: 100%; }
.group-head .bar { display: inline-flex; gap: 3px; }
.group-head .bar i { width: 8px; height: 8px; border-radius: 2px; background: var(--ink); display: inline-block; }

/* 표 (넓은 화면) */
.tablebox { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 1000px; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); user-select: none; }
th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
th[aria-sort] button { color: var(--ink); }
th .arrow { font-size: 10px; width: 8px; }
.l { text-align: left; }
.c { text-align: center; }
td.name a { font-weight: 600; text-decoration: none; }
td.name a:hover { text-decoration: underline; }
td.name .code { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: 6px; }
tr.hot td { background: var(--hot-row); }
tr.hot td:first-child { box-shadow: inset 3px 0 0 var(--hot-edge); }
.theme-cell { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
td .tags { justify-content: flex-start; flex-wrap: nowrap; }

/* 정배열 막대: 단기 → 장기 6칸. 채운 칸 = 순서 맞음, 빈 칸 = 뒤집힘 */
.strip { display: inline-flex; align-items: center; gap: 8px; }
.cells { display: inline-flex; gap: 3px; }
.cell { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.cell i { display: block; width: 10px; height: 14px; border-radius: 2px; box-sizing: border-box; }
.cell.on i { background: var(--seg-on); }
.cell.gap i { background: transparent; border: 1.5px dashed var(--muted); }
.wait { font-size: 12px; color: var(--ink); white-space: nowrap; }
.wait.done { color: var(--muted); }
.strip.big { flex-direction: column; align-items: flex-start; gap: 4px; }
.strip.big .cells { gap: 4px; }
.strip.big .cell i { width: 40px; height: 12px; }
.strip.big .cell small { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.strip.big .cell.gap small { color: var(--ink); font-weight: 600; }
.strip.big .wait { font-size: 13px; font-weight: 600; white-space: normal; }
@media (max-width: 380px) { .strip.big .cell i { width: 34px; } }

/* 배지 */
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.tag.hot { background: var(--hot-bg); color: var(--hot); }
.tag.lead { background: var(--lead-bg); color: var(--lead); }
.tag.lag { background: var(--lag-bg); color: var(--lag); }
.tag.multi { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.brk { font-family: var(--mono); font-size: 12px; }

/* 카드 (좁은 화면) */
.cards { display: none; }
@media (max-width: 760px) {
  .tablebox { display: none; }
  .cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
}
.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; overflow-wrap: anywhere; }
.card.hot { background: var(--hot-row); border-color: var(--hot-edge); box-shadow: inset 4px 0 0 var(--hot-edge); }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-top a { font-weight: 700; font-size: 16px; text-decoration: none; }
.card-top .code { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: 6px; }
.card-top .price { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 15px; }
.card-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px; }
.card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.card-grid div { display: flex; flex-direction: column; }
.card-grid > div > span { font-size: 11px; color: var(--muted); }
.card-grid b { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; font-size: 14px; }
.card-foot { font-size: 12px; color: var(--muted); }
.card-foot b { color: var(--ink); font-weight: 600; }
.card .tags { justify-content: flex-start; }
.chart-btn {
  justify-self: start; display: inline-flex; align-items: center; height: 32px; padding: 0 14px;
  border-radius: 6px; background: var(--ink); color: var(--bg);
  font-size: 13px; font-weight: 700; text-decoration: none;
}
.chart-btn:hover { opacity: .85; }

.empty, .error { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 32px 16px; text-align: center; color: var(--muted); }
.error { text-align: left; color: var(--ink); }
.error code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 3px; }

/* 보는 법 안내 */
.guide { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 18px; }
.guide summary { cursor: pointer; padding: 12px 16px; font-weight: 700; font-size: 15px; list-style: none; display: flex; justify-content: space-between; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "펼치기"; font-size: 12px; font-weight: 500; color: var(--muted); }
.guide[open] summary::after { content: "접기"; }
.guide-body { padding: 0 16px 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px 32px; }
.guide-body section { min-width: 0; }
.guide h3 { font-size: 14px; margin: 12px 0 6px; }
.guide p, .guide li, .guide dd { font-size: 13px; line-height: 1.65; max-width: 62ch; }
.guide p { margin: 0 0 8px; }
.guide ul { margin: 0 0 8px; padding-left: 18px; }
.guide .demo-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.guide .demo-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.terms { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 12px; }
.terms dt { font-size: 13px; font-weight: 600; }
.terms dd { margin: 0; }
@media (max-width: 480px) {
  .terms { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .terms dd { margin-bottom: 8px; }
}

.foot { margin-top: 28px; font-size: 12px; color: var(--muted); max-width: 80em; }
.foot p { margin: 0 0 6px; }

@media (max-width: 480px) {
  h1 { font-size: 22px; }
  .controls { width: 100%; }
}
