:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e6e8ee;
  --muted: #8a92a6;
  --up: #26a69a;
  --down: #ef5350;
  --exit: #5b6476;
  --accent: #f0b429;
  /* chart (read by the canvas, so literal colours only) */
  --bull-fill: #0f1115;
  --bull-line: #26a69a;
  --bear-fill: #ef5350;
  --bear-line: #ef5350;
  --doji: #8a92a6;
  --barnum: #b4bac6;
  --overlay: rgba(0,0,0,.55);
  --backdrop: rgba(0,0,0,.6);
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f3f4f6;
  --line: #e2e5ea;
  --text: #1a1d23;
  --muted: #6b7280;
  --up: #158a7b;
  --down: #d93636;
  --exit: #6b7280;
  --bull-fill: #ffffff;
  --bull-line: #3d424a;
  --bear-fill: #000000;
  --bear-line: #3d424a;
  --doji: #3d424a;
  --barnum: #6b7280;
  --overlay: rgba(255,255,255,.9);
  --backdrop: rgba(0,0,0,.35);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
}
#app { display: flex; flex-direction: column; height: 100dvh; height: 100vh; }
@supports (height: 100dvh) { #app { height: 100dvh; } }

#top {
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.cell { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.cell span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pos { color: var(--up); } .neg { color: var(--down); }

button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
.icon { background: none; font-size: 22px; padding: 4px 8px; color: var(--text); }

#chartWrap { position: relative; flex: 1; min-height: 0; touch-action: none; cursor: pointer; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hint {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 16px; background: var(--overlay); color: var(--muted);
  font-size: 12px; pointer-events: none; transition: opacity .6s;
}
#hint.gone { opacity: 0; }
/* top-left stack: Reset view (when shown) above the timeframe selector */
#chartTools {
  position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column;
  align-items: flex-start; gap: 6px;
}
#zoomReset {
  padding: 6px 10px; border-radius: 14px;
  background: var(--overlay); color: var(--muted); font-size: 12px; border: 1px solid var(--line);
}
#zoomReset.hidden { display: none; }
#tfBar {
  display: flex; gap: 2px; padding: 3px;
  border-radius: 14px; background: var(--overlay); border: 1px solid var(--line);
}
#tfBar button {
  min-width: 32px; height: 26px; padding: 0 6px; border-radius: 11px; background: none;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
#tfBar button.on { background: var(--line); color: var(--text); }
#tfBar button:disabled { opacity: .35; }
#tfOpts { display: none; gap: 2px; }
#tfBar.open #tfOpts { display: flex; }
#tfToggle { display: flex; align-items: center; gap: 5px; color: var(--text) !important; }
#tfBar.open #tfToggle { border-right: 1px solid var(--line); border-radius: 11px 0 0 11px; padding-right: 8px; }
#tfToggle .tri { font-size: 9px; color: var(--muted); }

#controls {
  display: flex; gap: 8px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.trade {
  flex: 1; height: 56px; border-radius: 10px; font-size: 18px; font-weight: 700; letter-spacing: .05em;
  color: #fff; transition: transform .05s, filter .1s;
}
.trade:active { transform: scale(.96); filter: brightness(1.2); }
.trade:disabled { opacity: .35; }
.buy { background: var(--up); } .sell { background: var(--down); } .exit { background: var(--exit); flex: .8; }

.modal {
  position: fixed; inset: 0; background: var(--backdrop); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.modal.hidden { display: none; }
.card {
  width: 100%; max-width: 460px; max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  -webkit-user-select: text; user-select: text;
}
.cardHead { display: flex; justify-content: space-between; align-items: center; }
h2 { margin: 0 0 4px; font-size: 20px; } h3 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); }
.muted { color: var(--muted); margin: 0 0 12px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stat { background: var(--bg); border-radius: 8px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.row { display: flex; gap: 8px; margin-top: 12px; }
.btn { flex: 1; height: 44px; border-radius: 8px; background: var(--line); font-weight: 600; }
.btn.primary { background: var(--accent); color: #111; }
.btn.danger { background: transparent; border: 1px solid var(--down); color: var(--down); }
.tabs { display: flex; gap: 6px; margin-top: 8px; }
.tab { padding: 6px 12px; border-radius: 14px; background: var(--bg); color: var(--muted); }
.tab.on { background: var(--line); color: var(--text); }
.ind { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.indHead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.indHead b { flex: 1; }
.swatch { width: 14px; height: 14px; border-radius: 50%; }
.indDel { background: none; color: var(--down); font-size: 13px; padding: 4px; }
.ind label { display: flex; align-items: center; gap: 10px; padding: 5px 0; color: var(--muted); font-size: 13px; }
.ind label input { margin-left: auto; }
.ind input[type=number] {
  width: 80px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 16px; text-align: right;
}
.ind input[type=color] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.ind input[type=range] { width: 130px; accent-color: var(--accent); }
.ind output { width: 38px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.toggle + .toggle { margin-top: 6px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 6px; }
.seg button { flex: 1; height: 38px; border-radius: 8px; background: none; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.muted.small { font-size: 12px; margin: 6px 0 0; }
.toggle {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); border-radius: 10px; padding: 12px; cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .knob { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--line); transition: background .15s; }
.toggle .knob::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.toggle input:checked + .knob { background: var(--up); }
.toggle input:checked + .knob::after { transform: translateX(18px); }
#equity { width: 100%; height: 120px; display: block; background: var(--bg); border-radius: 8px; }
