/* ─── Custom Properties ─────────────────────────────────────────────────── */
:root {
  --bg: #0f0f1a;
  --surface: #1c1c2e;
  --surface2: #2a2a3e;
  --accent: #6c63ff;
  --accent-dark: #4e47cc;
  --green: #22c55e;
  --green-dark: #16a34a;
  --red: #ef4444;
  --red-dark: #b91c1c;
  --text: #f1f1f5;
  --text-muted: #9090a8;
  --border: #3a3a52;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --timer-size: 120px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  height: 100%;
  /* Prevent zoom on input focus on iOS */
  touch-action: manipulation;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screen Management ─────────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  padding: 24px 20px env(safe-area-inset-bottom, 20px);
  flex-direction: column;
  align-items: stretch;
}

.screen.active {
  display: flex;
}

/* ─── Typography ────────────────────────────────────────────────────────── */
h1 {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

h2 {
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 700;
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  min-height: 56px;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-success {
  background: var(--green);
  color: #fff;
  flex: 1;
}
.btn-success:hover { background: var(--green-dark); }

.btn-danger {
  background: var(--surface2);
  color: var(--text-muted);
  flex: 1;
  border: 2px solid var(--border);
}
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid var(--border);
}

.end-game-row {
  padding: 0 20px env(safe-area-inset-bottom, 12px);
  padding-bottom: max(env(safe-area-inset-bottom), 12px);
}

.btn-end-game {
  width: 100%;
  font-size: 0.85rem;
  min-height: 44px;
  padding: 10px 16px;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-full { width: 100%; }

/* ─── Setup Screen ──────────────────────────────────────────────────────── */
#screen-setup {
  gap: 24px;
  padding-top: 40px;
}

.game-title {
  text-align: center;
}

.game-title h1 {
  background: linear-gradient(135deg, #6c63ff, #a78bfa, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-title .tagline {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

/* How to Play */
.how-to-play {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.how-to-play summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-tap-highlight-color: transparent;
}

.how-to-play summary::-webkit-details-marker { display: none; }

.how-to-play summary::after {
  content: '▸';
  transition: transform 0.2s;
}

.how-to-play[open] summary::after {
  transform: rotate(90deg);
}

.how-to-play-body {
  padding: 0 18px 16px;
}

.how-to-play-body ol {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.how-to-play-body ol li strong {
  color: var(--text);
}

/* Player Count */
.section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.player-count-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.count-btn {
  aspect-ratio: 1;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.count-btn:active { transform: scale(0.94); }

.count-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Player Name Inputs */
#player-names {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.name-input {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 14px 16px;
  width: 100%;
  transition: border-color 0.15s;
  /* Prevent iOS zoom */
  font-size: max(16px, 1rem);
}

.name-input:focus {
  outline: none;
  border-color: var(--accent);
}

.name-input::placeholder { color: var(--text-muted); }

/* ─── Round Intro Screen ─────────────────────────────────────────────────── */
#screen-intro {
  gap: 0;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.intro-icon {
  font-size: 5rem;
  margin-bottom: 16px;
  line-height: 1;
}

#intro-player-name {
  color: var(--accent);
}

.intro-subtitle {
  color: var(--text-muted);
  margin-top: 10px;
  font-size: 1rem;
  line-height: 1.5;
}

.intro-ready-btn {
  margin-top: 40px;
  width: 100%;
  max-width: 320px;
}

/* ─── Playing Screen ─────────────────────────────────────────────────────── */
#screen-play {
  gap: 0;
  padding: 0;
}

.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.play-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.play-round-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.play-player-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.play-score-badge {
  background: var(--surface2);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--border);
}

/* Word Card */
.word-card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 16px;
}

.difficulty-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.difficulty-badge.tier-1 { color: var(--green); border-color: var(--green); }
.difficulty-badge.tier-2 { color: #60a5fa; border-color: #60a5fa; }
.difficulty-badge.tier-3 { color: #fb923c; border-color: #fb923c; }
.difficulty-badge.tier-4 { color: var(--red); border-color: var(--red); }

.word-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  width: 100%;
  box-shadow: var(--shadow);
  animation: cardIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardIn {
  from { opacity: 0; transform: scale(0.85) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.word-text {
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* Timer */
.timer-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.timer-ring-wrap {
  position: relative;
  width: var(--timer-size);
  height: var(--timer-size);
}

.timer-ring-wrap svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.timer-ring-bg {
  fill: none;
  stroke: var(--surface2);
  stroke-width: 6;
}

.timer-ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.5s;
}

.timer-ring-progress.urgent {
  stroke: var(--red);
}

.timer-number {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: var(--text);
  transition: color 0.5s;
}

.timer-number.urgent { color: var(--red); }

@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.timer-ring-wrap.urgent {
  animation: timerPulse 0.8s ease-in-out infinite;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 12px;
  padding: 16px 20px 10px;
  flex-shrink: 0;
}

.action-buttons .btn {
  font-size: 1.2rem;
  padding: 20px 16px;
  min-height: 68px;
}

/* ─── Turn End Screen ────────────────────────────────────────────────────── */
#screen-turn-end {
  gap: 20px;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-top: 48px;
}

.turn-result-icon {
  font-size: 4rem;
  line-height: 1;
}

.turn-score-big {
  font-size: 4rem;
  font-weight: 900;
  color: var(--green);
  line-height: 1;
}

.turn-score-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.scoreboard {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  width: 100%;
  max-width: 360px;
}

.scoreboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.scoreboard-row:last-child { border-bottom: none; }

.scoreboard-row.current-player {
  background: rgba(108, 99, 255, 0.12);
}

.scoreboard-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.current-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(108, 99, 255, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
}

.scoreboard-score {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
}

/* ─── Game Over Screen ───────────────────────────────────────────────────── */
#screen-game-over {
  gap: 20px;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-top: 48px;
}

.winner-icon {
  font-size: 5rem;
  line-height: 1;
}

.winner-name {
  color: var(--accent);
}

.final-score-display {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--green);
}

.final-score-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.spacer { flex: 1; }
.mt-auto { margin-top: auto; }

.hidden { display: none !important; }

/* ─── Responsive Tweaks ──────────────────────────────────────────────────── */
@media (max-width: 360px) {
  .player-count-grid { grid-template-columns: repeat(4, 1fr); }
  .word-text { font-size: 1.6rem; }
}

@media (min-width: 600px) {
  body {
    background: #07070f;
  }
  .screen {
    margin: 24px auto;
    min-height: auto;
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  #screen-play { min-height: 640px; }
}
