/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screens ──────────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: #1a1a2e;
}
.screen.active { display: flex; }
.screen.overlay {
  background: rgba(10, 10, 20, 0.88);
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.screen-inner {
  width: 100%;
  max-width: 420px;
  padding: 24px 20px;
  margin: auto;
}
.center { text-align: center; }

/* ── Typography ──────────────────────────────────────────────────── */
.logo {
  font-size: 2rem;
  font-weight: 800;
  color: #f0c040;
  margin-bottom: 8px;
}
.subtitle {
  font-size: 1.1rem;
  color: #aaa;
  margin-bottom: 20px;
}
.hint {
  font-size: 0.85rem;
  color: #666;
  margin-top: 12px;
}

/* ── QR Box ──────────────────────────────────────────────────────── */
#qr-box {
  display: inline-block;
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  margin: 16px auto;
}
#qr-box img, #qr-box canvas { display: block; }

/* ── Link Row ────────────────────────────────────────────────────── */
.link-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.link-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #111;
  color: #ddd;
  font-size: 0.8rem;
}
.link-row button {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: #f0c040;
  color: #111;
  font-weight: 700;
  cursor: pointer;
}

/* ── Mode Buttons ────────────────────────────────────────────────── */
#mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px 20px;
  border-radius: 12px;
  border: 2px solid #333;
  background: #16213e;
  color: #e0e0e0;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
}
.mode-btn:active { background: #0f3460; border-color: #f0c040; }
.mode-btn[data-mode="versus"]      { border-color: #1565c0; }
.mode-btn[data-mode="versus_best"] { border-color: #6a1b9a; }
.mode-btn[data-mode="koop"]        { border-color: #2e7d32; }
.mode-btn.disabled { opacity: 0.4; pointer-events: none; }
.mode-name { font-size: 1.1rem; font-weight: 700; }
.mode-desc { font-size: 0.85rem; color: #888; margin-top: 4px; }

/* ── Difficulty Buttons ──────────────────────────────────────────── */
#diff-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px 20px;
  border-radius: 12px;
  border: 2px solid #333;
  background: #16213e;
  color: #e0e0e0;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
}
.diff-btn:active { background: #0f3460; border-color: #f0c040; }
.diff-name { font-size: 1.1rem; font-weight: 700; }
.diff-desc { font-size: 0.85rem; color: #888; margin-top: 4px; }

/* ── Custom Form ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

#custom-form { margin-top: 16px; }
.form-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}
.form-row label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #aaa;
}
.form-row input {
  width: 70px;
  padding: 10px 8px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #111;
  color: #ddd;
  font-size: 1rem;
  text-align: center;
}

.primary-btn {
  padding: 14px 32px;
  border-radius: 10px;
  border: none;
  background: #f0c040;
  color: #111;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  margin-bottom: 10px;
}
.ghost-btn {
  padding: 12px 24px;
  border-radius: 10px;
  border: 2px solid #444;
  background: transparent;
  color: #aaa;
  font-size: 0.9rem;
  cursor: pointer;
  width: 100%;
}

/* ── Progress Bar ────────────────────────────────────────────────── */
.progress-track {
  width: 100%;
  height: 10px;
  background: #333;
  border-radius: 99px;
  overflow: hidden;
  margin: 20px 0 12px;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #f0c040, #e86a2c);
  border-radius: 99px;
  width: 0%;
  transition: width 0.2s ease;
}

/* ── Game Screen ─────────────────────────────────────────────────── */
#screen-game {
  display: none;
  flex-direction: column;
}
#screen-game.active { display: flex; }

.game-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: #16213e;
  border-bottom: 1px solid #222;
  gap: 10px;
  flex-shrink: 0;
}
.badge {
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge.p0 { background: #1565c0; color: #fff; }
.badge.p1 { background: #6a1b9a; color: #fff; }

.move-count {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  color: #aaa;
}
.mode-badge {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
.mode-badge.versus      { background: #1565c0; color: #fff; }
.mode-badge.versus_best { background: #6a1b9a; color: #fff; }
.mode-badge.koop        { background: #2e7d32; color: #fff; }

.icon-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #111;
  color: #e0e0e0;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Versus Best Banner ──────────────────────────────────────────── */
#versus-best-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px;
  background: #2d1b4e;
  border-bottom: 1px solid #4a1b9a;
  font-size: 0.85rem;
  color: #ccc;
  flex-shrink: 0;
}
#versus-best-banner.hidden { display: none !important; }
.countdown-num {
  font-size: 1.1rem;
  font-weight: 800;
  color: #f0c040;
  min-width: 32px;
}
.countdown-num.urgent { color: #e53935; animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.5; } }

#canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

@media (pointer: fine) {
  .dpad { display: none; }
}
#game-canvas {
  display: block;
  border-radius: 8px;
}

/* ── D-Pad ───────────────────────────────────────────────────────── */
.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 20px;
  flex-shrink: 0;
  gap: 4px;
  background: #16213e;
  border-top: 1px solid #222;
}
.dpad-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.dpad-center { width: 56px; height: 56px; }
.dpad-btn {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 1px solid #333;
  background: #0f3460;
  color: #e0e0e0;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
.dpad-btn:active { background: #1565c0; }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal {
  background: #16213e;
  border: 2px solid #333;
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  max-width: 360px;
  width: 90%;
}
.modal h2 { font-size: 1.5rem; margin-bottom: 12px; }
.modal p { color: #aaa; margin-bottom: 24px; }
.btn-row { display: flex; gap: 12px; }
.btn-row button { flex: 1; }

.victory-modal { animation: pop 0.4s ease; }
@keyframes pop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Victory Moves ───────────────────────────────────────────────── */
.victory-moves {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.victory-moves.hidden { display: none !important; }
.move-pill {
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 0.95rem;
  font-weight: 700;
}
.move-pill.p0 { background: #1565c0; color: #fff; }
.move-pill.p1 { background: #6a1b9a; color: #fff; }
.move-pill.winner { outline: 3px solid #f0c040; }
.move-pill.koop { background: #2e7d32; color: #fff; }

/* ── Icons ───────────────────────────────────────────────────────── */
.big-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}
#victory-title { font-size: 1.8rem; font-weight: 800; color: #f0c040; }
#victory-sub   { color: #aaa; margin-top: 8px; font-size: 1rem; margin-bottom: 0; }
