:root {
  --bg-0: #0b0d12;
  --bg-1: #131722;
  --bg-2: #1d2230;
  --ink: #e8e6dd;
  --ink-dim: #a8a497;
  --accent: #c0392b;
  --accent-glow: rgba(192, 57, 43, 0.45);
  --gold: #d4a85a;
  --villager: #4a7a8c;
  --wolf: #8b1a1a;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, #1a1f2e 0%, var(--bg-0) 60%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
}

body {
  min-height: 100dvh;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) 18px env(safe-area-inset-bottom, 0);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding: 24px 0;
  animation: fade-in 0.3s ease both;
}
.screen.active {
  display: flex;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Title */
.title {
  text-align: center;
  margin-bottom: 28px;
}
.title h1 {
  font-size: clamp(2.4rem, 8vw, 3.2rem);
  margin: 0;
  letter-spacing: 0.04em;
  font-variant: small-caps;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(192, 57, 43, 0.35);
}
.tagline {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-style: italic;
  font-size: 0.95rem;
}

/* Panel cards */
.card {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border: 1px solid rgba(212, 168, 90, 0.18);
  border-radius: var(--radius);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.panel {
  padding: 24px;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 10px;
}

.counter {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}
.counter-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(212, 168, 90, 0.4);
  background: var(--bg-2);
  color: var(--gold);
  font-size: 1.6rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.counter-btn:hover {
  background: var(--bg-1);
}
.counter-btn:active {
  transform: scale(0.92);
}

#player-count {
  width: 90px;
  height: 64px;
  text-align: center;
  font-size: 2rem;
  font-weight: bold;
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: inherit;
  -moz-appearance: textfield;
}
#player-count::-webkit-outer-spin-button,
#player-count::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#player-count:focus {
  outline: none;
}

.hint {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.85rem;
  margin: 8px 0 16px;
  font-style: italic;
}

/* Role preview list */
.role-preview {
  margin: 8px 0 20px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}
.role-preview-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.95rem;
}
.role-preview-row .count {
  color: var(--gold);
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}
.role-preview-row.wolf .name {
  color: #e57373;
}

/* Primary button */
.primary-btn {
  display: block;
  width: 100%;
  padding: 16px 20px;
  font-size: 1.1rem;
  font-family: inherit;
  font-variant: small-caps;
  letter-spacing: 0.1em;
  color: var(--ink);
  background: linear-gradient(180deg, #8b2317, #5a160e);
  border: 1px solid rgba(212, 168, 90, 0.5);
  border-radius: 10px;
  cursor: pointer;
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.primary-btn:hover {
  box-shadow:
    0 8px 24px rgba(192, 57, 43, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.primary-btn:active {
  transform: translateY(1px);
}
.primary-btn.hidden {
  visibility: hidden;
}

/* Reveal screen */
.reveal-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  width: 100%;
}
.reveal-counter {
  color: var(--ink-dim);
  font-variant: small-caps;
  letter-spacing: 0.2em;
  font-size: 0.95rem;
}

/* Flipping card */
.card-flip {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 3 / 4;
  perspective: 1400px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.5, 0, 0.3, 1);
}
.card-flip.flipped .card-inner {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(212, 168, 90, 0.3);
  box-shadow:
    0 16px 50px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
}
.card-back {
  align-items: center;
  justify-content: center;
}
.card-back-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.card-back-label {
  position: absolute;
  bottom: 22px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--ink);
  letter-spacing: 0.3em;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
  opacity: 0.75;
}
.card-front {
  transform: rotateY(180deg);
  padding: 16px;
  align-items: center;
  text-align: center;
  background: linear-gradient(180deg, #1a1f2e, #0e1118);
}
.card-front img {
  width: 100%;
  max-height: 55%;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 10px;
}
.card-front h2 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-variant: small-caps;
  letter-spacing: 0.06em;
  color: var(--gold);
}
.role-team {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}
.role-team.wolf {
  color: #e57373;
}
.role-team.villager {
  color: #9bbac5;
}
.card-front p:last-child {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink);
  flex: 1;
  overflow-y: auto;
}

/* Moderator screen */
#moderator {
  justify-content: flex-start;
  padding: 18px 0 32px;
  gap: 14px;
}

.mod-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}
.phase-label {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.phase-toggle {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid rgba(212, 168, 90, 0.25);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.phase-tab {
  padding: 10px 28px;
  background: transparent;
  border: none;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.phase-tab[aria-selected="true"] {
  background: linear-gradient(180deg, #8b2317, #5a160e);
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(192, 57, 43, 0.45);
}
.phase-tab:not([aria-selected="true"]):hover {
  color: var(--ink);
}

.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold);
  margin: 0 0 4px;
}
.section-hint {
  margin: 0 0 12px;
  color: var(--ink-dim);
  font-size: 0.82rem;
  font-style: italic;
}

#moderator-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Roster */
.roster {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.alive-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.alive-toggle:hover {
  border-color: rgba(212, 168, 90, 0.35);
}
.alive-toggle .seat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-1);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.alive-toggle .role-name {
  flex: 1;
  font-size: 0.98rem;
}
.alive-toggle .alive-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(76, 175, 80, 0.18);
  color: #81c784;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.roster-row.wolf .role-name {
  color: #e57373;
}
.roster-row.dead .alive-toggle {
  opacity: 0.45;
}
.roster-row.dead .role-name {
  text-decoration: line-through;
}
.roster-row.dead .alive-pill {
  background: rgba(192, 57, 43, 0.22);
  color: #e57373;
}

/* Action checklist */
.actions {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-row label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.4;
  transition: opacity 0.15s ease;
}
.action-row input[type="checkbox"] {
  margin: 2px 0 0;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: var(--gold);
  cursor: pointer;
}
.action-row.checked label {
  opacity: 0.45;
}
.action-row.checked .action-text {
  text-decoration: line-through;
}
.action-row.note label {
  background: rgba(212, 168, 90, 0.06);
  border-color: rgba(212, 168, 90, 0.25);
  font-style: italic;
}
.action-row.conditional label {
  background: transparent;
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.12);
}
.action-row.conditional .action-text::before {
  content: "If applicable\00a0\00b7\00a0";
  color: var(--ink-dim);
  font-style: italic;
}

/* Secondary button */
.secondary-btn {
  display: block;
  width: 100%;
  padding: 12px 20px;
  margin-top: 6px;
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.secondary-btn:hover {
  color: var(--ink);
  border-color: rgba(212, 168, 90, 0.35);
}

/* Game over banner */
.game-over {
  text-align: center;
}
.game-over h2 {
  color: var(--gold);
  font-size: 1.6rem;
  margin-top: 0;
  letter-spacing: 0.04em;
}
.game-over p {
  color: var(--ink-dim);
  margin: 0 0 22px;
}
.hidden {
  display: none !important;
}
