: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;
  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 {
    height: 100dvh;
    height: 100vh;
    overflow: 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;
    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 {
  padding: 0;
}

:fullscreen .game__header,
:-webkit-full-screen .game__header,
:fullscreen .game__footer,
:-webkit-full-screen .game__footer {
  display: none;
}

:fullscreen .game,
:-webkit-full-screen .game {
  max-width: 100%;
  gap: 4px;
}

:fullscreen .game__panel,
:-webkit-full-screen .game__panel {
  padding: 4px;
  border-radius: 0;
  border: none;
  background: #050508;
}

:fullscreen canvas,
:-webkit-full-screen canvas {
  border-radius: 0;
  border: none;
  width: 100%;
  max-height: calc(100dvh - 50px);
}
