:root {
  --chamber: #17302a;
  --bench: #22433a;
  --bench-hi: #2c5448;
  --rule: #3b6356;
  --brass: #c9a646;
  --brass-dim: #8f7a3c;
  --ledger: #ede6d2;
  --ledger-dim: #b9b4a2;
  --ink: #1b1a17;
  --liberal: #8db3e2;
  --liberal-deep: #2d4f7a;
  --fascist: #d0553f;
  --fascist-deep: #6e2418;
  --danger: #e2735e;

  --display: "Big Shoulders Display", "Arial Narrow", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;

  --r-sm: 4px;
  --r-md: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, #234a3f 0%, transparent 60%),
    repeating-linear-gradient(90deg, rgba(0,0,0,.06) 0 2px, transparent 2px 22px),
    var(--chamber);
  color: var(--ledger);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

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

h1, h2, h3 { font-family: var(--display); font-weight: 800; line-height: 1; margin: 0; letter-spacing: .01em; }
p { margin: 0 0 .75em; }
.muted { color: var(--ledger-dim); }
.small { font-size: 15px; }

button, input { font: inherit; }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

.btn {
  appearance: none;
  border: 0;
  border-radius: var(--r-sm);
  padding: 14px 18px;
  min-height: 48px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: .02em;
  color: var(--ink);
  background: var(--brass);
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25);
  transition: transform .08s ease;
}
.btn:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 rgba(0,0,0,.25); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ledger); box-shadow: inset 0 0 0 2px var(--rule); }
.btn.block { width: 100%; }
.btn.ja { background: var(--ledger); }
.btn.nein { background: var(--ink); color: var(--ledger); box-shadow: inset 0 0 0 2px var(--ledger-dim); }
.btn.danger { background: var(--danger); }
.btn.chosen { outline: 3px solid var(--brass); outline-offset: 3px; }

input[type=text] {
  width: 100%;
  padding: 12px 14px;
  min-height: 48px;
  border-radius: var(--r-sm);
  border: 2px solid var(--rule);
  background: var(--chamber);
  color: var(--ledger);
}
input[type=text]:focus { border-color: var(--brass); outline: none; }
label { display: block; margin: 0 0 6px; color: var(--ledger-dim); font-size: 15px; }
.field { margin-bottom: 16px; }

/* ---------- home ---------- */
.home-title {
  font-size: clamp(64px, 20vw, 108px);
  font-weight: 900;
  line-height: .86;
  margin: 28px 0 8px;
  color: var(--ledger);
}
.home-title span { display: block; color: var(--brass); }
.home-lede { max-width: 34ch; margin-bottom: 32px; color: var(--ledger-dim); }
.panel {
  background: var(--bench);
  border-radius: var(--r-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.or { text-align: center; color: var(--ledger-dim); margin: 6px 0 16px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.credit { margin-top: 28px; font-size: 13px; color: var(--ledger-dim); }
.credit a { color: var(--ledger-dim); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.roomcode { font-family: var(--display); font-size: 30px; font-weight: 900; letter-spacing: .12em; }
.roomcode small { display: block; font-family: var(--serif); font-size: 13px; letter-spacing: 0; color: var(--ledger-dim); font-weight: 400; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #6fbf73; display: inline-block; margin-left: 8px; vertical-align: middle; }
.conn.off { background: var(--danger); }

/* ---------- envelope (role reveal) ---------- */
.envelope {
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  border: 0;
  width: 100%;
  min-height: 92px;
  border-radius: var(--r-md);
  background: var(--ledger);
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  margin-bottom: 18px;
  text-align: left;
  -webkit-touch-callout: none;
}
.envelope .flap {
  position: absolute; inset: 0;
  background:
    linear-gradient(160deg, transparent 49.5%, rgba(0,0,0,.12) 50%, transparent 50.5%),
    linear-gradient(20deg, transparent 49.5%, rgba(0,0,0,.12) 50%, transparent 50.5%),
    var(--ledger);
  display: flex; align-items: center; justify-content: center; gap: 14px;
  transition: transform .28s cubic-bezier(.3,.7,.2,1), opacity .2s;
  z-index: 2;
}
.seal {
  width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #e0bf5a, var(--brass) 55%, var(--brass-dim));
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.flap-text { font-family: var(--display); font-weight: 800; font-size: 22px; color: var(--ink); }
.envelope.open .flap { transform: translateY(-100%); opacity: 0; }
.envelope .contents { padding: 16px 18px; position: relative; z-index: 1; }
.role-name { font-family: var(--display); font-weight: 900; font-size: 40px; line-height: 1; }
.role-liberal .role-name { color: var(--liberal-deep); }
.role-fascist .role-name, .role-hitler .role-name { color: var(--fascist-deep); }
.contents p { margin: 6px 0 0; font-size: 16px; }
.contents .notes { margin-top: 10px; padding-top: 8px; border-top: 1px dashed rgba(0,0,0,.25); }

/* ---------- board ---------- */
.board { margin-bottom: 18px; }
.track { margin-bottom: 12px; }
.track-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.track-head h3 { font-size: 20px; }
.track.liberal h3 { color: var(--liberal); }
.track.fascist h3 { color: var(--fascist); }
.slots { display: grid; gap: 6px; }
.slots.five { grid-template-columns: repeat(5, 1fr); }
.slots.six { grid-template-columns: repeat(6, 1fr); }
.slot {
  aspect-ratio: 5 / 7;
  border-radius: var(--r-sm);
  border: 2px dashed var(--rule);
  display: flex; align-items: center; justify-content: center;
  color: var(--ledger-dim);
  position: relative;
}
.slot svg { width: 46%; height: auto; opacity: .7; }
.slot.final { border-style: solid; }
.slot.filled { border: 0; }
.slot.just { animation: stamp .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes stamp { from { transform: scale(1.35) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }

.card {
  aspect-ratio: 5 / 7;
  width: 100%;
  border-radius: var(--r-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6%;
  font-family: var(--display); font-weight: 900;
  box-shadow: 0 2px 0 rgba(0,0,0,.3);
  position: relative;
  overflow: hidden;
}
.card.L { background: var(--liberal); color: var(--liberal-deep); }
.card.F { background: var(--fascist); color: var(--fascist-deep); }
.card .emblem { width: 52%; height: auto; }
.card .word { font-size: clamp(11px, 3.3vw, 16px); letter-spacing: .04em; }
.card::after { content: ""; position: absolute; inset: 5%; border: 1.5px solid currentColor; border-radius: 2px; opacity: .35; }

.meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 15px; color: var(--ledger-dim); }
.tracker { display: flex; align-items: center; gap: 8px; }
.pip { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brass-dim); }
.pip.on { background: var(--brass); border-color: var(--brass); }
.pip.chaos { border-color: var(--danger); }

/* ---------- action panel ---------- */
.action {
  background: var(--bench);
  border-radius: var(--r-md);
  padding: 18px;
  margin-bottom: 18px;
  border-left: 4px solid var(--brass);
}
.action.waiting { border-left-color: var(--rule); }
.action h2 { font-size: 30px; margin-bottom: 8px; }
.action p:last-child { margin-bottom: 0; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.choice {
  appearance: none; border: 2px solid var(--rule); background: var(--chamber); color: var(--ledger);
  border-radius: var(--r-sm); padding: 12px; min-height: 48px; text-align: left; cursor: pointer; font-size: 17px;
}
.choice:hover { border-color: var(--brass-dim); }
.choice.sel { border-color: var(--brass); background: #3a3820; }
.vote-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.vote-row .btn { font-size: 30px; min-height: 72px; }
.hand { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.hand.two { grid-template-columns: repeat(2, 1fr); max-width: 66%; }
.hand button { appearance: none; border: 0; padding: 0; background: none; cursor: pointer; border-radius: var(--r-sm); }
.hand button.sel .card { outline: 3px solid var(--brass); outline-offset: 3px; transform: translateY(-4px); }
.hand button .card { transition: transform .12s; }
.stack { display: grid; gap: 8px; margin-top: 12px; }

/* ---------- players ---------- */
.players { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 6px; }
.players li {
  display: flex; align-items: center; gap: 10px;
  background: var(--bench); border-radius: var(--r-sm);
  padding: 10px 12px; min-height: 48px;
}
.players li.dead { opacity: .45; text-decoration: line-through; }
.players .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .you { color: var(--ledger-dim); font-size: 14px; }
.badge {
  font-family: var(--display); font-weight: 800; font-size: 15px;
  padding: 2px 8px; border-radius: 3px; background: var(--chamber); color: var(--ledger-dim);
  white-space: nowrap;
}
.badge.pres { background: var(--brass); color: var(--ink); }
.badge.chanc { background: var(--ledger); color: var(--ink); }
.badge.ja { background: var(--ledger); color: var(--ink); }
.badge.nein { background: var(--ink); color: var(--ledger); }
.badge.offline { color: var(--danger); }
.badge.role-liberal { background: var(--liberal); color: var(--liberal-deep); }
.badge.role-fascist, .badge.role-hitler { background: var(--fascist); color: var(--fascist-deep); }
.kick { appearance: none; border: 0; background: none; color: var(--ledger-dim); cursor: pointer; font-size: 20px; padding: 4px 8px; }

/* ---------- log ---------- */
details.log { background: var(--bench); border-radius: var(--r-md); padding: 4px 16px; }
details.log summary { cursor: pointer; padding: 10px 0; font-family: var(--display); font-weight: 800; font-size: 20px; }
.log ol { list-style: none; margin: 0 0 12px; padding: 0; font-size: 15px; display: flex; flex-direction: column-reverse; }
.log li { padding: 5px 0; border-top: 1px solid var(--rule); }
.log li.liberal { color: var(--liberal); }
.log li.fascist, .log li.danger { color: var(--fascist); }
.log li.power { color: var(--brass); }

.section-title { font-size: 22px; margin: 0 0 8px; }

/* ---------- game over ---------- */
.verdict { text-align: left; padding: 22px 20px; border-radius: var(--r-md); margin-bottom: 18px; color: var(--ink); }
.verdict.liberal { background: var(--liberal); }
.verdict.fascist { background: var(--fascist); }
.verdict h2 { font-size: clamp(48px, 15vw, 76px); font-weight: 900; }
.verdict p { margin: 8px 0 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 140%);
  background: var(--ledger); color: var(--ink);
  padding: 12px 18px; border-radius: var(--r-sm); max-width: calc(100vw - 32px);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  transition: transform .25s ease;
  z-index: 50;
}
#toast.show { transform: translate(-50%, 0); }

.banner {
  background: var(--chamber); border: 2px solid var(--rule); border-radius: var(--r-sm);
  padding: 10px 12px; margin-bottom: 12px; font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
