/*
 * Clef app (css/app.css): /app only, after css/clef.css. The round bar, the decision card, the side panel,
 * the hour in progress and your rounds. Mobile first, checked at 360 px; no horizontal scroll at any width.
 * CSP: no inline styles; dynamic values arrive as custom properties set through the CSSOM (--p, --a, --b, --s, --x).
 */

/* ------------------------------------------------------------------ round bar */

.rb { background: var(--alabaster); border-bottom: 1px solid var(--line); padding-top: clamp(22px, 4vw, 40px); }
.rb-in { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.rb-left { display: grid; gap: 6px; min-width: 0; }
.rb-eyebrow { gap: 10px; flex-wrap: wrap; }
.rb-title { font: 600 clamp(28px, 4.4vw, 46px)/1.05 var(--display); letter-spacing: -.03em; color: var(--ink); font-variant-numeric: tabular-nums; }
.rb-sub { font: 500 13.5px/1.4 var(--mono); color: var(--muted); letter-spacing: -.01em; }
.rb-right { display: grid; justify-items: end; gap: 2px; }
.rb-count { font: 600 clamp(30px, 4.6vw, 48px)/1 var(--mono); letter-spacing: -.04em; color: var(--ink); font-variant-numeric: tabular-nums; }
.rb-count-k { font: 600 11.5px/1.3 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.rb-prog { position: relative; height: 3px; margin-top: clamp(18px, 3vw, 28px); background: var(--line); border-radius: 3px 3px 0 0; overflow: hidden; }
.rb-prog-fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--p, 0) * 100%); background: linear-gradient(90deg, var(--carrot), var(--orange)); transition: width 1s linear; }

.rb-chip, .side-chip { height: 24px; font-size: 12px; letter-spacing: 0; text-transform: none; }
.chip.is-open { background: var(--chip); color: var(--rust); }
.chip.is-soon { background: var(--concrete); color: var(--muted); }
.chip.is-soon .dot { background: var(--faint); }
.chip.is-ok { background: #e6f4ec; color: var(--good); }
.chip.is-ok .dot { background: var(--good); }

@media (max-width: 560px) {
  .rb-in { align-items: flex-start; }
  .rb-right { justify-items: start; grid-auto-flow: column; align-items: baseline; gap: 10px; }
  .rb-count { font-size: 30px; }
}

/* ------------------------------------------------------------------ grid */

.app-grid { display: grid; grid-template-columns: minmax(0, 1fr) 368px; gap: 28px; align-items: start; margin-top: clamp(20px, 3vw, 32px); }
.app-main { display: grid; gap: 28px; min-width: 0; }
.app-side { position: sticky; top: calc(var(--hdr-h) + 16px); min-width: 0; }
.app-yours { margin-top: clamp(36px, 5vw, 56px); margin-bottom: clamp(56px, 8vw, 96px); }

@media (max-width: 1000px) {
  .app-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .app-side { position: static; order: 2; }
  .app-main { display: contents; }
  .app-main > .card { order: 1; }
  .app-main > .live { order: 3; }
}

/* ------------------------------------------------------------------ the decision card */

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: clamp(16px, 2.6vw, 28px); box-shadow: var(--shadow-1); min-width: 0; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px 20px; flex-wrap: wrap; }
.card-titles { display: grid; gap: 6px; min-width: 0; }
.card > *, .live > *, .side-card > * { min-width: 0; }
.card-title { font: 600 clamp(20px, 2.4vw, 24px)/1.2 var(--display); letter-spacing: -.02em; color: var(--ink); }
.card-view button { display: inline-flex; align-items: center; gap: 6px; }
.card-note { font-size: 13.5px; line-height: 1.45; color: var(--muted); max-width: 520px; }

.card-banner { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; padding: 12px 14px; border-radius: var(--r); background: #eef8f2; border: 1px solid #c5e6d2; color: #1d5e3e; font-size: 14px; line-height: 1.45; }
.card-banner-ico { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--good); color: #fff; margin-top: -1px; }
.card-banner-ico svg { width: 12px; height: 12px; }

.card-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-top: 18px; padding-bottom: 4px; }
.card-legend { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 2px 12px; min-height: 36px; min-width: 0; max-width: 100%; font-size: 13px; color: var(--muted); }
.ref-legend { display: inline-flex; align-items: center; gap: 8px; }
.ref-legend.is-waiting { opacity: .55; }
.ref-key { width: 2px; height: 14px; border-radius: 2px; background: var(--eclipse); opacity: .6; }
.ref-note { font-size: 12.5px; line-height: 1.4; color: var(--muted); text-wrap: pretty; }
.card-btns { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.card-btns .btn:disabled { opacity: .5; }

.qs { display: grid; }
.q { padding-block: 22px 24px; border-top: 1px solid var(--line); min-width: 0; }
.q:first-child { margin-top: 14px; }
.q:last-child { padding-bottom: 4px; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.q-label { font: 600 12px/1 var(--mono); letter-spacing: .06em; color: var(--orange-text); text-transform: uppercase; }
.q-asset { display: inline-flex; align-items: center; gap: 6px; font: 600 12.5px/1 var(--mono); color: var(--ink); }
.q-text { margin: 10px 0 18px; font: 600 clamp(16.5px, 1.8vw, 18.5px)/1.35 var(--display); letter-spacing: -.012em; color: var(--ink); text-wrap: balance; }

/* the kit's rows inside the card: keep the helper text on phones too, it carries the score buckets */
.card .pb-group { gap: 16px; }
.card .pb .pb-sub { font-size: 12.5px; color: var(--muted); }
@media (max-width: 420px) {
  .card .pb .pb-sub { display: inline; }
  .card .pb .pb-name { font-size: 14.5px; }
}
@media (max-width: 359px) {
  .card .pb .pb-sub { display: none; }
}
.card.is-readonly .pb-num { background: var(--alabaster); }

/* ------------------------------------------------------------------ as a Clef call */

.call { margin-top: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.call-lede { font-size: 14.5px; color: var(--muted); max-width: 640px; }
.call-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 1180px) { .call-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); } }
.call .code { min-width: 0; }
.call .code pre { max-height: 440px; overflow: auto; white-space: pre; }
.call-pending { font-size: 13px; color: var(--muted); }
@media (max-width: 560px) { .call .code pre { font-size: 12px; padding: 14px; } }

/* ------------------------------------------------------------------ side panel */

.side-card { background: var(--cream); border: 1.5px solid var(--amber); border-radius: var(--r-lg); padding: clamp(18px, 2.4vw, 24px); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.side-head .panel-label { font-size: 12.5px; }

.stake { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.stake-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.stake-field { display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--paper); transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.stake-field:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255, 94, 31, .16); }
.stake-field .logo { box-shadow: none; }
.stake-input { flex: 1; min-width: 0; width: 0; height: 100%; border: 0; padding: 0; background: transparent; outline: none; font: 600 21px/1 var(--mono); letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.stake-input.is-bad { color: var(--bad); }
.stake-input:disabled { color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
.stake-unit { font: 600 13px/1 var(--mono); color: var(--muted); }
.stake-meta { display: flex; justify-content: space-between; gap: 10px; min-height: 18px; font: 500 12.5px/1.4 var(--mono); color: var(--muted); }
.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 2px; }
.preset { height: 32px; border-radius: 999px; border: 1px solid var(--amber-soft); background: var(--paper); font: 500 12.5px/1 var(--mono); color: var(--rust); transition: border-color .2s var(--ease), background-color .2s var(--ease), color .2s var(--ease); }
.preset:hover:not(:disabled) { border-color: var(--amber); color: var(--orange-deep); }
.preset[aria-pressed='true'] { background: var(--chip); border-color: var(--amber); color: var(--ink); font-weight: 600; }
.preset:disabled { opacity: .45; }
.stake-lim { font-size: 12px; color: var(--muted); }

.stats { margin: 18px 0 18px; border-top: 1px solid var(--amber-soft); }
.stat { padding: 14px 0; border-bottom: 1px solid var(--amber-soft); display: grid; gap: 6px; }
.stat dt { font: 600 11.5px/1.2 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--rust); opacity: .85; }
.stat dd { margin: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.stat dd.is-col, .stat-range dd { display: grid; gap: 0; }
.stat-v { font: 600 19px/1.15 var(--mono); letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--muted); }

.rng-same { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.rng { display: flex; justify-content: space-between; gap: 12px; }
.rng-end { display: grid; gap: 3px; min-width: 0; }
.rng-end.is-best { justify-items: end; text-align: right; }
.rng-k { font-size: 11.5px; color: var(--muted); }
.rng-v { font: 600 15.5px/1.15 var(--mono); letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rng-p { font: 500 12.5px/1 var(--mono); color: var(--muted); min-height: 13px; }
.rng-p.up { color: var(--good); }
.rng-p.down { color: var(--bad); }
.rng-bar { position: relative; height: 6px; margin-top: 12px; border-radius: 999px; background: var(--sand); }
.rng-fill { position: absolute; top: 0; bottom: 0; left: calc(var(--a, 0) * 1%); width: calc((var(--b, 0) - var(--a, 0)) * 1%); border-radius: 999px; background: var(--orange); transition: left .5s var(--ease-out), width .5s var(--ease-out); }
.rng-stake { position: absolute; top: -4px; width: 2px; height: 14px; margin-left: -1px; left: calc(var(--s, 50) * 1%); border-radius: 2px; background: var(--eclipse); transition: left .5s var(--ease-out); }
.rng-exp { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 12px; }
.rng-ev { font: 600 13.5px/1.2 var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rng-ev.up { color: var(--good); }
.rng-ev.down { color: var(--bad); }
.rng-note { margin-top: 10px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }

.side-btn { margin-top: 2px; }
.side-btn.is-busy::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.1s var(--ease) infinite; }
.side-btn.btn-ghost:disabled { color: var(--good); border-color: #c5e6d2; background: #f3faf6; opacity: 1; }
.side-note { display: flex; align-items: flex-start; gap: 8px; margin-top: 12px; font-size: 13.5px; line-height: 1.45; color: var(--body); }
.side-note .ico { margin-top: 2px; color: var(--muted); }
.side-note.is-error { color: var(--bad); }
.side-note.is-error .ico { color: var(--bad); }
.side-note.is-soon { color: var(--rust); }
.side-note.is-soon .ico { color: var(--orange-2); }
.side-note.is-ok { color: var(--good); }
.side-note.is-ok .ico { color: var(--good); }
.side-fee { margin-top: 10px; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ the hour in progress */

.live { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: clamp(16px, 2.6vw, 28px); min-width: 0; }
.live-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--orange); animation: pulse 1.6s var(--ease) infinite; }
.live-title { margin-top: 8px; font: 600 clamp(17px, 2vw, 20px)/1.25 var(--display); letter-spacing: -.015em; color: var(--ink); font-variant-numeric: tabular-nums; }
.live-left { font: 600 14px/1 var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.live-prog { position: relative; height: 2px; margin-top: 16px; background: var(--line); border-radius: 2px; overflow: hidden; }
.live-prog-fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--p, 0) * 100%); background: var(--orange); transition: width 1s linear; }
.live-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px 36px; margin-top: 20px; }
@media (max-width: 720px) { .live-grid { grid-template-columns: minmax(0, 1fr); } }
.live-col { min-width: 0; }
.live-sub { margin-bottom: 12px; font: 600 11.5px/1.2 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }

.moves { display: grid; gap: 12px; }
.mv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(64px, 110px) 70px; align-items: center; gap: 12px; }
.mv-name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.mv-sym { font: 600 13.5px/1 var(--mono); color: var(--ink); }
.mv-full { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-bar { position: relative; height: 6px; border-radius: 999px; background: var(--concrete); }
.mv-mid { position: absolute; left: 50%; top: -3px; width: 1px; height: 12px; background: var(--line-2); }
.mv-fill { position: absolute; top: 0; bottom: 0; left: 50%; width: calc(var(--x, 0) * 50%); border-radius: 0 999px 999px 0; background: var(--orange); transition: width .6s var(--ease-out); }
.mv-fill.is-neg { left: auto; right: 50%; width: calc(var(--x, 0) * -50%); border-radius: 999px 0 0 999px; background: var(--rust); opacity: .75; }
.mv-val { font: 500 13.5px/1 var(--mono); text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.mv-val.up { color: var(--good); }
.mv-val.down { color: var(--bad); }
@media (max-width: 420px) { .mv-full { display: none; } .mv { grid-template-columns: minmax(0, 1fr) 72px 64px; gap: 10px; } }

.leads { display: grid; gap: 16px; }
.ld { display: grid; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--line); min-width: 0; }
.ld:last-child { border-bottom: 0; padding-bottom: 0; }
.ld-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ld-label { font: 600 11.5px/1 var(--mono); letter-spacing: .06em; color: var(--orange-text); }
.ld-detail { font: 500 12.5px/1.2 var(--mono); color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.live-empty { font-size: 13.5px; color: var(--muted); }
.live-soft { margin-top: 14px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.live-mine { margin-top: 18px; padding: 14px 16px; border-radius: var(--r-md); background: var(--cream); border: 1px solid var(--amber-soft); display: grid; gap: 8px; }
.live-mine .live-sub { margin-bottom: 2px; color: var(--rust); }
.mine-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.mine-k { color: var(--body); }
.mine-v { font: 600 14.5px/1.2 var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.mine-v.up { color: var(--good); }
.mine-v.down { color: var(--bad); }
.live-note { margin-top: 18px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.live.is-loading .moves, .live.is-loading .leads { opacity: .6; }

/* ------------------------------------------------------------------ your rounds */

.yours-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px 20px; flex-wrap: wrap; margin-bottom: 18px; }
.yours-title { margin-top: 6px; font: 600 clamp(22px, 2.8vw, 28px)/1.15 var(--display); letter-spacing: -.02em; color: var(--ink); }
.yours-sum { margin-top: 6px; font: 500 13px/1.4 var(--mono); color: var(--muted); }
.yours-empty { display: grid; justify-items: center; gap: 10px; padding: 36px 18px; border: 1px dashed var(--line-2); border-radius: var(--r-md); background: var(--alabaster); text-align: center; font-size: 14.5px; color: var(--muted); }
.yours-empty-ico { color: var(--faint); }
.yours-empty p { text-wrap: balance; }
.yours-empty .btn { margin-top: 4px; }

.yr-table { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: var(--paper); }
.yr { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1fr) minmax(0, .9fr); align-items: center; gap: 12px; padding: 13px 18px; border-top: 1px solid var(--line); font-size: 14px; color: var(--ink); }
.yr-head { border-top: 0; background: var(--alabaster); padding-block: 11px; font: 600 11px/1.2 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.yr .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.yr-k { display: none; }
.yr-n { display: inline-flex; align-items: center; gap: 6px; font: 600 14px/1 var(--mono); font-variant-numeric: tabular-nums; }
.yr-tx { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: var(--r-xs); color: var(--faint); transition: color .2s var(--ease), background-color .2s var(--ease); }
.yr-tx:hover { color: var(--orange-deep); background: var(--cream); }
.yr-when { font-size: 13px; color: var(--muted); }
.yr-pay.up { color: var(--good); }
.yr-pay.down { color: var(--bad); }
.yr-st { text-align: right; }
.nil-soft { font: 400 12.5px/1 var(--sans); color: var(--muted); }
.st { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 9px; border-radius: 999px; font: 600 12px/1 var(--sans); white-space: nowrap; }
.st .ico { width: 12px; height: 12px; }
.st-open { background: var(--chip); color: var(--rust); }
.st-live { background: var(--cream-2); color: var(--orange-deep); }
.st-settling { background: var(--concrete); color: var(--muted); }
.st-won { background: #e6f4ec; color: var(--good); }
.st-lost { background: #fbe7e2; color: var(--bad); }
.st-even { background: var(--concrete); color: var(--ink); }
.st-void { background: var(--concrete); color: var(--muted); }
.st-claimed { background: var(--paper); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line-2); }
.yr-foot { margin-top: 10px; font-size: 12.5px; color: var(--muted); }

@media (max-width: 720px) {
  .yr-head { display: none; }
  .yr { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: 'n n st' 'when when when' 'stake score pay'; gap: 6px 12px; padding: 14px 16px; }
  .yr:nth-child(2) { border-top: 0; }
  .yr-n { grid-area: n; font-size: 15px; }
  .yr-st { grid-area: st; }
  .yr-when { grid-area: when; }
  .yr-stake { grid-area: stake; }
  .yr-score { grid-area: score; }
  .yr-pay { grid-area: pay; }
  .yr .num { text-align: left; display: grid; gap: 3px; margin-top: 4px; }
  .yr .num .yr-k { display: block; font: 600 10.5px/1 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
  .yr-n .yr-k { display: none; }
  .yours-claim { width: 100%; }
}



/* ------------------------------------------------------------------ phones: tap targets, no zoom, keyboard */

@media (max-width: 760px) {
  /* review first, then stake and Submit side by side, so the iOS keyboard never hides the button */
  .side-card { display: flex; flex-direction: column; }
  .side-head { order: 0; }
  .stats { order: 1; margin: 0 0 18px; }
  .stake { order: 2; }
  .side-btn { order: 3; margin-top: 16px; }
  .side-note { order: 4; }
  .side-fee { order: 5; }
  .stats { border-top: 0; }
  .stat:first-child { padding-top: 0; }
}

/* touch: tablets too (768 portrait, coarse pointers at any width), like the shell's 44 px rule in css/clef.css */
@media (max-width: 820px), (pointer: coarse) {
  .preset { height: 44px; font-size: 13px; }
  .card-btns .btn, .yours-empty .btn { --btn-h: 44px; }
  .card .seg button, .card-view button { height: 44px; }
  .card .seg { padding: 2px; }
  .yr-tx { width: 44px; height: 44px; margin: -10px 0; }
  /* 16 px inputs: iOS Safari zooms the page on focus below that */
  .card .pb-num { height: 44px; }
  .card .pb-num input { font-size: 16px; }
  .card .pb.is-drag .pb-track { height: 44px; margin: -6px 0 -10px; }
}

/* ------------------------------------------------------------------ first paint holds its shape (CLS)
   The layout is built empty and filled a frame later (the schema and the chain come in async). Without these, the
   round bar, the card and the footer jump at 1024 px and up (CLS 0.71 measured at 1280). */
main[data-app-root] { min-height: calc(100svh - var(--hdr-h, 64px)); }
.rb-sub { min-height: 1.4em; }
.rb-count { min-height: 1em; }
.qs:empty { min-height: 880px; }
