/* Chart — a trading terminal, not a landing page.
   Restraint is the brief: the candles are the content, everything else recedes. */

:root {
  --gold: #E0B23C;
  --gold-hi: #F3D277;
  --up: #37BE7E;
  --down: #F0565B;

  --bg: #0B0C11;
  --surface: #12141C;
  --surface-2: #191C26;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);

  --text: #EDEFF5;
  --muted: #8D93A6;
  --faint: #5A6072;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.04) inset;

  --tap: 44px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* An explicit `display` in a class rule beats the browser's own [hidden]
   styling, so anything given display:flex stays visible even when hidden is
   set. This makes the attribute mean what it says everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 "IBM Plex Sans", ui-sans-serif, -apple-system, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  /* The chart owns all gestures inside its bounds; the page never scrolls. */
  overflow: hidden;
  touch-action: manipulation;
}

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 7px; }
.mark { color: var(--gold); font-size: 13px; }
.brandname {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 14px;
}

.price-block {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: flex-end;
}

.price {
  font: 600 20px/1 "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  letter-spacing: -0.02em;
  transition: color 180ms var(--ease);
}
.price.tick-up { color: var(--up); }
.price.tick-down { color: var(--down); }
.price.stale { color: var(--faint); }

.change {
  font: 500 12px/1 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--muted);
}
.change.pos { color: var(--up); }
.change.neg { color: var(--down); }

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: 0 0 auto;
}
.status[data-state="live"] .dot { background: var(--up); box-shadow: 0 0 0 3px rgba(55, 190, 126, 0.16); }
.status[data-state="stale"] .dot { background: #E8A33D; box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.16); }
.status[data-state="closed"] .dot { background: var(--faint); }
.status[data-state="sample"] .dot { background: var(--gold); box-shadow: 0 0 0 3px rgba(224, 178, 60, 0.16); }
.status[data-state="connecting"] .dot,
.status[data-state="reconnecting"] .dot { background: #E8A33D; box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.14); }
.status[data-state="error"] .dot,
.status[data-state="offline"] .dot { background: var(--down); box-shadow: 0 0 0 3px rgba(240, 86, 91, 0.14); }
.status[data-state="live"] .status-text { color: var(--up); }
.status[data-state="stale"] .status-text { color: #E8A33D; }
.status[data-state="connecting"] .status-text,
.status[data-state="reconnecting"] .status-text { color: #E8A33D; }
.status[data-state="error"] .status-text,
.status[data-state="offline"] .status-text { color: var(--down); }
.status.is-quiet { display: none; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  transition: color 140ms var(--ease), border-color 140ms var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* The mode control is intentionally text-backed on desktop: a pencil alone
   is easy to miss, while "Editing" makes the annotation affordance obvious. */
.mode-btn {
  min-height: 34px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(224, 178, 60, 0.08);
  border: 1px solid rgba(224, 178, 60, 0.55);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font: 600 11px/1 "IBM Plex Sans", system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  transition: background 140ms var(--ease), color 140ms var(--ease), border-color 140ms var(--ease);
}
.mode-btn:hover { background: rgba(224, 178, 60, 0.16); }
.mode-btn[aria-pressed="false"] {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.mode-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

body[data-edit="1"] .toolbar { box-shadow: inset 0 2px 0 rgba(224, 178, 60, 0.72); }

/* ------------------------------------------------------------ symbols */

.symbols {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

/* The quick row scrolls; the search button stays put, because "find my
   instrument" must never itself be the thing that scrolled off the edge. */
.sym-list {
  display: flex;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.sym-list::-webkit-scrollbar { display: none; }

.sym-search {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.sym-search:hover { color: var(--text); border-color: var(--line-strong); }
.sym-search:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.sym {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 13px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font: 600 13px/1 "IBM Plex Sans", system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}
.sym:hover { color: var(--text); background: var(--surface-2); }
.sym[aria-pressed="true"] {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--gold);
}
.sym:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ------------------------------------------------------------- chart */

.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;

  /* The chart owns every gesture inside its bounds. Without this the browser
     competes for drags — trying to scroll the page or double-tap-zoom — which
     shows up as a drag that stutters or dies halfway. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  /* Stops iOS showing the long-press "copy / share" callout over the chart. */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#chart { position: absolute; inset: 0; }

/* Drawings live on their own canvas above the chart.
   It is PURELY VISUAL and never receives pointer events — interaction is
   handled on .chart-wrap in the capture phase instead, so grabbing a drawing
   and panning the chart can coexist. An overlay that takes pointer events
   swallows every pan gesture the moment a drawing exists. */
#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* Must sit above the charting library's own canvases. Without an explicit
     z-index they paint over this one and the drawings are invisible. */
  z-index: 5;
}

/* ------------------------------------------------------------- legend */

/* The OHLC readout. Sits over the chart's own top-left dead space, so it costs
   no vertical room — the candles keep the full height. */
.legend {
  position: absolute;
  top: 8px;
  left: 12px;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  max-width: calc(100% - 90px);
}

.legend-title {
  font: 600 12px/1.4 "IBM Plex Sans", system-ui, sans-serif;
  color: var(--text);
  letter-spacing: -0.01em;
}

.legend-ohlc {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font: 500 11px/1.4 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--muted);
}
.legend-ohlc b { color: var(--faint); font-weight: 500; }
.legend-ohlc.up span { color: var(--up); }
.legend-ohlc.down span { color: var(--down); }
.legend-ohlc b + span { margin-right: 4px; }

.legend-change { margin-left: 2px; }

.legend-indicators { display: flex; gap: 10px; }
.legend-ind { font: 500 11px/1.4 "IBM Plex Mono", ui-monospace, monospace; }

.legend-sample {
  font: 600 10px/1.4 "IBM Plex Sans", system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* On a phone the legend must stay at most two short lines. A four-line legend
   eats the candles it is meant to describe, so O/H/L drop out and the close —
   the number actually being read — stays. */
@media (max-width: 620px) {
  .legend {
    gap: 1px 8px;
    top: 6px;
    left: 8px;
    max-width: calc(100% - 70px);
    flex-direction: column;
  }
  .legend-title { font-size: 11px; }
  .legend-ohlc, .legend-ind { font-size: 10px; }
  .legend-ohlc b,
  .legend-ohlc b + span { display: none; }
  .legend-ohlc b:nth-of-type(4),
  .legend-ohlc b:nth-of-type(4) + span { display: inline; }
  .legend-change { display: inline; }
  .legend-indicators { gap: 8px; }
}

/* ----------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.timeframes, .tools, .history, .toolgroup { display: flex; gap: 4px; align-items: center; }

/* On a narrow screen the timeframes scroll and the drawing tools stay pinned.
   The tools are the reason this app exists — they must never be the thing that
   disappears off the edge. */
.timeframes {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.timeframes::-webkit-scrollbar { display: none; }

.toolgroup { flex: 0 0 auto; margin-left: auto; gap: 8px; }

.history { gap: 2px; padding-left: 6px; border-left: 1px solid var(--line); }
.tool[disabled] { opacity: 0.32; cursor: default; }
.tool[disabled]:hover { background: transparent; color: var(--muted); }

.tf, .tool {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font: 600 13px/1 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}
.tf:hover, .tool:hover { color: var(--text); background: var(--surface-2); }
.tf[aria-pressed="true"], .tool[aria-pressed="true"] {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--gold);
}
.tf:focus-visible, .tool:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.tool.danger:hover { color: var(--down); }

.tool-label { font-size: 12px; }

/* Phone toolbar: two rows.
   Six drawing tools, six timeframes, indicators and history cannot share one
   375px row without something being pushed off the edge — and on this app the
   thing that gets pushed off is always a primary control. Two rows costs ~44px
   of height and makes everything reachable, which is the right trade. */
/* Word labels on the tools cost ~250px. Below this the toolgroup starves the
   timeframe row and the higher timeframes silently scroll off the edge — which
   is exactly what happens on a phone held in landscape (852px wide). */
@media (max-width: 900px) {
  .tool-label { display: none; }
}

@media (max-width: 620px) {
  .tf, .tool { min-width: 40px; padding: 0 8px; }

  .toolbar {
    flex-wrap: wrap;
    gap: 4px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .timeframes {
    order: 1;
    flex: 1 1 100%;
    justify-content: space-between;
  }
  .toolgroup {
    order: 2;
    flex: 1 1 100%;
    margin-left: 0;
    gap: 2px;
    justify-content: space-between;
    border-top: 1px solid var(--line);
    padding-top: 4px;
    /* Last-resort scroll: even after shrinking, a narrow phone in a large
       font size can overflow. Scrolling keeps every control reachable rather
       than silently clipping the ones on the end. */
    overflow-x: auto;
    scrollbar-width: none;
  }
  .toolgroup::-webkit-scrollbar { display: none; }

  .tf, .tool { min-width: 36px; padding: 0 6px; }
  .tools { gap: 2px; }
  .history { padding-left: 4px; gap: 0; }
  .history .tool { min-width: 30px; padding: 0 3px; }

  /* Nudge bar clears the taller toolbar. */
  .nudge, .hint { bottom: calc(118px + var(--safe-b)); }
}

/* Phone editing panel.
   Word buttons do not fit beside the slider at 375px, so Done and Delete
   become glyphs and the alert loses its label. Everything stays a 44px target;
   only the wording is dropped. */
/* (The phone editing panel is styled at the very bottom of this file — it has
   to come after the base .nudge rules to win at equal specificity.) */

/* Very narrow: the percentage change is the first thing to go — the price and
   the feed state matter more. */
@media (max-width: 420px) {
  .price { font-size: 17px; }
  .change { display: none; }
  .brandname { display: none; }
  .status { font-size: 10px; }
}

/* ------------------------------------------------------------- nudge */

/* Compact drawing inspector. One job per row: identity → adjust → extras.
   Must stay short — on a phone the chart is the product, not this panel. */
.nudge {
  position: absolute;
  left: 50%;
  bottom: calc(72px + var(--safe-b));
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 16px));
  background: rgba(18, 20, 28, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px 10px 8px;
  z-index: 20;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: rise 200ms var(--ease);
}
/* User dragged it out of the default dock — fixed so it stays put while the
   chart chrome reflows, and free of the centering transform. */
.nudge.is-floating {
  position: fixed;
  right: auto;
  bottom: auto;
  transform: none;
  animation: none;
  touch-action: none;
}
@keyframes rise {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .nudge { animation: none; } }

.nudge-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nudge-swatch-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
}
.nudge-swatch-btn:hover { border-color: var(--gold); }
.nudge-swatch-btn[aria-expanded="true"] { border-color: var(--gold); }
.nudge-swatch-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.nudge-swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
}

.nudge-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* Room to grab on a phone without fighting the − / + targets. */
  padding: 2px 4px 2px 0;
  border-radius: 8px;
}
.nudge-meta:active { cursor: grabbing; }
.nudge.is-dragging {
  opacity: 0.92;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.nudge.is-dragging .nudge-meta { cursor: grabbing; }
.nudge-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.nudge-value {
  font: 600 18px/1.1 "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -0.02em;
}

.nudge-done {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 999px;
  color: #17120A;
  font: 600 13px/1 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
}
.nudge-done:hover { background: var(--gold-hi); }
.nudge-done:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.nudge-colors {
  display: flex;
  gap: 8px;
  padding: 10px 2px 2px;
  justify-content: center;
}
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease);
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-pressed="true"] { border-color: var(--text); transform: scale(1.12); }
.swatch:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.nudge-adjust {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.nudge-step {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  font: 600 18px/1 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
}
.nudge-step:hover { background: #222634; }
.nudge-step:active { transform: translateY(1px); }
.nudge-step:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.nudge-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.nudge-note {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: 400 13px/1 "IBM Plex Sans", system-ui, sans-serif;
}
.nudge-note::placeholder { color: var(--faint); }
.nudge-note:focus-visible {
  outline: none;
  border-color: rgba(224, 178, 60, 0.55);
}

.nudge-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 600 12px/1 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}
.nudge-chip:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface); }
.nudge-chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.nudge-chip[aria-pressed="true"] {
  color: var(--gold);
  border-color: rgba(224, 178, 60, 0.55);
  background: rgba(224, 178, 60, 0.08);
}
.nudge-chip:disabled { opacity: 0.38; cursor: default; }
.nudge-chip:disabled:hover { color: var(--muted); background: transparent; border-color: var(--line); }
.nudge-chip.danger {
  color: var(--down);
  border-color: rgba(240, 86, 91, 0.4);
  background: rgba(240, 86, 91, 0.08);
}
.nudge-chip.danger:hover {
  color: #fff;
  border-color: rgba(240, 86, 91, 0.7);
  background: rgba(240, 86, 91, 0.22);
}
.nudge-chip-ico { font-size: 11px; opacity: 0.85; }

/* -------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(340px, calc(100vw - 24px));
}

.toast {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 12px 34px 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--gold);
  border-left-width: 3px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: slide-in 240ms var(--ease);
}
.toast strong { font-size: 13px; color: var(--gold); font-weight: 600; }
.toast span { font-size: 12px; color: var(--text); line-height: 1.45; }

.toast-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.toast-close:hover { color: var(--text); background: var(--surface); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* -------------------------------------------------------------- hint */

.hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(76px + var(--safe-b));
  background: rgba(25, 28, 38, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 15;
  pointer-events: none;
  animation: rise 180ms var(--ease);
}

/* ---------------------------------------------------------- settings */

dialog {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  padding: 0;
  width: min(420px, calc(100vw - 28px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.settings-form { padding: 18px; }
.settings-form h2 { margin: 0 0 16px; font-size: 17px; letter-spacing: -0.01em; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: 400 14px/1 ui-monospace, "SF Mono", monospace;
}
.field select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: 400 14px/1 ui-sans-serif, system-ui, sans-serif;
}
.field input:focus-visible,
.field select:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.field small { display: block; margin-top: 6px; font-size: 11px; color: var(--faint); }

.field.checkbox { display: flex; align-items: center; gap: 10px; }
.field.checkbox input { width: 18px; height: 18px; accent-color: var(--gold); }
.field.checkbox span { margin: 0; font-size: 13px; color: var(--text); }

.settings-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  color: #17120A;
  font: 600 14px/1 ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  transition: background 120ms var(--ease);
}
.btn:hover { background: var(--gold-hi); }
.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--muted); }
.btn.ghost:hover { background: var(--surface); color: var(--text); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.credit { margin: 18px 0 0; font-size: 11px; color: var(--faint); line-height: 1.6; }
.credit a { color: var(--muted); }

/* ------------------------------------------------------- shortcuts */

.shortcuts { margin: 20px 0 0; }
.shortcuts h3 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.shortcuts ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; }
.shortcuts li { font-size: 12px; color: var(--muted); }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 5px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 600 11px/1 ui-monospace, "SF Mono", monospace;
  color: var(--text);
  text-align: center;
}



/* Scroll affordance. The symbol row holds more instruments than fit on a
   phone, and a hard cut at the edge reads as "that's all there is". A fade
   says "keep swiping" without spending any space on an arrow. */
@media (max-width: 620px) {
  .sym-list {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
  }
}

/* A favourite reads as a favourite without spending a whole star on the row. */
.sym.is-fav::before {
  content: "★";
  margin-right: 5px;
  font-size: 9px;
  color: var(--gold);
  vertical-align: 1px;
}

/* ===================================================================
   DRAWINGS SHEET + BACK-TO-LIVE
   =================================================================== */

/* Appears only when you have panned away from the newest candle. Getting back
   to "now" by dragging is tedious on a phone; this is one tap. */
.jump {
  position: absolute;
  right: 12px;
  bottom: calc(120px + var(--safe-b));
  z-index: 18;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--gold);
  border-radius: 999px;
  color: var(--gold);
  font: 600 12px/1 ui-sans-serif, system-ui, sans-serif;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: rise 200ms var(--ease);
}
.jump:hover { background: #222634; }
.jump:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .jump { animation: none; } }

.sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(460px, 100%);
  max-height: 68vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  z-index: 41;
  padding-bottom: var(--safe-b);
  animation: sheet-up 260ms var(--ease);
}
@keyframes sheet-up {
  from { transform: translateX(-50%) translateY(24px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
  margin: 8px auto 2px;
  flex: 0 0 auto;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.sheet-head strong { font-size: 14px; letter-spacing: -0.01em; }

.sheet-close {
  margin-left: auto;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.sheet-close:hover { color: var(--text); }

.sheet-list { overflow-y: auto; flex: 1 1 auto; padding: 6px; }

.sheet-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: 10px;
}
.sheet-row + .sheet-row { margin-top: 2px; }
.sheet-row:hover { background: var(--surface); }
.sheet-row.is-selected { background: rgba(224, 178, 60, 0.10); }

.sheet-pick {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.sheet-pick:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

.sheet-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.sheet-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sheet-row-head {
  font: 500 13px/1.3 ui-sans-serif, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.sheet-note {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-alert { margin-left: auto; color: var(--gold); font-size: 11px; }

.sheet-del {
  flex: 0 0 auto;
  width: var(--tap);
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--faint);
  font-size: 13px;
  cursor: pointer;
}
.sheet-del:hover { color: var(--down); background: var(--surface); }
.sheet-del:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

.sheet-empty { margin: 20px 12px 6px; color: var(--muted); font-size: 13px; text-align: center; }
.sheet-empty-tip { margin: 0 18px 16px; color: var(--faint); font-size: 12px; text-align: center; line-height: 1.45; }

.sheet-foot {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.btn.ghost.danger { color: var(--down); border-color: rgba(240, 86, 91, 0.4); width: 100%; }
.btn.ghost.danger:hover { background: rgba(240, 86, 91, 0.1); color: var(--down); }
.btn:disabled { opacity: 0.4; cursor: default; }

@media (max-width: 620px) {
  .jump { bottom: calc(124px + var(--safe-b)); right: 10px; }
  .sheet { max-height: 62vh; }
}


/* ------------------------------------------------------ practice banner */

.practice-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(224, 178, 60, 0.08);
  border-bottom: 1px solid rgba(224, 178, 60, 0.22);
  color: var(--gold-hi);
  font-size: 12px;
  line-height: 1.35;
  flex: 0 0 auto;
}
.practice-mark { color: var(--gold); flex: 0 0 auto; font-size: 11px; }
.practice-banner > span:nth-child(2) { flex: 1 1 auto; min-width: 0; }
.practice-dismiss {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}
.practice-dismiss:hover { color: var(--text); background: rgba(255,255,255,0.06); }

/* -------------------------------------------------------- loading veil */

.loading-veil {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  gap: 12px;
  justify-items: center;
  background: rgba(11, 12, 17, 0.72);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}
.loading-pulse {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(224,178,60,0.22);
  border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-pulse { animation: none; border-top-color: var(--gold); } }

/* -------------------------------------------------------------- coach */

.coach {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(var(--safe-b) + 16px));
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px));
  z-index: 70;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  animation: rise-coach 220ms var(--ease);
}
@keyframes rise-coach {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .coach { animation: none; } }

.coach-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.coach h2 {
  margin: 0 0 8px;
  font-size: 18px;
  letter-spacing: -0.02em;
  font-weight: 600;
}
.coach-body {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}
.coach-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.coach-step {
  margin-right: auto;
  font-size: 12px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- help */

.help-sheet { z-index: 55; }
.help-foot { justify-content: flex-start; }

.help-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}
.help-item + .help-item { margin-top: 2px; }
.help-item[open] { background: var(--surface); }
.help-item summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  list-style: none;
}
.help-item summary::-webkit-details-marker { display: none; }
.help-item summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--gold);
  transition: transform 140ms var(--ease);
}
.help-item[open] summary::before { transform: rotate(90deg); }
.help-item p {
  margin: 8px 0 2px 1em;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.legend-vol {
  font: 500 11px/1.4 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--faint);
}



@media (max-width: 420px) {
  .practice-banner { font-size: 11px; padding: 7px 10px; }
  .coach { padding: 16px 14px 12px; }
  .coach h2 { font-size: 16px; }
}


/* Phone inspector — still three short rows, never a half-screen sheet. */
@media (max-width: 620px) {
  .nudge {
    width: calc(100vw - 12px);
    bottom: calc(118px + var(--safe-b));
    padding: 9px 10px 9px;
    border-radius: 12px;
  }
  .nudge-value { font-size: 17px; }
  .nudge-step { width: 40px; height: 40px; border-radius: 11px; }
  .nudge-done { min-height: 36px; padding: 0 12px; }
  .nudge-note { min-height: 38px; font-size: 14px; }
  .nudge-chip { min-height: 38px; padding: 0 11px; }
}


/* ---------------------------------------------------- mobile / app shell */

@media (max-width: 620px) {
  .topbar {
    gap: 8px;
    padding: 6px 10px;
    padding-top: max(6px, env(safe-area-inset-top, 0px));
  }
  .price { font-size: 18px; }
  .symbols {
    gap: 2px;
    padding: 4px 8px 6px;
  }
  .sym {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
  }
  .practice-banner {
    padding: 6px 10px;
    font-size: 11px;
    gap: 8px;
  }
  .toolbar {
    padding-top: 4px;
    padding-bottom: calc(4px + var(--safe-b));
  }
  .icon-btn { width: 32px; height: 32px; }
  .mode-btn { width: 32px; min-height: 32px; padding: 0; }
  .mode-btn .edit-label { display: none; }
}

/* Native WebView: less chrome, more candles. */
body[data-app="1"] .brandname { display: none; }
body[data-app="1"] .practice-banner { display: none !important; }
body[data-app="1"] .credit { display: none; }

@media (max-width: 620px) {
  body[data-app="1"] .topbar {
    padding: 4px 8px;
    padding-top: max(4px, env(safe-area-inset-top, 0px));
  }
  body[data-app="1"] .symbols { padding: 2px 6px 4px; }
  body[data-app="1"] .nudge {
    bottom: calc(110px + var(--safe-b));
  }
  body[data-app="1"] .hint {
    bottom: calc(110px + var(--safe-b));
  }
}

/* When the soft keyboard opens for a note, keep the docked inspector visible.
   A user-placed floating panel stays where they put it. */
body.keyboard-open .nudge:not(.is-floating) {
  bottom: calc(12px + var(--safe-b)) !important;
}
body.keyboard-open .toolbar,
body.keyboard-open .jump {
  visibility: hidden;
}


/* -------------------------------------------------------- empty-state tip */

.chart-tip {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(340px, calc(100% - 24px));
  padding: 10px 10px 10px 14px;
  background: rgba(25, 28, 38, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: rise 220ms var(--ease);
}
.chart-tip p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
}
.chart-tip strong { color: var(--gold); font-weight: 600; }
.chart-tip-dismiss {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.chart-tip-dismiss:hover { color: var(--text); background: var(--surface); }

body[data-app="1"] .chart-tip { bottom: 12px; }
@media (max-width: 620px) {
  .chart-tip { bottom: 10px; padding: 9px 8px 9px 12px; }
  .chart-tip p { font-size: 12px; }
}


/* ===================================================================
   PICKER SHEETS — tools, indicators, overlays, instruments
   =================================================================== */

/* Every entry names itself and explains itself in one line. This is where a
   new trader finds out what "Fib" means without leaving the app. */
.pick-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 11px 12px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease);
}
.pick-row + .pick-row { margin-top: 2px; }
.pick-row:hover { background: var(--surface); }
.pick-row:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.pick-row:disabled { opacity: 0.38; cursor: default; }
.pick-row:disabled:hover { background: transparent; }
.pick-row[aria-pressed="true"] { background: rgba(224, 178, 60, 0.10); }
.pick-row[aria-pressed="true"] .pick-glyph { color: var(--gold); }

.pick-glyph {
  flex: 0 0 auto;
  width: 26px;
  text-align: center;
  font-size: 16px;
  line-height: 1.3;
  color: var(--muted);
}

.pick-swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 3px;
}

.pick-text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pick-text strong {
  font: 600 13px/1.3 "IBM Plex Sans", system-ui, sans-serif;
  letter-spacing: -0.01em;
}
.pick-text span {
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.pick-add,
.pick-check {
  flex: 0 0 auto;
  align-self: center;
  width: 22px;
  text-align: center;
  color: var(--gold);
  font-size: 15px;
}

.pick-row kbd { flex: 0 0 auto; align-self: center; }

.sheet-section {
  margin: 12px 12px 6px;
  font: 600 11px/1 "IBM Plex Sans", system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
}
.sheet-section:first-child { margin-top: 4px; }

.sheet-intro {
  margin: 6px 12px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* ------------------------------------------------- active indicator rows */

.active-row {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface);
}
.active-row + .active-row { margin-top: 4px; }

.active-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.active-head strong {
  flex: 1 1 auto;
  min-width: 0;
  font: 600 13px/1.3 "IBM Plex Mono", ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.active-head .pick-swatch { margin-top: 0; }

.row-icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.row-icon:hover { color: var(--text); border-color: var(--line-strong); }
.row-icon.danger:hover { color: var(--down); border-color: rgba(240, 86, 91, 0.45); }
.row-icon:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.active-params {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.param {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.param input {
  width: 62px;
  min-height: 32px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: 500 12px/1 "IBM Plex Mono", ui-monospace, monospace;
}
.param input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ------------------------------------------------------------ sheet tabs */

.tabs { display: flex; gap: 4px; flex: 1 1 auto; }
.tab {
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font: 600 13px/1 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--gold);
}
.tab:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.studies-foot { display: flex; }
.studies-foot .btn { width: 100%; }

/* -------------------------------------------------------- symbol search */

.sheet-search {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 38px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  font: 400 14px/1 "IBM Plex Sans", system-ui, sans-serif;
}
.sheet-search::placeholder { color: var(--faint); }
.sheet-search:focus-visible { outline: none; border-color: rgba(224, 178, 60, 0.55); }

.sheet-del.is-fav { color: var(--gold); }
.sheet-row.is-hidden-drawing .sheet-pick { opacity: 0.45; }

/* --------------------------------------------------------- fatal error */

.fatal {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: rgba(11, 12, 17, 0.94);
}
.fatal strong { font-size: 15px; color: var(--down); }
.fatal p {
  margin: 0;
  max-width: 42ch;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* ===================================================================
   TOOLBAR ON SMALL SCREENS
   Nine controls have to share one row on a 375px phone. They do it by
   stacking a small word under each glyph rather than by dropping the word:
   an unlabelled ⇕ tells a new trader nothing, and this app is for new
   traders. The history icons keep their icon-only form because ↶ ↷ ☰ are
   already universal, and that is what buys the width for the rest.
   =================================================================== */

@media (max-width: 900px) {
  .tools .tool,
  #more-btn,
  #studies-btn,
  #gold-btn {
    flex-direction: column;
    gap: 2px;
    padding: 0 4px;
    min-width: 46px;
    line-height: 1.1;
  }
  .tools .tool .tool-label,
  #more-btn .tool-label,
  #studies-btn .tool-label,
  #gold-btn .tool-label {
    display: block;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: inherit;
    opacity: 0.85;
  }
  .history .tool-label { display: none; }
}

@media (max-width: 620px) {
  .tools .tool,
  #more-btn,
  #studies-btn,
  #gold-btn { min-width: 42px; }
  .history .tool { min-width: 32px; }
}

@media (max-width: 380px) {
  .tools .tool,
  #more-btn,
  #studies-btn,
  #gold-btn { min-width: 38px; padding: 0 2px; }
  .tools .tool .tool-label,
  #more-btn .tool-label,
  #studies-btn .tool-label,
  #gold-btn .tool-label { font-size: 8.5px; }
  .history .tool { min-width: 28px; }
}

/* On a phone the legend must not eat the candles it describes.
   Volume is already visible as bars, and the status pill already says
   "Practice" — repeating both costs two lines of a chart that only has about
   twenty of them. */
@media (max-width: 620px) {
  .legend { max-width: calc(100% - 78px); }
  .legend-vol { display: none; }
  .legend-sample { display: none; }
}

/* A keyboard hint on a device with no keyboard is noise. */
body[data-touch="1"] .pick-row kbd { display: none; }

/* Candle countdown, laid out beside the instrument name so it can never land
   on top of the price axis or the readout. */
.legend-countdown {
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font: 600 10px/1.6 "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}
.legend-countdown.is-urgent { color: var(--down); background: rgba(240, 86, 91, 0.14); }

/* The timeframe row is the one thing allowed to scroll off the edge — the
   drawing tools must never be. A fade says "there is more this way" without
   spending width on an arrow. */
.timeframes {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent 100%);
  mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent 100%);
}

/* ===================================================================
   GOLD ANALYSIS — sheet controls and the market context panel
   =================================================================== */

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}
.preset {
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 600 12px/1 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
}
.preset:hover { color: var(--text); border-color: var(--line-strong); }
.preset[aria-pressed="true"] {
  color: var(--gold);
  border-color: rgba(224, 178, 60, 0.55);
  background: rgba(224, 178, 60, 0.08);
}
.preset:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.gold-intro { margin-bottom: 0; padding-bottom: 10px; }
.gold-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 12px 10px;
}
.gold-preset-card {
  min-height: 68px;
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease);
}
.gold-preset-card.is-recommended { grid-column: 1 / -1; }
.gold-preset-card:hover { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.gold-preset-card[aria-pressed="true"] {
  background: rgba(224, 178, 60, 0.08);
  border-color: rgba(224, 178, 60, 0.62);
}
.gold-preset-card:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.gold-preset-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.gold-preset-head strong { color: var(--text); font-size: 13px; line-height: 1.2; }
.gold-preset-badge {
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(224, 178, 60, 0.11);
  color: var(--gold);
  font-size: 10px;
  font-weight: 600;
}
.gold-preset-selected { margin-left: auto; color: var(--gold); font-weight: 700; }
.gold-preset-what { font-size: 11px; line-height: 1.35; color: var(--muted); }
.gold-detail-help {
  margin: -1px 12px 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.gold-customize-toggle {
  width: calc(100% - 24px);
  min-height: 54px;
  margin: 4px 12px 10px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}
.gold-customize-toggle:hover { border-color: var(--line-strong); }
.gold-customize-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.gold-customize-text { min-width: 0; display: grid; gap: 3px; }
.gold-customize-text strong { color: var(--text); font-size: 13px; }
.gold-customize-text span { color: var(--muted); font-size: 11px; }
.gold-customize-icon { margin-left: auto; color: var(--gold); font-size: 14px; }
.gold-replay-row { margin-bottom: 12px; }

.layer-row { border-radius: 10px; }
.layer-row + .layer-row { margin-top: 2px; }
.layer-row.is-on { background: rgba(224, 178, 60, 0.06); }

/* Settings appear only once a layer is on — the controls for something
   switched off are how a settings screen becomes unreadable. */
.layer-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 2px 12px 12px 12px;
}
.setting {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.setting-bool { gap: 7px; }
.setting-wide { flex: 1 1 100%; }
.setting input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--gold); }
.setting input[type="number"] { width: 64px; }
.setting input[type="text"] { flex: 1 1 auto; min-width: 0; }
.setting input[type="number"],
.setting input[type="text"],
.setting select {
  min-height: 44px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: 500 12px/1 "IBM Plex Mono", ui-monospace, monospace;
}
.setting select { text-transform: capitalize; }
.setting :focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.windows-editor { flex: 1 1 100%; display: grid; gap: 6px; }
.window-row { min-height: 44px; display: flex; align-items: center; gap: 6px; }
.window-toggle {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.window-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--gold); }
.window-name {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: 500 12px/1 "IBM Plex Sans", system-ui, sans-serif;
}
.window-hour {
  width: 54px;
  min-height: 44px;
  padding: 0 6px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: 500 12px/1 "IBM Plex Mono", ui-monospace, monospace;
}
.window-tz { font-size: 10px; color: var(--faint); white-space: nowrap; }

.clean-toggle { margin-left: auto; min-height: 44px; padding: 0 12px; font-size: 12px; }
#gold-sheet .sheet-close { min-width: 44px; min-height: 44px; }
.clean-toggle[aria-pressed="true"] {
  color: var(--gold);
  border-color: rgba(224, 178, 60, 0.55);
  background: rgba(224, 178, 60, 0.08);
}

@media (max-width: 520px) {
  .window-row { flex-wrap: wrap; }
  .window-tz { flex: 1 1 100%; margin-left: 26px; }
}

/* ------------------------------------------------------ context panel */

/* Sits over the chart's right-hand dead space so it costs no candle height.
   Everything in it is a statement about what has happened — never advice. */
.context-panel {
  position: absolute;
  top: 8px;
  right: 62px;
  z-index: 7;
  width: 186px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  padding: 9px 11px 10px;
  background: rgba(18, 20, 28, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.context-title {
  margin: 0 0 6px;
  font: 600 11px/1.3 "IBM Plex Sans", system-ui, sans-serif;
  letter-spacing: -0.01em;
  color: var(--text);
}
.context-section {
  margin: 8px 0 3px;
  font: 600 9px/1 "IBM Plex Sans", system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
}
.context-section:first-of-type { margin-top: 2px; }

.context-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 1px 0;
}
.context-key {
  flex: 0 0 auto;
  min-width: 42px;
  font: 500 10px/1.5 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--faint);
}
.context-value {
  flex: 1 1 auto;
  min-width: 0;
  font: 500 10px/1.5 "IBM Plex Sans", system-ui, sans-serif;
  color: var(--muted);
  text-align: right;
}
.context-row.bias-bullish .context-value { color: var(--up); }
.context-row.bias-bearish .context-value { color: var(--down); }
.context-row.is-current .context-key { color: var(--gold); }

.context-warn {
  margin: 8px 0 0;
  font-size: 9px;
  line-height: 1.4;
  color: var(--gold);
}

/* On a phone the panel would cover a third of the chart, so it drops to a
   single compact column and gives up the width it does not have. */
@media (max-width: 620px) {
  .context-panel {
    right: 4px;
    top: 4px;
    width: 148px;
    padding: 7px 8px 8px;
    max-height: 46%;
  }
  .context-key { min-width: 34px; font-size: 9px; }
  .context-value { font-size: 9px; }
  .context-title { font-size: 10px; }
}

/* Panel body must not steal chart taps — only the collapse control is live. */
.context-panel { pointer-events: none; }
.context-panel .context-title { pointer-events: auto; }

.context-title {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 6px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font: 600 11px/1.3 "IBM Plex Sans", system-ui, sans-serif;
  letter-spacing: -0.01em;
  text-align: left;
  cursor: pointer;
}
.context-title:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.context-chevron { margin-left: auto; color: var(--faint); font-size: 9px; }
.context-panel.is-collapsed { max-height: none; overflow: visible; }
.context-panel.is-collapsed .context-title { margin-bottom: 3px; }

.context-note {
  margin: 4px 0 0;
  font-size: 9px;
  line-height: 1.4;
  color: var(--faint);
}

/* ------------------------------------------------------------- replay */

/* Sits above the toolbar and only exists during a replay session, so the live
   chart is never cluttered by controls for a mode nobody is in. */
.replay-bar {
  position: absolute;
  left: 50%;
  bottom: calc(72px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 19;
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(440px, calc(100vw - 16px));
  padding: 7px 9px;
  background: rgba(18, 20, 28, 0.96);
  border: 1px solid var(--gold);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.replay-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.replay-btn:hover { background: var(--surface-2); }
.replay-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.replay-btn.is-primary { background: var(--gold); border-color: var(--gold); color: #17120A; }
.replay-btn.is-primary:hover { background: var(--gold-hi); }
.replay-btn.is-exit { color: var(--muted); }
.replay-btn.is-exit:hover { color: var(--down); border-color: rgba(240, 86, 91, 0.45); }

.replay-seek {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--gold);
  height: 20px;
}

.replay-time {
  flex: 0 0 auto;
  font: 500 10px/1 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--muted);
  white-space: nowrap;
}

.replay-speed {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 4px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: 500 11px/1 "IBM Plex Mono", ui-monospace, monospace;
}

/* A replay is a different mode, and the chrome should say so at a glance. */
body.is-replaying .topbar { box-shadow: inset 0 -2px 0 var(--gold); }
body.is-replaying .price { color: var(--gold); }

@media (max-width: 620px) {
  .replay-bar {
    width: calc(100vw - 12px);
    bottom: calc(118px + var(--safe-b));
    gap: 4px;
    padding: 6px;
  }
  .replay-btn { width: 32px; height: 32px; }
  .replay-time { display: none; }
}

/* --------------------------------------------------------- risk fields */

.risk-fields {
  margin: 18px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.risk-fields legend {
  padding: 0 6px;
  font: 600 12px/1 "IBM Plex Sans", system-ui, sans-serif;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.risk-note {
  margin: 0 0 10px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--faint);
}
.risk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.risk-grid label { display: flex; flex-direction: column; gap: 4px; }
.risk-grid span { font-size: 11px; color: var(--muted); }
.risk-grid input {
  min-height: 34px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: 500 13px/1 "IBM Plex Mono", ui-monospace, monospace;
}
.risk-grid input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
@media (max-width: 420px) { .risk-grid { grid-template-columns: 1fr; } }
