:root {
  --bg: #06060f;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f6ff;
  --muted: #8d95b0;
  --cyan: #00d4ff;
  --purple: #7c5cff;
  --glow: rgba(120, 90, 255, 0.45);
  --gold: #ffd700;
  --danger: #ff4466;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  color: var(--text);
  overflow-x: hidden;
}

body.play-mode {
  overflow: hidden;
  height: 100dvh;
}

html[lang="en"] body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ── Background ── */
.page-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-grid {
  position: absolute;
  inset: -50%;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(500px) rotateX(60deg);
  animation: grid-drift 24s linear infinite;
  mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, black, transparent);
}

@keyframes grid-drift {
  to { transform: perspective(500px) rotateX(60deg) translateY(48px); }
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: orb-float 14s ease-in-out infinite;
}

.orb-1 { width: 380px; height: 380px; background: #6c3bff; top: -100px; left: -60px; }
.orb-2 { width: 320px; height: 320px; background: #00d4aa; top: 30%; right: -80px; animation-delay: -5s; opacity: 0.35; }
.orb-3 { width: 260px; height: 260px; background: #ff3d7f; bottom: 5%; left: 25%; animation-delay: -9s; opacity: 0.28; }

@keyframes orb-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(24px, -16px) scale(1.06); }
}

.wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  padding: 52px 12px max(16px, env(safe-area-inset-bottom));
  padding-top: max(48px, calc(env(safe-area-inset-top) + 40px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

body.play-mode .wrapper {
  max-width: 100%;
  padding-left: max(6px, env(safe-area-inset-left));
  padding-right: max(6px, env(safe-area-inset-right));
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  gap: 3px;
}

body.play-mode .hud-shell {
  padding: 8px 12px;
  border-radius: 14px;
}

body.play-mode .hud-score-value {
  font-size: 1.25rem;
}

body.play-mode .hud-combo-value {
  font-size: 1rem;
}

body.play-mode .game-toolbar {
  margin-top: 6px;
}

.arcadebox-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(6, 6, 15, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.arcadebox-top-bar .back-link {
  color: var(--cyan);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 500;
}

.arcadebox-top-bar .back-link:hover {
  text-decoration: underline;
}

.lang-switch {
  display: flex;
  gap: 4px;
}

.lang-switch button {
  border: 1px solid rgba(124, 92, 255, 0.35);
  background: var(--surface);
  color: var(--text);
  font-size: 0.68rem;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.lang-switch button.active {
  background: rgba(124, 92, 255, 0.28);
  border-color: rgba(124, 92, 255, 0.65);
}

/* ── HUD ── */
.game-header {
  width: 100%;
}

.game-header.hidden {
  display: none;
}

.hud-shell {
  padding: 10px 14px;
  border-radius: 16px;
}

.hud-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.hud-row-secondary {
  margin-top: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.hud-label {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.hud-score-value {
  font-family: "Orbitron", monospace;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 12px rgba(0, 212, 255, 0.35));
}

.hud-combo-block {
  text-align: right;
  transition: transform 0.15s ease;
}

.hud-combo-block.hot {
  transform: scale(1.05);
}

.hud-combo-block.hot .hud-combo-value {
  color: var(--gold);
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.55));
}

.hud-combo-value {
  font-family: "Orbitron", monospace;
  font-size: 1.25rem;
  color: var(--cyan);
}

.hud-lives-wrap {
  display: flex;
  flex-direction: column;
}

.hud-lives {
  display: flex;
  gap: 3px;
  min-height: 1.1rem;
}

.hud-heart {
  color: var(--danger);
  font-size: 0.95rem;
  text-shadow: 0 0 8px rgba(255, 68, 102, 0.5);
  animation: heart-pop 0.25s ease;
}

@keyframes heart-pop {
  from { transform: scale(1.4); opacity: 0.5; }
  to { transform: scale(1); opacity: 1; }
}

.hud-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.78rem;
}

.hud-chip strong {
  font-family: "Orbitron", monospace;
  color: var(--cyan);
}

.hud-power {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  font-size: 0.72rem;
}

.hud-power-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
  flex-shrink: 0;
}

.hud-power strong {
  font-family: "Orbitron", monospace;
  font-size: 0.68rem;
  color: var(--text);
}

.boss-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.boss-bar-label {
  font-family: "Russo One", "Noto Sans SC", sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--danger);
  text-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
}

.boss-bar-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 68, 68, 0.35);
  overflow: hidden;
}

.boss-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff1744, #ff8800);
  box-shadow: 0 0 12px rgba(255, 68, 68, 0.55);
  transition: width 0.2s ease;
}

/* ── Arcade frame ── */
.game-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-height: 0;
}

.arcade-frame {
  position: relative;
  width: 100%;
  max-width: 480px;
  padding: 3px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--purple), var(--cyan), var(--purple));
  box-shadow:
    0 0 32px var(--glow),
    0 12px 40px rgba(0, 0, 0, 0.45);
}

.arcade-frame::before,
.arcade-frame::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 212, 255, 0.55);
  pointer-events: none;
  z-index: 2;
}

.arcade-frame::before {
  top: 8px;
  left: 8px;
  border-right: none;
  border-bottom: none;
  border-radius: 4px 0 0 0;
}

.arcade-frame::after {
  top: 8px;
  right: 8px;
  border-left: none;
  border-bottom: none;
  border-radius: 0 4px 0 0;
}

.arcade-frame-inner {
  position: relative;
  border-radius: 15px;
  overflow: hidden;
  background: #040810;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.65);
}

.arcade-frame-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.04) 2px,
    rgba(0, 0, 0, 0.04) 4px
  );
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100dvh - 180px);
  aspect-ratio: 9 / 16;
  background: transparent;
  position: relative;
  z-index: 0;
}

canvas:focus {
  outline: none;
}

.arcade-frame-inner:focus-within {
  box-shadow: inset 0 0 0 2px rgba(0, 212, 255, 0.35);
}

.combo-milestone {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-family: "Russo One", "Noto Sans SC", sans-serif;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  letter-spacing: 0.06em;
  color: var(--gold);
  text-shadow:
    0 0 20px rgba(255, 136, 0, 0.8),
    0 0 40px rgba(255, 215, 0, 0.4);
  pointer-events: none;
  white-space: nowrap;
}

.combo-milestone.pop {
  animation: combo-pop 1.2s ease forwards;
}

@keyframes combo-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.08); }
  75% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.95) translateY(-12px); }
}

.game-toolbar {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  padding-bottom: env(safe-area-inset-bottom);
}

.game-toolbar.hidden {
  display: none;
}

.ui-button {
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid rgba(124, 92, 255, 0.4);
  background: rgba(6, 6, 15, 0.75);
  color: var(--text);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.15s, box-shadow 0.15s;
}

.ui-button:hover {
  background: rgba(124, 92, 255, 0.22);
  box-shadow: 0 0 16px var(--glow);
}

.ui-button:active {
  transform: scale(0.97);
}

.hidden {
  display: none !important;
}

/* ── Glass panel ── */
.glass-panel {
  background: linear-gradient(145deg, rgba(16, 20, 40, 0.88), rgba(6, 8, 18, 0.94));
  border: 1px solid rgba(124, 92, 255, 0.28);
  border-radius: 20px;
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(124, 92, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(14px);
}

/* ── Menus ── */
.menu {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 4, 12, 0.78);
  backdrop-filter: blur(8px);
}

.menu.active {
  display: flex !important;
}

.menu-panel-enter {
  animation: panel-enter 0.35s ease;
}

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.menu-content {
  text-align: center;
  padding: 26px 28px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.menu-hero {
  margin-bottom: 18px;
}

.menu-hero-icon {
  display: block;
  font-size: 2.5rem;
  margin-bottom: 6px;
  filter: drop-shadow(0 0 16px var(--glow));
}

.menu h1 {
  font-family: "Russo One", "Noto Sans SC", sans-serif;
  font-size: 1.65rem;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #fff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0 0 6px;
}

.menu h2 {
  font-family: "Russo One", "Noto Sans SC", sans-serif;
  font-size: 1.25rem;
  color: var(--text);
  margin: 0 0 14px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.mode-label {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.tier-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.tier-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.tier-card:hover {
  border-color: rgba(124, 92, 255, 0.45);
}

.tier-card.active {
  border-color: rgba(0, 212, 255, 0.55);
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.18), rgba(0, 212, 255, 0.1));
  box-shadow: 0 0 20px var(--glow);
}

.tier-card-name {
  font-family: "Russo One", "Noto Sans SC", sans-serif;
  font-size: 0.95rem;
}

.tier-card-hint {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.tier-progress-wrap {
  margin-bottom: 16px;
}

.tier-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 8px;
}

.tier-progress-fill {
  height: 100%;
  width: 10%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), var(--cyan));
  transition: width 0.35s ease;
}

.tier-progress {
  font-family: "Orbitron", monospace;
  font-size: 0.72rem;
  color: var(--gold);
  margin: 0;
  letter-spacing: 0.03em;
}

.continue-hint {
  font-size: 0.72rem;
  color: var(--cyan);
  margin: -6px 0 10px;
  line-height: 1.4;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-button {
  display: block;
  width: 100%;
  padding: 12px 18px;
  border: 1px solid rgba(124, 92, 255, 0.35);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s, background 0.15s;
}

.menu-button.primary {
  background: linear-gradient(135deg, var(--purple), #5a8cff);
  border-color: transparent;
  box-shadow: 0 4px 20px var(--glow);
  font-weight: 700;
}

.menu-button.secondary {
  opacity: 0.85;
  font-size: 0.82rem;
}

.menu-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.25);
}

.menu-button:active {
  transform: translateY(0);
}

.level-select-panel {
  max-width: 540px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
  margin: 14px 0 18px;
}

.level-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: "Orbitron", monospace;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}

.level-cell::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
}

.level-cell.stars-1::after { background: rgba(255, 215, 0, 0.45); }
.level-cell.stars-2::after { background: linear-gradient(90deg, rgba(255, 215, 0, 0.5), rgba(255, 180, 0, 0.75)); }
.level-cell.stars-3::after { background: linear-gradient(90deg, var(--gold), #ffaa00); }

.level-cell:hover:not(.locked) {
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.3);
  transform: translateY(-2px);
}

.level-cell.locked {
  opacity: 0.38;
  cursor: not-allowed;
}

.level-cell.boss {
  border-color: rgba(255, 68, 68, 0.55);
  background: rgba(60, 12, 24, 0.45);
  animation: boss-pulse 2.5s ease-in-out infinite;
}

@keyframes boss-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 68, 68, 0); }
  50% { box-shadow: 0 0 14px rgba(255, 68, 68, 0.35); }
}

.level-cell .boss-tag {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.45rem;
  font-family: "Russo One", sans-serif;
  letter-spacing: 0.05em;
  color: #ff8888;
  line-height: 1;
}

.level-cell .mini-stars {
  font-size: 0.5rem;
  color: var(--gold);
  letter-spacing: -1px;
}

.star-row {
  font-size: 2.75rem;
  letter-spacing: 10px;
  margin: 14px 0;
}

.star-row .star {
  display: inline-block;
  color: rgba(255, 255, 255, 0.15);
  transform: scale(0.85);
}

.star-row .star.earned {
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.65);
  animation: star-earn 0.5s ease forwards;
}

.star-row .star[data-star="1"].earned { animation-delay: 0.1s; }
.star-row .star[data-star="2"].earned { animation-delay: 0.35s; }
.star-row .star[data-star="3"].earned { animation-delay: 0.6s; }

@keyframes star-earn {
  0% { transform: scale(0.2); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.summary-text {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.instructions-panel .instructions {
  text-align: left;
  margin: 12px 0;
  padding: 14px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.instructions p {
  margin: 7px 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--muted);
}

.power-grid-title {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 12px 0 10px;
  text-align: left;
}

.power-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  text-align: left;
}

.power-grid-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.72rem;
}

.power-grid-item.bad {
  opacity: 0.75;
}

.power-grid-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.high-score-tier {
  color: var(--cyan);
  font-family: "Orbitron", monospace;
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.high-score-list {
  margin: 10px 0;
  padding: 12px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  border: 1px solid var(--border);
  min-height: 100px;
}

.score-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  margin: 4px 0;
  background: rgba(124, 92, 255, 0.08);
  border-radius: 8px;
  font-family: "Orbitron", monospace;
  font-size: 0.82rem;
}

.score-rank {
  color: var(--cyan);
}

.message-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.touch-guide {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  padding: 16px;
}

.touch-guide-content {
  padding: 28px;
  text-align: center;
  max-width: 360px;
}

@media (orientation: landscape) and (max-height: 520px) {
  .wrapper {
    padding-top: max(36px, env(safe-area-inset-top));
    gap: 4px;
  }

  .hud-shell {
    padding: 6px 10px;
    border-radius: 12px;
  }

  .hud-score-value {
    font-size: 1.15rem;
  }

  .hud-combo-value {
    font-size: 0.95rem;
  }

  .hud-row-secondary {
    margin-top: 4px;
  }

  .hud-label {
    font-size: 0.55rem;
  }

  .arcade-frame {
    max-width: 100%;
    padding: 2px;
  }

  .game-toolbar {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0;
    z-index: 12;
    padding-bottom: 0;
  }

  .game-toolbar .ui-button {
    padding: 6px 14px;
    font-size: 0.72rem;
    background: rgba(6, 6, 15, 0.82);
  }

  .menu-content {
    max-height: 92dvh;
    padding: 16px;
  }

  .menu-hero-icon {
    font-size: 2rem;
  }
}

@media (max-width: 768px) {
  .wrapper {
    padding-top: 48px;
  }

  .menu-content {
    padding: 20px 18px;
  }

  .hud-score-value {
    font-size: 1.35rem;
  }

  .power-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .hud-row-primary {
    flex-wrap: wrap;
  }

  .level-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .tier-card-hint {
    font-size: 0.68rem;
  }
}
