:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: #060810;
  color: #d0d8e8;
}

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

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 16px;
  background:
    radial-gradient(ellipse at 40% 15%, rgba(255, 140, 50, 0.06) 0%, transparent 55%),
    radial-gradient(ellipse at 65% 85%, rgba(120, 80, 255, 0.05) 0%, transparent 55%),
    linear-gradient(170deg, #060810 0%, #0c1020 40%, #080c18 100%);
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.game {
  max-width: 540px;
  width: 100%;
  display: grid;
  gap: 16px;
}

.game__header,
.game__footer {
  text-align: center;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: #d0d8e8;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  opacity: 0.5;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.back-link:hover {
  opacity: 1;
  transform: translateX(-2px);
}

.game__header h1 {
  font-size: 2.2rem;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, #ff8c32, #ff5544, #cc44ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game__header p {
  color: rgba(208, 216, 232, 0.6);
  font-size: 0.95rem;
}

.game__panel {
  background: rgba(10, 14, 24, 0.85);
  border-radius: 18px;
  padding: 16px;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 140, 50, 0.08);
  display: grid;
  gap: 12px;
  justify-items: center;
}

canvas {
  width: min(100%, 480px);
  height: auto;
  aspect-ratio: 480 / 720;
  background: #050508;
  border-radius: 14px;
  border: 2px solid rgba(255, 100, 40, 0.25);
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 30px rgba(255, 100, 40, 0.06);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game__hud {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto auto;
  align-items: center;
  gap: 12px;
}

.hud__score {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(208, 216, 232, 0.5);
}

.hud__score strong {
  font-size: 1.7rem;
  color: #d0d8e8;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.hud__mute {
  border: none;
  background: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
  transition: background 0.15s ease, transform 0.15s ease;
}

.hud__mute:hover {
  background: rgba(255, 140, 50, 0.1);
  transform: scale(1.1);
}

.hud__mute:active {
  transform: scale(0.95);
}

.hud__button {
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #ff8c32, #ff4422);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  justify-self: end;
  box-shadow: 0 4px 10px rgba(255, 100, 40, 0.25);
}

.hud__button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255, 100, 40, 0.35);
}

.hud__button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(255, 100, 40, 0.15);
}

.game__footer p {
  color: rgba(208, 216, 232, 0.4);
  font-size: 0.88rem;
  font-style: italic;
}

/* ── Mobile portrait: fill viewport ── */
@media (max-width: 600px) {
  html, body {
    min-height: 100dvh;
    min-height: 100vh;
    overflow-x: hidden;
  }

  body {
    padding: 8px 6px;
    align-items: stretch;
  }

  .game {
    max-width: 100%;
    height: 100%;
    grid-template-rows: auto auto auto;
    gap: 6px;
  }

  .game__header {
    padding: 0 4px;
  }

  .game__header h1 {
    font-size: 1.4rem;
    margin-bottom: 0;
  }

  .game__header p {
    font-size: 0.78rem;
  }

  .back-link {
    font-size: 0.82rem;
    margin-bottom: 2px;
  }

  .game__panel {
    padding: 8px;
    gap: 8px;
    border-radius: 14px;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  canvas {
    max-width: 100%;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .game__hud {
    grid-template-columns: 1fr 1fr auto auto auto;
    gap: 8px;
    width: 100%;
  }

  .hud__score {
    font-size: 0.75rem;
    gap: 1px;
  }

  .hud__score strong {
    font-size: 1.3rem;
  }

  .hud__button {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .game__footer {
    display: none;
  }
}

/* ── Very short phones ── */
@media (max-width: 600px) and (max-height: 580px) {
  body {
    padding: 4px 4px;
  }

  .game {
    gap: 4px;
  }

  .game__header h1 {
    font-size: 1.2rem;
  }

  .game__header p {
    display: none;
  }

  .game__panel {
    padding: 6px;
    gap: 6px;
  }

  .hud__score strong {
    font-size: 1.1rem;
  }
}

/* ── Tablets ── */
@media (min-width: 768px) and (max-width: 1194px) {
  body {
    padding: 40px 24px;
  }

  .game {
    max-width: 640px;
    gap: 20px;
  }

  .game__panel {
    padding: 20px;
  }

  .game__header h1 {
    font-size: 2.5rem;
  }
}

/* ── Landscape mobile: side-by-side layout ── */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 8px;
    align-items: stretch;
  }

  .game {
    max-width: 100%;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr auto;
    gap: 8px;
  }

  .game__header {
    grid-column: 1 / -1;
    display: none;
  }

  .game__panel {
    grid-column: 1 / -1;
    padding: 6px;
    gap: 6px;
  }

  canvas {
    /* In landscape, limit height not width */
    width: auto;
    height: calc(100dvh - 70px);
    max-height: calc(100dvh - 70px);
  }

  .game__footer {
    display: none;
  }
}

/* ── Fullscreen mode: maximize canvas ── */
:fullscreen body,
:-webkit-full-screen body,
body.pseudo-fullscreen {
  padding: 0;
}

:fullscreen .game__header,
:-webkit-full-screen .game__header,
body.pseudo-fullscreen .game__header,
:fullscreen .game__footer,
:-webkit-full-screen .game__footer,
body.pseudo-fullscreen .game__footer,
:fullscreen .achievements-panel,
:-webkit-full-screen .achievements-panel,
body.pseudo-fullscreen .achievements-panel {
  display: none !important;
}

:fullscreen .game,
:-webkit-full-screen .game,
body.pseudo-fullscreen .game {
  max-width: 100%;
  gap: 4px;
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #050508;
  overflow: hidden;
}

:fullscreen .game__panel,
:-webkit-full-screen .game__panel,
body.pseudo-fullscreen .game__panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  padding: 0;
  border-radius: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  gap: 0;
}

:fullscreen canvas,
:-webkit-full-screen canvas,
body.pseudo-fullscreen canvas {
  border-radius: 0;
  border: none;
  box-shadow: 0 0 80px rgba(255, 180, 50, 0.12), 0 0 160px rgba(255, 180, 50, 0.05);
}

:fullscreen .game__hud,
:-webkit-full-screen .game__hud,
body.pseudo-fullscreen .game__hud {
  width: 100%;
  max-width: 600px;
  padding: 4px 12px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 10px;
  color: #fff;
}

:fullscreen .hud__score,
:-webkit-full-screen .hud__score,
body.pseudo-fullscreen .hud__score {
  color: rgba(255, 255, 255, 0.6);
}

:fullscreen .hud__score strong,
:-webkit-full-screen .hud__score strong,
body.pseudo-fullscreen .hud__score strong {
  color: #fff;
}

:fullscreen .hud__button,
:-webkit-full-screen .hud__button,
body.pseudo-fullscreen .hud__button {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

:fullscreen .hud__button:hover,
:-webkit-full-screen .hud__button:hover,
body.pseudo-fullscreen .hud__button:hover {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: none;
}

:fullscreen .lb-toggle-btn,
:-webkit-full-screen .lb-toggle-btn,
body.pseudo-fullscreen .lb-toggle-btn {
  display: none !important;
}

:fullscreen #leaderboardPanel,
:-webkit-full-screen #leaderboardPanel,
body.pseudo-fullscreen #leaderboardPanel {
  display: none !important;
}

/* ── Achievements ────────────────────────────────────────── */
.achievements-panel { text-align: center; margin-top: 0.5rem; }
.achievements-toggle {
  border: 1px solid rgba(255,140,50,0.2);
  border-radius: 999px; padding: 8px 20px;
  background: rgba(20,12,12,0.6); color: rgba(255,200,160,0.7);
  font-weight: 600; font-size: 0.85rem; cursor: pointer; font-family: inherit;
  transition: background 0.2s, border-color 0.2s;
}
.achievements-toggle:hover { background: rgba(255,140,50,0.08); border-color: rgba(255,140,50,0.4); }
.achievements-list { display: none; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.achievements-list.open { display: flex; }
.achievement-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 10px;
  font-size: 0.78rem; border: 1px solid rgba(255,140,50,0.1);
  background: rgba(20,12,12,0.5); color: rgba(255,200,160,0.4);
  transition: all 0.3s;
}
.achievement-item.unlocked { border-color: rgba(255,215,0,0.4); background: rgba(255,215,0,0.08); color: #ffd700; }
.achievement-item__icon { font-size: 1.1rem; }
.achievement-popup {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-120px);
  display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-radius: 14px;
  background: rgba(10,10,10,0.95); border: 2px solid rgba(255,215,0,0.5);
  box-shadow: 0 8px 30px rgba(0,0,0,0.6), 0 0 20px rgba(255,215,0,0.15);
  z-index: 1000; transition: transform 0.5s cubic-bezier(0.34,1.56,0.64,1); pointer-events: none;
}
.achievement-popup.show { transform: translateX(-50%) translateY(0); }
.achievement-popup__icon { font-size: 1.6rem; }
.achievement-popup__text { display: flex; flex-direction: column; gap: 2px; }
.achievement-popup__text strong { color: #ffd700; font-size: 0.9rem; }
.achievement-popup__text span { color: rgba(255,200,160,0.7); font-size: 0.78rem; }
