:root {
  --bg: #0b0d14;
  --deep: #07080d;
  --card: #11141c;
  --raised: #1a1e28;
  --line: rgba(238, 240, 245, 0.08);
  --text: #eef0f5;
  --secondary: #a3a9b8;
  --muted: #7a8296;
  --accent: #f7931a;
  --up: #4cc38a;
  --down: #e5484d;
  --sans: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/20px var(--sans);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: rgba(247, 147, 26, 0.28); color: var(--text); }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 188px minmax(420px, 1.05fr) minmax(480px, 0.78fr);
  grid-template-rows: 56px minmax(0, 1fr) 40px;
  grid-template-areas:
    "top top top"
    "side stage signal"
    "tape tape tape";
  overflow: hidden;
  background: var(--bg);
}

.top { grid-area: top; }
.side { grid-area: side; }
.stage { grid-area: stage; }
.signal { grid-area: signal; }
.tape { grid-area: tape; }

.top, .side, .signal, .tape { background: var(--deep); }
.top { border-bottom: 1px solid var(--line); }
.side { border-right: 1px solid var(--line); }
.signal { border-left: 1px solid var(--line); }
.tape { border-top: 1px solid var(--line); }

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.brand h1 { margin: 0; font-size: 16px; line-height: 20px; font-weight: 500; }
.pair { font: 500 13px/16px var(--mono); white-space: nowrap; }
.pair span { color: var(--muted); font-weight: 400; }
.vbar { width: 1px; height: 16px; background: var(--line); flex: 0 0 1px; }
.px {
  font: 500 28px/32px var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: color 200ms linear;
}
.px .digit { display: inline-block; }
.chg {
  font: 500 13px/16px var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--secondary);
  white-space: nowrap;
}
.chg.up, .up { color: var(--up); }
.chg.down, .down { color: var(--down); }
.stat { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.stat .k { color: var(--muted); font-size: 12px; line-height: 16px; }
.stat .v { font: 500 13px/16px var(--mono); font-variant-numeric: tabular-nums; }
.stat-extra { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; min-width: 8px; }
.status { display: flex; align-items: center; gap: 8px; color: var(--secondary); font-size: 13px; line-height: 16px; white-space: nowrap; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.dot[data-mode="on"] { background: var(--up); }
.dot[data-mode="wait"] { background: var(--accent); }
.dot[data-mode="off"] { background: var(--down); }

.side { overflow: auto; padding: 16px; scrollbar-width: thin; scrollbar-color: rgba(238, 240, 245, 0.2) transparent; }
.group + .group { margin-top: 24px; }
.group-label { margin: 0 0 8px; color: var(--muted); font-size: 12px; line-height: 16px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  margin: 0 -8px;
  padding: 0 8px;
  border-radius: 6px;
  cursor: pointer;
}
.toggle + .toggle { margin-top: 2px; }
.toggle:hover { background: var(--raised); }
.toggle input { width: 14px; height: 14px; margin: 0; accent-color: #eef0f5; }
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: rgba(238, 240, 245, 0.04);
  box-shadow: inset 0 0 0 1px var(--line);
}
.side .seg { margin-top: 8px; }
.seg button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 28px;
}
.seg button[aria-pressed="true"] {
  background: var(--raised);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.seg button:hover { color: var(--text); }

.stage {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 128px;
  background: var(--bg);
}
.stage.no-sub { grid-template-rows: auto minmax(0, 1fr) 0px; }
.stage.no-sub #subPlot { display: none; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  min-height: 48px;
  padding: 8px 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.ohlc {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 10px;
  font: 12px/16px var(--mono);
  color: var(--secondary);
}
.ohlc b { font-weight: 500; color: var(--text); }
.plot { position: relative; min-height: 0; min-width: 0; }
.plot.sub { border-top: 1px solid var(--line); }
.plot canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.float-legend {
  position: absolute;
  top: 8px;
  left: 12px;
  right: 100px;
  height: 16px;
  overflow: hidden;
  display: flex;
  gap: 4px 12px;
  pointer-events: none;
  font: 12px/16px var(--mono);
  color: var(--secondary);
}
.osc-hint { color: var(--muted); }
.banner {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 64px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  z-index: 2;
}
.banner[hidden] { display: none; }
.banner p { margin: 0; color: var(--secondary); max-width: 420px; }

.mini, .ghost {
  height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--secondary);
  font-size: 12px;
  line-height: 26px;
}
.mini:hover, .ghost:hover { color: var(--text); background: var(--raised); }
#follow[hidden] { display: none; }

.signal {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 0;
}
.board-head h2 { margin: 0; font-size: 16px; line-height: 20px; font-weight: 500; }
.board-head p { margin: 2px 0 0; color: var(--secondary); font-size: 12px; line-height: 16px; }
.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, auto);
  align-content: start;
  gap: 8px;
  padding: 8px 12px;
}
.call-card {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px 10px;
  background: var(--card);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-label { font-size: 13px; line-height: 16px; font-weight: 500; }
.clockbox { display: flex; align-items: center; gap: 6px; }
.clock-time { font: 500 13px/16px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock-time.rolled { color: var(--accent); }
.call { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.call-word { font-size: 26px; line-height: 30px; font-weight: 500; display: inline-block; }
.call-word.flat { color: var(--text); }
.call-score { font: 500 13px/16px var(--mono); color: var(--secondary); font-variant-numeric: tabular-nums; }
.lead {
  margin: 0;
  color: var(--secondary);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-fact { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.card-fact span { color: var(--muted); font-size: 12px; line-height: 16px; }
.card-fact b { font: 500 12px/16px var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.card-meter { margin-top: 2px; }
.card-wait { color: var(--muted); font: 12px/16px var(--mono); white-space: nowrap; }
.card-wait[hidden] { display: none; }
.call-card .primary { flex: 0 0 auto; width: 100%; height: 30px; margin-top: 6px; line-height: 30px; }
.paper-jump {
  flex: 0 0 auto;
  height: 32px;
  margin: 0 12px 10px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: 12px/16px var(--mono);
  text-align: left;
}
.paper-jump:hover { color: var(--text); background: var(--raised); }

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  max-width: calc(100vw - 32px);
}
dialog::backdrop { background: rgba(7, 8, 13, 0.72); }
.dialog-card {
  width: min(440px, calc(100vw - 32px));
  max-height: min(760px, calc(100dvh - 48px));
  overflow: auto;
  padding: 16px;
  background: var(--deep);
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45), inset 0 0 0 1px var(--line);
  scrollbar-width: thin;
  scrollbar-color: rgba(238, 240, 245, 0.2) transparent;
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { margin: 0; font-size: 16px; line-height: 20px; font-weight: 500; }
#ruleHorizons { margin-top: 12px; }
#ruleHorizons button { flex: 1 1 0; padding: 0 2px; }
.threshold { display: block; margin-top: 12px; }
.threshold-row { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 12px; line-height: 16px; }
.threshold-row b { color: var(--text); font-family: var(--mono); font-weight: 500; }
.fine { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 16px; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  margin: 0;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: rgba(238, 240, 245, 0.16);
  border-radius: 1px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: #eef0f5;
}
input[type="range"]::-moz-range-track {
  height: 2px;
  background: rgba(238, 240, 245, 0.16);
  border: 0;
  border-radius: 1px;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #eef0f5;
}
.actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.primary {
  flex: 1;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #1a1206;
  font-size: 14px;
  line-height: 36px;
  font-weight: 500;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.primary:hover { background: #ffa01f; }
.primary:active { background: #e08612; }
.primary:disabled { opacity: 0.45; cursor: default; }
.primary:disabled:hover { background: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; color: var(--secondary); font-size: 13px; line-height: 20px; white-space: nowrap; cursor: pointer; }
.check input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.auto-note { min-height: 16px; margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 16px; }
.block-label { margin: 16px 0 8px; color: var(--muted); font-size: 12px; line-height: 16px; }
.strat { padding: 8px 0; border-bottom: 1px solid var(--line); }
.strat:last-child { border-bottom: 0; }
.strat-top { display: flex; align-items: center; gap: 8px; }
.strat-name { flex: 1; min-width: 0; font-size: 14px; line-height: 20px; }
.strat-score { font: 500 13px/16px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.strat-score.up { color: var(--up); }
.strat-score.down { color: var(--down); }
.strat.off .strat-name, .strat.off .strat-note { color: var(--muted); }
.stepper { display: flex; align-items: center; }
.stepper button {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  font: 500 14px/22px var(--mono);
}
.stepper button:hover { background: var(--raised); }
.stepper .w { width: 20px; text-align: center; font: 500 13px/16px var(--mono); }
.strat-note { margin: 2px 0 0; color: var(--secondary); font-size: 12px; line-height: 16px; }
.meter { position: relative; height: 4px; margin-top: 6px; background: rgba(238, 240, 245, 0.08); border-radius: 2px; }
.strat.off .meter { visibility: hidden; }
.meter::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -2px;
  width: 1px;
  height: 8px;
  background: rgba(238, 240, 245, 0.28);
}
.meter i { position: absolute; top: 0; height: 4px; border-radius: 2px; }
.meter i.pos { left: 50%; background: var(--up); }
.meter i.neg { right: 50%; background: var(--down); }
.paper-head { display: flex; align-items: center; gap: 8px; min-height: 28px; margin-top: 16px; }
.paper-head h3 { margin: 0; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--secondary); }
#paperStat { color: var(--muted); font: 12px/16px var(--mono); }
#spark { margin-left: auto; display: block; }
.paper { max-height: 168px; overflow: auto; scrollbar-width: thin; scrollbar-color: rgba(238, 240, 245, 0.2) transparent; }
.paper-empty { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 16px; }
.paper-row {
  display: grid;
  grid-template-columns: 62px 16px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  height: 32px;
  font-size: 12px;
  line-height: 16px;
}
.paper-hz { font-family: var(--mono); color: var(--muted); }
.paper-time, .paper-px { font-family: var(--mono); color: var(--secondary); }
.paper-px { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.paper-hit { text-align: right; color: var(--secondary); white-space: nowrap; }
.paper-hit.yes { color: var(--up); }
.paper-hit.no { color: var(--down); }
.disclaimer { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 16px; }

.tape { display: flex; align-items: center; gap: 16px; padding: 0 16px; overflow: hidden; }
.tape-k { flex: 0 0 auto; color: var(--muted); font-size: 12px; line-height: 16px; }
.tape-row {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  overflow: hidden;
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 24px), transparent);
}
.tape-empty { color: var(--muted); font-size: 12px; line-height: 16px; }
.print { display: inline-flex; align-items: center; gap: 6px; font: 12px/16px var(--mono); white-space: nowrap; }
.print .tm { color: var(--muted); }
.print .sz { color: var(--secondary); }
.print.up .sd, .print.up .px { color: var(--up); }
.print.down .sd, .print.down .px { color: var(--down); }

@keyframes digit {
  from { transform: translateY(35%); opacity: 0.2; }
  to { transform: none; opacity: 1; }
}
.digit.tick { animation: digit 180ms cubic-bezier(.2, .7, .2, 1); }
@keyframes print-in {
  from { transform: translateX(-8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.print { animation: print-in 180ms ease; }
@keyframes word-in {
  from { transform: translateY(4px); opacity: 0.35; }
  to { transform: none; opacity: 1; }
}
.call-word.flip { animation: word-in 180ms cubic-bezier(.2, .7, .2, 1); }
@keyframes row-in {
  from { transform: translateY(-4px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.paper-row.in { animation: row-in 180ms ease; }
.meter i { transition: width 160ms linear; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1180px) {
  .stat-extra { display: none; }
}

@media (max-width: 1080px) {
  html, body { height: auto; overflow: auto; }
  .app {
    height: auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  .side {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .group + .group { margin-top: 0; }
  .group-label { margin: 0 8px 0 0; }
  .side .seg { margin-top: 0; }
  .stage { height: min(520px, 58dvh); flex: none; display: grid; }
  .signal { overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  .board { grid-template-rows: none; grid-auto-rows: minmax(156px, auto); }
  .paper { max-height: 240px; }
  .tape {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    height: 40px;
  }
  .app { padding-bottom: 40px; }
}

@media (max-width: 720px) {
  .top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand status" "price chg";
    align-items: center;
    column-gap: 10px;
    row-gap: 0;
    padding: 8px 12px 6px;
  }
  .brand { grid-area: brand; }
  .status { grid-area: status; margin-left: 0; justify-self: end; font-size: 12px; }
  .px { grid-area: price; font-size: 22px; line-height: 28px; }
  .chg { grid-area: chg; justify-self: end; }
  .vbar, .spacer { display: none; }
  .board { grid-template-columns: 1fr; }
}
