/* Acca Lab — dark betting-app look.
   Layout: one column under a sticky header + stake ticker, five views switched by a bottom tab bar. */
:root {
  --bg: #0c1316;          /* deep teal-black */
  --surface: #131d21;
  --surface-2: #1a272c;
  --line: #24353b;
  --text: #e8efec;
  --muted: #8ba19b;
  --amber: #ffb547;       /* actions, brand */
  --amber-ink: #241500;
  --profit: #46d88f;
  --profit-bg: rgba(70, 216, 143, 0.12);
  --loss: #ff6f61;
  --loss-bg: rgba(255, 111, 97, 0.12);
  --even: #c7d2cf;
  --focus: #7cc4ff;

  --font-display: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --font-body: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --r: 12px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --tabbar-h: 62px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 var(--font-body);
  min-height: 100dvh;
  /* Start below the iPhone status bar so the sticky header never slides over the content */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  background: var(--bg); z-index: 30;
}
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: 0.02em; margin: 0; text-wrap: balance; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; margin-top: 8px; }
.num, td, .money input, .ticker { font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-inner, .ticker, main {
  max-width: 640px; margin: 0 auto;
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
}
.top-inner { display: flex; align-items: center; justify-content: space-between; padding-block: 10px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 1.5rem/1 var(--font-display); letter-spacing: 0.03em; text-transform: uppercase; }
.brand-mark { width: 30px; height: 30px; stroke: none; }
.ticker {
  display: flex; gap: 6px 14px; flex-wrap: wrap; padding-block: 0 10px;
  font: 500 0.95rem/1.2 var(--font-display); letter-spacing: 0.03em; color: var(--muted); text-transform: uppercase;
}
.ticker b { color: var(--text); font-weight: 600; }
.ticker .profit { color: var(--profit); }
.ticker .loss { color: var(--loss); }

main { padding-block: 16px; }
.view { display: flex; flex-direction: column; gap: 14px; animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0.4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } * { transition: none !important; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; flex-direction: row; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; white-space: nowrap; font-size: 0.95rem; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); }
.btn-ghost { background: transparent; border-style: dashed; color: var(--amber); }
.btn.wide { width: 100%; }
.btn.danger, .link-btn.danger { color: var(--loss); }
.btn:disabled { opacity: 0.5; cursor: default; }
.link-btn { background: none; border: 0; color: var(--amber); font-weight: 600; padding: 6px 2px; cursor: pointer; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: transparent; border: 1px solid var(--line); color: var(--text); cursor: pointer; flex: none;
}
.icon-btn.small { width: 28px; height: 28px; font-size: 1.1rem; background: var(--bg); }

.import-row { display: grid; grid-template-columns: 1.25fr 1.2fr 0.8fr; gap: 8px; }
.import-row .btn { padding: 0 8px; gap: 6px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Panels & fields ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.panel-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head { margin-top: 6px; }
.count { color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); margin: 0; max-width: 65ch; }
.hint.small { font-size: 0.85rem; }
.example-note { margin: 0; font-size: 0.9rem; color: var(--amber); }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; border: 1px dashed var(--line); border-radius: var(--r); margin: 0; }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
textarea { resize: vertical; line-height: 1.4; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
input:focus, select:focus, textarea:focus { border-color: var(--amber); outline: none; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid > label { min-width: 0; }
@media (max-width: 380px) { .field-grid { grid-template-columns: 1fr; } }
.suffix, .money { position: relative; display: flex; flex-direction: row; align-items: center; gap: 0; }
.suffix i { position: absolute; right: 12px; font-style: normal; color: var(--muted); pointer-events: none; font-size: 0.9rem; }
.suffix input { padding-right: 46px; }
.suffix select { padding-right: 56px; background-position: calc(100% - 50px) 50%, calc(100% - 45px) 50%; }
.money > span { position: absolute; left: 12px; color: var(--muted); font-weight: 600; pointer-events: none; }
.money input { padding-left: 28px; font: 600 1.5rem/1 var(--font-display); min-height: 52px; }

/* switch */
.switch { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 600; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; transition: background 0.15s; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--amber); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--amber-ink); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.ew { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.inline-field { flex-direction: row; align-items: center; gap: 8px; }
.inline-field select { width: auto; }

/* ---------- Selections ---------- */
.sel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: sel; }
.sel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 10px 10px 12px; display: grid; gap: 8px;
  grid-template-columns: 22px minmax(0, 1fr); align-items: center;
  border-left: 4px solid var(--line);
}
.sel[data-result=win], .sel[data-result=deadheat] { border-left-color: var(--profit); }
.sel[data-result=place] { border-left-color: var(--amber); }
.sel[data-result=lose] { border-left-color: var(--loss); }
.sel[data-result=void] { border-left-color: var(--muted); }
.sel-n { font: 700 1.2rem/1 var(--font-display); color: var(--muted); text-align: center; }
.sel-name { min-width: 0; }
.sel .sel-odds { width: 76px; flex: none; text-align: center; font: 600 1.25rem/1 var(--font-display); color: var(--amber); }
input.sel-odds.bad { border-color: var(--loss); color: var(--loss); }
.sel-row2 { grid-column: 2 / -1; display: flex; gap: 8px; align-items: center; }
.sel-row2 .dec::before { content: "dec "; opacity: 0.7; }
.sel-row2 select { width: auto; min-height: 36px; padding-block: 4px; font-size: 0.9rem; }
.sel-row2 .dec { color: var(--muted); font-size: 0.85rem; margin-right: auto; white-space: nowrap; }
.sel-row2 .link-btn { font-size: 0.9rem; }
.sel-more { grid-column: 2 / -1; display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.sel-more label { font-size: 0.8rem; }
.sel-more input { min-height: 38px; }
.sel-more .link-btn { padding-bottom: 10px; }

/* import */
.import-panel { border-color: color-mix(in srgb, var(--amber) 40%, var(--line)); }
#shotPreview { max-height: 220px; width: auto; margin: 0 auto; border-radius: 8px; border: 1px solid var(--line); }
.progress { display: grid; gap: 6px; }
.progress p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--amber); transition: width 0.2s; }
.found { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.found input.sel-odds { width: 72px; }
.found li { display: grid; grid-template-columns: auto minmax(0, 1fr) 72px; gap: 8px; align-items: center; }
.found input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--amber); }
.found input[type=text] { min-height: 38px; }

/* ---------- Chips & segmented ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip small { color: var(--muted); font-weight: 500; }
.chip[aria-pressed=true] { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); }
.chip[aria-pressed=true] small { color: var(--amber-ink); opacity: 0.75; }
.chip:disabled { opacity: 0.35; cursor: default; }
.chips.quick .chip { min-height: 34px; padding: 0 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 4px; gap: 4px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; font-size: 0.92rem; }
.seg button[aria-checked=true] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.stake-box { display: flex; flex-direction: column; gap: 10px; }
.per-size { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.per-size label { min-width: 0; }
.per-size .money input { font-size: 1.2rem; min-height: 46px; }

table { border-collapse: collapse; width: 100%; }
.breakdown td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.breakdown td:last-child { text-align: right; font-weight: 600; }
.breakdown tr.total td { border-bottom: 0; font: 600 1.15rem/1.2 var(--font-display); letter-spacing: 0.02em; }

details.panel > summary, details.guide > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.panel > summary::after, details.guide > summary::after { content: "+"; color: var(--amber); font-size: 1.2rem; line-height: 1; }
details[open].panel > summary::after, details[open].guide > summary::after { content: "–"; }
details.panel:not([open]) { gap: 0; }

/* ---------- Returns ---------- */
.hero-card {
  border-radius: var(--r); padding: 16px; display: grid; gap: 4px;
  background: var(--surface); border: 1px solid var(--line);
}
.hero-card .eyebrow { font: 600 0.85rem/1 var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.hero-card .big { font: 700 2.4rem/1.05 var(--font-display); letter-spacing: 0.01em; }
.hero-card .big.profit { color: var(--profit); }
.hero-card .big.loss { color: var(--loss); }
.hero-card p { margin: 0; color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
.outcomes th { text-align: left; font: 600 0.8rem/1 var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 12px; background: var(--surface); }
.outcomes th:not(:first-child), .outcomes td:not(:first-child) { text-align: right; }
.outcomes td { padding: 12px; border-top: 1px solid var(--line); font: 600 1.15rem/1.1 var(--font-display); white-space: nowrap; }
.outcomes td:first-child { color: var(--muted); }
.outcomes tbody tr { cursor: pointer; }
.outcomes tbody tr.goal td:first-child { color: var(--text); }
.outcomes tbody tr.open { background: var(--surface); }
.outcomes .detail td { font: 400 0.9rem/1.4 var(--font-body); white-space: normal; text-align: left; color: var(--muted); padding-top: 0; border-top: 0; cursor: default; }
.outcomes .detail b { color: var(--text); font-weight: 600; }
.profit { color: var(--profit); }
.loss { color: var(--loss); }
.zero { color: var(--even); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font: 600 0.75rem/1.4 var(--font-body); letter-spacing: 0.04em; text-transform: uppercase; }
.pill.profit { background: var(--profit-bg); }
.pill.loss { background: var(--loss-bg); }
.settle .big { font: 700 2rem/1 var(--font-display); }
.settle p { margin: 0; }

/* ---------- Plans ---------- */
.plans { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; }
.plan.top { border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); }
.plan-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.plan-head h3 { margin: 0; font-size: 1.25rem; }
.plan-head span { color: var(--muted); font-size: 0.85rem; text-align: right; }
.plan dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.plan dt { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.plan dd { margin: 2px 0 0; font: 600 1.2rem/1.1 var(--font-display); }
.plan .btn { min-height: 40px; }

/* ---------- Chat ---------- */
.chat-view { min-height: calc(100dvh - 210px); }
.chat-meta { display: flex; justify-content: space-between; align-items: center; }
.provider { font-size: 0.85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.provider::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--profit); }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--amber); color: var(--amber-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { align-self: stretch; max-width: none; background: var(--loss-bg); color: var(--text); border: 1px solid color-mix(in srgb, var(--loss) 40%, transparent); }
.msg img { max-height: 160px; border-radius: 10px; margin-bottom: 6px; }
.msg .applied { display: flex; gap: 10px; align-items: center; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 0.85rem; color: var(--profit); }
.msg .applied .link-btn { font-size: 0.85rem; }
.msg.thinking { color: var(--muted); }
.msg.thinking::after { content: "…"; animation: blink 1s steps(3) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.suggestions { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.suggestions button { flex: none; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.9rem; }
.composer {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 6px; display: grid; gap: 6px;
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea { border: 0; background: transparent; min-height: 42px; max-height: 140px; resize: none; padding: 10px 6px; }
.composer .icon-btn { border: 0; }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--amber); color: var(--amber-ink); display: grid; place-items: center; cursor: pointer; flex: none; }
.send:disabled { opacity: 0.4; }
.attach-preview { position: relative; width: max-content; }
.attach-preview img { height: 64px; border-radius: 8px; }
.attach-preview .icon-btn { position: absolute; top: -8px; right: -8px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.tabbar button {
  height: var(--tabbar-h); border: 0; background: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font: 600 0.78rem/1 var(--font-body); letter-spacing: 0.02em; -webkit-tap-highlight-color: transparent;
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar button[aria-current=page] { color: var(--amber); }
@media (min-width: 700px) {
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: 560px; bottom: 12px; border: 1px solid var(--line); border-radius: 18px; padding: 0; }
}

/* ---------- Settings sheet ---------- */
dialog.sheet {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  width: min(560px, 100%); max-width: 100%; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border-radius: 20px 20px 0 0;
}
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet-inner { display: flex; flex-direction: column; gap: 12px; padding: 18px var(--gutter-r) calc(18px + env(safe-area-inset-bottom, 0px)) var(--gutter-l); }
.sheet-inner > label { color: var(--text); font-weight: 600; }
.key-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.guide { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.guide ol { padding-left: 20px; margin: 10px 0; display: grid; gap: 6px; }
.guide a { color: var(--amber); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
