/* Caddie, the app. Flat and square-cut: no rounded corners, no shadows, one loud colour (the flag) used sparingly.
   Colours come from brand.css (written by the build from src/brand.js). Phone first; wider screens get more room. */
@font-face { font-family: "Bricolage Grotesque"; src: url("/fonts/bricolage-grotesque.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Hanken Grotesk"; src: url("/fonts/hanken-grotesk-normal.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  color-scheme: dark;
  --display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --body: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --gap: 12px;
  --pad: max(16px, env(safe-area-inset-left, 0px));
  --tabs: 62px;
}
* { box-sizing: border-box; }
html { background: var(--night); }
body { margin: 0; background: var(--night); color: var(--chalk); font: 400 16px/1.45 var(--body); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums lining-nums; min-height: 100dvh; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--display); font-weight: 650; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: 30px; line-height: 1.08; }
h2 { font-size: 21px; line-height: 1.15; }
h3 { font: 650 15px/1.2 var(--body); }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--flag); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--chalk); color: var(--night); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }
.noscript { padding: 24px var(--pad); }

/* ---- the top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px var(--pad); padding-top: max(10px, env(safe-area-inset-top, 0px)); background: var(--night); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font: 700 20px/1 var(--display); letter-spacing: -0.02em; }
.mark { width: 26px; height: 26px; flex: none; }
.mark .pin { fill: var(--flag); }
.top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mode { display: flex; align-items: baseline; gap: 8px; background: var(--turf); border: 1px solid var(--line); padding: 7px 10px; min-width: 0; }
.mode-name { font-weight: 650; font-size: 13px; color: var(--gold); }
.mode.real .mode-name { color: var(--green); }
.mode-money { font-weight: 650; font-size: 14px; white-space: nowrap; }

/* ---- buttons, fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border: 1px solid var(--chalk); background: var(--chalk); color: var(--night); font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-line { background: transparent; color: var(--chalk); border-color: var(--line); }
.btn-line:hover { background: var(--turf); border-color: var(--mist); }
.btn-long { background: var(--green); border-color: var(--green); color: #04130c; }
.btn-long:hover { background: #22c98b; }
.btn-short { background: var(--red); border-color: var(--red); color: #1a0502; }
.btn-short:hover { background: #ff6a56; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-wide { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--chalk); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--mist); }
.input { display: flex; align-items: center; border: 1px solid var(--line); background: var(--turf); min-height: 46px; }
.input:focus-within { border-color: var(--chalk); }
.input > span { padding: 0 0 0 12px; color: var(--mist); font-weight: 600; }
.input > input { flex: 1; min-width: 0; width: 100%; border: 0; background: none; padding: 0 12px; height: 44px; font-weight: 650; font-size: 17px; outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 32px; padding: 0 10px; background: none; border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--mist); }
.chip:hover { color: var(--chalk); border-color: var(--mist); }
.chip[aria-pressed="true"] { color: var(--night); background: var(--chalk); border-color: var(--chalk); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); }
.seg > button { min-height: 44px; background: none; border: 0; font-weight: 700; color: var(--mist); }
.seg > button + button { border-left: 1px solid var(--line); }
.seg > button[aria-pressed="true"] { background: var(--chalk); color: var(--night); }
.seg.side > button[aria-pressed="true"][data-v="long"] { background: var(--green); color: #04130c; }
.seg.side > button[aria-pressed="true"][data-v="short"] { background: var(--red); color: #1a0502; }

/* ---- the view */
main { padding: 18px var(--pad) calc(var(--tabs) + 28px + env(safe-area-inset-bottom, 0px)); max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; outline: none; }
.head { display: flex; flex-direction: column; gap: 6px; }
.sub { color: var(--mist); max-width: 60ch; }
.card { border: 1px solid var(--line); background: var(--turf); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.muted { color: var(--mist); }
.small { font-size: 13px; }
.up { color: var(--green); }
.down { color: var(--red); }
.num { font-weight: 650; }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.tag.long { color: var(--green); border-color: var(--green); }
.tag.short { color: var(--red); border-color: var(--red); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: 14px; }
.kv > dt { color: var(--mist); margin: 0; }
.kv > dd { margin: 0; font-weight: 650; text-align: right; }
dl { margin: 0; }
.empty { border: 1px dashed var(--line); padding: 22px 16px; color: var(--mist); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }

/* ---- tabs: along the bottom on a phone */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--night); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabs > button { position: relative; height: var(--tabs); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; background: none; border: 0; border-top: 2px solid transparent; color: var(--mist); font-size: 12px; font-weight: 650; }
.tabs > button svg { width: 22px; height: 22px; }
.tabs > button[aria-current="page"] { color: var(--chalk); border-top-color: var(--flag); }
.count { position: absolute; top: 8px; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px; background: var(--flag); color: #1a0502; font: 800 11px/17px var(--body); font-style: normal; text-align: center; }

/* ---- setups */
.setup { gap: 14px; }
.setup-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.coin { font: 700 22px/1 var(--display); letter-spacing: -0.02em; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.levels > div { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.levels > div + div { border-left: 1px solid var(--line); }
.levels b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
.levels span { font-size: 12px; color: var(--mist); font-weight: 600; }
.record { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--mist); }
.record b { color: var(--chalk); }
.spark { display: block; width: 100%; height: 64px; }
.done { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center; font-size: 14px; }

/* ---- the chart and the ticket */
.chart { display: block; width: 100%; height: 230px; border: 1px solid var(--line); background: var(--turf); }
.trade { display: flex; flex-direction: column; gap: 16px; }
.pick { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pick-coin { display: flex; align-items: baseline; gap: 10px; background: none; border: 0; padding: 0; text-align: left; }
.pick-coin .coin { font-size: 28px; }
.pick-coin i { font-style: normal; color: var(--mist); font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.px { font: 650 22px/1 var(--display); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sum { border: 1px solid var(--line); }
.sum > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; font-size: 14px; }
.sum > div + div { border-top: 1px solid var(--line); }
.sum b { font-weight: 700; }
.warn { border: 1px solid var(--gold); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.warn.hard { border-color: var(--red); }
.warn h3 { color: var(--gold); }
.warn.hard h3 { color: var(--red); }
.warn .chips { margin-top: 2px; }
.coins { display: flex; flex-direction: column; max-height: 60dvh; overflow: auto; border: 1px solid var(--line); }
.coins > button { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: baseline; padding: 12px; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.coins > button:hover { background: var(--turf); }
.coins b { font-weight: 700; }

/* ---- open trades */
.pos-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pnl { font: 700 24px/1 var(--display); }
.track { position: relative; height: 26px; margin: 2px 0 14px; }
.track::before { content: ""; position: absolute; left: 0; right: 0; top: 12px; height: 2px; background: var(--line); }
.track > i { position: absolute; top: 5px; width: 2px; height: 16px; background: var(--mist); }
.track > i.stop { background: var(--red); }
.track > i.target { background: var(--green); }
.track > i.now { top: 2px; width: 10px; height: 22px; margin-left: -5px; background: var(--chalk); }
.track > span { position: absolute; top: 26px; font-size: 11px; color: var(--mist); font-weight: 600; transform: translateX(-50%); white-space: nowrap; }
.track > span.l { transform: none; }
.track > span.r { transform: translateX(-100%); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- the coach */
.score { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.grade { width: 84px; height: 84px; display: grid; place-items: center; border: 2px solid var(--chalk); font: 800 46px/1 var(--display); }
.grade.sm { width: 34px; height: 34px; font-size: 19px; border-width: 1px; flex: none; }
.grade.S, .grade.A { border-color: var(--green); color: var(--green); }
.grade.C { border-color: var(--gold); color: var(--gold); }
.grade.D { border-color: var(--red); color: var(--red); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stats > div { background: var(--turf); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stats b { font: 700 20px/1.1 var(--display); }
.stats span { font-size: 12px; color: var(--mist); font-weight: 600; }
.habit { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.habit:first-child { border-top: 0; padding-top: 0; }
.habit p { grid-column: 1 / -1; color: var(--mist); font-size: 14px; }
.tradeline { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; width: 100%; padding: 12px 0; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; }
.tradeline:first-child { border-top: 0; }
.parts { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px 46px; }
.part { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; font-size: 14px; }
.part p { grid-column: 1 / -1; color: var(--mist); font-size: 13px; }
.bar { height: 6px; background: var(--line); }
.bar > i { display: block; height: 100%; background: var(--chalk); }
details > summary { cursor: pointer; font-weight: 650; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; font-weight: 700; color: var(--mist); }
details[open] > summary::after { content: "−"; }
details > .stack { margin-top: 12px; }

/* ---- the bag */
.bagrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.bagrow:first-child { border-top: 0; }
input[type="range"] { width: 100%; accent-color: var(--flag); height: 32px; }

/* ---- toasts and the sheet */
/* (toasts sit under the top bar, never over the buttons at the foot of a card) */
.toasts { position: fixed; left: 0; right: 0; top: calc(66px + env(safe-area-inset-top, 0px)); z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 var(--pad); pointer-events: none; }
.toast { pointer-events: auto; width: 100%; max-width: 520px; background: var(--chalk); color: var(--night); padding: 12px 14px; font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.toast button { background: none; border: 0; font-weight: 800; text-decoration: underline; color: var(--night); padding: 0; }
.sheet { width: min(560px, 100%); max-width: 100%; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 1px solid var(--line); border-bottom: 0; background: var(--night); color: var(--chalk); }
.sheet::backdrop { background: rgba(3, 8, 6, 0.72); }
.sheet-in { display: flex; flex-direction: column; gap: 14px; padding: 18px var(--pad) calc(18px + env(safe-area-inset-bottom, 0px)); overflow: auto; max-height: 92dvh; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.x { background: none; border: 1px solid var(--line); width: 36px; height: 36px; flex: none; font-weight: 700; }
.choice { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; width: 100%; padding: 14px; background: var(--turf); border: 1px solid var(--line); }
.choice:hover, .choice[aria-pressed="true"] { border-color: var(--chalk); }
.choice b { font-size: 16px; }
.choice span { color: var(--mist); font-size: 14px; }

@media (min-width: 900px) {
  :root { --tabs: 0px; }
  .tabs { position: sticky; top: 61px; bottom: auto; grid-template-columns: repeat(5, auto); justify-content: center; gap: 4px; border-top: 0; border-bottom: 1px solid var(--line); }
  .tabs > button { height: 48px; flex-direction: row; gap: 8px; padding: 0 18px; font-size: 14px; border-top: 0; border-bottom: 2px solid transparent; }
  .tabs > button[aria-current="page"] { border-bottom-color: var(--flag); }
  .count { position: static; }
  body { display: flex; flex-direction: column; }
  .tabs { order: 1; }
  main { order: 2; width: 100%; padding-bottom: 48px; }
  .toasts { order: 3; top: 118px; }
  .sheet { margin: auto; border-bottom: 1px solid var(--line); }
  main.wide { max-width: 1080px; }
  .trade { display: grid; grid-template-columns: 1.15fr 1fr; align-items: start; gap: 24px; }
  .chart { height: 380px; }
  h1 { font-size: 36px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 0.22s ease-out; }
  @keyframes rise { from { transform: translateY(-8px); opacity: 0; } }
}
