*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --green: #4ecca3;
  --gold: #f5c842;
  --night-bg: #0d0d1a;
  --night-accent: #5533ff;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screens ── */

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

.screen.active {
  display: flex;
}

/* ── Home ── */

h1 {
  font-size: 2.4rem;
  text-align: center;
  margin-top: 20vh;
  margin-bottom: 8px;
  line-height: 1.2;
}

.subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  text-align: center;
}

.form-group {
  width: 100%;
  margin-bottom: 16px;
}

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1.1rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--accent);
}

input[type="text"]::placeholder {
  color: var(--text-dim);
}

.button-row {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-bottom: 16px;
}

.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  width: 100%;
  min-height: 48px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--accent);
  color: white;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.primary:disabled {
  background: #555;
  cursor: not-allowed;
}

.btn.secondary {
  background: var(--bg-input);
  color: var(--text);
}

.btn.secondary:hover {
  background: #1a4a8a;
}

.hidden {
  display: none !important;
}

.error-text {
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: 8px;
  text-align: center;
}

/* ── Lobby ── */

.room-code-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 32px;
  margin-bottom: 24px;
}

.room-code-display .label {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.share-link-btn {
  margin-top: 8px;
  padding: 10px 24px;
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  background: transparent;
  color: var(--gold);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.share-link-btn:active {
  background: rgba(245, 200, 66, 0.15);
}

.player-list {
  width: 100%;
  margin-bottom: 24px;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 1rem;
}

.player-item .host-badge {
  font-size: 0.75rem;
  background: var(--gold);
  color: #111;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.player-item .you-badge {
  font-size: 0.75rem;
  background: var(--green);
  color: #111;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.player-item.disconnected {
  opacity: 0.4;
}

/* ── Role Selection ── */

.role-selection {
  width: 100%;
  margin-bottom: 20px;
}

.role-selection h3 {
  margin-bottom: 4px;
}

.role-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.role-btn {
  padding: 12px 8px;
  border: 2px solid var(--bg-input);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  min-height: 48px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  position: relative;
}

.role-btn:active {
  transform: scale(0.97);
}

.role-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
}

.role-btn .count {
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

.role-btn:not(.selected) .count {
  display: none;
}

.lobby-wait {
  color: var(--text-dim);
  text-align: center;
}

/* ── Role Card ── */

.phase-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 24px;
  margin-bottom: 16px;
}

.role-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 40px 28px;
  text-align: center;
  width: 100%;
  border: 3px solid var(--accent);
}

.role-card h2 {
  font-size: 2rem;
  margin-bottom: 12px;
  text-transform: capitalize;
}

.role-card p {
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1.5;
}

.timer-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 24px;
  text-align: center;
}

/* ── Night ── */

.night-theme {
  background: var(--night-bg);
}

.night-timer {
  font-size: 3rem;
  font-weight: 800;
  color: var(--night-accent);
  margin-bottom: 24px;
  font-variant-numeric: tabular-nums;
}

.night-action-ui {
  width: 100%;
}

.night-action-ui h3 {
  text-align: center;
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.action-prompt {
  text-align: center;
  margin-bottom: 16px;
  color: var(--text-dim);
}

/* Player/Center pick buttons for night */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.pick-btn {
  padding: 16px 12px;
  border: 2px solid var(--bg-input);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s;
  min-height: 48px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.pick-btn:active {
  transform: scale(0.97);
}

.pick-btn.selected {
  border-color: var(--night-accent);
  background: rgba(85, 51, 255, 0.2);
}

.pick-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-submit-action {
  background: var(--night-accent);
  color: white;
  width: 100%;
  margin-top: 8px;
}

.action-submitted {
  text-align: center;
  color: var(--green);
  font-size: 1.2rem;
  margin-top: 16px;
}

.no-action-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 32px 0;
}

/* ── Night Results ── */

.result-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  width: 100%;
  margin-bottom: 16px;
  line-height: 1.6;
}

.result-content .highlight {
  color: var(--gold);
  font-weight: 600;
}

/* ── Discussion / Notepad ── */

.notepad {
  width: 100%;
  margin-bottom: 20px;
}

.notepad-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 6px;
}

.notepad-row .player-name {
  font-weight: 600;
}

.notepad-row select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

/* ── Reveal ── */

.reveal-table {
  width: 100%;
  margin-bottom: 16px;
}

.reveal-row {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 6px;
  gap: 8px;
}

.reveal-row .name {
  flex: 1;
  font-weight: 600;
}

.reveal-row .original {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-transform: capitalize;
}

.reveal-row .arrow {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.reveal-row .final {
  color: var(--gold);
  font-weight: 600;
  text-transform: capitalize;
}

.reveal-row .same {
  color: var(--text-dim);
}

.reveal-center {
  width: 100%;
  margin-bottom: 20px;
}

.reveal-center h4 {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.center-cards {
  display: flex;
  gap: 8px;
}

.center-card {
  flex: 1;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
  text-align: center;
  text-transform: capitalize;
  color: var(--text-dim);
}

.guess-results {
  width: 100%;
  margin-bottom: 20px;
}

.guess-results h3 {
  margin-bottom: 8px;
}

.guess-row {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 4px;
  gap: 8px;
}

.guess-row .guess-name {
  flex: 1;
  font-weight: 600;
}

.guess-row .guess-role {
  text-transform: capitalize;
}

.guess-row .guess-correct {
  color: var(--green);
}

.guess-row .guess-wrong {
  color: var(--accent);
}

/* ── Seer center pick ── */
.seer-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.seer-mode-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--bg-input);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  font-size: 0.9rem;
}

.seer-mode-btn.active {
  border-color: var(--night-accent);
  background: rgba(85, 51, 255, 0.2);
}

/* ── Responsive ── */

@media (max-height: 600px) {
  h1 {
    margin-top: 10vh;
    font-size: 2rem;
  }
}
