:root {
  --ink: #1a1a2e;
  --sand: #c2b280;
  --salt: #e8e4e1;
  --coral: #ff7f50;
  --sea: #4a766e;
  --amber: #ffbf00;
  --shadow: rgba(26, 26, 46, 0.85);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  touch-action: none;
  font-family: 'Courier Prime', monospace;
  color: var(--salt);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Fullscreen Button */
#sg-fs-btn {
  position: fixed;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  cursor: pointer;
  z-index: 9999;
}
#sg-fs-btn:hover {
  background: rgba(0,0,0,0.7);
}

/* Mute Button */
#mute-btn {
  position: fixed;
  top: 8px;
  right: 40px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  cursor: pointer;
  z-index: 9999;
  font-size: 14px;
}
#mute-btn:hover {
  background: rgba(0,0,0,0.7);
}

/* Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}
.overlay.active {
  display: flex;
  pointer-events: auto;
}

/* Menu */
#menu-overlay {
  background: linear-gradient(180deg, rgba(26,26,46,0.95) 0%, rgba(26,26,46,0.75) 100%);
}
.menu-content {
  text-align: center;
  max-width: 480px;
  padding: 24px;
}
.game-title {
  font-family: 'Abril Fatface', cursive;
  font-size: clamp(2rem, 8vw, 4rem);
  color: var(--salt);
  text-shadow: 0 4px 12px rgba(0,0,0,0.5);
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}
.game-subtitle {
  font-family: 'Courier Prime', monospace;
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  color: var(--sand);
  margin-bottom: 32px;
  font-style: italic;
}
.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.menu-btn {
  font-family: 'Courier Prime', monospace;
  font-size: 1rem;
  padding: 10px 24px;
  border: 2px solid var(--sand);
  border-radius: 8px;
  background: transparent;
  color: var(--salt);
  cursor: pointer;
  min-width: 200px;
  transition: all 0.2s ease;
}
.menu-btn:hover {
  background: var(--sand);
  color: var(--ink);
}
.menu-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.menu-version {
  margin-top: 24px;
  font-size: 0.75rem;
  color: var(--sea);
}

/* HUD */
#hud {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  pointer-events: none;
}
#hud.active {
  display: flex;
}
.hud-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--salt);
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.hud-stealth {
  width: 120px;
  height: 8px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--salt);
  border-radius: 4px;
  overflow: hidden;
  display: none;
}
.hud-stealth.active {
  display: block;
}
.stealth-bar {
  width: 0%;
  height: 100%;
  background: var(--coral);
  transition: width 0.1s linear;
}
.hud-objective {
  font-size: 0.8rem;
  color: var(--amber);
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.hud-act {
  width: 120px;
  height: 8px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--salt);
  border-radius: 4px;
  overflow: hidden;
  display: none;
}
.hud-act.active {
  display: block;
}
.act-bar {
  width: 100%;
  height: 100%;
  background: var(--sea);
  transition: width 0.1s linear;
}

/* Pause */
#pause-overlay {
  background: rgba(26,26,46,0.85);
}
.pause-content {
  text-align: center;
}
.pause-content h2 {
  font-family: 'Abril Fatface', cursive;
  font-size: 2rem;
  margin-bottom: 24px;
  color: var(--salt);
}

/* Game Over */
#gameover-overlay {
  background: rgba(26,26,46,0.9);
}
.gameover-content {
  text-align: center;
  max-width: 360px;
  padding: 24px;
}
.gameover-content h2 {
  font-family: 'Abril Fatface', cursive;
  font-size: 2rem;
  margin-bottom: 16px;
  color: var(--salt);
}
.score-breakdown {
  text-align: left;
  margin: 16px 0;
  padding: 12px;
  border: 1px solid var(--sea);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
}
.score-breakdown div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.9rem;
}
.score-total {
  border-top: 1px solid var(--sea);
  margin-top: 8px;
  padding-top: 8px;
  font-weight: bold;
  color: var(--amber);
}
.name-entry {
  margin: 16px 0;
}
.name-entry label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.name-entry input {
  font-family: 'Courier Prime', monospace;
  font-size: 1.5rem;
  text-align: center;
  width: 100px;
  padding: 8px;
  border: 2px solid var(--sand);
  border-radius: 6px;
  background: var(--ink);
  color: var(--salt);
  text-transform: uppercase;
}

/* Leaderboard */
#leaderboard-overlay {
  background: rgba(26,26,46,0.9);
}
.leaderboard-content {
  text-align: center;
  max-width: 480px;
  padding: 24px;
}
.leaderboard-content h2 {
  font-family: 'Abril Fatface', cursive;
  font-size: 2rem;
  margin-bottom: 16px;
  color: var(--salt);
}
#leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
#leaderboard-table th,
#leaderboard-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
#leaderboard-table th {
  color: var(--sand);
  font-weight: bold;
}
#leaderboard-table td {
  color: var(--salt);
}
#leaderboard-table tbody tr:nth-child(1) td {
  color: var(--amber);
}
#leaderboard-table tbody tr:nth-child(2) td {
  color: var(--sand);
}
#leaderboard-table tbody tr:nth-child(3) td {
  color: var(--coral);
}

/* Tutorial */
#tutorial-overlay {
  background: rgba(26,26,46,0.92);
}
.tutorial-content {
  text-align: center;
  max-width: 480px;
  padding: 24px;
}
.tutorial-content h2 {
  font-family: 'Abril Fatface', cursive;
  font-size: 2rem;
  margin-bottom: 16px;
  color: var(--salt);
}
.tutorial-step {
  display: none;
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 24px;
  color: var(--salt);
}
.tutorial-step.active {
  display: block;
}
.tutorial-step strong {
  color: var(--amber);
}
.vision-cone {
  color: var(--coral);
  font-weight: bold;
}
.reactor-text {
  color: var(--sea);
  font-weight: bold;
}
.pebble-text {
  color: #a08060;
  font-weight: bold;
}
.scripture-text {
  color: var(--amber);
  font-weight: bold;
}
.tutorial-nav {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
#tutorial-page {
  font-size: 0.85rem;
  color: var(--sand);
}

/* Mobile Controls */
#mobile-controls {
  display: none;
  z-index: 50;
  pointer-events: none;
}
#mobile-controls.active {
  display: flex;
}
#joystick-zone {
  position: absolute;
  bottom: 80px;
  left: 40px;
  width: 120px;
  height: 120px;
  pointer-events: auto;
}
#action-buttons {
  position: absolute;
  bottom: 80px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  pointer-events: auto;
}
.touch-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: rgba(0,0,0,0.3);
  color: var(--salt);
  font-family: 'Courier Prime', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.touch-btn:active {
  background: rgba(255,255,255,0.2);
}

/* Responsive */
@media (max-width: 480px) {
  .menu-content {
    padding: 16px;
  }
  .game-title {
    font-size: clamp(1.5rem, 10vw, 2.5rem);
  }
  .menu-btn {
    min-width: 160px;
    font-size: 0.9rem;
  }
}
