:root {
  color-scheme: light;
  --bg: #f7f7f2;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #6b7280;
  --line: #d8d8ce;
  --accent: #0f766e;
  --danger: #b42318;
  --night: #20283b;
  --day: #f5b841;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }
.app-shell { min-height: 100vh; padding: 16px; }
.app-shell-reveal { padding: 0; }
.phase { max-width: 1180px; margin: 0 auto; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-weight: 800; text-transform: uppercase; font-size: 12px; }
.muted { color: var(--muted); }
.canvas-board {
  --chip-size: 64px;
  position: relative;
  width: 100%;
  height: clamp(420px, 68vh, 680px);
  margin: 16px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  touch-action: none;
}

.chip {
  --wake-glow: rgba(15, 118, 110, 0.3);
  position: absolute;
  width: var(--chip-size);
  height: var(--chip-size);
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fdfdfb;
  color: var(--ink);
  font-weight: 850;
  letter-spacing: 0;
  box-shadow: 0 6px 18px rgba(32, 33, 36, 0.12);
  cursor: default;
  user-select: none;
}

.chip-label {
  max-width: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-draggable {
  cursor: grab;
}

.chip-draggable:active {
  cursor: grabbing;
}

.chip-selectable {
  border-color: var(--accent);
  cursor: pointer;
}

.chip-selectable:focus-visible,
.chip-draggable:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.3);
  outline-offset: 3px;
}

.chip-mod {
  border-color: #334155;
  background: #202124;
  color: #ffffff;
}

.chip.chip-role-mafia {
  --wake-glow: rgba(153, 27, 27, 0.34);
  border-color: #991b1b;
  background: #fff1f2;
  color: #3f0b0b;
}

.chip.chip-role-doctor {
  --wake-glow: rgba(4, 120, 87, 0.34);
  border-color: #047857;
  background: #ecfdf5;
  color: #064e3b;
}

.chip.chip-role-detective {
  --wake-glow: rgba(180, 83, 9, 0.34);
  border-color: #b45309;
  background: #fffbeb;
  color: #3d2503;
}

.chip.chip-role-jester {
  --wake-glow: rgba(124, 58, 237, 0.34);
  border-color: #7c3aed;
  background: #f5f3ff;
  color: #2e1065;
}

.chip-night-active {
  z-index: 2;
  animation: night-chip-glow 1.35s ease-in-out infinite;
}

.chip-dead {
  opacity: 0.45;
  text-decoration: line-through;
}

.role-icon,
.role-option-icon {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: #334155;
  color: #ffffff;
  line-height: 1;
}

.role-icon-svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.role-icon-mafia {
  background: #991b1b;
}

.role-icon-doctor {
  background: #047857;
}

.role-icon-detective {
  background: #b45309;
}

.role-icon-jester {
  background: #7c3aed;
}

.night-marker-list {
  position: absolute;
  right: 2px;
  bottom: 2px;
  display: flex;
  gap: 2px;
}

.night-marker {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid var(--panel);
  border-radius: 50%;
  color: #ffffff;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(32, 33, 36, 0.16);
}

.night-marker-attack {
  background: #dc2626;
}

.night-marker-save {
  background: #0f766e;
}

.night-marker-svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes night-chip-glow {
  0%, 100% {
    box-shadow: 0 6px 18px rgba(32, 33, 36, 0.12), 0 0 0 0 var(--wake-glow);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 8px 22px rgba(32, 33, 36, 0.18), 0 0 0 8px var(--wake-glow);
    transform: scale(1.04);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chip-night-active {
    animation: none;
    box-shadow: 0 8px 22px rgba(32, 33, 36, 0.18), 0 0 0 6px var(--wake-glow);
  }
}

.phase-banner {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  background: var(--panel);
}

.phase-banner h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.setup-summary {
  margin-bottom: 0;
}

.language-field {
  max-width: 220px;
  margin-top: 12px;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.compact-grid,
.player-list,
.role-option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
  font-weight: 750;
}

.field input,
.field select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #ffffff;
  color: var(--ink);
}

.count-stepper {
  display: grid;
  grid-template-columns: 48px minmax(28px, 1fr) 48px;
  gap: 6px;
  align-items: stretch;
}

.count-stepper-button {
  min-height: 48px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.count-stepper-button:disabled {
  opacity: 0.45;
}

.count-stepper-value {
  min-height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  font-size: 18px;
  font-weight: 900;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.setup-action {
  margin-left: auto;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.button-icon-svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 800;
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

button.danger {
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--danger);
  background: #fff7f6;
}

.role-assignment-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.role-assignment-header h2,
.role-assignment-header p {
  margin: 0;
}

.current-role {
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  font-weight: 850;
}

.role-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.role-option-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.18);
}

.role-option-icon {
  position: static;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
}

.role-option-icon .role-icon-svg {
  width: 14px;
  height: 14px;
}

.error-list {
  color: var(--danger);
  font-weight: 750;
}

.success {
  color: var(--accent);
  font-weight: 850;
}

.night-banner {
  background: var(--night);
  color: #ffffff;
  border-color: var(--night);
}

.night-banner .eyebrow {
  color: #9de7d9;
}

.prompt {
  margin: 8px 0 12px;
  font-size: 18px;
  font-weight: 800;
}

.night-status {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.night-status-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.night-status-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.error-message {
  color: var(--danger);
  font-weight: 850;
}

.detective-banner {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 18px;
  background: #111827;
  color: #ffffff;
  text-align: center;
  padding: 20px;
}

.detective-result {
  max-inline-size: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(48px, 12vw, 180px);
  font-weight: 1000;
  line-height: 0.95;
  letter-spacing: 0;
}

.phase-role-reveal {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #111827;
  color: #ffffff;
}

.role-reveal-card {
  width: min(100%, 520px);
  display: grid;
  gap: 16px;
  text-align: center;
}

.role-reveal-card h1 {
  margin: 0;
  font-size: clamp(32px, 9vw, 64px);
  line-height: 1;
}

.role-reveal-hold {
  min-height: min(54vh, 420px);
  display: grid;
  gap: 14px;
  place-items: center;
  border-color: rgba(255, 255, 255, 0.18);
  background: #1f2937;
  color: #ffffff;
  touch-action: none;
  user-select: none;
}

.role-reveal-result {
  max-inline-size: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(44px, 13vw, 120px);
  font-weight: 1000;
  line-height: 0.95;
  letter-spacing: 0;
}

.role-reveal-return .role-reveal-card {
  gap: 22px;
}

.result-mafia {
  background: #450a0a;
}

.result-villager {
  background: #064e3b;
}

.day-banner {
  background: var(--day);
  color: #3d2a04;
  border-color: #d99a12;
}

.day-banner .eyebrow {
  color: #6f4d05;
}

.nominee-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.nominee {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.nominee-leading {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.2);
}

.vote-threshold {
  margin: 8px 0 12px;
  padding: 10px;
  border: 1px solid rgba(15, 118, 110, 0.25);
  border-radius: 8px;
  background: #eefaf7;
  color: #134e4a;
  font-weight: 800;
}

.nominee-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.nominee-ready {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.22);
}

.vote-ready-badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.vote-controls {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: 8px;
  align-items: stretch;
}

.vote-stepper {
  min-height: 56px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.vote-total {
  min-height: 56px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.vote-total strong {
  font-size: 22px;
  line-height: 1;
}

.vote-total span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.player-count-field {
  margin-bottom: 10px;
}

.endgame-banner {
  background: #111827;
  color: #ffffff;
  border-color: #111827;
}

.endgame-banner .eyebrow {
  color: #d1d5db;
}

.final-list {
  display: grid;
  gap: 6px;
  padding-left: 20px;
}

@media (max-width: 680px) {
  .app-shell {
    padding: 8px;
  }

  .app-shell.app-shell-reveal {
    padding: 0;
  }

  .phase-banner {
    padding: 12px;
    margin-bottom: 10px;
  }

  .phase-banner h1 {
    font-size: 24px;
  }

  .panel {
    padding: 10px;
    margin-bottom: 10px;
  }

  .prompt {
    margin: 6px 0 10px;
    font-size: 16px;
  }

  .phase-role-reveal {
    padding: 12px;
  }

  .role-reveal-hold {
    min-height: 48vh;
  }

  .night-status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  .night-status-item {
    min-height: 44px;
    padding: 8px;
  }

  .compact-grid,
  .player-list,
  .role-option-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
  }

  .canvas-board {
    --chip-size: 58px;
    aspect-ratio: 1 / 1;
    height: auto;
    margin: 10px 0;
  }

  .chip {
    width: 58px;
    height: 58px;
  }

  .action-row {
    gap: 8px;
    margin-top: 10px;
  }

  .role-icon {
    width: 22px;
    height: 22px;
  }

  .night-marker {
    width: 22px;
    height: 22px;
  }

  .role-icon-svg {
    width: 14px;
    height: 14px;
  }

  .night-marker-svg {
    width: 14px;
    height: 14px;
  }
  .nominee-list {
    grid-template-columns: 1fr;
  }

  .vote-controls {
    grid-template-columns: 64px 1fr 64px;
  }
}
