:root {
  --bg: #f4f4f6; --card: #ffffff; --ink: #16171b; --muted: #6b6e78; --line: #e4e4ea;
  --gold: #c9a227; --goldink: #7a5d00; --goldbg: #fbf6e3;
  --long: #1f7a4d; --longbg: #e6f4ec; --short: #a3271e; --shortbg: #fdecea;
  --accent: #2f6fed; --warnbg: #fff4dc; --warn: #8a5a00;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b22; --ink: #eceef3; --muted: #9aa0ad; --line: #2a2e38;
    --goldbg: #2a2413; --goldink: #e7c65a; --longbg: #12291e; --long: #5fd39a; --shortbg: #32161a; --short: #ff8a80;
    --accent: #6b9bff; --warnbg: #2e2612; --warn: #f3c969;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
/* iOS home-screen apps: on a page too short to scroll, fixed bottom bars float a
   status-bar height above the bottom (Live/History); Settings scrolls so it was fine */
html { min-height: calc(100% + env(safe-area-inset-top, 0px)); }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; padding-bottom: calc(76px + var(--safe-b)); -webkit-tap-highlight-color: transparent; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: #05070f; color: #fff; box-shadow: inset 0 -2px 0 #c9a227; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand img { border-radius: 7px; }
.brand b { color: var(--gold); }
/* signal-engine status: coloured light + a few words; tap for the detail */
.status[hidden] { display: none; }
.status { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; margin: -4px -4px -4px 0; padding: 4px 11px 4px 9px; border-radius: 99px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); color: #d7dae2; font: 600 12.5px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; letter-spacing: .01em; white-space: nowrap; cursor: pointer; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: #666; flex: none; }
.status.online .dot { background: #3ecf8e; box-shadow: 0 0 0 3px rgba(62,207,142,.18); }
.status.paused .dot { background: #f3c969; box-shadow: 0 0 0 3px rgba(243,201,105,.18); }
.status.offline .dot { background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255,107,107,.18); }
.status.online { color: #bdf0d8; } .status.paused { color: #f7e2ad; } .status.offline { color: #ffc1bb; }
/* 5-tap screen check (troubleshooting) */
.diag { position: fixed; left: 12px; right: 12px; top: calc(56px + env(safe-area-inset-top, 0px)); z-index: 20; padding: 12px; border-radius: 12px; background: #000; color: #9ef0c4; border: 1px solid #3ecf8e; font: 12px/1.5 "SF Mono", Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.diag b { display: block; color: #fff; margin-bottom: 4px; }
main { max-width: 640px; margin: 0 auto; padding: 14px 16px; }
h1 { font-size: 21px; margin: 6px 0 12px; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 12px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .center { text-align: center; } .small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.trade-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.posted { margin: -4px 0 10px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--muted); }
.pill.long { background: var(--longbg); color: var(--long); } .pill.short { background: var(--shortbg); color: var(--short); }
.pill.gold { background: var(--goldbg); color: var(--goldink); } .pill.warn { background: var(--warnbg); color: var(--warn); }
.signal { background: var(--goldbg); border-radius: 10px; padding: 10px 12px; font: 13px/1.6 "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.signal .t { font-weight: 700; }
.line { display: flex; align-items: flex-start; gap: 8px; }
.line span { flex: 1; }
.you { margin: 6px 0 0; padding: 8px 10px; border-left: 3px solid var(--gold); background: rgba(201,162,39,.08); border-radius: 6px; font-size: 13.5px; }
.you div + div { margin-top: 2px; }
.timeline { list-style: none; margin: 10px 0 0; padding: 0; }
.timeline li { border-top: 1px solid var(--line); padding: 10px 0; }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline .what { font-weight: 600; margin: 2px 0; }
button, .btn { font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 10px 14px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; }
button.ghost { background: transparent; color: var(--accent); }
button.copy { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; background: transparent; color: var(--accent); flex: none; }
button.block, .btn.block { width: 100%; box-sizing: border-box; }
button.danger { border-color: var(--short); background: transparent; color: var(--short); }
button:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1; min-width: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 15px; }
input, select { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; margin-top: 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
label.check input { width: 22px; height: 22px; margin: 0; }
input.mono { font-family: "SF Mono", Menlo, Consolas, monospace; letter-spacing: .03em; text-transform: uppercase; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warnbg); color: var(--warn); font-size: 14px; margin-bottom: 12px; }
.notice.info { background: var(--goldbg); color: var(--goldink); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
/* ---- bottom tab bar: dark navy with gold accents, same in both themes ---- */
.tabs[hidden] { display: none; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: #05070f; border-top: 1px solid rgba(201,162,39,.45); box-shadow: 0 -8px 24px rgba(0,0,0,.25); padding-bottom: var(--safe-b); z-index: 5; }
/* keyboard up (iOS/Android): hide the bottom bars, like a native app */
@media (max-width: 899px) { body.kb-open .tabs, body.kb-open .savebar { display: none; } }
.tabs a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 58px; color: #8b91a0; text-decoration: none; font-weight: 600; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; transition: color .15s ease; }
.tabs a svg { transition: transform .15s ease; }
.tabs a.on { color: #e7c65a; }
.tabs a.on::before { content: ''; position: absolute; top: -1px; left: 50%; width: 36px; height: 3px; margin-left: -18px; border-radius: 0 0 3px 3px; background: linear-gradient(90deg, #f6e2a0, #9c7a2e); }
.tabs a.on svg { transform: translateY(-1px); }
.tabs a:active { color: #f6e2a0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); background: #16171b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10; max-width: 90vw; }
.foot { font-size: 12px; color: var(--muted); margin-top: 18px; }

/* ---- page headers & back navigation ---- */
.pagehead { position: sticky; top: calc(48px + env(safe-area-inset-top, 0px)); z-index: 4; display: grid; grid-template-columns: minmax(88px, auto) 1fr minmax(88px, auto); align-items: center; gap: 8px; margin: -14px -16px 14px; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.pagehead h1 { margin: 0; font-size: 18px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pagehead.inline { position: static; margin: 0 0 10px; padding: 0; border: 0; background: none; }
.pagehead-spacer { display: block; }
button.back { justify-self: start; min-height: 44px; min-width: 88px; padding: 8px 14px; border-radius: 10px; font-size: 16px; background: var(--card); color: var(--accent); border: 1px solid var(--line); text-align: left; }
button.done { justify-self: end; min-height: 44px; min-width: 88px; padding: 8px 16px; font-size: 16px; }
.pagetitle { margin-top: 4px; }
.plainlink { text-decoration: none; color: inherit; } .plainlink h2 { margin: 0; }
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
button.big, .btn.big { min-height: 50px; font-size: 16px; }
button, .btn { min-height: 44px; }
button.copy { min-height: 36px; }
.btn.ghost { background: transparent; color: var(--accent); }
a.btn.block { display: block; margin-top: 10px; }

/* ---- settings save bar ---- */
.savebar { position: fixed; left: 0; right: 0; bottom: calc(58px + var(--safe-b)); z-index: 6; display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--card); border-top: 2px solid var(--gold); box-shadow: 0 -6px 18px rgba(0,0,0,.18); }
.savebar[hidden] { display: none; }
.savebar-msg { flex: 1; font-weight: 600; font-size: 14px; }
.savebar button { min-width: 96px; }
body.has-savebar { padding-bottom: calc(146px + var(--safe-b)); }

/* ---- phones & tablets: an app-style frame ----
   The page itself never scrolls here: header / scrolling content / tab bar
   form one full-height column, and only #scroller scrolls. iOS mis-places
   position:fixed bars when the DOCUMENT scrolls (after the keyboard closes
   it can leave the page shifted, and at the bottom of a page there's no room
   to nudge it back), so here nothing is fixed to the screen at all. */
@media (max-width: 899px) {
  /* --app-h is set by app.js (real screen height, see frameHeight()) */
  html { height: var(--app-h, 100%); min-height: 0; overflow: hidden; overscroll-behavior: none; }
  body { height: var(--app-h, 100%); overflow: hidden; overscroll-behavior: none; display: flex; flex-direction: column; padding-bottom: 0; }
  body.has-savebar { padding-bottom: 0; }
  .bar { position: relative; flex: none; }
  .scroller { order: 1; flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .tabs { order: 2; position: relative; bottom: auto; flex: none; }
  main { padding-bottom: 24px; }
  /* sticky inside the scroller now, so it pins to the top of the content */
  .pagehead { top: 0; }
  /* unsaved-changes bar: pinned to the bottom of the content, above the tabs */
  .savebar { position: sticky; bottom: 0; left: auto; right: auto; margin: 16px -16px -24px; }
  .toast { bottom: calc(76px + var(--safe-b)); }
}

/* ---- desktop: tabs move to the top, content a little wider ---- */
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  body.has-savebar { padding-bottom: 96px; }
  main { max-width: 760px; }
  .tabs { position: sticky; top: 48px; bottom: auto; justify-content: center; gap: 8px; border-top: 0; border-bottom: 1px solid rgba(201,162,39,.45); box-shadow: none; padding: 0; }
  .tabs a { flex: 0 0 auto; flex-direction: row; gap: 8px; height: 48px; padding: 0 22px; font-size: 12.5px; }
  .tabs a svg { width: 18px; height: 18px; }
  .tabs a.on::before { top: auto; bottom: -1px; border-radius: 3px 3px 0 0; }
  .tabs a:hover { color: #e7c65a; }
  .pagehead { top: 96px; margin-top: 0; }
  .savebar { bottom: 0; justify-content: center; }
  .savebar-msg { flex: 0 1 auto; margin-right: 12px; }
  .toast { bottom: 90px; }
}
/* weekly progress card */
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 4px 0 10px; }
.meter span { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.card.week.hit { border-color: var(--gold); }
.card.week p:last-child { margin-bottom: 0; }
/* ---- trade ticket (opening instruction) ---- */
.ticket { border-radius: 12px; border: 1px solid var(--line); border-left: 4px solid var(--muted); background: var(--bg); padding: 12px 14px; }
.ticket.long { border-left-color: var(--long); } .ticket.short { border-left-color: var(--short); }
.ticket-head { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 700; line-height: 1.3; }
.ticket-icon { font-size: 15px; flex: none; }
.ticket-sub { margin: 2px 0 10px; font-size: 13px; color: var(--muted); }
.ticket-rows { display: grid; grid-template-columns: 64px 1fr; gap: 8px 12px; margin: 0; padding: 10px 0 0; border-top: 1px solid var(--line); }
.ticket-rows dt { color: var(--muted); font-size: 13px; font-weight: 600; padding-top: 1px; }
.ticket-rows dd { margin: 0; font-weight: 600; }
.ticket-rows dd small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.ticket-rows code { font: 600 15px "SF Mono", Menlo, Consolas, monospace; padding: 1px 6px; border-radius: 6px; background: var(--goldbg); color: var(--goldink); }
.ticket-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; }
.ticket-section-title { font-weight: 700; margin-bottom: 2px; }
.ticket-detail { margin: 8px 0 0; }
.ticket-foot { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
/* follow-up updates: icon + bold action, plain detail under it */
.upd-icon { display: inline-block; width: 1.5em; }
.upd-detail { font-size: 14px; color: var(--muted); margin: 2px 0 0 1.5em; }

/* ---- live progress (stop -> target bar) ---- */
.progress { margin: 12px 0 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.progress-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.progress-move { font-size: 22px; font-weight: 700; }
.progress-move.up { color: var(--long); } .progress-move.down { color: var(--short); }
.track { position: relative; height: 10px; border-radius: 99px; margin: 10px 0 4px; display: flex; overflow: visible; background: var(--line); }
.track .zone { display: none; }
.track::before { content: ""; position: absolute; inset: 0; border-radius: 99px; background: linear-gradient(90deg, var(--shortbg) 0, var(--shortbg) var(--entry-at, 50%), var(--longbg) var(--entry-at, 50%), var(--longbg) 100%); }
.mk { position: absolute; top: 50%; transform: translate(-50%, -50%); }
.mk.entry { width: 2px; height: 18px; background: var(--muted); }
.mk.stopmk { width: 0; height: 0; top: 50%; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 7px solid var(--short); margin-top: 12px; }
.mk.price { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--line); }
.mk.price.up { background: var(--long); } .mk.price.down { background: var(--short); }
.progress-ends { display: flex; justify-content: space-between; margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips.filter { margin: 0 0 12px; }
button.chip { padding: 6px 14px; border-radius: 99px; background: transparent; color: var(--muted); border: 1px solid var(--line); font-size: 13px; }
button.chip.on { background: var(--goldbg); color: var(--goldink); border-color: var(--gold); }

/* ---- win / loss / breakeven results ---- */
.pill.result { font-size: 11px; font-weight: 600; padding: 1px 8px; display: inline-flex; align-items: center; gap: 4px; }
.rsym { font-size: 13px; line-height: 1; } .rsym.win { color: #1f9d63; } .rsym.loss { color: #c9372c; } .rsym.be { color: #b8860b; }

.progress.compact .progress-move { font-size: 17px; }

.progress-ends { position: relative; display: block; height: 16px; margin-top: 10px; }
.progress-ends span { position: absolute; top: 0; }
.progress-ends .end-l { left: 0; } .progress-ends .end-r { right: 0; }
.progress-ends .end-m { transform: translateX(-50%); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.pager button { min-height: 44px; min-width: 104px; }
.pager button:disabled { opacity: .35; cursor: default; }
