/* TradingView dark chrome; every value is sampled and documented in docs/theme.md. */
:root {
  --bg: #000000;
  --panel: #131313;
  --hover: #1a1a1a;
  --sel: #2b2b2b;
  --line: #2b2b2b;
  --line-strong: #464646;
  --text: #b8b8b8;
  --strong: #f2f2f2;
  --muted: #8c8c8c;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #f2f2f2;
  --on-accent: #000000;
  font-family: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
body { display: flex; flex-direction: column; height: 100dvh; }

a { color: var(--text); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { font-weight: 600; }
.symbol { color: var(--muted); }
.nav { margin-left: auto; display: flex; gap: 4px; }
.nav a { padding: 4px 8px; border-radius: 4px; color: var(--muted); }
.nav a:hover { background: var(--hover); color: var(--strong); }
.nav a.active { color: var(--strong); }

.seg { display: flex; gap: 2px; }
.seg button {
  background: none; border: 0; color: var(--muted); padding: 4px 8px; border-radius: 4px;
  font: inherit; cursor: pointer;
}
.seg button:hover { background: var(--hover); color: var(--strong); }
.seg button[aria-pressed="true"] { color: var(--strong); background: var(--sel); }

.menu { position: relative; }
.menu-btn {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--text);
  padding: 4px 8px; border-radius: 4px; font: inherit; cursor: pointer;
}
.menu-btn:hover, .menu-btn[aria-expanded="true"] { background: var(--hover); }
.menu-btn svg { width: 10px; height: 10px; fill: none; stroke: var(--muted); stroke-width: 1.4; }
.popover {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; width: 280px; max-width: calc(100vw - 24px);
  padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45); max-height: calc(100dvh - 80px); overflow-y: auto;
}
.tf-group + .tf-group { margin-top: 8px; }
.tf-title { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tf-row { display: flex; flex-wrap: wrap; gap: 2px; }
.tf-row button {
  min-width: 44px; padding: 5px 8px; background: none; border: 0; border-radius: 4px; color: var(--text);
  font: inherit; cursor: pointer;
}
.tf-row button:hover { background: var(--sel); }
.tf-row button[aria-pressed="true"] { color: var(--strong); background: var(--sel); }
.tf-row button.off { color: var(--muted); opacity: .45; cursor: not-allowed; }
.tf-row button.off:hover { background: none; }
.tf-custom { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.tf-custom label { color: var(--muted); }
.tf-custom input, .tf-sessions input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 4px;
  padding: 4px 6px; font: inherit;
}
.tf-custom input { flex: 1; min-width: 0; }
.tf-custom input:focus, .tf-sessions input:focus { outline: none; border-color: var(--accent); }
.tf-custom .btn { padding: 4px 10px; }
.tf-sessions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; color: var(--muted); }
.tf-sessions input { width: 60px; }
.tf-hint { margin: 8px 0 0; font-size: 12px; }
#tf-err { margin: 6px 0 0; font-size: 12px; }
#tf-err:empty { display: none; }

/* v5: the indicator panels */
.menu-btn kbd { margin: 0; color: var(--muted); }

.risk-line { flex: 1 1 100%; margin: 0; color: var(--text); font-variant-numeric: tabular-nums; order: 5; }
.risk-line.over { color: #ffb74d; }
.risk-line:empty { display: none; }
.rule .acct { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.rule .acct input { width: 90px; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 4px; padding: 4px 6px; font: inherit; }
.field input#contracts { width: 56px; }

.range-panel {
  position: absolute; z-index: 3; bottom: 34px; left: 10px; width: 318px; max-width: calc(100% - 20px);
  max-height: calc(100% - 64px); overflow-y: auto; font-size: 12px; font-variant-numeric: tabular-nums;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
}
.range-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; background: none; border: 0;
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.range-head b { color: var(--strong); font-weight: 600; }
.range-head svg { width: 10px; height: 10px; margin-left: auto; fill: none; stroke: var(--muted); stroke-width: 1.4; transition: transform .12s; }
.range-head[aria-expanded="false"] svg { transform: rotate(-90deg); }
.range-body { padding: 0 8px 6px; }
.range-body p { margin: 4px 0 0; }
.range-panel table { font-size: 12px; }
.range-panel th, .range-panel td { padding: 2px 5px; }
.range-panel th:nth-child(4), .range-panel td:nth-child(4) { text-align: left; border-left: 1px solid var(--line); padding-left: 8px; }

.trade { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chart-row { flex: 1; display: flex; min-height: 0; }
.chart-wrap { position: relative; flex: 1; min-width: 0; min-height: 260px; }

/* Drawing rail: 52px wide like TradingView's, 28px icons, a hover-only corner arrow per group. */
.rail {
  display: flex; flex-direction: column; align-items: stretch; width: 52px; flex: none; padding: 8px 0;
  border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; overflow-x: hidden;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail .grp { position: relative; flex: none; display: flex; justify-content: center; height: 38px; align-items: center; }
.rail .rb {
  display: grid; place-items: center; padding: 0; border: 0; border-radius: 4px; background: none;
  color: var(--text); cursor: pointer; font: inherit;
}
.rail .rb.main { width: 36px; height: 36px; }
.rail .rb svg { width: 28px; height: 28px; display: block; }
.rail .rb.main:hover, .rail .grp:hover .rb.main { background: var(--hover); color: var(--strong); }
.rail .rb.main[aria-pressed="true"] { background: var(--sel); color: var(--strong); }
.rail .rb:disabled { opacity: .35; cursor: default; background: none; color: var(--text); }
.rail .rb:focus-visible, .fly-row:focus-visible, .fav:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rail .rb.arrow {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 10px; height: 36px;
  border-radius: 4px 0 0 4px; opacity: 0; color: var(--muted);
}
.rail .rb.arrow svg { width: 8px; height: 12px; }
.rail:hover .rb.arrow, .rail .rb.arrow[aria-expanded="true"], .rail .rb.arrow:focus-visible { opacity: 1; }
.rail .rb.arrow:hover { background: var(--hover); color: var(--strong); }
.rail .sep { flex: none; height: 1px; margin: 5px 10px; background: var(--line); }

.flyout {
  position: fixed; z-index: 40; width: 292px; max-width: calc(100vw - 16px); padding: 6px 0; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.flyout.menu-list { width: 232px; }
.fly-title { padding: 10px 14px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.fly-sep { height: 1px; margin: 6px 0; background: var(--line); }
.fly-row {
  display: grid; grid-template-columns: 28px 1fr auto 24px; align-items: center; gap: 0 12px; min-height: 36px;
  padding: 0 8px 0 14px; cursor: pointer; color: var(--text); user-select: none;
}
.menu-list .fly-row { grid-template-columns: 28px 1fr; }
.menu-list.no-ico { width: auto; min-width: 232px; }
.menu-list.no-ico .fly-row { grid-template-columns: 1fr; padding-left: 14px; padding-right: 14px; white-space: nowrap; }
.fly-row:hover, .fly-row:focus-visible { background: var(--sel); }
.fly-row[aria-checked="true"] { color: var(--strong); }
.fly-row[aria-checked="true"] .fly-ico { color: var(--accent); }
.menu-list .fly-row[aria-checked="true"] .fly-name::after { content: ""; display: inline-block; width: 5px; height: 9px; margin-left: 10px; border: solid var(--accent); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); }
.fly-row[aria-disabled="true"] { opacity: .4; cursor: default; }
.fly-ico { display: grid; place-items: center; color: var(--text); }
.fly-ico svg { width: 28px; height: 28px; }
.fly-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fly-key { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fly-star {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 4px;
  background: none; color: var(--muted); cursor: pointer; opacity: 0;
}
.fly-star svg { width: 20px; height: 20px; }
.fly-row:hover .fly-star, .fly-row:focus-within .fly-star, .fly-star[aria-pressed="true"] { opacity: 1; }
.fly-star:hover { color: var(--strong); }
.fly-star[aria-pressed="true"] { color: #ffb74d; }
.fly-star[aria-pressed="true"] svg path { fill: currentColor; }
.fly-back {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px; border: 0; background: none;
  color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.fly-back svg { transform: rotate(180deg); color: var(--muted); }
.fly-back:hover { background: var(--sel); }
.glyph-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 6px 10px 8px; }
.glyph { height: 44px; border: 0; border-radius: 4px; background: none; font-size: 24px; color: var(--text); cursor: pointer; }
.glyph:hover { background: var(--sel); }

.favbar {
  position: absolute; z-index: 6; display: flex; align-items: center; gap: 2px; padding: 3px 6px 3px 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}
.fav-grip { display: grid; place-items: center; width: 18px; height: 34px; color: var(--muted); cursor: grab; touch-action: none; }
.fav-grip svg { width: 20px; height: 28px; }
.fav {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 4px;
  background: none; color: var(--text); cursor: pointer;
}
.fav svg { width: 28px; height: 28px; }
.fav:hover { background: var(--sel); color: var(--strong); }
.fav[aria-pressed="true"] { background: var(--sel); color: var(--strong); }
.fav:disabled { opacity: .35; cursor: default; background: none; }
.favtoggle {
  position: absolute; z-index: 6; left: 8px; bottom: 72px; display: grid; place-items: center; width: 28px; height: 28px;
  padding: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); color: var(--muted); cursor: pointer;
}
.favtoggle svg { width: 22px; height: 22px; }
.favtoggle[aria-pressed="true"] { color: #ffb74d; }
.favtoggle[aria-pressed="true"] svg path { fill: currentColor; }

.zoom-layer { position: absolute; inset: 0; z-index: 5; cursor: zoom-in; touch-action: none; }
.zoom-box { position: absolute; display: none; border: 1px solid var(--accent); background: rgba(242, 242, 242, .12); pointer-events: none; }
/* Dot and Arrow pointers. An inline cursor from the chart or the drawing library (hover over a drawing, an armed tool) still wins. */
.chart-wrap[data-cursor="dot"] .chart td, .chart-wrap[data-cursor="dot"] .chart canvas {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12'><circle cx='6' cy='6' r='3' fill='%23f2f2f2' stroke='%23000000' stroke-width='1'/></svg>") 6 6, default;
}
.chart-wrap[data-cursor="arrow-cursor"] .chart td, .chart-wrap[data-cursor="arrow-cursor"] .chart canvas { cursor: default; }
.chart-wrap[data-mode="eraser"] .chart, .chart-wrap[data-mode="eraser"] .chart * { cursor: not-allowed !important; }

.text-edit {
  position: absolute; z-index: 4; width: 180px; padding: 3px 6px; font: inherit;
  background: var(--panel); color: var(--text); border: 1px solid var(--accent); border-radius: 4px;
}
.pos-info { width: 100%; margin: 0; font-variant-numeric: tabular-nums; }
.chart { position: absolute; inset: 0; }
.legend {
  position: absolute; top: 6px; left: 10px; z-index: 3; pointer-events: none;
  font-size: 12px; line-height: 18px; font-variant-numeric: tabular-nums;
}
.legend .k { color: var(--muted); margin-right: 2px; }
.legend .v { margin-right: 8px; }

.panel { border-top: 1px solid var(--line); padding: 8px 12px; background: var(--bg); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.field input {
  width: 70px; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 4px; padding: 5px 6px; font: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }

.btn {
  background: var(--panel); border: 1px solid var(--line-strong); color: var(--strong);
  border-radius: 4px; padding: 7px 12px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--strong); }
.btn.long { background: var(--up); border-color: var(--up); color: #000; }
.btn.short { background: var(--down); border-color: var(--down); color: #000; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn:disabled { opacity: .5; cursor: default; }
kbd {
  font: 11px ui-monospace, Menlo, monospace; opacity: .75; margin-right: 4px;
  border: 1px solid currentColor; border-radius: 3px; padding: 0 3px;
}

.muted { color: var(--muted); }
.error { color: var(--down); margin: 6px 0 0; }
.up { color: var(--up); }
.down { color: var(--down); }

.stats { flex: 1; overflow: auto; padding: 16px; max-width: 960px; width: 100%; margin: 0 auto; }
.stats h2 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 24px 0 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.tile { background: var(--panel); border-radius: 4px; padding: 10px 12px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 20px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; }

/* v3: data badge, session rules, countdown, save for later, History */
.badge {
  padding: 1px 6px; border: 1px solid var(--line); border-radius: 2px; color: var(--muted); font-size: 12px;
  white-space: nowrap;
}
.rule { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; cursor: pointer; }
.rule + .rule { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.rule input { margin-top: 3px; accent-color: var(--accent); }
.rule b { display: block; font-weight: 600; }
.rule .muted { display: block; font-size: 12px; margin-top: 2px; }

.info-row { margin-bottom: 6px; gap: 8px 16px; }
.info-row:has(.countdown[hidden]):has(.save[hidden]) { display: none; }
.countdown { margin: 0; flex: 1; min-width: 200px; color: var(--text); font-variant-numeric: tabular-nums; }
.countdown.late { color: #ffb74d; }
.save { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; flex-wrap: wrap; }
.save-btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; }
.save-btn svg { flex: none; }
.save-btn[aria-pressed="true"] { color: #ffb74d; border-color: #ffb74d; }
.note {
  width: 220px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 4px; padding: 5px 8px; font: inherit;
}
.note:focus { outline: none; border-color: var(--accent); }
.notice {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
}

.history { max-width: 860px; }
.hist-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hist-head h2 { margin: 0; }
.hist-head .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.hist-list { margin: 12px 0; }
.hist-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.hist-main { min-width: 0; flex: 1 1 280px; font-variant-numeric: tabular-nums; }
.hist-when { color: var(--muted); font-size: 12px; }
.hist-what { margin-top: 2px; overflow-wrap: anywhere; }
.hist-note { margin-top: 2px; overflow-wrap: anywhere; }
.hist-note:empty { display: none; }
.hist-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.hist-actions .btn { padding: 5px 10px; }
.hist-save[aria-pressed="true"] { color: #ffb74d; border-color: #ffb74d; }
.tag {
  display: inline-block; margin-left: 4px; padding: 0 5px; border: 1px solid var(--line); border-radius: 2px;
  color: var(--muted); font-size: 11px;
}
a.btn { display: inline-block; }

/* v4: replay before deciding */
.replay { margin-bottom: 8px; gap: 8px 12px; }
.replay-note { margin: 0; flex: 1; min-width: 0; color: var(--text); }
.replay-note:empty { display: none; }
.replay .actions { align-items: stretch; }
.menu.speed { position: relative; display: flex; }
.speed .btn { display: inline-flex; align-items: center; gap: 6px; }
.speed .btn svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 1.4; opacity: .75; }
.speed .popover { top: auto; bottom: calc(100% + 4px); left: auto; right: 0; width: 230px; padding: 4px; }
.speed-item {
  display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 4px;
  color: var(--text); padding: 7px 10px; font: inherit; cursor: pointer;
}
.speed-item:hover { background: var(--sel); }
.speed-item[aria-checked="true"] { color: var(--strong); background: var(--sel); }
.speed-item .muted { display: block; font-size: 12px; }
.table-wrap + h2 { margin-top: 24px; }

@media (max-width: 520px) {
  .menu { position: static; }
  .symbol { order: 9; flex-basis: 100%; } /* the long session text gets its own row */
  .nav { margin-left: auto; }
  .popover { position: fixed; left: 12px; right: 12px; top: var(--pop-top, 48px); width: auto; max-height: calc(100dvh - var(--pop-top, 48px) - 12px); }
  .range-panel { bottom: 30px; width: calc(100% - 20px); }
  .chart-row { flex-direction: column; }
  .rail {
    flex-direction: row; align-items: center; width: auto; padding: 4px 6px; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .rail .grp { width: 48px; height: 44px; }
  .rail .rb.main { width: 38px; height: 40px; }
  .rail .rb.arrow { opacity: .8; height: 40px; }
  .rail .sep { width: 1px; height: 26px; margin: 0 6px; }
  .flyout { left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; max-width: none; max-height: 62dvh !important; border-radius: 10px 10px 0 0; padding-bottom: env(safe-area-inset-bottom, 0); }
  .flyout.menu-list { width: auto; }
  .fly-row { min-height: 44px; }
  .fly-star { opacity: 1; }
  .favbar { max-width: calc(100% - 16px); overflow-x: auto; }
  .actions kbd { display: none; } /* no keyboard on a phone; keeps each button on one line */
  .actions { margin-left: 0; width: 100%; }
  .actions .btn { flex: 1; }
  .menu.speed { flex: 1; }
  .menu.speed .btn { width: 100%; justify-content: center; }
  .speed .popover { position: absolute; top: auto; bottom: calc(100% + 4px); left: auto; right: 0; width: min(230px, calc(100vw - 24px)); max-height: none; }
  .save { margin-left: 0; width: 100%; }
  .save .note { flex: 1; width: auto; }
  .hist-actions { width: 100%; }
  .hist-actions .btn { flex: 1; text-align: center; }
}

@media (hover: none) {
  .menu-btn kbd { display: none; }
  .fly-key { display: none; } /* shortcuts need a keyboard */
  .rail .rb.arrow { opacity: .8; }
}

/* v5: indicators legend, the Indicators dialog and the settings dialog */
.legend { max-width: calc(100% - 90px); }
.leg-inds { margin-top: 2px; pointer-events: none; }
.leg-toggle {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 4px; height: 18px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 3px; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; pointer-events: auto;
}
.leg-toggle svg { width: 9px; height: 9px; fill: none; stroke: currentColor; stroke-width: 1.4; transition: transform .12s; }
.leg-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.leg-toggle:hover { color: var(--strong); }
.leg-inds.collapsed .leg-row { display: none; }
.leg-row { background: color-mix(in srgb, var(--bg) 72%, transparent); display: flex; align-items: center; gap: 6px; height: 20px; pointer-events: auto; width: fit-content; max-width: 100%; border-radius: 3px; padding: 0 2px; }
.leg-row:hover, .leg-row:focus-within { background: var(--panel); }
.leg-row.off .leg-name, .leg-row.off .leg-val { opacity: .45; text-decoration: line-through; }
.leg-name { white-space: nowrap; }
.leg-val { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.leg-btns { display: none; gap: 0; margin-left: 2px; }
.leg-row:hover .leg-btns, .leg-row:focus-within .leg-btns { display: inline-flex; }
.leg-btns button, .icon-btn {
  display: grid; place-items: center; width: 22px; height: 20px; padding: 0; background: none; border: 0; border-radius: 3px;
  color: var(--muted); cursor: pointer;
}
.leg-btns button:hover, .icon-btn:hover { background: var(--sel); color: var(--strong); }
.leg-btns svg, .icon-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; grid-template-columns: minmax(0, 1fr); place-items: start center; padding: 8vh 12px 12px;
  background: rgba(0, 0, 0, .55);
}
.modal[hidden] { display: none; }
.modal-box {
  width: 520px; max-width: 100%; min-width: 0; max-height: 84dvh; display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 8px 16px; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--strong); overflow-wrap: anywhere; }
.ind-search {
  margin: 0 16px 8px; padding: 8px 10px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; font: inherit;
}
.ind-search:focus { outline: none; border-color: var(--accent); }
.ind-list { overflow-y: auto; border-top: 1px solid var(--line); min-height: 0; }
.ind-item {
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px; width: 100%; padding: 9px 16px; background: none; border: 0;
  border-bottom: 1px solid var(--line); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.ind-item:hover, .ind-item:focus-visible { background: var(--sel); }
.ind-name { color: var(--strong); }
.ind-item > * { min-width: 0; overflow-wrap: anywhere; }
.ind-about { grid-column: 1; font-size: 12px; }
.ind-n { grid-row: 1; grid-column: 2; color: var(--muted); font-size: 12px; align-self: center; }
#ind-empty { margin: 12px 16px; }
.ind-status { margin: 0; padding: 8px 16px; border-top: 1px solid var(--line); min-height: 18px; font-size: 12px; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { padding: 7px 12px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font: inherit; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--strong); border-bottom-color: var(--accent); }
.set-body { padding: 8px 16px; overflow-y: auto; min-height: 90px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; color: var(--text); }
.set-row select, .set-row input[type="number"] {
  width: 140px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 5px 6px; font: inherit;
}
.set-row input[type="color"] { width: 44px; height: 28px; padding: 0; background: none; border: 1px solid var(--line); border-radius: 4px; }
.set-row input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
.modal-foot .spacer { flex: 1; }

@media (max-width: 520px) {
  .modal { padding-top: 4vh; }
  .legend { max-width: calc(100% - 70px); }
  .set-row select, .set-row input[type="number"] { width: 120px; }
}
@media (hover: none) {
  .leg-btns { display: inline-flex; }
}

/* Right-click menus (ctxmenu.js): the rail's flyout, with a shortcut or state column at the right. */
.ctx-menu { z-index: 60; width: auto; min-width: 232px; max-width: calc(100vw - 16px); }
.menu-list.no-ico.ctx-menu .fly-row { grid-template-columns: 1fr auto; gap: 0 28px; }
.ctx-menu .fly-row { min-height: 32px; }
.ctx-menu .fly-sep { margin: 4px 0; }
.ctx-menu:focus { outline: none; }
.ctx-menu .fly-row:focus, .ctx-menu .fly-row:focus-visible { outline: none; background: var(--sel); }
.ctx-menu.kbd .fly-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ctx-menu .fly-row[aria-checked="true"] .fly-name::after { margin-left: 10px; }
.ctx-menu .fly-key svg { display: block; }

/* v6: the result card. Over the chart, top center; a bottom sheet on a phone. */
.result-card {
  position: absolute; z-index: 20; top: 150px; left: 12px; width: min(424px, calc(100% - 24px));
  padding: 12px 14px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5); color: var(--text);
}
.result-card[hidden], .rc-tab[hidden] { display: none; }
.rc-head { display: flex; align-items: flex-start; gap: 8px; cursor: grab; touch-action: none; }
.rc-head:active { cursor: grabbing; }
.rc-head .icon-btn { margin-left: auto; flex: none; cursor: pointer; }
.rc-head .icon-btn svg { width: 16px; height: 16px; }
.rc-title { min-width: 0; }
.rc-verdict { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 700; color: var(--strong); }
.result-card[data-tone="win"] .rc-verdict { color: var(--up); }
.result-card[data-tone="loss"] .rc-verdict { color: var(--down); }
.rc-numbers { display: flex; flex-wrap: wrap; gap: 2px 12px; margin: 6px 0 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--strong); }
.rc-numbers[hidden] { display: none; }
.rc-sides { margin-top: 10px; font-size: 13px; }
.rc-sides th, .rc-sides td { padding: 5px 8px; }
.rc-sides td { font-variant-numeric: tabular-nums; }
.rc-detail { margin: 10px 0 0; font-size: 12px; line-height: 1.5; }
.rc-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.rc-actions:has(.rc-main[hidden]) { grid-template-columns: 1fr; }
.rc-main { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px; text-align: left; border-color: var(--strong); }
.rc-main:disabled { border-color: var(--line-strong); }
.rc-label { font-weight: 600; }
.rc-sub { font-size: 12px; color: var(--muted); }
.rc-why { margin: 6px 0 0; font-size: 12px; }
.rc-why[hidden], .rc-main[hidden], .rc-small[hidden] { display: none; }
.rc-more { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.rc-small { padding: 4px 10px; font-size: 12px; }
.rc-more .note { flex: 1; min-width: 140px; width: auto; }
.rc-tab {
  position: absolute; z-index: 20; top: 150px; left: 12px; max-width: calc(100% - 24px);
  padding: 5px 12px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 4px; color: var(--strong);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rc-tab[data-tone="win"] { color: var(--up); }
.rc-tab[data-tone="loss"] { color: var(--down); }
.rc-tab:hover { border-color: var(--strong); }
@media (max-width: 520px) {
  .result-card {
    position: fixed; top: auto !important; left: 0 !important; right: 0; bottom: 0; width: auto; max-height: 72dvh; overflow-y: auto;
    border-radius: 10px 10px 0 0; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 45;
  }
  .rc-head { cursor: default; }
  .rc-actions .rc-main kbd, .rc-more kbd { display: none; } /* no keyboard on a phone */
  .rc-tab { position: fixed; top: auto !important; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); right: 10px; left: auto !important; z-index: 45; }
}
