:root {
  color-scheme: light dark;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eceef8;
  --text: #171a2e;
  --muted: #565b78;
  --border: #dde0ef;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --wolf: #b3283f;
  --good: #0c6e49;
  --warn: #8a5a00;
  --danger: #b3283f;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(20 22 43 / 6%), 0 4px 16px rgb(20 22 43 / 6%);
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1020;
    --surface: #181b33;
    --surface-2: #232748;
    --text: #eceefb;
    --muted: #9aa0c4;
    --border: #2b3059;
    --accent: #8b8bff;
    --accent-text: #0e1020;
    --wolf: #ff6b81;
    --good: #46d49a;
    --warn: #f0b944;
    --danger: #ff6b81;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
body {
  font:
    16px/1.45 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
}
.boot {
  padding: 2rem;
  color: var(--muted);
}

/* ---------- Layout ---------- */
.screen {
  padding: max(16px, env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.screen.no-nav {
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

h1 {
  font-size: 1.6rem;
  margin: 4px 0 0;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.05rem;
  margin: 0;
}
h3 {
  font-size: 0.95rem;
  margin: 0;
}
p {
  margin: 0;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.center {
  text-align: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.active {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent),
    var(--shadow);
}
.card.done {
  border-style: dashed;
  box-shadow: none;
}
.card.hero {
  background: linear-gradient(160deg, #23285a, #14162b);
  color: #eceefb;
  border: none;
}
.card.hero .muted {
  color: #b4b9dd;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.row.wrap {
  flex-wrap: wrap;
}
.row.between {
  justify-content: space-between;
}
.grow {
  flex: 1;
  min-width: 0;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Buttons ---------- */
button,
.btn {
  font: inherit;
  color: inherit;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 46px;
  cursor: pointer;
  transition:
    transform 0.05s,
    background 0.15s;
}
button:active {
  transform: scale(0.98);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
}
button.danger {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}
button.ghost {
  background: transparent;
}
button.block {
  width: 100%;
}
button.icon {
  min-width: 46px;
  padding: 10px;
  font-size: 1.2rem;
  line-height: 1;
}
button.small {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.85rem;
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}

/* ---------- Forms ---------- */
input[type='text'],
input[type='password'],
input[type='number'],
select {
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 46px;
  width: 100%;
}
input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}
.stepper .value {
  font-size: 2.6rem;
  font-weight: 700;
  min-width: 3ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}
.switch input {
  width: 46px;
  height: 26px;
  accent-color: var(--accent);
}

/* ---------- Chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.95rem;
}
.chip.sel {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
}
.chip.dead {
  text-decoration: line-through;
  color: var(--muted);
}
.chip.wolf {
  border-color: color-mix(in srgb, var(--wolf) 55%, transparent);
}
.chip:disabled {
  opacity: 0.35;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.dorf {
  color: var(--good);
}
.badge.wolf {
  color: var(--wolf);
}
.badge.solo {
  color: var(--warn);
}

/* ---------- Deck ---------- */
.role-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.role-row:first-of-type {
  border-top: 0;
}
.role-row .emoji {
  font-size: 1.7rem;
  width: 2.2rem;
  text-align: center;
}
.role-row.zero .emoji {
  filter: grayscale(1);
  opacity: 0.6;
}
.role-row.zero strong {
  color: var(--muted);
}
.count {
  min-width: 2ch;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.meter {
  height: 10px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
}
.meter > span {
  display: block;
  height: 100%;
}
.meter .dorf {
  background: var(--good);
}
.meter .wolf {
  background: var(--wolf);
}
.meter .solo {
  background: var(--warn);
}
.issue {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
}
.issue.error {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  color: var(--danger);
}
.issue.warn {
  background: color-mix(in srgb, var(--warn) 16%, var(--surface));
  color: var(--warn);
}

/* ---------- Spieler ---------- */
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.player-row:first-of-type {
  border-top: 0;
}
.player-row.dead .pname {
  text-decoration: line-through;
  color: var(--muted);
}
.player-row .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  background: var(--surface-2);
  flex: none;
}
.player-row .avatar.hidden {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 700;
}
.player-row.picked {
  outline: 2px solid var(--accent);
  border-radius: 12px;
}
.pname {
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---------- Ablauf ---------- */
.step-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.step-head .emoji {
  font-size: 1.8rem;
}
.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--surface-2);
  color: var(--muted);
}
.step-num.ok {
  background: var(--good);
  color: #fff;
}
.script {
  font-style: italic;
  color: var(--muted);
  font-size: 0.92rem;
  border-left: 3px solid var(--border);
  padding-left: 10px;
}
.notice {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 0.95rem;
}
.notice.wolf {
  background: color-mix(in srgb, var(--wolf) 16%, var(--surface));
  color: var(--wolf);
  font-weight: 600;
}
.notice.good {
  background: color-mix(in srgb, var(--good) 16%, var(--surface));
  color: var(--good);
  font-weight: 600;
}

.phase-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.phase-bar .title {
  font-weight: 700;
  font-size: 1.1rem;
}

.announce {
  font-size: 1.15rem;
  line-height: 1.5;
}
.timer {
  font-size: 3rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.timer.low {
  color: var(--danger);
}

.log-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
}
.log-item:first-of-type {
  border-top: 0;
}
.log-group {
  font-weight: 700;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- Bottom-Navigation ---------- */
.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.nav button {
  border: 0;
  border-radius: 0;
  background: transparent;
  height: var(--nav-h);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
}
.nav button .ico {
  font-size: 1.4rem;
  line-height: 1;
}
.nav button.on {
  color: var(--accent);
  font-weight: 700;
}

/* ---------- Overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(8 9 20 / 82%);
  display: grid;
  place-items: center;
  padding: 20px;
}
.sheet {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 24px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.bigcard {
  font-size: 4.5rem;
  line-height: 1;
}
.bigname {
  font-size: 1.7rem;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  max-width: 600px;
  margin: 0 auto;
  z-index: 40;
  background: var(--danger);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

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

/* Feinschliff */
.card.hero .chip {
  background: rgb(255 255 255 / 12%);
  color: #eceefb;
  border-color: rgb(255 255 255 / 20%);
}
.row.wrap > button.grow {
  flex: 1 1 30%;
}
.role-row .grow > .row {
  align-items: center;
}

/* Nachtmodus: stark gedimmt für dunkle Räume */
:root[data-dim] {
  color-scheme: dark;
  --bg: #04050a;
  --surface: #0b0d18;
  --surface-2: #141830;
  --text: #c4c8ea;
  --muted: #8f95bd;
  --border: #1b2040;
  --accent: #7878ea;
  --accent-text: #04050a;
  --shadow: none;
}
:root[data-dim] .card.hero {
  background: #0b0d18;
}

.toast.update {
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
}
.toast.update button {
  background: rgb(255 255 255 / 25%);
  color: inherit;
  border-color: transparent;
}
