:root {
  --bg: #0b2923;
  --bg-deep: #07201b;
  --panel: #113a31;
  --panel-2: #16463b;
  --line: #2a5c4e;
  --text: #e8f2ee;
  --muted: #93b5a9;
  --gold: #e6bd5c;
  --gold-ink: #2a1f06;
  --win: #77e6a6;
  --lose: #ff9288;
  --danger: #ff6b5e;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: radial-gradient(120% 80% at 50% -10%, #14473c 0%, var(--bg) 45%, var(--bg-deep) 100%) fixed;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .005em; }
h2 { font-size: 1.15rem; margin-bottom: .6rem; }
p { margin: 0 0 .75rem; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.win { color: var(--win); }
.lose { color: var(--lose); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: .65rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  min-height: 44px;
  transition: background .12s, transform .08s;
}
.btn:hover { background: #1c5648; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.primary:hover { background: #f0cb76; }
.btn.danger { color: var(--danger); border-color: #7a3b36; background: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: .4rem .75rem; min-height: 36px; font-size: .9rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent;
  display: inline-grid; place-items: center; line-height: 1; font-size: 1.1rem;
}

input[type=text], input:not([type]), input[inputmode] {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6rem .75rem;
  min-height: 44px;
}
input::placeholder { color: #5f8479; }
label.field { display: block; margin-bottom: .9rem; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: .75rem; }

/* ---------- home ---------- */
.home { max-width: 460px; margin: 0 auto; padding: 2.5rem 1.25rem 3rem; }
.fan { display: flex; justify-content: center; margin: .5rem 0 1.6rem; height: 96px; align-items: center; }
.fan .chip { margin: 0 -14px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.45)); }
.fan .chip:nth-child(1) { transform: rotate(-14deg) translateY(6px); }
.fan .chip:nth-child(2) { transform: rotate(-7deg) translateY(1px); }
.fan .chip:nth-child(3) { transform: rotate(2deg) translateY(-4px); }
.fan .chip:nth-child(4) { transform: rotate(9deg) translateY(1px); }
.fan .chip:nth-child(5) { transform: rotate(16deg) translateY(6px); }
.home h1 { font-size: 2.4rem; text-align: center; }
.lede { text-align: center; color: var(--muted); margin: .5rem auto 2rem; max-width: 34ch; }
.card {
  background: linear-gradient(180deg, var(--panel) 0%, #0f3329 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.home .card { margin-bottom: 1rem; }
.home .btn { width: 100%; }
.recent { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.recent button {
  width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center;
  background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; min-height: 48px;
}
.code-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .18em; font-weight: 700; color: var(--gold);
}

/* ---------- room chrome ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(.7rem + env(safe-area-inset-top)) 1rem .7rem;
  background: rgba(7, 32, 27, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top .title { flex: 1; min-width: 0; }
.top h1 { font-size: 1.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { display: flex; gap: .6rem; align-items: center; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--win); margin-right: .3rem; }
.dot.off { background: var(--danger); }
.phase {
  border: 1px solid var(--line); border-radius: 999px; padding: 0 .55rem; font-size: .75rem; color: var(--text);
}
.phase.counting { border-color: var(--gold); color: var(--gold); }
.phase.settled { border-color: var(--win); color: var(--win); }
.offline-bar { background: #5a2420; color: #ffd9d4; text-align: center; padding: .4rem; font-size: .85rem; }

.view { max-width: 600px; margin: 0 auto; padding: 1rem 1rem calc(6rem + env(safe-area-inset-bottom)); display: grid; gap: 1rem; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(7, 32, 27, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { max-width: 600px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.nav button {
  background: none; border: 0; padding: .85rem .25rem .8rem; color: var(--muted);
  font-weight: 600; position: relative; min-height: 52px;
}
.nav button[aria-current=page] { color: var(--gold); }
.nav button[aria-current=page]::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; background: var(--gold); border-radius: 0 0 3px 3px;
}
.badge {
  display: inline-block; min-width: 1.3em; padding: 0 .35em; margin-left: .3em; border-radius: 999px;
  background: var(--gold); color: var(--gold-ink); font-size: .75rem; line-height: 1.4;
}

/* ---------- players ---------- */
.pot { display: flex; justify-content: space-between; align-items: flex-end; }
.pot-label { color: var(--muted); font-size: .85rem; }
.pot-amt { font-family: var(--serif); font-size: 2.4rem; line-height: 1.1; }
.pot-meta { text-align: right; color: var(--muted); font-size: .9rem; }

.req { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .55rem 0; border-top: 1px solid var(--line); }
.req:first-of-type { border-top: 0; }
.req .who { min-width: 0; }
.req .acts { display: flex; gap: .4rem; flex-shrink: 0; }

.player .p-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.p-name { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }
.you { font-family: var(--sans); font-size: .7rem; border: 1px solid var(--gold); color: var(--gold); border-radius: 999px; padding: 0 .45rem; margin-left: .4rem; vertical-align: middle; }
.p-total { font-size: 1.15rem; font-weight: 600; }
.buyins { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; min-height: 1.6rem; }
.pill { display: inline-flex; align-items: center; gap: .2rem; background: var(--bg-deep); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .2rem .1rem .65rem; font-size: .9rem; }
.pill.plain { padding-right: .65rem; }
.pill button { border: 0; background: transparent; color: var(--muted); width: 24px; height: 24px; border-radius: 50%; line-height: 1; }
.pill button:hover { color: var(--danger); }
.p-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.log { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; font-size: .9rem; }
.log li { display: flex; gap: .6rem; }
.log time { color: var(--muted); flex-shrink: 0; width: 4.6em; font-variant-numeric: tabular-nums; }

.watch-banner { display: flex; align-items: center; justify-content: space-between; gap: .75rem; border: 1px dashed var(--gold); border-radius: var(--radius); padding: .75rem 1rem; }

/* ---------- chips tab ---------- */
.chip-list { display: grid; gap: .5rem; }
.chip-item {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left;
  background: var(--bg-deep); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem;
}
.chip-item .nm { flex: 1; font-weight: 600; }
.chip-item .vl { font-size: 1.1rem; font-weight: 600; }
.chip-item .edit { color: var(--muted); font-size: .8rem; }
.chip { flex-shrink: 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: .5rem 1rem; align-items: center; }
.kv input { width: 8.5em; text-align: right; }

.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: .5rem; margin: .4rem 0 .9rem; }
.palette button { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 2px rgba(0,0,0,.35); }
.palette button[aria-pressed=true] { border-color: var(--gold); }
.modal-chip { display: flex; justify-content: center; margin-bottom: 1rem; }

/* ---------- count ---------- */
.progress { height: 8px; border-radius: 99px; background: var(--bg-deep); overflow: hidden; margin: .6rem 0; }
.progress > i { display: block; height: 100%; background: var(--gold); }
.callout { border: 1px solid var(--gold); border-radius: 12px; padding: .7rem .9rem; font-size: .92rem; background: rgba(230, 189, 92, .08); }
.callout.err { border-color: var(--lose); background: rgba(255, 146, 136, .08); }
.cc-head { width: 100%; display: flex; justify-content: space-between; align-items: center; background: none; border: 0; padding: 0; text-align: left; gap: .5rem; }
.cc-head .st { font-size: .8rem; color: var(--muted); }
.cc-head .st.done { color: var(--win); }
.cc-body { margin-top: .75rem; display: grid; gap: .55rem; }
.cc-row { display: grid; grid-template-columns: 40px 1fr auto 4.5rem; gap: .6rem; align-items: center; }
.cc-row .nm { font-weight: 600; line-height: 1.2; }
.cc-row .nm small { display: block; color: var(--muted); font-weight: 400; }
.cc-row .sub { text-align: right; font-size: .9rem; }
.stepper { display: flex; align-items: center; }
.stepper button { width: 40px; height: 44px; border: 1px solid var(--line); background: var(--panel-2); font-size: 1.2rem; }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper input { width: 3.6rem; min-height: 44px; border-radius: 0; text-align: center; padding: 0; border-left: 0; border-right: 0; }
.cc-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; border-top: 1px solid var(--line); padding-top: .75rem; margin-top: .25rem; flex-wrap: wrap; }

/* ---------- settle ---------- */
table.board { width: 100%; border-collapse: collapse; font-size: .95rem; }
.board th { text-align: right; font-weight: 500; color: var(--muted); font-size: .8rem; padding: 0 0 .4rem .5rem; }
.board th:first-child, .board td:first-child { text-align: left; padding-left: 0; }
.board td { text-align: right; padding: .5rem 0 .5rem .5rem; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.board td:first-child { font-family: var(--serif); font-weight: 600; font-size: 1.02rem; overflow-wrap: anywhere; }
.board td.net { font-weight: 700; }
.pay { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.pay:first-of-type { border-top: 0; }
.pay .who { line-height: 1.3; }
.pay .amt { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; color: var(--gold); white-space: nowrap; }
.settle-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }

/* ---------- modal & toast ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(2, 12, 10, .7);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 1.1rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
.sheet h2 { font-size: 1.3rem; }
.sheet .actions { display: flex; gap: .6rem; margin-top: .4rem; }
.sheet .actions .btn { flex: 1; }
.bigcode { font-size: 2.2rem; text-align: center; margin: .2rem 0 .8rem; }
.list-btns { display: grid; gap: .45rem; margin: .5rem 0 1rem; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 18px; } }

#toast {
  position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #f4f1e8; color: #1b2a25; padding: .55rem .95rem; border-radius: 10px; font-weight: 600; font-size: .92rem;
  z-index: 60; opacity: 0; pointer-events: none; transition: opacity .15s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
.loading { text-align: center; padding: 4rem 1rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (max-width: 380px) {
  .cc-row { grid-template-columns: 34px 1fr auto; }
  .cc-row .sub { grid-column: 2 / 4; text-align: left; }
}
