:root {
  color-scheme: light dark;
  --bg: #f3f4f1; --card: #ffffff; --ink: #161a17; --muted: #5b645d; --line: #dde1da;
  --accent: #1d5c46; --accent-ink: #ffffff;
  --good: #17713f; --bad: #b3261e; --warn-bg: #fff2cf; --warn-ink: #6b4700; --bad-bg: #fde7e5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101311; --card: #1a1f1b; --ink: #edf1ed; --muted: #a0aaa2; --line: #2e352f;
    --accent: #6fcfa6; --accent-ink: #08140f;
    --good: #66d492; --bad: #ff8a80; --warn-bg: #3b2f0e; --warn-ink: #ffd978; --bad-bg: #3d1a17;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
main, .top { max-width: 560px; margin: 0 auto; }
main { padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
h1 { font-size: 26px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 0 0 10px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.label { font-size: 13px; color: var(--muted); }
.sub { font-size: 14px; color: var(--muted); margin-top: 4px; }
.aside { font-size: 13px; color: var(--muted); font-weight: 400; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.notice, .stop { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: var(--warn-bg); color: var(--warn-ink); }
.stop { background: var(--bad-bg); color: var(--bad); font-weight: 650; }

.balance { font-size: 48px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.track { position: relative; height: 10px; background: var(--line); border-radius: 6px; margin-top: 16px; }
.fill { height: 100%; width: 0; background: var(--accent); border-radius: 6px; }
.mark { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--ink); border-radius: 2px; }
.track-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

.step { border-left-width: 6px; }
.step.on { border-left-color: #d69a00; }
.step.off { border-left-color: var(--good); }
.state { font-size: 22px; font-weight: 700; }

.cap { margin-bottom: 12px; }
.cap-head { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.cap .track { height: 8px; margin-top: 6px; }
.cap.loss .fill { background: var(--bad); }
.cap.profit .fill { background: var(--good); }
.cap.hit .cap-head { font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 8px; }
.stat .v { font-size: 19px; font-weight: 650; }
.stat .k { font-size: 12px; color: var(--muted); }

.strip { font-size: 14px; padding: 10px 14px; margin-bottom: 10px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-ink); }
.strip:empty { display: none; }
.strip.stopped { background: var(--bad-bg); color: var(--bad); font-weight: 650; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row > * { min-width: 0; }
.field { display: block; font-size: 13px; color: var(--muted); margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.field legend { padding: 0; margin-bottom: 4px; }
input[type="text"], input[type="date"], select {
  display: block; width: 100%; min-width: 0; height: 46px; margin-top: 4px; padding: 0 12px;
  font-size: 16px; /* below 16px iOS zooms on focus */
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input[type="date"] { -webkit-appearance: none; appearance: none; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
.signed { display: flex; gap: 6px; margin-top: 4px; }
.signed input[type="text"] { margin-top: 0; }
.sign { flex: 0 0 46px; height: 46px; font-size: 22px; font-weight: 700; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 8px; font-size: 15px; color: var(--ink); white-space: nowrap; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }
.tabs { background: var(--card); margin-bottom: 12px; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -4px 0 12px; }
.chips button { min-height: 38px; padding: 0 14px; background: transparent; border: 1px solid var(--line); border-radius: 20px; }

.warnings { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.warnings ul { margin: 4px 0 0; padding-left: 18px; }
.error { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.edit-banner { font-weight: 650; margin-bottom: 12px; }
.primary { width: 100%; min-height: 52px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; font-weight: 700; font-size: 17px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; min-height: 40px; padding: 0 14px; }
.wide { width: 100%; margin-top: 8px; }
.fine { font-size: 12px; color: var(--muted); text-align: center; margin: 10px 0 0; }

.list { list-style: none; margin: 0; padding: 0; }
.bet { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; overflow-wrap: anywhere; }
.bet-meta { font-size: 13px; color: var(--muted); }
.bet-pick { display: flex; justify-content: space-between; gap: 10px; font-size: 17px; font-weight: 650; margin-top: 4px; }
.bet-pick .price { white-space: nowrap; overflow-wrap: normal; }
.bet-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: 14px; margin-top: 6px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-ink); }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.results button { min-height: 44px; background: transparent; border: 1px solid var(--line); border-radius: 10px; font-weight: 650; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions button { font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 24px; font-size: 14px; width: max-content; max-width: 90vw; z-index: 3; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 2; }
.tabbar button { flex: 1; min-height: 58px; background: transparent; border: 0; color: var(--muted); font-weight: 600; border-top: 3px solid transparent; }
.tabbar button[aria-current="page"] { color: var(--ink); border-top-color: var(--accent); }

@media (max-width: 360px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .balance { font-size: 40px; }
  .seg span { font-size: 13px; }
  .row { grid-template-columns: 1fr; gap: 0; }
}
