:root {
  --bg: #0F1226;
  --ink: #FAF7F2;
  --muted: rgba(250, 247, 242, 0.7);
  --accent: #22D3EE;
  --accent-2: #FF4D6D;
  --player: #22D3EE;
  --cpu: #FF7849;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, #18306b 0%, transparent 60%),
    radial-gradient(1000px 500px at 100% 110%, #3a1530 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  display: grid;
  place-items: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 50;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: background 0.15s, color 0.15s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.back-link:hover { background: rgba(255, 255, 255, 0.12); color: var(--ink); }

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(96vw, 900px);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 900 / 560;
  max-height: 88dvh;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #131a3a 0%, #0c0f24 100%);
  cursor: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 24px;
  background: rgba(10, 12, 30, 0.78);
  backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade-in 0.25s ease;
}
.overlay.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(40px, 9vw, 64px);
  line-height: 0.95;
  background: linear-gradient(135deg, #22D3EE, #F6C453 55%, #FF4D6D);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 16px rgba(255, 77, 109, 0.25));
}
.title span { display: block; }

.toast-title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(30px, 8vw, 46px);
}

.best { color: var(--muted); font-size: 15px; font-weight: 600; }
.best span { color: var(--accent); }
.score-line strong {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(30px, 7vw, 44px);
  color: var(--ink);
  display: block;
}

.howto { color: var(--muted); font-size: 14px; max-width: 360px; line-height: 1.45; margin-top: 4px; }

.diff { display: flex; gap: 10px; }
.diff-btn {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--muted);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  padding: 9px 24px;
  border-radius: 999px;
  transition: all 0.15s ease;
  min-height: 44px;
}
.diff-btn.is-on {
  color: #0F1226;
  background: linear-gradient(135deg, #22D3EE, #10B981);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(34, 211, 238, 0.3);
}
.diff-btn:hover:not(.is-on) { border-color: rgba(255, 255, 255, 0.4); color: var(--ink); }

.btn {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: 20px;
  color: #0F1226;
  border: none;
  cursor: pointer;
  padding: 14px 48px;
  border-radius: 999px;
  background: linear-gradient(135deg, #FF7849, #FF4D6D);
  box-shadow: 0 10px 28px rgba(255, 77, 109, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 34px rgba(255, 77, 109, 0.45); }
.btn:active { transform: translateY(0) scale(0.99); }

.sound-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 30;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 17px;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
.sound-toggle:hover { background: rgba(255, 255, 255, 0.16); }

/* Push arcade-ui fullscreen button left of the sound toggle (44px + 10px gap + 12px right inset = 66px) */
.arcade-ui-fs { right: max(66px, calc(env(safe-area-inset-right) + 66px)) !important; }

/* Portrait rotate hint — shows only on narrow portrait screens */
.portrait-hint {
  display: none;
}

@media (orientation: portrait) and (max-width: 600px) {
  .portrait-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg);
    color: var(--ink);
    text-align: center;
    padding: 32px;
    font-family: 'Fredoka', system-ui, sans-serif;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
  }
  .portrait-hint-icon {
    font-size: 64px;
    animation: rotate-hint 1.8s ease-in-out infinite;
    display: block;
  }
  @keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    40%       { transform: rotate(90deg); }
    60%       { transform: rotate(90deg); }
  }
  .stage, .back-link { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  .btn, .diff-btn { transition: none; }
  .portrait-hint-icon { animation: none; }
}
