:root {
  color-scheme: dark;
  --bg: #05090f;
  --panel: #0a1018;
  --raise: #101924;
  --hover: #172331;
  --line: rgba(120, 160, 190, 0.14);
  --text: #e8eee9;
  --muted: #8c9fb0;
  --dim: #5f7486;
  --teal: #78e1d5;
  --gold: #e8bd7d;
  --sell: #f09a5a;
  --f-tc: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --f-mono: "JetBrains Mono Variable", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --top: 48px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-tc);
  font-size: 14px;
}
button,
select,
input {
  font: inherit;
  color: inherit;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- top bar: one quiet row, like a trading terminal ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--top);
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.symbol {
  display: flex;
  flex: none;
  align-items: baseline;
  gap: 8px;
  padding-right: 14px;
  border-right: 1px solid var(--line);
}
.symbol b {
  font-family: var(--f-mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.symbol small {
  color: var(--muted);
  font-size: 12px;
}
.tools {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.seg {
  display: inline-flex;
  flex: none;
  padding: 2px;
  border-radius: 8px;
  background: var(--raise);
}
.seg button,
.tools summary {
  min-height: 28px;
  padding: 3px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 12px;
  cursor: pointer;
}
.seg button:hover,
.tools summary:hover {
  color: var(--text);
}
.seg button[aria-pressed="true"] {
  background: var(--hover);
  color: var(--teal);
}
.check input {
  accent-color: var(--teal);
}
.live {
  flex: none;
  margin-left: auto;
  white-space: nowrap;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 12px;
}
.live::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--dim);
  vertical-align: 1px;
}
.live[data-state="on"]::before {
  background: var(--teal);
  box-shadow: 0 0 0 3px rgba(120, 225, 213, 0.15);
}
.live[data-state="stale"]::before {
  background: var(--sell);
}

/* ---------- menus (indicators, sharing, notifications) ---------- */
.ind,
.share,
.notify {
  position: relative;
  flex: none;
}
.tools summary {
  display: inline-flex;
  align-items: center;
  list-style: none;
  font-family: var(--f-tc);
}
.tools summary::-webkit-details-marker {
  display: none;
}
.ind summary::after {
  content: "▾";
  margin-left: 5px;
  color: var(--dim);
  font-size: 10px;
}
.ind[open] summary,
.share[open] summary,
.notify[open] summary {
  background: var(--hover);
  color: var(--text);
}
.ind-panel,
.share-panel,
.notify-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 10;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.ind-panel {
  display: flex;
  gap: 22px;
}
.ind-panel fieldset {
  min-width: 180px;
  margin: 0;
  padding: 0;
  border: 0;
}
.ind-panel legend {
  margin-bottom: 8px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.08em;
}
.ind-list {
  display: grid;
  gap: 7px;
}
.ind-list label,
.ind-panel .check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}
.ind-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}
.ind-select select {
  min-height: 28px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--raise);
}
.share-panel {
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 24px));
}
.share-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.share-panel input {
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raise);
  font-family: var(--f-mono);
  font-size: 12px;
}
.share-actions {
  display: flex;
  gap: 8px;
}
.share-actions button,
.share-line {
  flex: 1;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raise);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.share-line {
  border-color: #06c755;
  background: #06c755;
  color: #fff;
  font-weight: 600;
}
.notify[data-on="true"] summary::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--teal);
}
.notify-panel {
  /* The last menu in the bar: open toward the left so it stays on screen. */
  left: auto;
  right: 0;
  display: grid;
  gap: 12px;
  width: min(380px, calc(100vw - 24px));
}
.notify-switch {
  min-height: 36px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: var(--teal);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
}
.notify-switch[aria-pressed="true"] {
  background: transparent;
  color: var(--teal);
}
.notify-note,
.notify-foot {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.notify-foot {
  color: var(--dim);
}
.notify-panel fieldset {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}
.notify-panel legend {
  margin-bottom: 6px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.08em;
}
.notify-panel .check {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: baseline;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}
.notify-panel .check small {
  color: var(--dim);
  font-size: 11px;
}

.notify-line {
  display: grid;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.notify-line h3 {
  margin: 0;
  font-size: 13px;
}
.notify-line p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.notify-line-link {
  justify-self: start;
  color: #06c755;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

/* ---------- toasts (notify.js) ---------- */
.toasts {
  position: fixed;
  top: calc(var(--top) + 10px);
  right: 12px;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}
.toast p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.toast small {
  color: var(--dim);
  font-size: 11px;
}
.toast-actions {
  display: flex;
  gap: 8px;
}
.toast-actions button {
  min-height: 30px;
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--raise);
  color: var(--text);
  cursor: pointer;
}
.toast-actions button:first-child {
  border-color: var(--teal);
  color: var(--teal);
}

/* ---------- chart ---------- */
.stage {
  position: relative;
  height: max(520px, calc(100vh - var(--top) - 34px));
  height: max(520px, calc(100dvh - var(--top) - 34px));
}
#chart {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
#chart.row-resize {
  cursor: row-resize;
}
/* Zoom and back-to-latest float over the chart's lower right, left of the price axis. */
.chart-tools {
  position: absolute;
  right: 86px;
  bottom: 34px;
  display: flex;
  gap: 4px;
  opacity: 0.55;
  transition: opacity 0.15s;
}
.stage:hover .chart-tools,
.chart-tools:focus-within {
  opacity: 1;
}
.chart-tools button {
  min-width: 30px;
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(16, 25, 36, 0.92);
  color: var(--text);
  font-family: var(--f-mono);
  font-size: 12px;
  cursor: pointer;
}
.chart-tools button:hover {
  border-color: var(--teal);
}
.status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}
.status[hidden] {
  display: none;
}

/* ---------- footer ---------- */
.note {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  min-height: 34px;
  padding: 8px 16px;
  color: var(--dim);
  font-size: 12px;
}
.note p {
  margin: 0;
}
.help summary {
  color: var(--muted);
  cursor: pointer;
}
.help[open] {
  flex-basis: 100%;
  padding-bottom: 16px;
}
.help p {
  margin: 6px 0;
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 720px) {
  :root {
    --top: 92px;
  }
  /* Two rows: brand, symbol and status, then the tools scrolling sideways. */
  .topbar {
    flex-wrap: wrap;
    align-content: center;
    gap: 6px 12px;
    padding: 6px 12px;
  }
  .brand span {
    display: none;
  }
  .tools {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tools::-webkit-scrollbar {
    display: none;
  }
  .seg button,
  .tools summary {
    min-height: 32px;
  }
  .ind-panel,
  .share-panel,
  .notify-panel {
    position: fixed;
    top: calc(var(--top) + 6px);
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - var(--top) - 20px);
    max-height: calc(100dvh - var(--top) - 20px);
    overflow-y: auto;
  }
  .ind-panel {
    flex-direction: column;
    gap: 14px;
  }
  .ind-list label {
    min-height: 30px;
  }
  .chart-tools {
    right: 66px;
    opacity: 0.85;
  }
  .stage {
    height: max(440px, calc(100vh - var(--top) - 40px));
    height: max(440px, calc(100dvh - var(--top) - 40px));
  }
}

/* ---------- replay (?case=<id>) ---------- */
.live[data-state="replay"]::before {
  background: var(--gold);
}
.replay {
  position: absolute;
  top: 10px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(560px, calc(100% - 100px));
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(10, 16, 24, 0.92);
  transform: translateX(-50%);
}
.replay[hidden] {
  display: none;
}
.replay button,
.replay select {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--raise);
  font-family: var(--f-mono);
  font-size: 12px;
  cursor: pointer;
}
.replay button:hover {
  border-color: var(--teal);
}
.replay input[type="range"] {
  flex: 1;
  min-width: 60px;
  accent-color: var(--gold);
}
.rp-clock {
  flex: none;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 12px;
}
/* The script's narration, placed by app.js near the top of the price pane. */
.caption {
  position: absolute;
  left: 50%;
  max-width: min(720px, calc(100% - 110px));
  margin: 0;
  padding: 9px 16px;
  border: 1px solid rgba(232, 189, 125, 0.35);
  border-radius: 10px;
  background: rgba(5, 9, 15, 0.88);
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}
.caption[hidden] {
  display: none;
}
/* ?rec=1: a clean frame for screen recording, with the captions in a band under the chart. */
.rec {
  --band: 22vh;
}
.rec .tools,
.rec .chart-tools,
.rec .replay,
.rec .live,
.rec .note {
  display: none;
}
.rec .stage {
  height: calc(100vh - var(--top) - var(--band));
  height: calc(100dvh - var(--top) - var(--band));
}
.rec .caption {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: none;
  height: var(--band);
  padding: 0 28px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  font-size: 24px;
  transform: none;
}
.rec .caption[hidden] {
  display: none;
}
@media (max-width: 720px) {
  .rec {
    --top: 48px;
  }
  .rec .topbar {
    flex-wrap: nowrap;
  }
  .replay {
    width: calc(100% - 76px);
    left: 8px;
    transform: none;
  }
  .caption {
    max-width: calc(100% - 80px);
    left: calc(50% - 29px);
    font-size: 15px;
  }
  .rec .caption {
    left: 0;
    max-width: none;
    font-size: 20px;
  }
}
