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

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

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 16px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(57, 255, 20, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(0, 184, 148, 0.05) 0%, transparent 60%),
    linear-gradient(170deg, #050a05 0%, #0a1a0a 40%, #051005 100%);
  transition: background 0.5s ease;
}

/* Theme body backgrounds */
body.theme-cyber {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(138, 43, 226, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(75, 0, 130, 0.06) 0%, transparent 60%),
    linear-gradient(170deg, #0a0515 0%, #120a1a 40%, #0a0510 100%);
}
body.theme-ocean {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(0, 150, 255, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(0, 200, 200, 0.06) 0%, transparent 60%),
    linear-gradient(170deg, #040a14 0%, #081420 40%, #040a14 100%);
}
body.theme-sunset {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 100, 50, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(255, 50, 100, 0.06) 0%, transparent 60%),
    linear-gradient(170deg, #140808 0%, #1a100a 40%, #140808 100%);
}
body.theme-retro {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(0, 255, 0, 0.06) 0%, transparent 60%),
    linear-gradient(170deg, #000 0%, #001100 40%, #000 100%);
}

.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: #c8f7c5;
  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, #39ff14, #00b894);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game__header p {
  color: rgba(200, 247, 197, 0.6);
  font-size: 0.95rem;
}

.game__panel {
  background: rgba(10, 20, 10, 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(57, 255, 20, 0.08);
  display: grid;
  gap: 12px;
  justify-items: center;
}

canvas {
  width: min(100%, 480px);
  height: auto;
  aspect-ratio: 1;
  background: #0a0f0a;
  border-radius: 14px;
  border: 2px solid rgba(57, 255, 20, 0.3);
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 30px rgba(57, 255, 20, 0.08);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: 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(200, 247, 197, 0.5);
}

.hud__score strong {
  font-size: 1.7rem;
  color: #c8f7c5;
  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;
  color: #c8f7c5;
  transition: background 0.15s ease, transform 0.15s ease;
}

.hud__mute:hover {
  background: rgba(57, 255, 20, 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, #39ff14, #00cc44);
  color: #052005;
  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(57, 255, 20, 0.2);
}

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

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

/* Settings bar */
.settings-bar {
  width: 100%;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: rgba(200, 247, 197, 0.6);
}

.setting-group label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.setting-group select {
  background: rgba(20, 40, 20, 0.8);
  color: #c8f7c5;
  border: 1px solid rgba(57, 255, 20, 0.2);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease;
}

.setting-group select:focus {
  border-color: rgba(57, 255, 20, 0.5);
}

/* D-pad */
.dpad {
  display: none;
  grid-template-columns: 60px 60px 60px;
  grid-template-rows: 60px 60px 60px;
  gap: 4px;
  justify-items: center;
  align-items: center;
  margin-top: 4px;
}

.dpad__btn {
  width: 56px;
  height: 56px;
  border: 2px solid rgba(57, 255, 20, 0.3);
  border-radius: 12px;
  background: rgba(10, 20, 10, 0.7);
  color: rgba(200, 247, 197, 0.8);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease, transform 0.1s ease, border-color 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.dpad__btn:active {
  background: rgba(57, 255, 20, 0.2);
  border-color: rgba(57, 255, 20, 0.6);
  transform: scale(0.92);
}

.dpad__center {
  border: none;
  background: none;
  cursor: default;
}

.dpad__up { grid-column: 2; grid-row: 1; }
.dpad__left { grid-column: 1; grid-row: 2; }
.dpad__center { grid-column: 2; grid-row: 2; }
.dpad__right { grid-column: 3; grid-row: 2; }
.dpad__down { grid-column: 2; grid-row: 3; }

/* Show D-pad on touch devices */
@media (pointer: coarse) {
  .dpad {
    display: grid;
  }
}

/* Achievements panel */
.achievements-panel {
  text-align: center;
}

.achievements-toggle {
  border: 1px solid rgba(57, 255, 20, 0.2);
  border-radius: 999px;
  padding: 8px 20px;
  background: rgba(10, 20, 10, 0.6);
  color: rgba(200, 247, 197, 0.7);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.achievements-toggle:hover {
  background: rgba(57, 255, 20, 0.08);
  border-color: rgba(57, 255, 20, 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(57, 255, 20, 0.1);
  background: rgba(10, 20, 10, 0.5);
  color: rgba(200, 247, 197, 0.4);
  transition: all 0.3s ease;
}

.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 */
.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(200, 247, 197, 0.7);
  font-size: 0.78rem;
}

/* Tutorial overlay */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}

.tutorial-overlay.active {
  display: flex;
}

.tutorial-card {
  background: rgba(10, 20, 10, 0.95);
  border: 2px solid rgba(57, 255, 20, 0.3);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(57, 255, 20, 0.05);
}

.tutorial-card h2 {
  font-size: 1.6rem;
  margin-bottom: 8px;
  background: linear-gradient(90deg, #39ff14, #00b894);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tutorial-card p {
  color: rgba(200, 247, 197, 0.75);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.tutorial-visual {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  margin-bottom: 16px;
}

.tutorial-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(57, 255, 20, 0.2);
  transition: background 0.3s ease;
}

.tutorial-dot.active {
  background: #39ff14;
}

.tutorial-btn {
  border: none;
  border-radius: 999px;
  padding: 12px 32px;
  background: linear-gradient(135deg, #39ff14, #00cc44);
  color: #052005;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 15px rgba(57, 255, 20, 0.25);
}

.tutorial-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(57, 255, 20, 0.35);
}

.tutorial-skip {
  display: block;
  margin: 12px auto 0;
  border: none;
  background: none;
  color: rgba(200, 247, 197, 0.4);
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.2s ease;
}

.tutorial-skip:hover {
  color: rgba(200, 247, 197, 0.7);
}

.game__footer p {
  color: rgba(200, 247, 197, 0.4);
  font-size: 0.88rem;
  font-style: italic;
}

/* Fullscreen styles */
.game:fullscreen,
.game:-webkit-full-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #050a05;
  padding: 16px;
}

/* --- Mobile portrait: fill viewport, maximize canvas --- */
@media (max-width: 600px) {
  html, body {
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  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;
  }

  .settings-bar {
    gap: 8px;
  }

  .setting-group {
    font-size: 0.75rem;
  }

  .dpad {
    grid-template-columns: 52px 52px 52px;
    grid-template-rows: 52px 52px 52px;
    gap: 3px;
  }

  .dpad__btn {
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
  }

  .achievements-panel {
    display: none;
  }

  .game__footer {
    display: none;
  }
}

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

  .game {
    gap: 4px;
  }

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

  .game__header p {
    display: none;
  }

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

  .settings-bar {
    display: none;
  }

  .dpad {
    grid-template-columns: 46px 46px 46px;
    grid-template-rows: 46px 46px 46px;
    gap: 2px;
  }

  .dpad__btn {
    width: 42px;
    height: 42px;
    font-size: 1rem;
    border-radius: 10px;
  }

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

/* --- Landscape on mobile --- */
@media (max-height: 500px) and (orientation: landscape) {
  html, body {
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    padding: 4px 8px;
  }

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

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

  .game__header p,
  .game__footer,
  .achievements-panel {
    display: none;
  }

  .back-link {
    font-size: 0.75rem;
    margin-bottom: 0;
  }

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

  canvas {
    width: auto;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    border-radius: 8px;
  }

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

  .hud__button {
    padding: 6px 12px;
    font-size: 0.75rem;
  }

  .settings-bar {
    display: none;
  }
}

@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;
  }
}
