/* ==========================================================
  AI HORIZON Stylesheet
  Organized for maintainability. Sections:
    1. Design Tokens / Root Variables
    2. Base / Reset
    3. Canvas & Layout Containers
    4. Game HUD (header, score, info)
    5. Overlays (game over, dialogs)
    6. Forms / Initials Entry & Actions
    7. Leaderboard
    8. About Page
    9. Utilities (visibility, a11y)
   10. Media Queries (responsive/adaptive)
  ========================================================== */

/* 1. Design Tokens / Root Variables ----------------------- */
:root {
  --btn-bg: linear-gradient(45deg, var(--color-btn-gradient-start), var(--color-btn-gradient-end));
  --btn-bg-hover: linear-gradient(
    45deg,
    var(--color-btn-gradient-hover-start),
    var(--color-btn-gradient-hover-end)
  );
  --btn-radius: 999px;
  --color-bg: #111;
  --color-border: #333;
  --color-btn-focus-outline: #b20000;
  --color-btn-gradient-end: #555;
  --color-btn-gradient-hover-end: #777;
  --color-btn-gradient-hover-start: #555;
  --color-btn-gradient-start: #333;
  --color-connection-online: var(--color-text);
  --color-connection-offline: var(--color-text);
  --color-text: #fff;
  --color-text-secondary: #ddd;
  --color-title-shadow: #ddd;
  --page-vertical: var(--space-6);
  --radius-1: 4px;
  --radius-2: 12px;
  --radius-3: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 40px;
  --leaderboard-rows-desktop: 3;
  --leaderboard-rows-mobile: 3;
  --leaderboard-row-gap: var(--space-2);
  --leaderboard-row-padding-block: var(--space-2);
  --leaderboard-row-border: 1px;
  --leaderboard-line-height: 20px;
  --leaderboard-row-block: calc(
    var(--leaderboard-line-height) + (2 * var(--leaderboard-row-padding-block)) +
      (2 * var(--leaderboard-row-border))
  );
  --dramatic-duration: 500ms;
}
/* 2. Base / Reset ---------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
  overflow: hidden;
  user-select: none;
}
/* 3. Canvas & Layout Containers -------------------------- */
#gameCanvas {
  cursor: crosshair;
  display: block;
  height: 100%;
  width: 100%;
  touch-action: none;
  outline: none;
  pointer-events: auto;
}
.game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  width: 100vw;
}
/* 4. Game HUD -------------------------------------------- */
.game-header {
  backface-visibility: hidden;
  left: 0;
  padding: var(--space-2) var(--space-5);
  padding-top: max(var(--page-vertical), env(safe-area-inset-top));
  position: absolute;
  right: 0;
  top: 0;
  transform: translateZ(0);
  z-index: 999;
}
.score-display {
  align-items: center;
  display: flex;
  font-size: 1rem;
  font-weight: bold;
  justify-content: space-between;
  position: relative;
  width: 100%;
  z-index: 20;
}
.score {
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-1);
  color: var(--color-text);
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  position: relative;
}
@keyframes timer-flash {
  0% {
    box-shadow: 0 0 0 rgba(255, 80, 80, 0);
    transform: translateZ(0);
  }
  50% {
    box-shadow:
      0 0 16px var(--finale-glow1, rgba(255, 60, 60, 0.7)),
      0 0 32px var(--finale-glow2, rgba(255, 0, 0, 0.3));
    transform: translateZ(0) scale(1.02);
  }
  100% {
    box-shadow: 0 0 0 rgba(255, 80, 80, 0);
    transform: translateZ(0);
  }
}
#timerBox.finale,
#timer.finale {
  animation: timer-flash 750ms ease-in-out infinite;
  border-color: var(--finale-color, #ff4d4d);
}
#highScoreBox {
  transition:
    border-color 175ms ease,
    box-shadow 175ms ease;
}
#highScoreBox.connection-online,
#currentScoreBox.connection-online,
#timerBox.connection-online {
  border-color: var(--color-border);
  box-shadow: none;
  color: var(--color-connection-online);
}
#highScoreBox.connection-offline,
#currentScoreBox.connection-offline,
#timerBox.connection-offline {
  border-color: var(--color-border);
  box-shadow: none;
  color: var(--color-connection-offline);
}
.game-info {
  backface-visibility: hidden;
  background: var(--color-bg);
  bottom: 0;
  left: 0;
  padding: var(--space-5);
  padding-bottom: var(--space-5) !important;
  padding-top: var(--space-6) !important;
  position: fixed;
  right: 0;
  transform: translateZ(0);
  z-index: 10;
}
.game-info h1 {
  font-size: clamp(1.5rem, 3vw + 1rem, 2.5rem);
  margin-bottom: var(--space-6);
  text-align: center;
  text-shadow: 0 0 20px var(--color-title-shadow);
}
.instructions {
  font-size: clamp(1rem, 1.2vw + 0.8rem, 1.25rem);
  text-align: center;
}
.instructions p {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-7);
}
/* 5. Overlays -------------------------------------------- */
.game-over-screen {
  align-items: center;
  display: flex;
  inset: 0;
  justify-content: center;
  padding-top: max(var(--page-vertical), env(safe-area-inset-top));
  padding-bottom: max(var(--page-vertical), env(safe-area-inset-bottom));
  position: fixed;
  z-index: 2000;
  overscroll-behavior: none;
  touch-action: none;
}
.dramatic-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  pointer-events: none;
  opacity: 0;
  z-index: 4000;
}
@keyframes dramatic-flash {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}
.dramatic-overlay.show {
  animation: dramatic-flash var(--dramatic-duration) ease-out both;
}
@keyframes screen-punch {
  0% {
    transform: translateZ(0) scale(1);
  }
  14% {
    transform: translateZ(0) scale(1.05);
  }
  100% {
    transform: translateZ(0) scale(1);
  }
}
.screen-punch {
  animation: screen-punch var(--dramatic-duration) cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
@media (max-width: 480px) {
  .game-over-screen {
    z-index: 3000;
  }
  #initialsScreen {
    z-index: 2000;
  }
  #gameOverScreen {
    z-index: 3000;
  }
}
@supports (height: 100svh) {
  .game-over-screen {
    min-height: 100svh;
  }
}
@supports (height: 100dvh) {
  .game-over-screen {
    height: 100dvh;
    overflow-y: auto;
  }
}
@supports (height: 100svh) and (height: 100dvh) {
  .game-over-screen {
    min-height: 100svh;
    height: 100dvh;
  }
}
.game-over-content {
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-3);
  padding: var(--space-5);
  padding-top: var(--space-6) !important;
  text-align: center;
}
.game-over-content h2 {
  color: var(--color-text);
  font-size: clamp(1.5rem, 3vw + 1rem, 2.5rem);
  margin-bottom: var(--space-6);
  text-shadow: 0 0 20px var(--color-title-shadow);
}
.game-over-content p {
  color: var(--color-text-secondary);
  font-size: clamp(1.1rem, 1.2vw + 0.9rem, 1.5rem);
  margin-bottom: var(--space-6);
}
/* 6. Forms / Initials Entry & Actions -------------------- */
.action-button {
  background: var(--btn-bg);
  border: none;
  border-radius: var(--btn-radius);
  color: var(--color-text);
  cursor: pointer;
  display: block;
  font-size: 1rem;
  font-weight: bold;
  margin: 0 auto;
  min-height: 44px;
  min-width: 200px;
  padding: var(--space-3) var(--space-6);
  transition:
    background 0.2s ease,
    outline-color 0.2s ease,
    transform 0.1s ease;
}
.action-button:active {
  transform: translateY(1px);
}
.action-button:disabled,
.action-button[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.action-button:focus-visible {
  outline: 3px solid var(--color-btn-focus-outline);
  outline-offset: -3px;
}
.action-button:hover {
  background: var(--btn-bg-hover);
}
.action-group {
  display: block;
  text-align: center;
}
.action-link {
  color: var(--color-text-secondary);
  display: inline-block;
  font-weight: 600;
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
}
.action-link:focus-visible {
  outline: 3px solid var(--color-btn-focus-outline);
  outline-offset: -3px;
}
.action-link:hover {
  color: var(--color-text);
}
.js-force-focus {
  outline: 3px solid var(--color-btn-focus-outline) !important;
  outline-offset: -3px !important;
}
.initials-entry {
  align-items: center;
  display: flex;
  flex-direction: column;
}
.initials-entry .action-button {
  margin-bottom: 0;
}
.post-game-message {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-5);
  text-align: center;
}
.post-game-message p {
  margin-bottom: var(--space-4);
}
.post-game-message ul,
.post-game-message ol {
  margin: 0 auto;
  padding-left: var(--space-5);
  text-align: left;
}
.initials-entry .initials-input {
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-1);
  color: var(--color-text);
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-5);
  max-width: 12rem;
  padding: 6px 8px;
  text-align: center;
  text-transform: uppercase;
  width: 8ch;
}
.initials-entry .initials-input:focus {
  border-color: var(--color-border);
  outline: 3px solid var(--color-btn-focus-outline);
  outline-offset: -3px;
}
.initials-entry .initials-label {
  display: block;
  margin-bottom: var(--space-5);
  text-align: center;
}
/* 9. Utilities (visibility, a11y) ------------------------ */
.hidden {
  display: none !important;
}
.desktop-only {
  display: block;
}
.mobile-only {
  display: none;
}
.sr-only {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}
.text-center {
  text-align: center !important;
}
/* 7. Leaderboard ----------------------------------------- */
.leaderboard {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-5);
  overscroll-behavior: contain;
  text-align: center;
  touch-action: none;
}
.leaderboard h3 {
  color: var(--color-text);
  font-size: 1rem;
  margin-bottom: var(--space-2);
  text-shadow: 0 0 8px var(--color-title-shadow);
}
#leaderboardList {
  -webkit-overflow-scrolling: touch;
  list-style-position: inside;
  margin: 0 auto;
  max-height: calc(
    var(--leaderboard-rows-desktop) * var(--leaderboard-row-block) +
      (var(--leaderboard-rows-desktop) - 1) * var(--leaderboard-row-gap)
  );
  max-width: min(32rem, 90vw);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-left: 0;
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
  touch-action: pan-y;
}
#leaderboardList li {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-1);
  color: var(--color-text);
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: var(--leaderboard-line-height);
  margin-bottom: var(--space-2);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  word-break: break-word;
}
#leaderboardList li:last-child {
  margin-bottom: 0;
}
#leaderboardList li:first-child {
  border-color: var(--color-border);
  box-shadow: none;
}
/* 8. About Page ------------------------------------------ */
.about-page {
  box-sizing: border-box;
  display: block;
  padding-bottom: var(--space-5) !important;
  padding-left: var(--space-5);
  padding-right: var(--space-5);
  padding-top: var(--space-6) !important;
}
.about-content {
  margin: 0 auto;
  max-width: 920px;
  text-align: center;
}
body.about-body,
.about-body {
  -webkit-overflow-scrolling: touch;
  height: auto;
  overflow: auto;
  user-select: text;
}
.about-content h1 {
  font-size: clamp(1.5rem, 3vw + 1rem, 2.5rem);
  margin-bottom: var(--space-5);
  margin-top: 0;
  text-align: center;
  text-shadow: 0 0 20px var(--color-title-shadow);
}
.about-content h3 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
  margin-top: var(--space-4);
}
.about-content .instructions {
  color: var(--color-text-secondary);
  margin: 8px auto 0;
  margin-bottom: var(--space-4);
  max-width: 720px;
  text-align: left;
}
.about-content p {
  color: var(--color-text-secondary);
  margin: 8px auto 0;
  max-width: 720px;
  text-align: left;
}
.about-content ul,
.about-content ol {
  margin: 8px auto 0;
  max-width: 720px;
  padding-left: 1.2em;
  text-align: left;
}
.about-content p.about-back {
  margin: 8px auto 0;
  max-width: 720px;
  padding-left: 0;
  text-align: center;
}
.about-content p.about-back .action-link {
  margin-top: 0;
  padding: var(--space-2) var(--space-3);
}
/* 10. Media Queries (responsive/adaptive) ---------------- */
@media (max-width: 480px) {
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: block !important;
  }
  .game-header {
    position: fixed;
  }
  .score {
    padding: 6px 10px;
  }
  #leaderboardList {
    max-height: calc(
      var(--leaderboard-rows-mobile) * var(--leaderboard-row-block) +
        (var(--leaderboard-rows-mobile) - 1) * var(--leaderboard-row-gap)
    );
  }
}
@media (hover: hover) and (pointer: fine) {
  .desktop-only {
    display: block;
  }
  .mobile-only {
    display: none;
  }
}
@media (hover: none) and (pointer: coarse) {
  .desktop-only {
    display: none;
  }
  .mobile-only {
    display: block;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
