/* ==========================================================================
   Punctula - Dots and Boxes Modern PWA Stylesheet
   Design System: Futuristic Glassmorphism & Neon Glow Aesthetics
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-primary: #090d16;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --border-glass: rgba(255, 255, 255, 0.12);

  /* Player Colors */
  --p1-color: #00f2fe;
  --p1-glow: rgba(0, 242, 254, 0.6);
  --p1-bg: rgba(0, 242, 254, 0.85);
  --p1-gradient: linear-gradient(135deg, #00c6ff 0%, #0072ff 100%);

  --p2-color: #ff0844;
  --p2-glow: rgba(255, 8, 68, 0.6);
  --p2-bg: rgba(255, 8, 68, 0.85);
  --p2-gradient: linear-gradient(135deg, #ff0844 0%, #ff4e50 100%);

  --neutral-line: #1e293b;
  --neutral-hover: rgba(255, 255, 255, 0.25);
  --dot-color: #f8fafc;
  --dot-glow: rgba(248, 250, 252, 0.6);

  /* Text & Typography */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* UI Dimensions & Shadows */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 24px;
  --radius-pill: 9999px;
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --shadow-neon-p1: 0 0 20px rgba(0, 242, 254, 0.4);
  --shadow-neon-p2: 0 0 20px rgba(255, 8, 68, 0.4);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Global Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}

/* Background Animated Gradient Mesh */
body::before {
  content: '';
  position: fixed;
  top: -20%;
  left: -20%;
  width: 140%;
  height: 140%;
  background: 
    radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(236, 72, 153, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.1) 0%, transparent 50%);
  z-index: -1;
  pointer-events: none;
  animation: bgPulse 12s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0% { transform: scale(1) rotate(0deg); }
  100% { transform: scale(1.05) rotate(3deg); }
}

/* App Container */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 16px;
  position: relative;
}

/* Header Navbar */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glass);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--p1-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-neon-p1);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Iconic Buttons */
.btn-icon {
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Variant Rules Info Icon */
.rules-info-btn {
  background: transparent;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.rules-info-btn:hover {
  transform: scale(1.25);
}

/* Control Panel / Mode Selector */
.control-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.segmented-control {
  display: flex;
  background: rgba(15, 23, 42, 0.8);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  gap: 4px;
}

.segment-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.segment-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Options Bar - Stacked Rows */
.options-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: rgba(17, 24, 39, 0.4);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
}

.option-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.pill-group {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.03);
  padding: 2px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-glass);
  flex-wrap: wrap;
}

.pill-btn {
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: var(--transition-fast);
}

.pill-btn.active {
  background: var(--p1-color);
  color: #000;
  font-weight: 700;
  box-shadow: 0 0 10px var(--p1-glow);
}

/* Scoreboard & Status Bar */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 16px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glass);
}

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  transition: var(--transition-normal);
}

.player-card.p1 {
  justify-content: flex-start;
}

.player-card.p2 {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.player-card.active.p1 {
  background: rgba(0, 242, 254, 0.15);
  border-color: var(--p1-color);
  box-shadow: var(--shadow-neon-p1);
}

.player-card.active.p2 {
  background: rgba(255, 8, 68, 0.15);
  border-color: var(--p2-color);
  box-shadow: var(--shadow-neon-p2);
}

.player-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
}

.p1 .player-avatar {
  background: var(--p1-color);
  color: #041225;
  box-shadow: 0 0 10px var(--p1-glow);
}

.p2 .player-avatar {
  background: var(--p2-color);
  color: #250409;
  box-shadow: 0 0 10px var(--p2-glow);
}

.player-info {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.player-score {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}

.turn-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.turn-badge {
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--p1-color);
  animation: pulseBadge 0.8s infinite alternate;
}

.game-timer {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

@keyframes pulseBadge {
  0% { transform: scale(1); }
  100% { transform: scale(1.08); }
}

/* Game Board Canvas Container */
.board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0;
  position: relative;
  width: 100%;
}

.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* SVG Interactive Board */
#boardSvg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* SVG Interactive Elements */
.svg-edge {
  stroke: var(--neutral-line);
  stroke-width: 8;
  stroke-linecap: round;
  cursor: pointer;
  transition: stroke var(--transition-fast), filter var(--transition-fast);
}

.svg-edge.blocked {
  stroke: #334155;
  stroke-dasharray: 6 4;
  stroke-width: 5;
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.svg-edge-hitbox {
  stroke: transparent;
  stroke-width: 28;
  stroke-linecap: round;
  cursor: pointer;
}

.svg-edge-hitbox:hover + .svg-edge.unclaimed {
  stroke: var(--neutral-hover);
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.4));
}

.svg-edge.p1 {
  stroke: var(--p1-color);
  filter: drop-shadow(0 0 8px var(--p1-glow));
  animation: edgeDraw 0.25s ease-out;
}

.svg-edge.p2 {
  stroke: var(--p2-color);
  filter: drop-shadow(0 0 8px var(--p2-glow));
  animation: edgeDraw 0.25s ease-out;
}

@keyframes edgeDraw {
  0% { stroke-dasharray: 100; stroke-dashoffset: 100; opacity: 0.5; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}

/* Shape Fills - SOLID COLOR FILLS ONLY (NO TEXT/INITIALS INSIDE!) */
.svg-box, .svg-triangle {
  fill: transparent;
  transition: fill 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.svg-box.claimed.p1, .svg-triangle.claimed.p1 {
  fill: var(--p1-color);
  opacity: 0.85;
  animation: shapeRipple 0.35s ease-out forwards;
  filter: drop-shadow(0 0 12px var(--p1-glow));
}

.svg-box.claimed.p2, .svg-triangle.claimed.p2 {
  fill: var(--p2-color);
  opacity: 0.85;
  animation: shapeRipple 0.35s ease-out forwards;
  filter: drop-shadow(0 0 12px var(--p2-glow));
}

@keyframes shapeRipple {
  0% { transform: scale(0.5); opacity: 0; transform-origin: center; }
  60% { transform: scale(1.05); opacity: 0.95; transform-origin: center; }
  100% { transform: scale(1); opacity: 0.85; transform-origin: center; }
}

.svg-dot {
  fill: var(--dot-color);
  filter: drop-shadow(0 0 6px var(--dot-glow));
  transition: transform 0.2s ease;
}

/* Footer Controls */
.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-action {
  flex: 1;
  padding: 12px 18px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-normal);
}

.btn-action:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

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

.btn-primary {
  background: var(--p1-gradient);
  border: none;
  color: #041225;
  box-shadow: var(--shadow-neon-p1);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 25px var(--p1-glow);
}

/* Ultra-Premium Player Name Input Component */
.premium-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
  text-align: left;
}

.premium-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--p1-color);
  display: flex;
  align-items: center;
  gap: 6px;
}

.premium-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid rgba(0, 242, 254, 0.3);
  border-radius: var(--radius-md);
  padding: 4px 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.premium-input-wrapper:focus-within {
  border-color: var(--p1-color);
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 0 20px var(--p1-glow), inset 0 0 10px rgba(0, 242, 254, 0.15);
  transform: translateY(-1px);
}

.premium-input-wrapper .input-icon {
  color: var(--p1-color);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  opacity: 0.9;
}

.premium-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 1.05rem;
  font-weight: 700;
  padding: 10px 0;
}

.premium-input::placeholder {
  color: var(--text-dim);
  font-weight: 400;
}

/* Form Controls Base */
.form-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

.form-input:focus {
  border-color: var(--p1-color);
  box-shadow: 0 0 12px var(--p1-glow);
}

/* Modals System */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 800;
}

/* QRCode Container Card */
.qrcode-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 12px auto;
  padding: 12px;
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: 0 0 20px var(--p1-glow);
  width: 164px;
  height: 164px;
}

.qrcode-wrapper img, .qrcode-wrapper canvas {
  width: 140px !important;
  height: 140px !important;
}

/* P2P Participants Badges */
.participant-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
}

.participant-badge.waiting {
  border-style: dashed;
  opacity: 0.7;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.badge-dot.p1 {
  background: var(--p1-color);
  box-shadow: 0 0 6px var(--p1-glow);
}

.badge-dot.p2 {
  background: var(--p2-color);
  box-shadow: 0 0 6px var(--p2-glow);
}

.badge-dot.waiting {
  background: #eab308;
}

/* Statistics Grid KPIs */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-kpi {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-glass);
  padding: 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-kpi-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--p1-color);
}

.stat-kpi-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Match History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.history-badge {
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.history-badge.win {
  background: rgba(0, 242, 254, 0.2);
  color: var(--p1-color);
  border: 1px solid var(--p1-color);
}

.history-badge.loss {
  background: rgba(255, 8, 68, 0.2);
  color: var(--p2-color);
  border: 1px solid var(--p2-color);
}

.history-badge.tie {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  border: 1px solid var(--border-glass);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.3s ease forwards;
}

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

/* Confetti Canvas overlay for wins and shape burst particles */
#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 150;
}

/* Desktop and installed-window layout */
@media (min-width: 720px) and (min-height: 500px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #app {
    width: min(100%, 1120px);
    max-width: 1120px;
    height: auto;
    min-height: 100vh;
    padding: 20px 24px 32px;
    display: grid;
    grid-template-columns: minmax(280px, 0.75fr) minmax(400px, 1.25fr);
    grid-template-areas:
      "header header"
      "controls board"
      "score board"
      "footer board";
    gap: 14px 22px;
    align-content: center;
  }

  .app-header { grid-area: header; }
  .control-bar { grid-area: controls; margin-top: 0; }
  .scoreboard { grid-area: score; margin-top: 0; }
  .board-container { grid-area: board; margin: 0; min-width: 0; }
  .game-footer { grid-area: footer; }

  .board-wrapper {
    max-width: min(100%, 620px);
  }
}
