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

:root {
  --bg:        #0a0a0f;
  --surface:   #13131d;
  --surface2:  #1a1a28;
  --border:    #2a2a3d;
  --text:      #c8c8d4;
  --text-dim:  #6b6b80;
  --accent:    #00e5a0;
  --accent2:   #00b8ff;
  --danger:    #ff4060;
  --warning:   #ffaa00;
  --glow:      0 0 20px rgba(0, 229, 160, 0.15);
  --font-pixel: 'Press Start 2P', monospace;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;
  --radius:    6px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Screens ─────────────────────────────────────────── */
.screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* padding: 24px; */
}

.hidden { display: none !important; }

/* ── Logo / Title ────────────────────────────────────── */
.title-block {
  text-align: center;
  padding: 20px 0 8px;
}

.logo {
  font-family: var(--font-pixel);
  font-size: 32px;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 30px rgba(0,229,160,0.4), 0 0 60px rgba(0,229,160,0.15);
}

.logo .accent {
  color: var(--accent);
}

.tagline {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.library-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 8px 16px;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--accent);
  background: rgba(0, 229, 160, 0.06);
  border: 1px solid rgba(0, 229, 160, 0.25);
  border-radius: 999px;
  text-decoration: none;
  transition: all 150ms ease-out;
}
.library-link:hover {
  background: rgba(0, 229, 160, 0.12);
  border-color: rgba(0, 229, 160, 0.5);
  box-shadow: 0 0 20px rgba(0, 229, 160, 0.2);
  color: var(--accent);
  text-decoration: none;
}
.library-link-icon {
  font-size: 14px;
}
.library-link-arrow {
  transition: transform 150ms ease-out;
}
.library-link:hover .library-link-arrow {
  transform: translateX(3px);
}
.library-link.hidden {
  display: none;
}

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
}

.card-label {
  position: absolute;
  top: -8px;
  left: 14px;
  background: var(--surface);
  padding: 0 8px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.rom-count {
  opacity: 0.5;
  letter-spacing: 1px;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  background: var(--border);
  border-color: var(--text-dim);
}

.btn:active {
  transform: scale(0.97);
}

.btn-icon {
  font-size: 16px;
}

.btn-rom {
  padding: 14px 28px;
  font-size: 14px;
}

.btn-mode {
  width: 100%;
  justify-content: center;
  padding: 14px;
}

.btn-mode:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: rgba(0, 229, 160, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary:hover {
  background: rgba(0, 229, 160, 0.2);
  box-shadow: var(--glow);
}

.btn-secondary {
  flex-shrink: 0;
  width: auto;
  padding: 14px 24px;
  background: rgba(0, 184, 255, 0.1);
  border-color: var(--accent2);
  color: var(--accent2);
}

.btn-secondary:hover {
  background: rgba(0, 184, 255, 0.2);
}

.btn-danger {
  background: rgba(255, 64, 96, 0.08);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 64, 96, 0.18);
}

.btn-icon-only {
  padding: 8px 12px;
  font-size: 18px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
}

.btn-icon-only:hover {
  background: rgba(255,255,255,0.1);
}

#btn-voice.voice-muted {
  opacity: 0.4;
}

.btn-import-save {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: center;
}

.btn-import-save:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* ── Footer ──────────────────────────────────────────── */
.menu-footer {
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.5;
  padding: 8px 0;
}

.menu-footer a {
  color: var(--accent2);
  text-decoration: none;
}

.menu-footer a:hover {
  text-decoration: underline;
}

/* ── Flash Notification ──────────────────────────────── */
#flash {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font-mono);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  box-shadow: 0 0 20px rgba(0,229,160,0.15);
}

#flash.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
  .system-btn {
    font-size: 10px;
    padding: 6px 12px;
  }
}

@media (max-width: 800px) {
  .game-main {
    width: 100%;
    min-height: auto;
  }

  .game-controls-hint { display: none !important; }

  .canvas-container {
    width: 100vw;
    height: calc(100vw * 3 / 4);
    aspect-ratio: 4 / 3;
    border: none;
    border-radius: 0;
  }

  #nes-canvas {
    object-fit: contain;
  }

  .screen {
    padding: 16px;
  }

  /* Game screen: pin canvas to top, no centering */
  #screen-game,
  #screen-game.chat-open {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 40px 0 0 0;
    min-height: 0;
    grid-template-columns: unset;
  }

  .chat-sidebar { display: none !important; }

  .logo {
    font-size: 24px;
  }

  .room-code-display {
    font-size: 22px;
  }

  .hud {
    top: 4px;
    right: 4px;
    gap: 8px;
    padding: 4px 8px;
  }

  .swap-prompt .btn-tiny-lg,
  .rematch-prompt .btn-tiny-lg {
    width: 88px;
    height: 48px;
    font-size: 22px;
  }

  .swap-prompt,
  .rematch-prompt {
    gap: 12px;
    padding: 12px 24px;
    font-size: 14px;
  }
}

/* Touch devices get the mobile layout regardless of viewport width
   (iPhone landscape is >800px wide but still a touch device). */
body.is-touch .game-main {
  width: 100%;
  min-height: auto;
}

body.is-touch .game-controls-hint { display: none !important; }

body.is-touch .canvas-container {
  width: 100vw;
  height: calc(100vw * 3 / 4);
  aspect-ratio: 4 / 3;
  border: none;
  border-radius: 0;
}

body.is-touch #nes-canvas {
  object-fit: contain;
}

body.is-touch #screen-game,
body.is-touch #screen-game.chat-open {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 40px 0 0 0;
  min-height: 0;
  grid-template-columns: unset;
}

body.is-touch .chat-sidebar { display: none !important; }

/* ── Subtle background pattern ───────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0,229,160,0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(0,184,255,0.03) 0%, transparent 60%);
  pointer-events: none;
  z-index: -1;
}

/* ── Achievements detail modal ─────────────────────── */
.achievements-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.achievements-modal.hidden { display: none; }

.achievements-modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: 90vw;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.achievements-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.achievements-modal-title {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.achievements-modal-body {
  padding: 12px 14px 16px;
  overflow-y: auto;
}

.cheevo-rom-name {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 4px 0;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cheevo-stats-row {
  display: flex;
  gap: 16px;
  padding: 6px 4px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.cheevo-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.cheevo-item.locked {
  opacity: 0.45;
  filter: grayscale(0.9);
}

.cheevo-item.unlocked {
  background: rgba(0, 229, 160, 0.06);
  border: 1px solid rgba(0, 229, 160, 0.25);
}

.cheevo-icon {
  font-size: 22px;
  text-align: center;
}

.cheevo-name {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.cheevo-desc {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
}

.cheevo-points {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text-dim);
}

.cheevo-modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Achievements counter — standalone overlay, not inside #hud */
.cheevo-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border);
  border-radius: 4px;
  z-index: 30;
  pointer-events: none;
}

.cheevo-hud.hidden { display: none; }

.cheevo-hud .hud-label {
  font-size: 13px;
  line-height: 1;
}

.cheevo-hud .hud-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
}
