:root {
  --bg: #FFF6EA;
  --card: #FFFFFF;
  --ink: #211C33;
  --muted: #756E8A;
  --line: #EBDFD0;
  --primary: #FF5A4E;
  --primary-ink: #FFFFFF;
  --gold: #F5B700;
  --gold-soft: #FFF1C2;
  --green: #12976A;
  --green-soft: #DDF5EA;
  --red-soft: #FFE3E0;
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

#app { max-width: 520px; margin: 0 auto; padding: 0 16px calc(110px + env(safe-area-inset-bottom)); }

/* ---------- shared pieces ---------- */
.card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.stack > * + * { margin-top: 14px; }
label.field { display: block; font-weight: 700; font-size: 14px; }
label.field span { display: block; margin-bottom: 6px; }
input[type=text], input[type=number] {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #FFFDF9;
  font-size: 16px;
  outline: none;
}
input:focus { border-color: var(--ink); }
.btn {
  display: block; width: 100%;
  padding: 15px 18px;
  border-radius: 14px;
  background: var(--primary); color: var(--primary-ink);
  font-weight: 800; font-size: 17px; text-align: center;
  box-shadow: 0 3px 0 #C93B31;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #C93B31; }
.btn:disabled { opacity: .45; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); box-shadow: none; }
.btn.small { display: inline-block; width: auto; padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.seg { display: flex; background: #F3E7D8; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 10px 6px; border-radius: 11px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(33, 28, 51, .12); }

/* ---------- home ---------- */
.hero { text-align: center; padding: 44px 0 26px; }
.hero .logo { width: 84px; height: 84px; display: block; margin: 0 auto; }
.hero h1 { font-size: 40px; font-weight: 900; letter-spacing: -1px; margin-top: 10px; }
.hero h1 b { color: var(--primary); }
.hero p { color: var(--muted); margin-top: 8px; }
.home .seg { margin-bottom: 14px; }
.occasions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.occasions label { position: relative; }
.occasions input { position: absolute; opacity: 0; inset: 0; }
.occasions span {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 12px;
  font-weight: 700; font-size: 14px; background: #FFFDF9;
}
.occasions input:checked + span { border-color: var(--ink); background: var(--gold-soft); }
.occasions input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; font-size: 22px !important; }
.fine { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }

/* ---------- event ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 14px 0 10px;
}
.top-row { display: flex; align-items: center; gap: 12px; }
.top h2 { flex: 1; min-width: 0; font-size: 20px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { color: var(--muted); font-size: 13px; }
.chips {
  flex: none; text-align: right;
  background: var(--gold-soft); border: 1.5px solid var(--gold);
  border-radius: 14px; padding: 6px 12px;
  font-weight: 900; font-size: 18px; line-height: 1.1;
}
.chips small { display: block; font-size: 11px; font-weight: 700; color: #8A6A00; }
.top .seg { margin-top: 12px; }

.bet { margin-top: 12px; }
.bet-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 800; }
.tag { padding: 3px 9px; border-radius: 99px; text-transform: uppercase; letter-spacing: .5px; }
.tag.open { background: var(--green-soft); color: var(--green); }
.tag.locked { background: var(--gold-soft); color: #8A6A00; }
.tag.settled { background: #ECE9F3; color: var(--muted); }
.tag.void { background: #ECE9F3; color: var(--muted); }
.pot { color: var(--muted); }
.bet h3 { font-size: 18px; font-weight: 800; margin-top: 10px; line-height: 1.25; overflow-wrap: anywhere; }
.bet .by { font-size: 13px; color: var(--muted); margin-top: 2px; }
.bet.void h3 { text-decoration: line-through; color: var(--muted); }
.opts { display: grid; gap: 8px; margin-top: 12px; }
.opt {
  position: relative; overflow: hidden;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: #FFFDF9; text-align: left; font-weight: 700;
}
.opt:not(:disabled):active { border-color: var(--ink); }
.opt .bar { position: absolute; inset: 0 auto 0 0; background: #F3E7D8; transition: width .3s; }
.opt .lbl, .opt .meta { position: relative; }
.opt .lbl { overflow-wrap: anywhere; }
.opt .meta { flex: none; font-size: 13px; color: var(--muted); font-weight: 600; }
.opt.mine { border-color: var(--ink); }
.opt.mine .bar { background: var(--gold-soft); }
.opt.won { border-color: var(--green); }
.opt.won .bar { background: var(--green-soft); }
.opt:disabled { color: var(--ink); }
.note { margin-top: 10px; font-size: 14px; font-weight: 700; }
.note.win { color: var(--green); }
.note.loss { color: #C93B31; }
.ctl { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1.5px dashed var(--line); }
.ctl button { padding: 7px 12px; border-radius: 10px; border: 1.5px solid var(--line); font-size: 13px; font-weight: 700; }
.ctl button.go { background: var(--ink); border-color: var(--ink); color: #fff; }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty .big { font-size: 44px; }
.empty p { margin: 6px 0 16px; }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: min(488px, calc(100% - 32px)); z-index: 6;
}
.fab:active { transform: translateX(-50%) translateY(2px); }

.board { margin-top: 12px; padding: 6px 18px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1.5px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .rank { width: 28px; text-align: center; font-weight: 900; color: var(--muted); }
.row .who { flex: 1; min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .who small { display: block; font-weight: 600; color: var(--muted); font-size: 12px; }
.row .pts { font-weight: 900; font-size: 18px; }
.row.me .who { color: var(--primary); }

.invite { margin-top: 12px; text-align: center; }
.invite .qr { width: 220px; max-width: 100%; margin: 4px auto 0; }
.invite .qr svg { width: 100%; height: auto; display: block; }
.invite .bigcode { font-size: 44px; font-weight: 900; letter-spacing: 8px; margin-right: -8px; }
.invite .link { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 20; background: rgba(33, 28, 51, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-body { animation: none; } .opt .bar { transition: none; } }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.sheet-head h3 { flex: 1; font-size: 20px; font-weight: 900; overflow-wrap: anywhere; }
.x { width: 34px; height: 34px; border-radius: 50%; background: #F3E7D8; font-weight: 900; flex: none; }
.amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.amounts button { padding: 14px 4px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); font-weight: 800; }
.amounts button.on { border-color: var(--gold); background: var(--gold-soft); }
.amounts button.wide { grid-column: 1 / -1; }
.sugg { display: grid; gap: 8px; }
.sugg button {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); font-weight: 700; font-size: 15px;
}
.sugg button .plus { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 900; }
.sugg button.done { opacity: .5; }
.sugg button.done .plus { background: var(--green); }
.sheet-body h4 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.choices input + input { margin-top: 8px; }

#toast {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -80px);
  z-index: 30; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-weight: 700; font-size: 14px; transition: transform .2s; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }
