:root {
  --ink: #f5f3ff;
  --ink-dim: #b8b5d9;
  --bg: #0b1030;
  --card: rgba(20, 24, 62, 0.92);
  --accent: #ffd166;
  --accent-2: #8be9fd;
  --line: rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
  cursor: crosshair;
}

#game:focus-visible {
  box-shadow: inset 0 0 0 3px var(--accent-2);
}

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.hud-chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.hud-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.5);
  white-space: nowrap;
}

.hud-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.hud-btn:hover, .hud-btn:focus-visible {
  transform: scale(1.1);
  border-color: var(--accent);
  outline: none;
}

.hud-btn[aria-pressed="false"] {
  opacity: 0.45;
  text-decoration: line-through;
}

.hint {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  max-width: min(92vw, 560px);
  text-align: center;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(11, 16, 48, 0.6);
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.6s;
}

.hint.faded { opacity: 0; }

.toast {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 10px 20px;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 32, 0.78);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.overlay.hidden { display: none; }

.overlay-card {
  width: min(92vw, 420px);
  max-height: 88vh;
  overflow-y: auto;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.overlay-card h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 6px;
  background: linear-gradient(120deg, #ffd166, #ff9e64, #8be9fd);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#overlay-sub {
  margin: 4px 0 14px;
  font-size: 13px;
  letter-spacing: 4px;
  color: var(--ink-dim);
  text-transform: uppercase;
}

#overlay-body {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink-dim);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.level-cell {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  padding: 10px 4px 6px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.level-cell:hover:not(:disabled), .level-cell:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
  outline: none;
}

.level-cell:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.level-cell .stars {
  display: block;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 1px;
  margin-top: 2px;
  color: var(--accent);
  min-height: 12px;
}

.cta {
  border: none;
  border-radius: 999px;
  padding: 12px 34px;
  font-size: 16px;
  font-weight: 700;
  color: #1a1233;
  background: linear-gradient(120deg, #ffd166, #ffb347);
  box-shadow: 0 8px 28px rgba(255, 209, 102, 0.35);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.cta:hover, .cta:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 34px rgba(255, 209, 102, 0.5);
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .hud-title { display: none; }
  .hint { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .hud-btn, .level-cell, .cta, .toast { transition: none; }
}
