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

* {
  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(0, 210, 255, 0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(180, 77, 255, 0.04) 0%, transparent 60%),
    linear-gradient(170deg, #04050f 0%, #0a0e24 40%, #060818 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: #c0d8ff;
  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, #00d4ff, #b44dff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

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

canvas {
  width: min(100%, 480px);
  height: auto;
  aspect-ratio: 3 / 4;
  background: #08091a;
  border-radius: 14px;
  border: 2px solid rgba(0, 210, 255, 0.25);
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 30px rgba(0, 210, 255, 0.06);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: 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(192, 216, 255, 0.5);
}

.hud__score strong {
  font-size: 1.7rem;
  color: #c0d8ff;
  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(0, 210, 255, 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, #00d4ff, #4488ff);
  color: #041020;
  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(0, 210, 255, 0.2);
}

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

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

/* Touch controls — hidden by default, shown via JS on touch devices */
.touch-controls {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 540px;
}

.touch-controls.visible {
  display: grid;
}

.touch-btn {
  border: 1px solid rgba(0, 210, 255, 0.25);
  border-radius: 12px;
  background: rgba(8, 12, 30, 0.85);
  backdrop-filter: blur(4px);
  color: #c0d8ff;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 14px 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s ease, transform 0.08s ease;
}

.touch-btn:active {
  background: rgba(0, 210, 255, 0.15);
  transform: scale(0.93);
}

.touch-btn--accent {
  background: rgba(0, 210, 255, 0.12);
  border-color: rgba(0, 210, 255, 0.4);
  color: #00d4ff;
}

.touch-btn--accent:active {
  background: rgba(0, 210, 255, 0.3);
}

.touch-btn--wide {
  grid-column: span 2;
  font-size: 1rem;
  padding: 12px 0;
}

/* Last row: soft drop + hold, fill the 5-col grid evenly */
.touch-btn--wide:nth-last-child(2) {
  grid-column: 1 / span 3;
}
.touch-btn--wide:last-child {
  grid-column: 4 / span 2;
}

.game__footer p {
  color: rgba(192, 216, 255, 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;
    overscroll-behavior: none;
  }

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

  .game {
    max-width: 100%;
    height: 100%;
    grid-template-rows: auto 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;
  }

  .touch-controls {
    gap: 6px;
    max-width: 100%;
  }

  .touch-btn {
    padding: 10px 0;
    font-size: 1rem;
    border-radius: 10px;
  }

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

  .touch-btn {
    padding: 8px 0;
    font-size: 0.9rem;
  }

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

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