:root {
  --color-bg: #0a0a12;
  --color-water: #0d1b2a;
  --color-water-light: #1b263b;
  --color-primary: #00f5d4;
  --color-secondary: #7b2cbf;
  --color-accent: #f72585;
  --color-gold: #ffd60a;
  --color-text: #e8e8e8;
  --color-text-muted: #b8b8b8;
  --color-card-bg: #14142a;
  --font-display: 'Rubik Mono One', 'Heebo', sans-serif;
  --font-body: 'Heebo', sans-serif;
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 3rem;
  --space-xl: 5rem;
  --radius-sm: 4px;
  --radius-md: 8px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.7;
  overflow-x: hidden;
  min-height: 100vh;
}

/* Skip link */
.skip-link {
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: var(--color-bg);
  font-weight: 700;
  text-decoration: none;
  z-index: 1000;
  transform: translateY(-100%);
  transition: transform 0.2s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

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

/* Scanlines - subtle CRT effect */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
}

/* Header */
.site-header {
  position: fixed;
  top: 0;
  inset-inline: 0;
  z-index: 100;
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(to bottom, var(--color-bg) 60%, transparent);
}

.header-content {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.logo-icon {
  font-size: 1.75rem;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--color-primary);
  text-shadow: 0 0 20px rgba(0, 245, 212, 0.5);
  letter-spacing: -0.02em;
}

.main-nav {
  display: flex;
  gap: var(--space-xs);
}

.nav-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.875rem;
  padding: var(--space-xs) var(--space-sm);
  background: transparent;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.nav-btn:hover {
  background: var(--color-primary);
  color: var(--color-bg);
}

.nav-btn:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

/* Hero */
.hero {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  padding-block-start: calc(var(--space-xl) + 60px);
  position: relative;
  overflow: hidden;
}

.hero-content {
  position: relative;
  z-index: 2;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 6vw, 3rem);
  color: var(--color-primary);
  text-shadow: 
    0 0 30px rgba(0, 245, 212, 0.6),
    0 0 60px rgba(0, 245, 212, 0.3);
  margin-block-end: var(--space-sm);
  letter-spacing: -0.02em;
}

.hero-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--color-text-muted);
  margin-block-end: var(--space-lg);
  max-width: 400px;
  margin-inline: auto;
}

.pixel-btn {
  font-family: var(--font-display);
  font-size: clamp(0.875rem, 2vw, 1rem);
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(135deg, var(--color-secondary), var(--color-accent));
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 
    0 4px 0 #4a1a6b,
    0 8px 24px rgba(123, 44, 191, 0.4);
}

.pixel-btn:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 6px 0 #4a1a6b,
    0 12px 32px rgba(123, 44, 191, 0.5);
}

.pixel-btn:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 3px;
}

.pixel-btn:active {
  transform: translateY(2px);
  box-shadow: 
    0 2px 0 #4a1a6b,
    0 4px 12px rgba(123, 44, 191, 0.4);
}

/* Hero decoration - harbor theme */
.hero-decoration {
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  height: 180px;
  overflow: hidden;
  pointer-events: none;
}

.harbor-elements {
  position: absolute;
  bottom: 60px;
  inset-inline: 0;
  height: 120px;
}

.lighthouse {
  position: absolute;
  inset-inline-end: 10%;
  bottom: 0;
  width: 24px;
  height: 80px;
  background: linear-gradient(to bottom, #fff 0%, #fff 10%, #e74c3c 10%, #e74c3c 30%, #fff 30%, #fff 50%, #e74c3c 50%, #e74c3c 70%, #fff 70%);
  border-radius: 4px 4px 0 0;
}

.lighthouse::before {
  content: '';
  position: absolute;
  top: -16px;
  inset-inline-start: 50%;
  width: 16px;
  height: 16px;
  background: var(--color-gold);
  border-radius: 50%;
  box-shadow: 0 0 20px var(--color-gold), 0 0 40px var(--color-gold);
  animation: lighthouse-glow 2s ease-in-out infinite;
  /* RTL-safe centering */
  margin-inline-start: -8px;
}

.buoy {
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 24px;
  background: linear-gradient(to bottom, #e74c3c 50%, #fff 50%);
  border-radius: 6px 6px 2px 2px;
}

.buoy-1 {
  inset-inline-start: 15%;
  animation: buoy-bob 3s ease-in-out infinite;
}

.buoy-2 {
  inset-inline-start: 35%;
  animation: buoy-bob 3s ease-in-out infinite 1s;
}

@keyframes lighthouse-glow {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes buoy-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.wave {
  position: absolute;
  bottom: 0;
  inset-inline-start: 0;
  width: 200%;
  height: 60px;
}

.wave-1 {
  background: 
    radial-gradient(ellipse 60px 20px at 30px 100%, var(--color-water) 50%, transparent 50%),
    radial-gradient(ellipse 60px 20px at 90px 100%, var(--color-water) 50%, transparent 50%);
  background-size: 120px 60px;
  animation: wave 6s linear infinite;
  opacity: 0.9;
}

.wave-2 {
  background: 
    radial-gradient(ellipse 40px 15px at 20px 100%, var(--color-water-light) 50%, transparent 50%),
    radial-gradient(ellipse 40px 15px at 60px 100%, var(--color-water-light) 50%, transparent 50%);
  background-size: 80px 40px;
  animation: wave 4s linear infinite reverse;
  opacity: 0.5;
  bottom: 10px;
}

@keyframes wave {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* Game Container */
.game-container {
  max-width: 960px;
  margin: 0 auto var(--space-xl);
  padding: var(--space-md);
  position: relative;
}

.game-hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-block-end: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-card-bg);
  border: 2px solid var(--color-water-light);
  border-radius: var(--radius-md);
}

.hud-item {
  text-align: center;
}

.hud-label {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.8125rem;
  color: var(--color-text);
  display: block;
  margin-block-end: var(--space-xs);
  letter-spacing: 0.02em;
}

.hud-value {
  font-family: var(--font-display);
  font-size: clamp(1rem, 3vw, 1.25rem);
  color: var(--color-gold);
  text-shadow: 0 0 10px rgba(255, 214, 10, 0.5);
}

.boost-bar {
  height: 28px;
  background: var(--color-water);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.boost-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  transition: width 0.2s ease;
  position: relative;
  border-radius: var(--radius-sm);
}

.boost-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 6px,
    rgba(255, 255, 255, 0.15) 6px,
    rgba(255, 255, 255, 0.15) 12px
  );
}

.boost-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--color-text);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

#gameCanvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--color-water);
  border: 3px solid var(--color-water-light);
  border-radius: var(--radius-md);
  display: block;
}

.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 18, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  border-radius: var(--radius-md);
}

.game-overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  padding: var(--space-lg);
  max-width: 90%;
}

.overlay-content h2 {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  color: var(--color-primary);
  margin-block-end: var(--space-sm);
}

.overlay-content p {
  color: var(--color-text-muted);
  margin-block-end: var(--space-md);
  font-size: 1rem;
}

.final-stats {
  background: var(--color-card-bg);
  padding: var(--space-md);
  margin-block-end: var(--space-md);
  border: 2px solid var(--color-gold);
  border-radius: var(--radius-md);
}

.final-stats[hidden] {
  display: none;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-xs) 0;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
}

.stat-row span:last-child {
  color: var(--color-gold);
}

/* Features */
.features {
  padding: var(--space-xl) var(--space-md);
  max-width: 960px;
  margin: 0 auto;
}

.section-title {
  font-family: var(--font-display);
  font-size: clamp(1.125rem, 3vw, 1.5rem);
  text-align: center;
  color: var(--color-primary);
  margin-block-end: var(--space-lg);
  text-shadow: 0 0 30px rgba(0, 245, 212, 0.4);
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

@media (min-width: 700px) {
  .features-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.feature-card {
  background: var(--color-card-bg);
  padding: var(--space-md);
  border: 2px solid var(--color-water-light);
  border-radius: var(--radius-md);
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(0, 245, 212, 0.15);
  border-color: var(--color-primary);
}

.feature-card:focus-within {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.feature-icon {
  font-size: 2.25rem;
  margin-block-end: var(--space-sm);
  display: block;
  line-height: 1;
}

.feature-card h3 {
  font-family: var(--font-display);
  font-size: 0.875rem;
  color: var(--color-gold);
  margin-block-end: var(--space-xs);
}

.feature-card p {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* Highscores */
.highscores-section {
  padding: var(--space-xl) var(--space-md);
  max-width: 500px;
  margin: 0 auto;
}

.highscores-table {
  background: var(--color-card-bg);
  border: 3px solid var(--color-water-light);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-header {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  padding: var(--space-sm);
  background: var(--color-water);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--color-primary);
}

.table-body {
  min-height: 120px;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  padding: var(--space-sm);
  border-block-end: 1px solid var(--color-water-light);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.875rem;
  transition: background 0.15s ease;
}

.table-row:last-child {
  border-block-end: none;
}

.table-row:hover {
  background: var(--color-water);
}

.table-row--empty {
  grid-template-columns: 1fr;
  text-align: center;
  color: var(--color-text-muted);
  font-weight: 400;
  padding: var(--space-md);
}

.table-row:first-child:not(.table-row--empty) span:first-child {
  color: var(--color-gold);
}

.table-row:nth-child(2) span:first-child {
  color: #c0c0c0;
}

.table-row:nth-child(3) span:first-child {
  color: #cd7f32;
}

/* Footer */
.site-footer {
  background: var(--color-water);
  padding: var(--space-md) var(--space-md) var(--space-lg);
  text-align: center;
  border-block-start: 3px solid var(--color-water-light);
}

.footer-logo {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--color-primary);
  margin-block-end: var(--space-xs);
}

.footer-credits {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Modal */
.instructions-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 18, 0.95);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
}

.instructions-modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--color-card-bg);
  padding: var(--space-lg);
  max-width: 480px;
  width: 100%;
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  inset-block-start: var(--space-sm);
  inset-inline-end: var(--space-sm);
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
  transition: color 0.15s ease;
}

.modal-close:hover,
.modal-close:focus {
  color: var(--color-accent);
}

.modal-close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.modal-content h2 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  color: var(--color-primary);
  margin-block-end: var(--space-md);
}

.modal-content h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--color-gold);
  margin-block-start: var(--space-md);
  margin-block-end: var(--space-sm);
}

.instructions-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.instruction-item .key {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.875rem;
  background: var(--color-water);
  padding: var(--space-xs) var(--space-sm);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  min-width: 56px;
  text-align: center;
  flex-shrink: 0;
}

.tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.tips-list li {
  padding: var(--space-xs) 0;
  padding-inline-start: var(--space-sm);
  border-inline-start: 3px solid var(--color-secondary);
}

/* Responsive */
@media (max-width: 600px) {
  .game-hud {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }
  
  .header-content {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .hero {
    padding-block-start: 100px;
  }
  
  .lighthouse {
    inset-inline-end: 5%;
    height: 60px;
    width: 18px;
  }
  
  .buoy {
    width: 10px;
    height: 20px;
  }
}

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

/* Focus visible for all interactive elements */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}