/*
================================================================================
  THE SNAKE AND THE HUNTER - DESIGN SYSTEM
================================================================================

  Modern CSS design system with comprehensive design tokens,
  component architecture, and visual enhancements.

  Table of Contents:
  1. Design Tokens
  2. Base Styles
  3. Components
     - Buttons
     - Forms
     - Cards
     - Modals
     - Badges
  4. Game-Specific Styles
     - SVG Game Board
     - Player Cards
     - Turn Indicators
  5. Layout
  6. Animations & Keyframes
  7. Responsive Design
  8. Accessibility

================================================================================
*/

/* ========================================
   1. DESIGN TOKENS
   ======================================== */

:root {
  /* === COLORS === */

  /* Neutrals - Dark theme optimized */
  --color-neutral-900: #0d0d15;
  --color-neutral-800: #1a1a2e;        /* Main background */
  --color-neutral-700: #16213e;        /* Surface/card */
  --color-neutral-600: #0f3460;        /* Secondary surface */
  --color-neutral-500: #2a2a4a;        /* Grid background */
  --color-neutral-400: #3a3a5a;        /* Borders */
  --color-neutral-300: #6b6b8a;        /* Tertiary */
  --color-neutral-200: #a0a0a0;        /* Muted text */
  --color-neutral-100: #eaeaea;        /* Primary text */
  --color-neutral-50: #ffffff;         /* Pure white */

  /* Brand Colors */
  --color-primary-600: #d63851;
  --color-primary-500: #e94560;
  --color-primary-400: #ff6b84;
  --color-success-600: #3db88a;
  --color-success-500: #4ecca3;
  --color-success-400: #6fffbd;

  /* Game-specific colors */
  --color-snake-head: #7fff00;
  --color-snake-tail: #00bfff;

  /* === SEMANTIC COLORS === */

  /* Backgrounds */
  --bg-body: var(--color-neutral-800);
  --bg-surface: var(--color-neutral-700);
  --bg-surface-elevated: var(--color-neutral-600);
  --bg-overlay: rgba(0, 0, 0, 0.85);
  --bg-grid: var(--color-neutral-500);

  /* Text */
  --text-primary: var(--color-neutral-100);
  --text-secondary: var(--color-neutral-200);
  --text-tertiary: var(--color-neutral-300);
  --text-inverse: var(--color-neutral-900);

  /* Borders */
  --border-subtle: var(--color-neutral-400);
  --border-default: var(--color-neutral-600);
  --border-strong: var(--color-neutral-300);

  /* Interactive */
  --interactive-primary: var(--color-primary-500);
  --interactive-primary-hover: var(--color-primary-400);
  --interactive-secondary: var(--color-success-500);
  --interactive-secondary-hover: var(--color-success-400);

  /* Game-specific semantic */
  --game-snake: var(--color-success-500);
  --game-hunter: var(--color-primary-500);

  /* Alpha variations for consistent transparency */
  --alpha-snake-10: rgba(78, 204, 163, 0.1);
  --alpha-snake-15: rgba(78, 204, 163, 0.15);
  --alpha-snake-20: rgba(78, 204, 163, 0.2);
  --alpha-snake-40: rgba(78, 204, 163, 0.4);
  --alpha-snake-80: rgba(78, 204, 163, 0.8);
  --alpha-hunter-10: rgba(233, 69, 96, 0.1);
  --alpha-hunter-20: rgba(233, 69, 96, 0.2);
  --alpha-white-10: rgba(255, 255, 255, 0.1);

  /* === SPACING === */
  --space-0: 0;
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-7: 2rem;      /* 32px */
  --space-8: 2.5rem;    /* 40px */
  --space-9: 3rem;      /* 48px */
  --space-10: 4rem;     /* 64px */

  /* === TYPOGRAPHY === */

  /* Font Families */
  --font-primary: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;

  /* Font Sizes - Major Third Scale (1.25) */
  --font-size-xs: 0.64rem;    /* ~10px */
  --font-size-sm: 0.8rem;     /* ~13px */
  --font-size-base: 1rem;     /* 16px */
  --font-size-md: 1.25rem;    /* 20px */
  --font-size-lg: 1.563rem;   /* ~25px */
  --font-size-xl: 1.953rem;   /* ~31px */
  --font-size-2xl: 2.441rem;  /* ~39px */
  --font-size-3xl: 3.052rem;  /* ~49px */

  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Line Heights */
  --line-height-tight: 1.2;
  --line-height-snug: 1.375;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;
  --line-height-loose: 2;

  /* Letter Spacing */
  --letter-spacing-tight: -0.025em;
  --letter-spacing-normal: 0;
  --letter-spacing-wide: 0.05em;
  --letter-spacing-wider: 0.1em;
  --letter-spacing-widest: 0.15em;

  /* === BORDER RADIUS === */
  --radius-none: 0;
  --radius-sm: 0.25rem;    /* 4px */
  --radius-base: 0.5rem;   /* 8px */
  --radius-md: 0.75rem;    /* 12px */
  --radius-lg: 1rem;       /* 16px */
  --radius-xl: 1.25rem;    /* 20px */
  --radius-full: 9999px;   /* Fully rounded */

  /* === SHADOWS === */

  /* Elevation Shadows - Multi-layer for depth */
  --shadow-none: none;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3), 0 1px 3px 0 rgba(0, 0, 0, 0.2);
  --shadow-base: 0 2px 4px -1px rgba(0, 0, 0, 0.3), 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -2px rgba(0, 0, 0, 0.3), 0 8px 12px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.5);

  /* Glow Shadows - Game-specific */
  --shadow-glow-snake-sm: 0 0 6px var(--color-success-500);
  --shadow-glow-snake-md: 0 0 12px var(--color-success-500);
  --shadow-glow-snake-lg: 0 0 20px var(--color-success-500), 0 0 30px var(--color-success-500);
  --shadow-glow-hunter-sm: 0 0 6px var(--color-primary-500);
  --shadow-glow-hunter-md: 0 0 12px var(--color-primary-500);
  --shadow-glow-hunter-lg: 0 0 20px var(--color-primary-500), 0 0 30px var(--color-primary-500);
  --shadow-glow-head: 0 0 6px var(--color-snake-head);
  --shadow-glow-tail: 0 0 6px var(--color-snake-tail);

  /* === TRANSITIONS & ANIMATIONS === */

  /* Durations */
  --duration-instant: 0ms;
  --duration-fast: 100ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
  --duration-slower: 500ms;

  /* Easing curves */
  --ease-linear: linear;
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* Common transition properties */
  --transition-fast: all var(--duration-fast) var(--ease-out);
  --transition-normal: all var(--duration-normal) var(--ease-out);
  --transition-slow: all var(--duration-slow) var(--ease-out);
  --transition-colors: color var(--duration-normal) var(--ease-out),
                       background-color var(--duration-normal) var(--ease-out),
                       border-color var(--duration-normal) var(--ease-out);
  --transition-transform: transform var(--duration-fast) var(--ease-out);
  --transition-opacity: opacity var(--duration-normal) var(--ease-out);

  /* === Z-INDEX === */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-popover: 500;
  --z-tooltip: 600;
  --z-notification: 700;
  --z-max: 999;

  /* === SIZES === */

  /* Icon sizes */
  --size-icon-xs: 0.75rem;   /* 12px */
  --size-icon-sm: 1rem;      /* 16px */
  --size-icon-base: 1.25rem; /* 20px */
  --size-icon-md: 1.5rem;    /* 24px */
  --size-icon-lg: 2rem;      /* 32px */
  --size-icon-xl: 3rem;      /* 48px */

  /* Button heights */
  --size-button-sm: 2rem;    /* 32px */
  --size-button-base: 2.5rem; /* 40px */
  --size-button-lg: 3rem;    /* 48px */

  /* Input heights */
  --size-input-sm: 2rem;
  --size-input-base: 2.5rem;
  --size-input-lg: 3rem;

  /* === GRADIENTS === */
  --gradient-primary: linear-gradient(135deg, #e94560 0%, #ff6b84 100%);
  --gradient-secondary: linear-gradient(135deg, #4ecca3 0%, #6fffbd 100%);
  --gradient-surface: linear-gradient(180deg, #16213e 0%, #0f1828 100%);
  --gradient-shimmer: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0) 100%
  );
}

/* ========================================
   2. BASE STYLES
   ======================================== */

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

body {
  font-family: var(--font-primary);
  background-color: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: var(--line-height-normal);
  font-size: var(--font-size-base);
}

/* ========================================
   3. COMPONENTS
   ======================================== */

/* --- Buttons --- */

.btn {
  /* Layout */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);

  /* Sizing */
  height: var(--size-button-base);
  padding: 0 var(--space-6);

  /* Typography */
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  text-decoration: none;
  white-space: nowrap;

  /* Visual */
  border: none;
  border-radius: var(--radius-base);
  cursor: pointer;
  user-select: none;

  /* Animation */
  transition: var(--transition-colors), var(--transition-transform), box-shadow var(--duration-normal) var(--ease-out);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* Button variants */
.btn-primary {
  background: var(--gradient-primary);
  color: var(--color-neutral-50);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 8px 16px -4px rgba(233, 69, 96, 0.4), 0 4px 8px -2px rgba(233, 69, 96, 0.3);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 2px solid var(--border-default);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--interactive-secondary);
  color: var(--interactive-secondary);
  box-shadow: var(--shadow-md);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  box-shadow: none;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--alpha-white-10);
  color: var(--text-primary);
}

/* Button sizes */
.btn-sm {
  height: var(--size-button-sm);
  padding: 0 var(--space-4);
  font-size: var(--font-size-sm);
}

.btn-lg {
  height: var(--size-button-lg);
  padding: 0 var(--space-7);
  font-size: var(--font-size-md);
}

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

/* Icon-only buttons */
.btn-icon {
  width: var(--size-button-base);
  padding: 0;
}

.btn-icon.btn-sm {
  width: var(--size-button-sm);
}

/* Specialized icon buttons */
.copy-btn,
.sound-btn,
.leave-btn,
.share-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  margin-left: var(--space-2);
  border-radius: var(--radius-sm);
  transition: var(--transition-colors);
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.copy-btn:hover,
.sound-btn:hover,
.share-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

.leave-btn:hover {
  color: var(--interactive-primary);
  background: var(--alpha-hunter-10);
}

/* Icon states for copy/share buttons */
.copy-btn .check-icon,
.share-btn .check-icon {
  display: none;
  color: var(--game-snake);
}

.copy-btn.copied .copy-icon,
.share-btn.copied .share-icon {
  display: none;
}

.copy-btn.copied .check-icon,
.share-btn.copied .check-icon {
  display: block;
  animation: checkmark-pop var(--duration-slow) var(--ease-out);
}

/* Sound button icon states */
.sound-btn .sound-off {
  display: none;
}

.sound-btn.muted .sound-on {
  display: none;
}

.sound-btn.muted .sound-off {
  display: block;
}

/* Copy code button (in game instructions) */
.copy-code-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  background: var(--bg-surface-elevated);
  border: 2px solid var(--game-snake);
  border-radius: var(--radius-base);
  padding: var(--space-3) var(--space-6);
  margin-top: var(--space-3);
  cursor: pointer;
  transition: var(--transition-transform), box-shadow var(--duration-normal) var(--ease-out);
}

.copy-code-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-glow-snake-md);
}

.copy-code-btn:active {
  transform: scale(0.98);
}

.copy-code-btn strong {
  font-size: var(--font-size-lg);
  font-family: var(--font-mono);
  letter-spacing: var(--letter-spacing-widest);
  color: var(--game-snake);
}

.copy-code-btn .copy-hint {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
}

.copy-code-btn.copied {
  border-color: var(--game-snake);
  background: var(--alpha-snake-20);
}

.copy-code-btn.copied .copy-hint {
  color: var(--game-snake);
}

/* Copy watch button */
.copy-watch-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-base);
  padding: var(--space-2) var(--space-4);
  margin-top: var(--space-3);
  margin-left: var(--space-2);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  transition: var(--transition-normal);
}

.copy-watch-btn:hover {
  border-color: var(--game-snake);
  color: var(--game-snake);
  background: var(--alpha-snake-15);
  transform: scale(1.02);
}

.copy-watch-btn:active {
  transform: scale(0.98);
}

.copy-watch-btn.copied {
  border-color: var(--game-snake);
  color: var(--game-snake);
  background: var(--alpha-snake-20);
}

/* Share spectator button */
.share-spectator-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-base);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: var(--font-size-base);
  transition: var(--transition-normal);
}

.share-spectator-btn:hover {
  border-color: var(--game-snake);
  color: var(--game-snake);
  background: var(--alpha-snake-15);
}

.share-spectator-btn.copied {
  border-color: var(--game-snake);
  color: var(--game-snake);
  background: var(--alpha-snake-20);
}

/* --- Forms --- */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  position: relative;
}

.form-group label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  line-height: var(--line-height-snug);
  transition: var(--transition-colors);
}

.form-group input,
.form-group select {
  /* Sizing */
  width: 100%;
  height: var(--size-input-base);
  padding: 0 var(--space-4);

  /* Typography */
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  line-height: var(--line-height-normal);

  /* Visual */
  background: var(--bg-body);
  border: 2px solid var(--border-default);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-sm);

  /* Animation */
  transition:
    border-color var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out),
    background-color var(--duration-normal) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

/* Hover state */
.form-group input:hover:not(:focus) {
  border-color: var(--border-strong);
  background: rgba(22, 33, 62, 0.5);
}

.form-group select:hover:not(:focus) {
  border-color: var(--border-strong);
  background-color: rgba(22, 33, 62, 0.5);
}

/* Focus state with glow effect */
.form-group input:focus {
  outline: none;
  border-color: var(--interactive-primary);
  background: var(--bg-body);
  box-shadow:
    0 0 0 3px var(--alpha-hunter-20),
    0 4px 12px rgba(233, 69, 96, 0.15);
  transform: translateY(-1px);
}

.form-group select:focus {
  outline: none;
  border-color: var(--interactive-primary);
  background-color: var(--bg-body);
  box-shadow:
    0 0 0 3px var(--alpha-hunter-20),
    0 4px 12px rgba(233, 69, 96, 0.15);
  transform: translateY(-1px);
}

/* Label color change on focus */
.form-group input:focus + label,
.form-group select:focus + label {
  color: var(--interactive-primary);
}

/* Placeholder styling */
.form-group input::placeholder {
  color: var(--text-tertiary);
  opacity: 0.6;
  transition: opacity var(--duration-normal) var(--ease-out);
}

.form-group input:focus::placeholder {
  opacity: 0.4;
}

/* Valid state (when input has value) */
.form-group input:valid:not(:placeholder-shown) {
  border-color: var(--game-snake);
}

.form-group input:valid:not(:placeholder-shown):not(:focus) {
  background: var(--alpha-snake-10);
}

/* Invalid state (only show after interaction) */
.form-group input:invalid:not(:placeholder-shown):not(:focus) {
  border-color: var(--interactive-primary);
  background: var(--alpha-hunter-10);
}

/* Select specific styling */
.form-group select {
  /* Remove default arrow */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  /* Custom arrow */
  padding-right: var(--space-10);
  cursor: pointer;

  /* Default state - arrow gray */
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23a0a0a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  background-size: 10px 6px;
}

/* Hover state - arrow white */
.form-group select:hover:not(:focus) {
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23eaeaea' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Focus state - arrow red */
.form-group select:focus {
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23e94560' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Select options styling */
.form-group select option {
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: var(--space-2);
}

/* Disabled state */
.form-group input:disabled,
.form-group select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-surface);
  border-color: var(--border-subtle);
}

.form-group input:disabled:hover,
.form-group select:disabled:hover {
  border-color: var(--border-subtle);
  transform: none;
}

/* Required field indicator (optional enhancement) */
.form-group label[for]:has(+ input[required])::after,
.form-group label[for]:has(+ select[required])::after {
  content: '*';
  color: var(--interactive-primary);
  margin-left: var(--space-1);
  font-weight: var(--font-weight-bold);
}

/* --- Cards --- */

.card {
  /* Layout */
  background: var(--gradient-surface);

  /* Spacing */
  padding: var(--space-6);

  /* Visual */
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-base);

  /* Animation */
  transition: var(--transition-slow);
}

.card h2 {
  margin-bottom: var(--space-4);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* Player cards */
.player-card {
  /* Layout */
  padding: var(--space-4);
  text-align: center;

  /* Visual */
  background: rgba(22, 33, 62, 0.6);
  border-radius: var(--radius-md);
  border: 2px solid transparent;

  /* Glassmorphism */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  /* Animation */
  transition:
    border-color var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out),
    transform var(--duration-normal) var(--ease-out);
}

.player-card.active {
  border-color: var(--interactive-primary);
}

.player-card.snake-role {
  border-color: var(--game-snake);
}

.player-card.snake-role.active {
  box-shadow:
    0 0 0 2px var(--game-snake),
    0 0 16px rgba(78, 204, 163, 0.4),
    var(--shadow-base);
}

.player-card.hunter-role {
  border-color: var(--game-hunter);
}

.player-card.hunter-role.active {
  box-shadow:
    0 0 0 2px var(--game-hunter),
    0 0 16px rgba(233, 69, 96, 0.4),
    var(--shadow-base);
}

.player-card.active.my-turn {
  animation: card-breathe 2s var(--ease-in-out) infinite;
}

.player-name {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-md);
  margin-bottom: var(--space-2);
}

.player-role {
  font-size: var(--font-size-sm);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: var(--space-2);
  font-weight: var(--font-weight-semibold);
}

.player-role.snake {
  background: var(--game-snake);
  color: var(--text-inverse);
}

.player-role.hunter {
  background: var(--game-hunter);
  color: var(--color-neutral-50);
}

.player-score {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.score-value {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

/* --- Modals --- */

.modal {
  /* Layout */
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);

  /* Visual */
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);

  /* Stacking */
  z-index: var(--z-modal);

  /* Animation */
  animation: modal-fade-in var(--duration-normal) var(--ease-out);
}

.modal.hidden {
  display: none;
}

.modal-content {
  /* Layout */
  background: var(--bg-surface);
  max-width: 28rem;
  width: 100%;
  text-align: center;

  /* Spacing */
  padding: var(--space-7);

  /* Visual */
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2xl);

  /* Animation */
  animation: modal-slide-up var(--duration-slow) var(--ease-out);
}

.modal-content h2 {
  margin-bottom: var(--space-4);
  color: var(--interactive-primary);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.modal-content .btn {
  margin-top: var(--space-2);
}

/* Modal variants */
.share-modal {
  max-width: 450px;
}

.share-modal h2 {
  margin-bottom: var(--space-2);
}

.share-modal > p {
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

/* Final scores in game over modal */
.final-scores {
  margin: var(--space-6) 0;
}

.score-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-default);
}

.round-message {
  margin: var(--space-4) 0;
  color: var(--text-secondary);
}

/* Share link container */
.share-link-container {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.share-link-container input {
  flex: 1;
  padding: var(--space-3);
  border: 2px solid var(--border-default);
  border-radius: var(--radius-base);
  background: var(--bg-body);
  color: var(--game-snake);
  font-size: var(--font-size-sm);
  font-family: var(--font-mono);
}

.share-link-container input:focus {
  outline: none;
  border-color: var(--game-snake);
}

.share-link-container .btn {
  width: auto;
  padding: 0 var(--space-6);
}

.share-link-container .btn.copied {
  background: var(--game-snake);
}

/* Dividers */
.divider,
.share-divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-secondary);
  margin: var(--space-4) 0;
}

.share-divider {
  font-size: var(--font-size-sm);
}

.divider::before,
.divider::after,
.share-divider::before,
.share-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-default);
}

/* --- Badges --- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-wider);
  text-transform: uppercase;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
}

.badge-snake {
  background: var(--game-snake);
  color: var(--text-inverse);
}

.badge-hunter {
  background: var(--game-hunter);
  color: var(--color-neutral-50);
}

.spectator-badge {
  background: var(--bg-surface-elevated);
  color: var(--game-snake);
  border-color: var(--game-snake);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  margin-right: var(--space-4);
}

/* Spectator count */
.spectator-count {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-left: var(--space-4);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.spectator-count svg {
  width: 14px;
  height: 14px;
}

/* ========================================
   4. GAME-SPECIFIC STYLES
   ======================================== */

/* --- SVG Game Board --- */

.grid-lines {
  pointer-events: none;
}

.grid-line {
  stroke: var(--border-subtle);
  stroke-width: 1;
  opacity: 0.3;
}

.grid-hit-area {
  fill: transparent;
  cursor: pointer;
  transition: fill var(--duration-fast) var(--ease-out);
}

.grid-hit-area:hover {
  fill: var(--alpha-white-10);
}

.grid-point {
  fill: var(--text-secondary);
  transition:
    fill var(--duration-fast) var(--ease-out),
    r var(--duration-fast) var(--ease-out),
    filter var(--duration-fast) var(--ease-out);
  pointer-events: none;
}

.grid-point.valid-move {
  fill: var(--game-snake);
  filter: drop-shadow(0 0 4px var(--game-snake));
  animation: pulse-point 1.5s var(--ease-in-out) infinite;
}

.grid-point.occupied {
  fill: var(--game-snake);
}

.snake-segment {
  stroke: var(--game-snake);
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: none;
}

.snake-endpoint {
  pointer-events: none;
}

.snake-endpoint.head {
  fill: var(--color-snake-head);
  filter: drop-shadow(var(--shadow-glow-head));
}

.snake-endpoint.tail {
  fill: var(--color-snake-tail);
  filter: drop-shadow(var(--shadow-glow-tail));
}

/* Segment hit areas for initial placement */
.segment-hit-area {
  stroke: transparent;
  stroke-width: 20;
  stroke-linecap: round;
  cursor: default;
  pointer-events: none;
}

.segment-hit-area.active {
  pointer-events: stroke;
  cursor: pointer;
}

.segment-hit-area.active:hover {
  stroke: var(--alpha-snake-40);
}

/* Move hit areas for playing phase */
.move-hit-area {
  stroke: transparent;
  stroke-width: 20;
  stroke-linecap: round;
  cursor: pointer;
  pointer-events: stroke;
}

.move-hit-area:hover {
  stroke: var(--alpha-snake-40);
}

/* --- Game Status & Instructions --- */

.game-status {
  display: flex;
  gap: var(--space-7);
  align-items: center;
  font-size: var(--font-size-base);
}

.round-info {
  color: var(--text-secondary);
}

.turn-info {
  font-weight: var(--font-weight-semibold);
  color: var(--interactive-primary);
}

.turn-info.my-turn {
  animation: pulse-glow 2s var(--ease-in-out) infinite;
}

.snake-length {
  color: var(--game-snake);
  font-weight: var(--font-weight-semibold);
}

.game-instructions {
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-base);
  max-width: 400px;
}

/* Board wrapper */
.board-wrapper {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  background: var(--bg-grid);
  border-radius: var(--radius-base);
  overflow: hidden;
}

.board-wrapper.turn-flash {
  animation: board-flash var(--duration-slower) var(--ease-out);
}

#game-board {
  width: 100%;
  height: 100%;
}

/* Spectator mode */
.spectator-mode .board-wrapper {
  pointer-events: none;
}

/* ========================================
   5. LAYOUT
   ======================================== */

/* --- Lobby Layout --- */

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: var(--space-7);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  margin-bottom: var(--space-7);
}

.logo-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

.logo {
  flex-shrink: 0;
}

header h1 {
  font-size: var(--font-size-2xl);
  color: var(--interactive-primary);
  margin-bottom: 0;
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

.subtitle {
  color: var(--text-secondary);
  font-size: var(--font-size-md);
  margin-top: var(--space-2);
}

.lobby {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

footer {
  text-align: center;
  margin-top: var(--space-7);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

footer a {
  color: var(--interactive-primary);
  text-decoration: none;
  transition: var(--transition-colors);
}

footer a:hover {
  text-decoration: underline;
}

/* --- Game Layout --- */

.game-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-7);

  /* Glassmorphism */
  background: rgba(22, 33, 62, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
}

.game-header h1 {
  font-size: var(--font-size-lg);
  color: var(--interactive-primary);
  font-weight: var(--font-weight-bold);
}

.room-info {
  display: flex;
  align-items: center;
}

.room-code {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.room-code strong {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  letter-spacing: var(--letter-spacing-wide);
  background: rgba(78, 204, 163, 0.1);
  border: 1px solid var(--alpha-snake-20);
  border-radius: var(--radius-sm);
  cursor: help;
  transition: var(--transition-colors);
}

.room-code strong:hover {
  background: rgba(78, 204, 163, 0.15);
  border-color: var(--alpha-snake-40);
}

.game-main {
  flex: 1;
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  gap: var(--space-4);
  padding: var(--space-4);
  max-height: calc(100vh - 70px);
}

.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.game-board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

/* --- Loading & Error Overlays --- */

.loading-overlay,
.error-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-body);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-max);
}

.loading-overlay.hidden,
.error-overlay.hidden {
  display: none;
}

.loading-content,
.error-content {
  text-align: center;
  color: var(--text-primary);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-surface);
  border-top-color: var(--game-snake);
  border-radius: 50%;
  animation: spin 1s var(--ease-linear) infinite;
  margin: 0 auto var(--space-4);
}

.error-content h2 {
  color: var(--interactive-primary);
  margin-bottom: var(--space-2);
  font-size: var(--font-size-xl);
}

.error-content p {
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

/* --- Confetti --- */

.confetti-container {
  position: fixed;
  pointer-events: none;
  z-index: var(--z-max);
}

.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-sm);
  animation: confetti-burst 0.8s var(--ease-out) forwards;
}

/* ========================================
   6. ANIMATIONS & KEYFRAMES
   ======================================== */

@keyframes checkmark-pop {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes confetti-burst {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(0);
    opacity: 0;
  }
}

@keyframes pulse-glow {
  0%, 100% {
    text-shadow: 0 0 5px var(--game-snake);
  }
  50% {
    text-shadow: var(--shadow-glow-snake-lg);
  }
}

@keyframes pulse-point {
  0%, 100% {
    r: 4;
    opacity: 0.8;
  }
  50% {
    r: 5;
    opacity: 1;
  }
}

@keyframes board-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(78, 204, 163, 0.8);
  }
  100% {
    box-shadow: 0 0 0 20px rgba(78, 204, 163, 0);
  }
}

@keyframes card-breathe {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 0 0 2px var(--game-snake),
      0 0 10px rgba(78, 204, 163, 0.3);
  }
  50% {
    transform: scale(1.02);
    box-shadow:
      0 0 0 2px var(--game-snake),
      0 0 20px rgba(78, 204, 163, 0.5);
  }
}

@keyframes modal-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-slide-up {
  from {
    opacity: 0;
    transform: translateY(var(--space-4));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================
   7. RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 900px) {
  .game-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .game-sidebar {
    flex-direction: row;
    justify-content: center;
  }

  .game-sidebar.left {
    order: 1;
  }

  .game-board-container {
    order: 2;
  }

  .game-sidebar.right {
    order: 3;
  }

  .player-card {
    flex: 1;
    max-width: 200px;
  }
}

@media (max-width: 500px) {
  .game-header {
    flex-direction: column;
    gap: var(--space-2);
  }

  .game-status {
    flex-direction: column;
    gap: var(--space-2);
  }
}

/* ========================================
   8. ACCESSIBILITY
   ======================================== */

/* Focus rings for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--interactive-primary);
  outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
