/* Layout: market clock band on top, then one card grid per market (open sessions first, crypto last),
   screener table at the bottom; details open in a <dialog>. Light/dark from the OS setting. */
:root {
  --bg: #f3f5f9; --surface: #ffffff; --ink: #131b2b; --muted: #5a6477; --line: #dde3ec;
  --accent: #2456c4; --accent-soft: #e6edfb;
  --up: #12804a; --down: #c2362b;
  --res: #9e5f08; --res-soft: #fcefd8;
  --open: #12804a; --open-soft: #dff1e7; --closed: #677184; --closed-soft: #e9edf3;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --f-display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1017; --surface: #131a25; --ink: #e4e9f1; --muted: #93a0b4; --line: #243041;
    --accent: #7ea8ff; --accent-soft: #1a2740;
    --up: #46c487; --down: #f27b70;
    --res: #f2b14c; --res-soft: #30250f;
    --open: #46c487; --open-soft: #15291f; --closed: #8d97a9; --closed-soft: #1b2330;
    color-scheme: dark;
  
  }
}
:root[data-theme="dark"] {
    --bg: #0b1017; --surface: #131a25; --ink: #e4e9f1; --muted: #93a0b4; --line: #243041;
    --accent: #7ea8ff; --accent-soft: #1a2740;
    --up: #46c487; --down: #f27b70;
    --res: #f2b14c; --res-soft: #30250f;
    --open: #46c487; --open-soft: #15291f; --closed: #8d97a9; --closed-soft: #1b2330;
    color-scheme: dark;
  
}

* { box-sizing: border-box; }
html:has(dialog[open]) { overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-body); }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.wrap {
  max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px;
  padding-block: max(16px, env(safe-area-inset-top)) 48px;
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
}
.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
h1 { margin: 0; font: 600 1.7rem/1.1 var(--f-display); letter-spacing: .01em; }
h2 { margin: 0; }
.updated { margin: 0; color: var(--muted); font-size: .85rem; }
.banner { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--res-soft); color: var(--res); font-weight: 500; }
.empty, .note { color: var(--muted); font-size: .88rem; margin: 0; }

/* ---- market clock ---- */
.clock { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 12px; }
.clock-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.clock-head h2 { font: 600 .82rem var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tz { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.tz label { color: var(--muted); font-size: .8rem; }
.now { font: 600 1.05rem var(--f-num); font-variant-numeric: tabular-nums; }
select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; max-width: 220px; }
.rows { display: grid; gap: 10px; }
.mrow { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 4px 14px; align-items: center; }
.mname { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.mst { font: .8rem var(--f-num); color: var(--muted); }
.track { position: relative; height: 18px; border-radius: 5px; background: var(--closed-soft); overflow: hidden; }
.seg { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--open) 24%, transparent); box-shadow: inset 2px 0 var(--open); }
.seg.live { background: color-mix(in srgb, var(--open) 55%, transparent); }
.nowline { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); }
.ticks { position: relative; height: 14px; font: 10px var(--f-num); color: var(--muted); }
.ticks span { position: absolute; transform: translateX(-50%); }
.ticks span:first-child { transform: none; }
@media (max-width: 560px) {
  .mrow { grid-template-columns: minmax(0, 1fr); }
  .mrow.axis > div:first-child { display: none; }
}

/* ---- range toggle ---- */
.frames { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.frames > span:first-child { color: var(--muted); font-size: .82rem; margin-right: 4px; }
.frames button, .tabs button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 5px 12px;
  font: 600 .85rem var(--f-num);
}
.frames button[aria-pressed="true"], .tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.legend { margin-left: auto; color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: 6px; }

/* ---- groups and cards ---- */
main { display: grid; gap: 22px; }
.group > h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 10px;
  font: 600 1.05rem var(--f-display); text-transform: uppercase; letter-spacing: .07em; }
.group > h2 small { font: 400 .8rem var(--f-body); text-transform: none; letter-spacing: 0; color: var(--muted); }
.pill { font: 600 .66rem var(--f-body); letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.pill.open { background: var(--open-soft); color: var(--open); }
.pill.closed { background: var(--closed-soft); color: var(--closed); }
.pill.setup { background: var(--accent); color: var(--surface); }
.pill.squeeze { background: var(--accent-soft); color: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 10px;
  display: grid; gap: 6px; min-width: 0; cursor: pointer; transition: border-color .15s;
}
.card:hover { border-color: var(--accent); }
.card header { display: grid; gap: 7px; min-width: 0; }
.card h3 { margin: 0; display: flex; align-items: center; gap: 6px; min-width: 0; font: 600 .98rem/1.25 var(--f-body); }
.card h3 .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; font: 600 .64rem var(--f-num); letter-spacing: .06em; padding: 2px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }
.res { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.chip, .res li { font: 600 .7rem var(--f-num); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.on, .res li.on { background: var(--res-soft); border-color: transparent; color: var(--res); }
.px { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.price { font: 600 1.2rem var(--f-num); font-variant-numeric: tabular-nums; }
.chg { font: 500 .9rem var(--f-num); font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); }
.spark { width: 100%; height: 56px; display: block; color: var(--muted); }
.spark.up { color: var(--up); } .spark.down { color: var(--down); }
.spark .line, .m-chart .line { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.spark .area, .m-chart .area { fill: currentColor; opacity: .1; }
.card footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 22px; font-size: .78rem; color: var(--muted); }

/* ---- monitor strip ---- */
.monitor { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.tile {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name chg" "val spark";
  gap: 2px 8px; align-items: center; padding: 8px 10px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-decoration: none;
}
.tile:hover { border-color: var(--accent); }
.t-name { grid-area: name; font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-chg { grid-area: chg; font: 500 .75rem var(--f-num); white-space: nowrap; }
.t-val { grid-area: val; font: 600 .95rem var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-spark { grid-area: spark; width: 56px; height: 22px; color: var(--muted); }
.t-spark.up { color: var(--up); } .t-spark.down { color: var(--down); }
.t-spark .line { fill: none; stroke: currentColor; stroke-width: 1.4; vector-effect: non-scaling-stroke; }
@media (max-width: 560px) {
  .monitor { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .tile { grid-template-columns: minmax(0, 1fr); grid-template-areas: "name" "val" "chg"; padding: 6px 8px; }
  .t-spark { display: none; }
  .t-val { font-size: .85rem; }
}

/* ---- screener and parking ---- */
.score { font: 600 .78rem var(--f-num); padding: 1px 6px; border-radius: 4px; background: var(--closed-soft); }
.score.s4 { background: var(--accent); color: var(--surface); }
.score.s3 { background: var(--accent-soft); color: var(--accent); }
td.note-cell { white-space: normal; min-width: 220px; color: var(--muted); }
.screen { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.screen > h2, .errors summary { font: 600 1.05rem var(--f-display); text-transform: uppercase; letter-spacing: .07em; }
.table { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
a { color: var(--accent); }
.errors { color: var(--muted); font-size: .85rem; }
.errors summary { cursor: pointer; color: var(--ink); font-size: .9rem; }

/* ---- detail modal ---- */
dialog {
  width: min(780px, calc(100vw - 24px)); max-width: none; max-height: calc(100dvh - 24px); overflow: auto;
  border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(8 12 20 / .55); }
.m-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.m-titles { min-width: 0; }
.m-head h2 { font: 600 1.4rem/1.15 var(--f-display); }
.m-head p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.icon { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 36px; height: 36px; flex: none; }
.m-px { display: flex; align-items: baseline; gap: 12px; margin: 10px 0; }
.m-px .price { font-size: 1.6rem; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs .tick { color: var(--res); margin-left: 4px; }
.tabs button[aria-selected="true"] .tick { color: inherit; }
.m-chart { margin: 12px 0 4px; color: var(--accent); min-height: 120px; }
.m-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.lv { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .8; }
.lv.at { stroke: var(--res); stroke-dasharray: none; stroke-width: 1.6; opacity: 1; }
.lvt, .axt { font: 10.5px var(--f-num); fill: var(--muted); }
.lvt.at { fill: var(--res); font-weight: 600; }
.axt.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; margin: 12px 0; }
.stats div { min-width: 0; }
.stats dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stats dd { margin: 2px 0 0; font: 500 .95rem var(--f-num); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.m-foot { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.m-foot button { justify-self: start; max-width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#m-next { justify-self: end; }
.hint { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: .75rem; }
@media (max-width: 560px) {
  dialog { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: 0;
    padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .hint { display: none; }
  .m-foot { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #m-prev { grid-area: 1 / 1; } #m-next { grid-area: 1 / 2; } #m-tv { grid-area: 2 / 1 / 3 / 3; justify-self: center; }
  .legend { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
