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

html {
  height: 100%;
  overflow: hidden;
  touch-action: none; /* prevents iOS from swallowing touches on WebGL canvas */
}

body {
  background: #000;
  font-family: monospace;
  overflow: hidden;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* bracket-terminal renders here — sits behind all overlays */
#canvas {
  display: block;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
  will-change: transform;
  touch-action: none;
}

/* ── Overlay base ── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #eee;
}

/* ── Menu overlay ── */
#menu-overlay { background: transparent; }

.menu-bg {
  position: absolute;
  inset: 0;
  background: #001a33;
  overflow: hidden;
}
.menu-bg-dim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 10, 0.62);
  z-index: 1;
}
.menu-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 20px;
}

.anim-dragon {
  position: absolute;
  font-size: 28px;
  left: 12%;
  animation: dragon-float 2.5s ease-in-out infinite;
  z-index: 0;
}
@keyframes dragon-float {
  0%, 100% { top: 38%; }
  50%       { top: 32%; }
}

.pipe-pair {
  position: absolute;
  width: 36px;
  height: 100%;
  z-index: 0;
  animation: pipe-scroll linear infinite;
}
.pipe-top, .pipe-bottom {
  position: absolute;
  width: 100%;
  background: #1a7a1a;
  border: 2px solid #0d5c0d;
}
.pipe-top    { top: 0; }
.pipe-bottom { bottom: 0; }

@keyframes pipe-scroll {
  from { left: 110%; }
  to   { left: -10%; }
}

.game-title {
  font-size: clamp(28px, 6vw, 48px);
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 0 20px #ffaa00, 0 2px 6px #000;
  letter-spacing: 4px;
  text-align: center;
  margin-bottom: 36px;
  line-height: 1.1;
}

.btn-primary {
  background: #ffd700;
  color: #000;
  font-family: monospace;
  font-weight: bold;
  font-size: 18px;
  letter-spacing: 3px;
  border: none;
  padding: 12px 56px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 215, 0, 0.4);
  margin-bottom: 20px;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary:not(:disabled):hover { background: #ffe033; }

.mode-btns {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.btn-mode {
  margin-bottom: 0;
  padding: 12px 32px;
  flex: 1;
}

.btn-secondary {
  background: transparent;
  color: #aaa;
  font-family: monospace;
  font-size: 14px;
  letter-spacing: 2px;
  border: 1px solid #555;
  padding: 9px 28px;
  border-radius: 4px;
  cursor: pointer;
}
.btn-secondary:hover { border-color: #888; color: #eee; }

.name-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
}
.name-label {
  font-size: 11px;
  color: #888;
  letter-spacing: 2px;
}
.name-input {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #444;
  color: #eee;
  font-family: monospace;
  font-size: 15px;
  text-align: center;
  padding: 8px 14px;
  border-radius: 3px;
  width: 200px;
  outline: none;
  transition: border-color 0.2s;
}
.name-input:focus { border-color: #ffd700; }
.name-input::placeholder { color: #444; }
.name-note {
  font-size: 10px;
  color: #555;
  text-align: center;
}

/* ── Game Over overlay ── */
#gameover-overlay {
  background: linear-gradient(to bottom, #0d0d1a, #1a0000);
  display: none;
}
.go-header { font-size: 36px; font-weight: 900; color: #ff4444; text-shadow: 0 0 14px #ff0000; letter-spacing: 4px; margin-bottom: 6px; }
.go-emoji  { font-size: 32px; margin-bottom: 16px; }

.result-box {
  background: rgba(255, 215, 0, 0.07);
  border: 1px solid rgba(255, 215, 0, 0.35);
  border-radius: 6px;
  padding: 12px 28px;
  text-align: center;
  margin-bottom: 18px;
  min-width: 220px;
}
.result-name  { font-size: 12px; color: #aaa; margin-bottom: 3px; letter-spacing: 1px; }
.result-score { font-size: 26px; font-weight: bold; color: #ffd700; }
.result-pos   { font-size: 12px; color: #aaa; margin-top: 4px; }
.result-pos span { color: #ffd700; font-weight: bold; }
.result-anon  { font-size: 11px; color: #555; margin-top: 4px; }

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 18px;
  max-width: 320px;
}
.score-table th {
  color: #555;
  font-weight: normal;
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid #222;
  letter-spacing: 1px;
  font-size: 11px;
}
.score-table td { padding: 5px 6px; color: #bbb; }
.score-table tr.highlight td { color: #ffd700; background: rgba(255, 215, 0, 0.07); font-weight: bold; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn-primary { margin-bottom: 0; padding: 9px 24px; font-size: 14px; }

.win-title {
  font-size: 36px;
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 0 20px #ffaa00, 0 0 40px #ff8800;
  letter-spacing: 4px;
  margin-bottom: 6px;
}
.win-subtitle {
  font-size: 20px;
  color: #ffffff;
  letter-spacing: 6px;
  margin-bottom: 8px;
}
.win-desc {
  font-size: 15px;
  color: #aaaaff;
  letter-spacing: 1px;
}

/* ── Scores overlay ── */
#scores-overlay {
  background: rgba(0, 0, 10, 0.96);
  display: none;
  overflow-y: auto;
}
.scores-title {
  font-size: 20px;
  color: #ffd700;
  letter-spacing: 3px;
  margin-bottom: 20px;
}
.scores-table-wrap {
  width: 100%;
  max-width: 360px;
  max-height: 60vh;
  overflow-y: auto;
}

/* ── Dragon animation ── */
@keyframes dragon-serpentine {
  0%   { transform: translateY(0px)  rotate(0deg); }
  25%  { transform: translateY(-4px) rotate(-2deg); }
  50%  { transform: translateY(0px)  rotate(0deg); }
  75%  { transform: translateY(4px)  rotate(2deg); }
  100% { transform: translateY(0px)  rotate(0deg); }
}

#dragon-sprite {
  animation: dragon-serpentine 1.1s ease-in-out infinite;
  transform-origin: center center;
}

/* ── Canvas scaling ── */
/* will-change already on #canvas above */

/* ── TAP hint ── */
#tap-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-family: monospace;
  font-size: 14px;
  letter-spacing: 2px;
  z-index: 5;
  pointer-events: none;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50%       { opacity: 1;   }
}

/* ── Ready-to-start overlay ── */
#ready-overlay {
  background: transparent;
  z-index: 50;
}
#ready-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: #eee;
  font-family: monospace;
}
.ready-title {
  font-size: clamp(20px, 5vw, 32px);
  color: #ffd700;
  letter-spacing: 4px;
  font-weight: 900;
}
.ready-hint {
  font-size: clamp(14px, 3.5vw, 18px);
  color: #aaa;
  letter-spacing: 2px;
  animation: pulse 1.5s ease-in-out infinite;
}
.ready-retro-box {
  border: 2px solid #ffd700;
  padding: 24px 32px;
  background: rgba(0, 0, 0, 0.85);
  font-size: clamp(13px, 3vw, 16px);
  color: #ffd700;
  letter-spacing: 3px;
  text-align: center;
  line-height: 2;
}

/* ── Pause overlay ── */
#pause-overlay {
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
}
.pause-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 8px;
  padding: 28px 40px;
  background: rgba(0, 0, 0, 0.5);
}
.pause-title {
  font-size: clamp(20px, 5vw, 28px);
  color: #ffd700;
  letter-spacing: 4px;
  font-weight: 900;
  font-family: monospace;
}
.pause-hint {
  font-size: clamp(12px, 3vw, 15px);
  color: #aaa;
  letter-spacing: 2px;
  font-family: monospace;
}

/* ── Mobile pause button ── */
#pause-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 215, 0, 0.45);
  border-radius: 10px;
  color: #ffd700;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}

/* ── Responsive fixes for existing overlays ── */
.name-input        { width: min(200px, 80vw); }
.score-table       { max-width: min(320px, 90vw); }
.result-box        { min-width: min(220px, 80vw); }
.go-header         { font-size: clamp(24px, 8vw, 36px); }
.btn-mode          { font-size: clamp(14px, 4vw, 18px); }
.scores-table-wrap { -webkit-overflow-scrolling: touch; }

@media (max-width: 380px) {
  .menu-content { padding: 12px; }
  .game-title   { font-size: 28px; margin-bottom: 20px; }
  .btn-primary  { padding: 10px 20px; }
  .btn-mode     { padding: 10px 16px; }
}
