/* AYA 트렌드 거래소 — 밤 시세판. 오름 = 빨강, 내림 = 파랑 (한국 시세 관례) · 숫자가 앞에 선다 */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --page: #10141b; --panel: #161b24; --raised: #1d2330; --hover: #202734; --line: #262d3a; --grid: #232a36; --axis: #3a4252;
  --text: #e8ecf3; --text2: #98a2b3; --text3: #7d8698;
  --up: #f2555a; --down: #4d8ff7; --up-wash: rgba(242, 85, 90, .14); --down-wash: rgba(77, 143, 247, .14);
  --neutral: #3a4150; --focus: #6aa3ff; --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --c1: #338ced; --c2: #e76624; --c3: #00a888; --c4: #d28e05; --c5: #e24d8b; --c6: #0aac23; --c7: #9887ef; --c8: #eb6263; --c9: #6b7384;
  --r: #eb6263; --g: #0aac23; --b: #338ced;
}
[data-theme="light"] {
  color-scheme: light;
  --page: #f4f6f9; --panel: #ffffff; --raised: #f0f3f7; --hover: #eef2f7; --line: #e3e7ee; --grid: #edf0f4; --axis: #c5ccd6;
  --text: #191f28; --text2: #4e5968; --text3: #6b7684;
  --up: #d6202f; --down: #1a5fd0; --up-wash: rgba(214, 32, 47, .09); --down-wash: rgba(26, 95, 208, .09);
  --neutral: #d4d9e1; --focus: #1a5fd0; --shadow: 0 8px 28px rgba(25, 31, 40, .14);
  --c1: #257de0; --c2: #f47230; --c3: #00b894; --c4: #f2a600; --c5: #ee7fac; --c6: #008a17; --c7: #6a4ce2; --c8: #ec4647; --c9: #8a93a3;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font: 15px/1.5 "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: -0.01em; padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; left: 12px; top: 12px; z-index: 50; background: var(--panel); padding: 8px 12px; }
.muted { color: var(--text2); }
.small { font-size: 13px; }
.num, td.c-num, .tile .v, .clock { font-variant-numeric: tabular-nums; }
h1, h2 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }

/* ---- 머리 */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 56px; background: var(--page); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.03em; }
.mark { display: inline-flex; gap: 3px; align-items: center; }
.mark i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.mark .r { background: var(--r); } .mark .g { background: var(--g); } .mark .b { background: var(--b); }
.mark.big i { width: 12px; height: 12px; }
.tabs { display: flex; gap: 2px; height: 100%; }
.tabs a {
  display: flex; align-items: center; padding: 0 14px; text-decoration: none; color: var(--text2); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--text); }
.tools { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.search { position: relative; }
.search input {
  width: 220px; height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
}
.search input::placeholder { color: var(--text3); }
.search-pop {
  position: absolute; right: 0; top: 40px; width: 320px; max-height: 360px; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.search-pop button {
  display: flex; width: 100%; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 0; background: none;
  border-radius: 6px; text-align: left; cursor: pointer;
}
.search-pop button:hover, .search-pop button:focus-visible { background: var(--hover); }
.clock { display: flex; align-items: center; gap: 7px; color: var(--text2); font-size: 13px; white-space: nowrap; }
.live { width: 7px; height: 7px; border-radius: 50%; background: var(--g); box-shadow: 0 0 0 3px rgba(10, 172, 35, .18); }
.clock.stale .live { background: var(--text3); box-shadow: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer;
  color: var(--text2); font-size: 15px;
}
.icon-btn:hover { color: var(--text); }
.text-btn { height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; color: var(--text2); font-size: 13px; padding: 0 10px; white-space: nowrap; }
.text-btn:hover { color: var(--text); }

/* ---- 지수 띠 */
.indices {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(148px, 1fr); gap: 1px; overflow-x: auto;
  background: var(--line); border-bottom: 1px solid var(--line); scrollbar-width: thin;
}
.tile {
  background: var(--page); padding: 10px 14px 8px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto;
  column-gap: 8px; min-width: 148px; border: 0; text-align: left; cursor: pointer;
}
.tile:hover { background: var(--panel); }
.tile.on { background: var(--raised); }
.tile .k { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tile .v { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.tile .d { font-size: 12px; font-weight: 600; align-self: end; justify-self: end; white-space: nowrap; }
.tile svg { grid-column: 1 / -1; width: 100%; height: 22px; display: block; margin-top: 2px; }
.tile.main .v { font-size: 22px; }
.dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: none; }

/* ---- 전광판 */
.tape { overflow: hidden; border-bottom: 1px solid var(--line); background: var(--panel); height: 34px; position: relative; }
.tape-track { display: inline-flex; white-space: nowrap; height: 34px; align-items: center; padding-left: 16px;
  animation: tape 70s linear infinite; font-size: 13px; }
.tape-track a { margin-right: 28px; }
.tape:hover .tape-track { animation-play-state: paused; }
.tape-track a { text-decoration: none; display: inline-flex; gap: 6px; align-items: baseline; }
.tape-track a:hover b { text-decoration: underline; }
.tape-track .lab { color: var(--text3); font-size: 12px; }
@keyframes tape { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .tape-track { animation: none; padding-left: 16px; }
  .tape { overflow-x: auto; }
}

/* ---- 공통 패널 */
main { padding: 16px 20px 40px; max-width: 1680px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.panel.inset { background: var(--raised); border: 0; }
.panel-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.lead { margin: -4px 0 12px; max-width: 70ch; }
.seg { display: inline-flex; background: var(--raised); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--text2); font-weight: 600; font-size: 14px; }
.seg.small button { padding: 3px 10px; font-size: 13px; }
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.filters { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.sel select { height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--raised); padding: 0 8px; }
.link-btn { border: 0; background: none; color: var(--text2); text-decoration: underline; cursor: pointer; padding: 0; margin-left: auto; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chips button { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 4px 12px; cursor: pointer; color: var(--text2); font-size: 13px; }
.chips button[aria-selected="true"] { background: var(--text); color: var(--page); border-color: var(--text); }
.note { margin: 0 0 12px; padding: 9px 12px; border-radius: 8px; background: var(--raised); color: var(--text2); font-size: 13px; }
.empty { color: var(--text2); padding: 24px 4px; margin: 0; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--text2); }

/* ---- 시장 */
.market { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr); gap: 16px; align-items: start; }
.board { padding-bottom: 6px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text3); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th.c-num, td.c-num { text-align: right; }
table.rank tbody tr { cursor: pointer; }
table.rank tbody tr:hover { background: var(--hover); }
table.rank tbody tr[aria-selected="true"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--text); }
.c-pos { width: 56px; white-space: nowrap; }
.c-pos b { font-size: 15px; }
.c-pos small { display: block; font-size: 11px; line-height: 1.1; }
.c-name { min-width: 180px; }
.nm { font-weight: 650; line-height: 1.3; display: flex; gap: 6px; align-items: center; }
.nm .t { word-break: keep-all; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sub { color: var(--text3); font-size: 12px; line-height: 1.3; }
.srcs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.srcs span { font-size: 11px; color: var(--text2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; line-height: 17px; white-space: nowrap; }
.badge { font-size: 10px; font-weight: 800; letter-spacing: .02em; border-radius: 4px; padding: 0 5px; line-height: 16px; flex: none;
  border: 1px solid var(--text2); color: var(--text); }
.c-cat { white-space: nowrap; font-size: 13px; color: var(--text2); }
.c-cat .dot { margin-right: 6px; }
td.c-num { font-weight: 650; white-space: nowrap; }
td.price { font-size: 15px; }
.c-vol { font-size: 12px; color: var(--text2); min-width: 150px; }
.c-spark { width: 96px; }
.c-spark svg { width: 96px; height: 28px; display: block; }
.star { border: 0; background: none; cursor: pointer; color: var(--text3); padding: 0 2px; font-size: 14px; line-height: 1; }
.star[aria-pressed="true"] { color: #f2b84b; }

/* ---- 상세 */
.detail { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.detail-empty { color: var(--text2); padding: 40px 12px; text-align: center; }
.d-head { display: flex; gap: 12px; align-items: flex-start; }
.d-head img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--raised); flex: none; }
.d-title { font-size: 20px; font-weight: 800; line-height: 1.25; letter-spacing: -0.03em; word-break: keep-all; }
.d-meta { color: var(--text2); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; }
.d-price { display: flex; align-items: baseline; gap: 12px; margin: 14px 0 4px; flex-wrap: wrap; }
.d-price .p { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.d-price .c { font-size: 16px; font-weight: 700; }
.d-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border-radius: 8px; overflow: hidden; margin: 12px 0; }
.d-stats div { background: var(--panel); padding: 8px 10px; }
.d-stats dt { font-size: 11px; color: var(--text3); }
.d-stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.d-sec { margin-top: 16px; }
.d-sec h2 { margin-bottom: 8px; }
.d-close { display: none; }
.src-row { display: grid; grid-template-columns: 84px minmax(0, 1fr) 60px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.src-row .bar { height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden; }
.src-row .bar i { display: block; height: 100%; background: var(--text2); border-radius: 3px; }
.src-row .r { text-align: right; font-variant-numeric: tabular-nums; color: var(--text2); }
.src-row a { color: var(--text); }
.links { list-style: none; padding: 0; margin: 0; }
.links li { padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.links a { text-decoration: none; }
.links a:hover { text-decoration: underline; }
.links small { color: var(--text3); margin-left: 6px; }
.desc { color: var(--text2); font-size: 14px; margin: 0; }

/* ---- 차트 */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text, .tile text { fill: var(--text3); font-size: 11px; font-variant-numeric: tabular-nums; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.cross { stroke: var(--text3); stroke-width: 1; pointer-events: none; }
.tip {
  position: fixed; z-index: 40; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; min-width: 120px; max-width: 280px;
}
.tip .h { color: var(--text2); margin-bottom: 4px; }
.tip .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-variant-numeric: tabular-nums; }
.tip .row b { font-size: 13px; }
.tip .key { width: 12px; height: 2px; display: inline-block; margin-right: 6px; vertical-align: middle; }
.ct-tabs { margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---- 흐름 */
.flow-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; margin-top: 16px; }
.heat { position: relative; height: 420px; border-radius: 8px; overflow: hidden; background: var(--raised); }
.heat .cell { position: absolute; border: 1px solid var(--panel); overflow: hidden; cursor: pointer; padding: 4px 6px; font-size: 12px; line-height: 1.25; }
.heat .cell b { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heat .cell:hover { outline: 2px solid var(--text); outline-offset: -2px; z-index: 2; }
.heat .grp { position: absolute; font-size: 11px; font-weight: 700; padding: 2px 6px; pointer-events: none; z-index: 1; }
.scale { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text3); margin-top: 8px; justify-content: flex-end; }
.scale-bar { width: 140px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--down), var(--neutral), var(--up)); }

/* ---- 유튜브 */
.yt-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.yt-layout.with { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); }
table.yt img { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; background: var(--raised); flex: none; }
.ytn { display: flex; gap: 10px; align-items: center; }
.ytn .t { font-weight: 650; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- 출처 */
table.src td { font-size: 14px; }
.ok { color: var(--text); } .bad { color: var(--text); font-weight: 700; } .off { color: var(--text3); }
.howto { margin-top: 20px; max-width: 80ch; }
.howto h2 { margin: 18px 0 6px; }
.howto pre { background: var(--raised); padding: 12px; border-radius: 8px; overflow-x: auto; }
.rules { padding-left: 18px; color: var(--text2); }

/* ---- 로그인 */
.login { position: fixed; inset: 0; z-index: 60; background: var(--page); display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); display: grid; gap: 10px; }
.login-card h1 { font-size: 22px; margin-top: 6px; }
.login-card p { margin: 0 0 8px; }
.login-card input { height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 12px; font-size: 16px; }
.login-card button { height: 44px; border-radius: 10px; border: 0; background: var(--text); color: var(--page); font-weight: 700; cursor: pointer; }
.login-card button:disabled { opacity: .6; }
.err { color: var(--up); min-height: 1.5em; margin: 0; font-size: 14px; }

.bottom-tabs { display: none; }
.loading { opacity: .55; transition: opacity .2s; }

/* ---- 좁은 화면 (폰) */
@media (max-width: 1080px) {
  .market { grid-template-columns: minmax(0, 1fr); }
  .detail { position: fixed; inset: 0; z-index: 35; max-height: none; border-radius: 0; border: 0; padding: 14px 16px 90px; display: none; }
  .detail.open { display: block; }
  .d-close { display: inline-flex; margin-bottom: 10px; border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
  .flow-grid { grid-template-columns: minmax(0, 1fr); }
  .yt-layout.with { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  /* 출처 표 → 한 줄에 하나씩 쌓기 */
  table.src thead { display: none; }
  table.src, table.src tbody { display: block; }
  table.src tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.src td { border: 0; padding: 0; font-size: 13px; text-align: left; }
  table.src td.s-name { flex: 1 1 calc(100% - 130px); font-weight: 650; font-size: 14px; }
  table.src td.s-state { flex: 0 0 auto; margin-left: auto; white-space: nowrap; }
  table.src td.s-last, table.src td.s-n, table.src td.s-ev { color: var(--text2); white-space: nowrap; }
  table.src td[data-k]::before { content: attr(data-k) " "; color: var(--text3); }
  table.src td.s-err:empty { display: none; }
  table.src td.s-err { flex: 1 0 100%; }
  body { font-size: 14px; }
  .top { padding: 0 12px; gap: 10px; height: 52px; }
  .tabs, .brand-name, .clock span#asof { display: none; }
  .search input { width: 150px; }
  .search-pop { width: calc(100vw - 24px); right: -60px; }
  main { padding: 10px 8px 90px; }
  .panel { padding: 12px 10px; border-radius: 10px; }
  .c-24, .c-cat, .c-vol { display: none; }
  .c-spark { width: 64px; } .c-spark svg { width: 64px; height: 24px; }
  .c-name { min-width: 0; }
  td { padding: 8px 5px; }
  .d-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .heat { height: 360px; }
  .bottom-tabs {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 36;
    background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-tabs a { display: grid; place-items: center; gap: 0; padding: 7px 0 8px; text-decoration: none; color: var(--text3); font-size: 11px; font-weight: 600; }
  .bottom-tabs a span { font-size: 17px; line-height: 1.2; }
  .bottom-tabs a[aria-current="page"] { color: var(--text); }
  table.yt img { width: 72px; height: 40px; }
}
@media print { .top, .tape, .bottom-tabs, .tools { display: none; } }
