/* ==========================================================================
   Classic Snake - Clean, Accessible, Zero-Dependency CSS
   ========================================================================== */

:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #273549;
  --canvas-bg: #0b1120;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-focus: #34d399;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #334155;
  --border-light: #475569;
  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
  --transition-fast: 0.15s ease;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Accessibility helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.hidden {
  display: none !important;
}

/* Base Styles */
body {
  font-family: var(--font);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.site-header {
  background-color: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.nav-back-link:hover {
  color: var(--text-main);
  background-color: var(--bg-surface-hover);
}

.nav-back-link:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

.game-badge {
  background-color: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Main Container */
.main-wrapper {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Hero Title */
.game-hero {
  text-align: center;
}

.game-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.game-subtitle {
  color: var(--text-muted);
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  max-width: 600px;
  margin: 0 auto;
}

/* Game Surface Card */
.game-card-surface {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  position: relative;
}

/* Stats Panel */
.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-item {
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  display: block;
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}

/* Toolbar Controls */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.difficulty-group {
  display: flex;
  background-color: rgba(15, 23, 42, 0.8);
  padding: 0.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  gap: 0.25rem;
}

.btn-diff {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-diff:hover {
  color: var(--text-main);
}

.btn-diff.active {
  background-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
}

.btn-diff:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 1px;
}

.utility-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-icon {
  background-color: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-light);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

.btn-action {
  background-color: var(--accent);
  border: none;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.9rem;
  height: 44px;
  padding: 0 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

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

.btn-action:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

/* Canvas Wrapper */
.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

#game-canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--canvas-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  display: block;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.6), inset 0 0 15px rgba(16, 185, 129, 0.05);
  outline: none;
  touch-action: none;
}

#game-canvas:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-focus);
}

/* Overlay Screen */
.canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: rgba(11, 17, 32, 0.85);
  backdrop-filter: blur(4px);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.overlay-content {
  text-align: center;
  padding: 1.5rem;
}

.overlay-badge {
  display: inline-block;
  background-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.65rem 1.25rem;
  border-radius: 9999px;
  margin-bottom: 0.75rem;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.overlay-subtext {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Mobile D-Pad Controls */
.mobile-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  max-width: 260px;
}

.dpad-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  width: 100%;
}

.dpad-btn {
  background-color: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 52px;
  height: 48px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all var(--transition-fast);
}

.dpad-btn:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent);
}

.dpad-btn:active {
  background-color: var(--accent);
  color: #ffffff;
  transform: scale(0.95);
}

.dpad-btn:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  .mobile-dpad {
    display: none; /* Desktop uses Keyboard */
  }
}

/* Modals */
.modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
  animation: fadeIn 0.3s ease;
}

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

.modal-content {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modalScaleUp 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalScaleUp {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.gameover-icon-wrapper {
  margin-bottom: 0.75rem;
  display: inline-flex;
}

.victory-heading {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.victory-subtext {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.gameover-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.v-stat {
  display: flex;
  flex-direction: column;
}

.v-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.v-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 0.2rem;
}

.new-best-banner {
  background-color: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
}

.btn-primary-large {
  background-color: var(--accent);
  color: #ffffff;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.85rem 1.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
  min-height: 48px;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  transition: background-color var(--transition-fast);
}

.btn-primary-large:hover {
  background-color: var(--accent-hover);
}

.btn-primary-large:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

/* SEO Content Section */
.content-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 3vw, 2.25rem);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.meta-freshness {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.meta-dot {
  color: var(--border-light);
}

.content-section h2 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.85rem;
  letter-spacing: -0.015em;
}

.content-section p {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.content-list {
  padding-left: 1.25rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.content-list strong {
  color: var(--text-main);
}

.content-list em {
  color: #cbd5e1;
  font-style: normal;
  font-weight: 600;
}

/* FAQ Accordion */
.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.faq-item[open] {
  border-color: var(--border-light);
}

.faq-question {
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: "+";
  font-size: 1.3rem;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.faq-item[open] .faq-question::after {
  content: "−";
  color: var(--accent);
}

.faq-question:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: -2px;
}

.faq-answer {
  padding: 0 1.25rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.faq-answer p {
  margin: 0;
}

/* Cross-Link Cards */
.cross-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.cross-link-card {
  background-color: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.cross-link-card:hover {
  border-color: var(--accent);
  background-color: var(--bg-surface-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.cross-link-card:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

.cl-title {
  color: var(--text-main);
  font-weight: 700;
  font-size: 1.05rem;
}

.cl-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Site Footer */
.site-footer {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 1.75rem 1rem;
  margin-top: auto;
}

.footer-container {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--text-main);
}

.footer-links a:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  .footer-container {
    flex-direction: row;
    justify-content: space-between;
  }
}
