:root {
  --bg: #0f1320;
  --bg-elev: #1a2032;
  --accent: #c0392b;
  --accent-2: #e67e22;
  --selected: #f1c40f;
  --text: #f5f6fa;
  --muted: #8a93a8;
  --ok: #27ae60;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  /* Avoid accidental text selection / long-press callouts during the game. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

/* ---------- screens ---------- */
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh; /* accounts for mobile browser chrome */
  flex-direction: column;
  align-items: center;
  /* Honor notches / home indicator via safe-area insets. */
  padding: calc(env(safe-area-inset-top) + 20px)
           calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 24px)
           calc(env(safe-area-inset-left) + 16px);
  gap: 20px;
}
.screen.active { display: flex; }

h1 { font-size: 2rem; text-align: center; }
.subtitle { color: var(--muted); text-align: center; }
.hidden { display: none !important; }

/* ---------- setup ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 560px;
}

.card-tile {
  position: relative;
  border: 3px solid transparent;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-elev);
  transition: transform 0.08s ease, border-color 0.12s ease, opacity 0.12s ease;
  opacity: 0.45;
  filter: grayscale(0.6);
}
.card-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
.card-tile .tile-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  font-size: 0.7rem;
  text-align: center;
  padding: 3px 2px;
  background: rgba(0, 0, 0, 0.6);
}
.card-tile.selected {
  opacity: 1;
  filter: none;
  border-color: var(--selected);
  transform: translateY(-2px);
}
.card-tile:active { transform: scale(0.96); }

.setup-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 560px;
}
.control {
  position: relative;
  display: flex;
  align-items: center;
}
.control-icon {
  position: absolute;
  left: 14px;
  font-size: 1.2rem;
  pointer-events: none;
}
.control select,
.control input {
  height: 56px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid #2c3346;
  border-radius: 12px;
  padding: 0 16px 0 44px;
  font-size: 1rem;
}
.control input[type="number"] { width: 120px; padding-right: 48px; }
.control-suffix {
  position: absolute;
  right: 16px;
  font-size: 0.95rem;
  color: var(--muted);
  pointer-events: none;
}
.setup-controls .primary-btn { height: 56px; padding: 0 28px; }

/* ---------- buttons ---------- */
.primary-btn, .secondary-btn, .danger-btn {
  border: none;
  border-radius: 12px;
  padding: 16px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.08s ease, opacity 0.12s ease;
}
.primary-btn { background: var(--accent); }
.secondary-btn { background: #34405c; }
.danger-btn { background: #7a2018; }
.primary-btn:active, .secondary-btn:active, .danger-btn:active { transform: scale(0.97); }
.primary-btn:disabled {
  background: #3a3f4d;
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- game ---------- */
#screen-game { justify-content: space-between; }

.card-stack {
  position: relative;
  width: 100%;
  max-width: 560px;
  flex: 1;
  min-height: 280px;
}
.stack-card {
  position: absolute;
  width: 110px;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  left: 50%;
  top: 50%;
}
.stack-card img {
  display: block;
  width: 100%;
  border-radius: 10px;
}

.game-status { text-align: center; }
.phase-label { font-size: 1.3rem; color: var(--accent-2); min-height: 1.6em; }
.timer-display {
  font-size: 4.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}

.game-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

/* ---------- voting ---------- */
.voting-text {
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 22px 24px;
  max-width: 560px;
  line-height: 1.6;
}
.voting-text p { margin-bottom: 12px; font-weight: 600; }
.voting-text ul { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- mobile (phones) ---------- */
@media (max-width: 480px) {
  .card-grid { gap: 8px; }
  .card-tile .tile-name { font-size: 0.62rem; }

  /* Keep soundtrack and timer side by side on one row; button spans below. */
  .setup-controls { gap: 12px; }
  .control { flex: 1; min-width: 0; }
  .control select,
  .control input[type="number"] { width: 100%; }
  .setup-controls .primary-btn { flex-basis: 100%; width: 100%; }

  /* Make the in-play controls span the screen width for big tap targets. */
  .game-controls { max-width: none; }
  .timer-display { font-size: 3.6rem; }
  .card-stack { min-height: 240px; }
}

/* Larger taps on coarse pointers regardless of width. */
@media (pointer: coarse) {
  .secondary-btn, .danger-btn { padding: 18px 28px; }
}
