:root {
  --felt: #0f3d22; --felt2: #14532d; --card: #1b6a3a; --ink: #f4f7f2; --muted: #a9c9b2; --accent: #f5c542; --danger: #e5604f;
  --line: rgba(255,255,255,.14);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--felt); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--felt2); position: sticky; top: 0; z-index: 5; }
h1 { margin: 0; font-size: 1.25rem; }
h2 { margin: 8px 0; font-size: 1.15rem; }
h3 { margin: 18px 0 6px; font-size: 1rem; color: var(--muted); }
main { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.badge, .tag { background: var(--accent); color: #231a00; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.tag.mate { background: #7dd3fc; color: #052233; }
.tag.gender { background: rgba(255,255,255,.18); color: var(--ink); padding: 0 7px; }

button, select, input { font: inherit; color: inherit; }
button { background: rgba(255,255,255,.1); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; min-height: 40px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #231a00; border-color: transparent; font-weight: 700; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.primary.danger { background: var(--danger); color: #fff; }
button.big { width: 100%; min-height: 56px; font-size: 1.15rem; margin: 12px 0; }
textarea { font: inherit; color: inherit; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical; }
input[type=text], input[type=number], input:not([type]), select { background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; margin: 16px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .92rem; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; margin: 0; }
legend { padding: 0 6px; color: var(--muted); }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--felt2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { flex: 1; border: 0; border-radius: 0; min-height: 56px; background: transparent; font-weight: 600; color: var(--muted); }
.tabs button.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* players */
ol.players, ul.rules, ul.log, ul.opening, ul.alloc, ul.drinklist, ul.fired { list-style: none; margin: 8px 0; padding: 0; }
.players li, .opening li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 6px; }
.seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.seats li { margin: 0; }
.seats li.turn { outline: 3px solid var(--accent); }
.seats li.tm { background: #5b4a12; }
.pname { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.drinks { white-space: nowrap; color: var(--muted); }
.opening li.current { outline: 2px solid var(--accent); }
.turnline { text-align: center; margin: 10px 0 0; font-size: 1.1rem; }
.streak { color: var(--accent); font-size: .85rem; margin-left: 6px; }

/* dice */
.dice-box { display: flex; justify-content: center; gap: 36px; padding: 34px 0 26px; }
.die-scene { --s: 76px; width: var(--s); height: var(--s); perspective: 500px; }
.die-toss { width: 100%; height: 100%; transform-style: preserve-3d; }
.die-toss.toss { animation: toss 1.1s ease-out; }
@keyframes toss {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-46px) scale(1.18); }
  65% { transform: translateY(0) scale(1); }
  80% { transform: translateY(-10px) scale(1.04); }
  100% { transform: translateY(0) scale(1); }
}
.die { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; }
.face { position: absolute; inset: 0; background: #fafaf5; border-radius: 14%; border: 1px solid #cfcfc4; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 12%; backface-visibility: hidden; box-shadow: inset 0 0 10px rgba(0,0,0,.18); }
.f1 { transform: rotateY(0deg) translateZ(calc(var(--s) / 2)); }
.f2 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.f3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.f4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.f5 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.pip { background: #1c1c1c; border-radius: 50%; margin: 12%; }
.f1 .pip { background: #c0392b; }
@media (prefers-reduced-motion: reduce) { .die-toss.toss { animation: none; } .die { transition: none !important; } }

/* result */
.result { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-height: 80px; }
.result.act { border-color: var(--accent); }
.total { font-size: 1.1rem; margin-bottom: 4px; }
.fired li { margin: 4px 0; }
.drink { margin: 3px 0; }
.note { color: var(--accent); font-weight: 700; margin: 6px 0 0; }
.house { list-style: none; margin: 8px 0; padding: 0; }
.house li { background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin-bottom: 6px; }
.house small { color: var(--muted); }
.log { font-size: .88rem; color: var(--muted); }
.log li { padding: 5px 0; border-bottom: 1px solid var(--line); }
details { margin: 14px 0; }
summary { cursor: pointer; color: var(--muted); padding: 6px 0; }

/* rules */
.rule { display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.rule.off .rule-text { opacity: .5; }
.rule-main { display: flex; gap: 12px; align-items: flex-start; }
.rule-text { display: flex; flex-direction: column; }
.rule-text small { color: var(--muted); }
.rule-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.rule-btns button { min-height: 36px; padding: 4px 10px; }
.switch input { position: absolute; opacity: 0; }
.switch span { display: block; width: 44px; height: 26px; border-radius: 99px; background: rgba(0,0,0,.4); position: relative; flex: none; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid #fff; }
.settings label { margin: 8px 0; }

/* modal */
dialog { background: var(--felt2); color: var(--ink); border: 1px solid var(--line); border-radius: 16px; padding: 16px; width: min(94vw, 520px); max-height: 90dvh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.65); }
.cond { display: grid; grid-template-columns: 1fr; gap: 6px; }
.cond input { max-width: 120px; }
.cond input[type=text] { max-width: none; }
.grid6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.cell { font-size: .7rem; text-align: center; padding: 4px 0; border-radius: 4px; background: rgba(0,0,0,.25); color: var(--muted); }
.cell.hit { background: var(--accent); color: #231a00; font-weight: 700; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.choices button { min-height: 52px; }
.alloc li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 44px; min-height: 44px; font-size: 1.3rem; }
.stepper b { min-width: 20px; text-align: center; font-size: 1.1rem; }
