:root {
  --primary: #827717;
  --secondary: #9E9D24;
  --accent: #AFB42B;
  --accent-glow: rgba(228, 63, 90, 0.4);
  --white-player: #CDDC39;
  --white-player-active: #F9FBE7;
  --black-player: #1f1f3a;
  --black-player-active: #2a2a50;
  --text-light: #e8e8e8;
  --text-dark: #1a1a2e;
  --text-muted: #8888aa;
  --warning: #f39c12;
  --critical: #e74c3c;
  --success: #2ecc71;
  --controls-bg: #0f0f23;
  --controls-border: #2a2a4a;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

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

html, body, #root {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--primary);
  color: var(--text-light);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--accent);
  color: white;
}

html {
  scroll-behavior: smooth;
}

.app-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== SETUP SCREEN ===== */
.setup-screen {
  height: 100%;
  overflow-y: auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(160deg, var(--primary) 0%, var(--secondary) 50%, #0f3460 100%);
}

.setup-header {
  text-align: center;
  margin-bottom: 2rem;
  animation: fadeInDown 0.5s ease;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.setup-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.setup-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.presets-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.category-group {
  animation: fadeInUp 0.4s ease both;
}

.category-group:nth-child(1) { animation-delay: 0.05s; }
.category-group:nth-child(2) { animation-delay: 0.1s; }
.category-group:nth-child(3) { animation-delay: 0.15s; }
.category-group:nth-child(4) { animation-delay: 0.2s; }

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

.category-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.category-icon {
  font-size: 1rem;
}

.preset-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.preset-btn {
  flex: 1 1 auto;
  min-width: 70px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--controls-border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-light);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.preset-btn:hover {
  background: rgba(228, 63, 90, 0.15);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.preset-btn:active {
  transform: translateY(0);
}

/* ===== CUSTOM SECTION ===== */
.custom-section {
  width: 100%;
  max-width: 480px;
  margin-top: 1.5rem;
  animation: fadeInUp 0.4s ease 0.25s both;
}

.custom-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.75rem 0;
  text-align: left;
  transition: color 0.2s;
}

.custom-toggle:hover {
  color: var(--accent);
}

.custom-form {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--controls-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  backdrop-filter: blur(4px);
  animation: fadeInUp 0.3s ease;
}

.custom-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.custom-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--controls-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-light);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.stepper-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.stepper-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 700;
  min-width: 2rem;
  text-align: center;
}

.start-custom-btn {
  padding: 0.75rem;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: white;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.start-custom-btn:hover {
  background: #c9354d;
  box-shadow: 0 4px 20px var(--accent-glow);
}

/* ===== CLOCK SCREEN ===== */
.clock-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.timer-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  overflow: hidden;
}

.timer-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.timer-white {
  background: var(--white-player);
  color: var(--text-dark);
}

.timer-white.active {
  background: var(--white-player-active);
}

.timer-white.active::before {
  background: radial-gradient(circle at center, rgba(228, 63, 90, 0.08) 0%, transparent 70%);
  opacity: 1;
}

.timer-black {
  background: var(--black-player);
  color: var(--text-light);
}

.timer-black.active {
  background: var(--black-player-active);
}

.timer-black.active::before {
  background: radial-gradient(circle at center, rgba(228, 63, 90, 0.12) 0%, transparent 70%);
  opacity: 1;
}

.timer-panel.warning .timer-time {
  color: var(--warning);
}

.timer-panel.critical .timer-time {
  color: var(--critical);
  animation: pulse 0.5s ease infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.6; }
}

.timer-panel.winner {
  opacity: 1;
}

.timer-panel.winner .timer-time {
  color: var(--success);
}

.timer-panel.loser {
  opacity: 0.4;
}

.timer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  z-index: 1;
}

.timer-content-flipped {
  transform: rotate(180deg);
}

.timer-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(3rem, 12vw, 5.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  transition: color 0.3s;
}

.timer-moves {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.5;
  min-height: 1.2rem;
}

.timer-hint {
  font-size: 0.85rem;
  opacity: 0.4;
  margin-top: 0.25rem;
  font-weight: 500;
}

.timer-indicator {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.25rem;
  animation: indicatorPulse 1.5s ease infinite;
}

@keyframes indicatorPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.timer-result {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.timer-panel.winner .timer-result {
  color: var(--success);
}

.timer-panel.loser .timer-result {
  color: var(--critical);
  opacity: 0.8;
}

/* ===== CONTROLS BAR ===== */
.controls-bar {
  background: var(--controls-bg);
  border-top: 1px solid var(--controls-border);
  border-bottom: 1px solid var(--controls-border);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  flex-shrink: 0;
  min-height: 56px;
}

.controls-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.controls-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.controls-moves {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
}

.controls-actions {
  display: flex;
  gap: 0.5rem;
}

.control-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--controls-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-light);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.control-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
}

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

.pause-btn.is-paused {
  background: var(--accent);
  border-color: var(--accent);
}

.back-btn:hover {
  background: rgba(228, 63, 90, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== PAUSE OVERLAY ===== */
.pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.pause-modal {
  text-align: center;
  padding: 2rem;
}

.pause-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.7;
}

.pause-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.pause-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.8;
  margin-bottom: 1.5rem;
}

.resume-btn {
  padding: 0.75rem 2.5rem;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: white;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.resume-btn:hover {
  box-shadow: 0 0 24px var(--accent-glow);
  transform: scale(1.05);
}

/* ===== GAME OVER BADGE ===== */
.gameover-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--controls-bg);
  border: 2px solid var(--accent);
  border-radius: 24px;
  padding: 0.5rem 1.5rem;
  z-index: 50;
  animation: badgePop 0.3s ease;
  box-shadow: 0 0 30px var(--accent-glow);
}

@keyframes badgePop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.gameover-badge span {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .setup-screen {
    padding: 1.5rem 1rem;
  }

  .setup-title {
    font-size: 1.6rem;
  }

  .preset-btn {
    padding: 0.65rem 0.75rem;
    font-size: 0.85rem;
    min-width: 60px;
  }

  .timer-time {
    font-size: clamp(2.5rem, 15vw, 4.5rem);
  }
}

@media (min-width: 641px) and (max-height: 700px) {
  .timer-time {
    font-size: 3.5rem;
  }
}

@media (min-height: 800px) {
  .timer-time {
    font-size: 6rem;
  }
}

<!-- WALKTHROUGH_SCRIPT:
[
  {"step": 1, "narration": "Welcome to Chess Clock! Choose a time control to get started. Pick from popular presets like Bullet, Blitz, Rapid, or Classical.", "view": "setup", "highlight_selector": ".presets-container", "wait_for": "user_interaction"},
  {"step": 2, "narration": "Or expand the Custom Time section to set your own minutes and increment.", "view": "setup", "highlight_selector": ".custom-toggle", "wait_for": "tap_to_continue"},
  {"step": 3, "narration": "Once you select a time control, the clock screen appears. Black's timer is at the top (flipped for the opposing player), White's is at the bottom.", "view": "game", "highlight_selector": ".clock-screen", "wait_for": "tap_to_continue"},
  {"step": 4, "narration": "Tap your side when your move is done to switch the clock. The active player's timer counts down. An increment is added after each tap.", "view": "game", "highlight_selector": ".timer-white", "wait_for": "user_interaction"},
  {"step": 5, "narration": "Use the center controls to pause, reset, or exit to the setup screen. When time runs critically low, the clock flashes red and plays a warning sound.", "view": "game", "highlight_selector": ".controls-bar", "wait_for": "tap_to_continue"}
]
-->

.time-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.time-controls-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.preset-card {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-card.active {
  border-color: rgba(99, 102, 241, 0.9);
  background: rgba(99, 102, 241, 0.18);
}

.preset-label {
  font-weight: 600;
}

.preset-meta {
  font-size: 0.9rem;
  opacity: 0.8;
}

.custom-time-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.time-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.time-input-row input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
}

.room-panel {
  width: 100%;
  max-width: 480px;
  margin-bottom: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--controls-border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(4px);
}

.room-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.room-panel-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
}

.presence-pill {
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.presence-pill.online {
  background: rgba(46, 204, 113, 0.16);
  color: var(--success);
}

.presence-pill.offline {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.room-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.room-input {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--controls-border);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text-light);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.room-buttons {
  display: flex;
  gap: 0.5rem;
}

.room-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--controls-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-light);
  font-weight: 700;
  cursor: pointer;
}

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

.room-meta {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.room-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.presence-pill::before {
  content: '';
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.9;
}

.presence-pill.connected {
  background: rgba(46, 204, 113, 0.16);
  color: var(--success);
}

.presence-pill.connecting {
  background: rgba(243, 156, 18, 0.16);
  color: var(--warning);
}

.presence-pill.disconnected {
  background: rgba(231, 76, 60, 0.14);
  color: var(--critical);
}

.presence-pill.waiting {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.clock-presence {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.2rem;
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.9;
}

.clock-presence-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.clock-presence-connected {
  color: var(--success);
}

.clock-presence-connecting {
  color: var(--warning);
}

.clock-presence-disconnected {
  color: var(--critical);
}

.clock-presence-waiting {
  color: var(--text-muted);
}

.timer-content .clock-presence {
  order: 3;
}

.game-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.analytics-panel {
  background: rgba(255, 255, 255, 0.04);
  border-top: 1px solid var(--controls-border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.analytics-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.analytics-header p {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.analytics-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.analytics-card {
  border: 1px solid var(--controls-border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.analytics-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.analytics-card strong {
  font-size: 1.1rem;
}

.analytics-card small {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.analytics-chart-wrap {
  width: 100%;
  height: 220px;
}

.analytics-chart {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.12);
}

@media (max-width: 640px) {
  .analytics-summary {
    grid-template-columns: 1fr;
  }

  .analytics-chart-wrap {
    height: 200px;
  }
}

.share-panel {
  margin-top: 0.25rem;
  border: 1px solid var(--controls-border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.14);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.share-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.share-panel-row h4 {
  font-size: 0.95rem;
  font-weight: 700;
}

.share-panel-row p {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.share-btn {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.share-btn:hover {
  box-shadow: 0 0 18px var(--accent-glow);
}

.share-feedback {
  font-size: 0.82rem;
  color: var(--success);
  font-weight: 600;
}

@media (max-width: 640px) {
  .share-panel-row {
    flex-direction: column;
    align-items: stretch;
  }

  .share-btn {
    width: 100%;
  }
}
