/* ==========================================================================
   BOARDGAME TIMER DESIGN SYSTEM
   ========================================================================== */

:root {
  /* Theme Colors */
  --bg-primary: #0a0c10;
  --panel-bg: rgba(22, 28, 38, 0.45);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  
  /* Brand/Accent Colors */
  --color-primary: #3b82f6;
  --color-primary-glow: rgba(59, 130, 246, 0.5);
  --color-danger: #ef4444;
  --color-danger-glow: rgba(239, 68, 68, 0.4);
  
  /* Warning Low-Time State Colors */
  --warning-bg: #4c0519; /* Deep dark crimson */
  --warning-glow: #e11d48; /* Vibrant crimson/rose glow */
  --warning-text: #ffe4e6;
  
  /* Player Swatches (Default glowing accents) */
  --player-color-1: #10b981; /* Emerald */
  --player-color-2: #f59e0b; /* Amber */
  --player-color-3: #3b82f6; /* Blue */
  --player-color-4: #ec4899; /* Pink */
  --player-color-5: #8b5cf6; /* Purple */
  --player-color-6: #14b8a6; /* Teal */
  --player-color-7: #f97316; /* Orange */
  --player-color-8: #84cc16; /* Lime */
  
  /* Active Player Accent (dynamic fallback) */
  --active-player-color: var(--player-color-1);
  --active-player-glow: rgba(16, 185, 129, 0.3);

  /* Glassmorphism Specs */
  --glass-blur: blur(25px);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

  /* Fonts */
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ==========================================================================
   RESET & SYSTEM STYLES
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  transition: background-color 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Background Ambient Glow Elements */
.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.15;
  pointer-events: none;
  transition: all 1.2s ease;
}

.bg-glow-1 {
  width: 400px;
  height: 400px;
  background-color: var(--color-primary);
  top: -10%;
  left: -10%;
}

.bg-glow-2 {
  width: 500px;
  height: 500px;
  background-color: #8b5cf6;
  bottom: -10%;
  right: -10%;
}

/* Main Container */
#app-container {
  width: 100%;
  height: 100%;
  max-width: 600px;
  max-height: 900px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ==========================================================================
   GLASS PANELS & CARDS
   ========================================================================== */

.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 32px;
  box-shadow: var(--glass-shadow);
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   BUTTONS & INPUTS
   ========================================================================== */

.primary-btn {
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 16px 32px;
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--color-primary-glow);
  transition: all 0.25s ease;
  width: 100%;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
}

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

.secondary-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-radius: 12px;
  padding: 12px 20px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  border-radius: 50px;
  padding: 10px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  color: var(--text-main);
}

.icon-btn.danger-hover:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--color-danger);
}

input[type="number"],
input[type="text"] {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 1rem;
  outline: none;
  transition: all 0.2s ease;
}

input[type="number"]:focus,
input[type="text"]:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

/* ==========================================================================
   SCREEN STATE MANAGEMENT
   ========================================================================== */

section {
  display: none;
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
  height: 100%;
}

section.active {
  display: flex;
  flex-direction: column;
  opacity: 1;
  transform: scale(1);
}

/* ==========================================================================
   SETUP SCREEN STYLES
   ========================================================================== */

#setup-screen {
  justify-content: center;
}

#setup-screen h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.setup-group {
  margin-bottom: 24px;
}

.setup-group h2 {
  font-size: 1.1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Time Input Configuration */
.time-inputs {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time-inputs .input-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.time-inputs label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.time-inputs input {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
}

.time-separator {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 18px;
}

/* Add Player Bar */
.add-player-container {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.add-player-container input {
  flex: 1;
}

/* Players List */
.players-list {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

/* Custom Scrollbar for list */
.players-list::-webkit-scrollbar {
  width: 6px;
}
.players-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}
.players-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
.players-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 16px;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.player-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.player-badge {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.player-name {
  font-weight: 500;
  font-size: 1rem;
}

.delete-player-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.delete-player-btn:hover {
  color: var(--color-danger);
}

/* ==========================================================================
   TIMER SCREEN STYLES
   ========================================================================== */

#timer-screen {
  justify-content: center;
  align-items: center;
  height: 100%;
}

/* The entire viewport minus controls is targetable */
.tap-target {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.timer-card {
  width: 100%;
  padding: 48px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
  position: relative;
  overflow: hidden;
}

/* Outer Border glow matching active player color */
.timer-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 24px;
  border: 2px solid var(--active-player-color);
  opacity: 0.8;
  pointer-events: none;
  transition: border-color 0.4s ease;
  box-shadow: inset 0 0 20px var(--active-player-glow);
}

.player-name-banner {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--active-player-color);
  margin-bottom: 24px;
  text-shadow: 0 0 20px var(--active-player-glow);
  transition: all 0.4s ease;
  text-transform: uppercase;
}

.clock {
  font-size: clamp(4.5rem, 15dvw, 7.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 24px;
  font-variant-numeric: tabular-nums; /* Critical for timer stability */
  transition: color 0.3s ease;
}

.next-player-banner {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 16px;
  transition: color 0.4s ease;
}

.tap-instruction {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  opacity: 0.6;
  margin-top: 10px;
}

/* Floating Controls Layer (At the bottom of screen) */
.timer-controls {
  padding: 20px 0;
  display: flex;
  justify-content: center;
  gap: 16px;
  width: 100%;
  z-index: 10;
}

/* ==========================================================================
   WARNING / PULSING ALARM STATE (< 15 seconds)
   ========================================================================== */

/* Body-level state class triggered when timer <= 15s */
body.warning-low-time {
  background-color: var(--warning-bg);
}

body.warning-low-time .bg-glow-1 {
  background-color: var(--warning-glow);
  opacity: 0.25;
  width: 500px;
  height: 500px;
}

body.warning-low-time .timer-card {
  background: rgba(80, 5, 20, 0.4);
  border-color: rgba(225, 29, 72, 0.2);
}

body.warning-low-time .timer-card::after {
  border-color: var(--warning-glow);
  box-shadow: inset 0 0 30px rgba(225, 29, 72, 0.5);
  animation: warningPulse 1s infinite alternate cubic-bezier(0.4, 0, 0.6, 1);
}

body.warning-low-time .player-name-banner {
  color: #fff;
  text-shadow: 0 0 15px var(--warning-glow);
}

body.warning-low-time .clock {
  color: #fff;
  text-shadow: 0 0 15px var(--warning-glow);
  animation: textBrighten 1s infinite alternate cubic-bezier(0.4, 0, 0.6, 1);
}

@keyframes warningPulse {
  0% {
    box-shadow: inset 0 0 20px rgba(225, 29, 72, 0.3);
    opacity: 0.7;
  }
  100% {
    box-shadow: inset 0 0 45px rgba(225, 29, 72, 0.7);
    opacity: 1;
  }
}

@keyframes textBrighten {
  0% {
    opacity: 0.95;
  }
  100% {
    opacity: 1;
    text-shadow: 0 0 25px var(--warning-glow);
  }
}

/* ==========================================================================
   ALARM DIALOG (Top-Layer Native <dialog> + Animations)
   ========================================================================== */

.glass-dialog {
  border: none;
  background: none;
  outline: none;
  margin: auto; /* Centers the dialog in the viewport */
  padding: 0;
}

/* Base (closed/exit) state */
.glass-dialog {
  opacity: 0;
  transform: scale(0.92);
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.3s;
  transition-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); /* Bounce effect */
  transition-behavior: allow-discrete;
}

/* Open state */
.glass-dialog[open] {
  opacity: 1;
  transform: scale(1);
  display: block;

  @starting-style {
    opacity: 0;
    transform: scale(0.92);
  }
}

/* Backdrop styles */
.glass-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  transition: 
    display 0.3s allow-discrete,
    overlay 0.3s allow-discrete,
    background-color 0.3s ease-out,
    backdrop-filter 0.3s ease-out;
}

.glass-dialog[open]::backdrop {
  background-color: rgba(8, 2, 4, 0.75);
  backdrop-filter: blur(8px);

  @starting-style {
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
  }
}

.dialog-content {
  background: rgba(30, 10, 15, 0.8);
  border: 2px solid var(--warning-glow);
  box-shadow: 0 0 50px rgba(225, 29, 72, 0.4);
  border-radius: 28px;
  padding: 40px;
  width: 90vw;
  max-width: 420px;
  text-align: center;
  backdrop-filter: var(--glass-blur);
}

.dialog-content h2 {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--warning-glow);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

#alarm-player-name {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 24px;
}

/* Alarm pulse ring animation */
.alarm-animation-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid var(--warning-glow);
  margin: 0 auto 32px auto;
  position: relative;
  animation: alarmRingPulse 1.2s infinite ease-out;
}

.alarm-animation-ring::after {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid var(--warning-glow);
  opacity: 0.5;
  animation: alarmRingPulseOuter 1.2s infinite ease-out;
}

@keyframes alarmRingPulse {
  0% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.6);
  }
  70% {
    transform: scale(1.1);
    box-shadow: 0 0 0 20px rgba(225, 29, 72, 0);
  }
  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(225, 29, 72, 0);
  }
}

@keyframes alarmRingPulseOuter {
  0% {
    transform: scale(0.8);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

/* ==========================================================================
   GAME PAUSED STATE
   ========================================================================== */

#timer-screen.game-paused .clock,
#timer-screen.game-paused .player-name-banner,
#timer-screen.game-paused .next-player-banner {
  opacity: 0.5;
}

#timer-screen.game-paused .timer-card::after {
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.2);
  animation: pausePulse 2s infinite alternate ease-in-out;
}

@keyframes pausePulse {
  0% {
    opacity: 0.4;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.1);
  }
  100% {
    opacity: 0.8;
    box-shadow: inset 0 0 25px rgba(255, 255, 255, 0.3);
  }
}

/* ==========================================================================
   PREFERS REDUCED MOTION SUPPORT
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  body.warning-low-time .timer-card::after,
  body.warning-low-time .clock,
  .alarm-animation-ring,
  .alarm-animation-ring::after,
  #timer-screen.game-paused .timer-card::after {
    animation: none !important;
  }
  
  .glass-dialog,
  .glass-dialog[open] {
    transform: none !important;
    transition-duration: 0.1s !important;
  }
  
  @starting-style {
    .glass-dialog[open] {
      transform: none !important;
    }
  }
}
