:root {
  --bg: #04060e;
  --ink: #e6edf3;
  --muted: #9aabc2;
  --dim: #8294ab;
  --cyan: #22d3ee;
  --violet: #a78bfa;
  --magenta: #f472b6;
  --amber: #fbbf24;
  --panel: rgba(8, 13, 24, 0.86);
  --line: rgba(80, 110, 150, 0.28);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Segoe UI", Inter, "Helvetica Neue", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

/* ---------------- HUD ---------------- */

.hud {
  position: fixed;
  inset: 0;
  padding: 22px 26px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 10;
}

.hud.hidden { opacity: 0; }

.hud-block { display: flex; gap: 26px; }

.hearts { display: flex; gap: 8px; }

.heart {
  width: 18px;
  height: 18px;
  background: var(--magenta);
  clip-path: polygon(50% 100%, 0 38%, 12% 12%, 32% 4%, 50% 18%, 68% 4%, 88% 12%, 100% 38%);
  filter: drop-shadow(0 0 8px rgba(244, 114, 182, 0.65));
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.heart.off {
  background: #2a1a24;
  filter: none;
  opacity: 0.55;
  transform: scale(0.82);
}

.stat { text-align: right; }

.stat .label,
.result .label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2.6px;
  color: var(--dim);
  margin-bottom: 2px;
}

.stat .value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.35);
}

.stat .unit { font-size: 12px; color: var(--muted); margin-left: 2px; }

/* ---------------- Overlay ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 45%, rgba(4, 6, 14, 0.10), rgba(4, 6, 14, 0.72));
  backdrop-filter: blur(3px);
  z-index: 20;
  transition: opacity 0.3s ease;
}

.overlay.hidden { opacity: 0; pointer-events: none; }

.panel {
  width: min(560px, 100%);
  padding: 34px 38px 30px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  text-align: center;
  animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 4px;
  color: var(--cyan);
  opacity: 0.85;
  margin-bottom: 14px;
}

.kicker.danger { color: var(--magenta); }

h1 {
  margin: 0 0 6px;
  font-size: clamp(38px, 7vw, 58px);
  line-height: 0.94;
  letter-spacing: -1.5px;
  font-weight: 800;
  background: linear-gradient(100deg, #ffffff 0%, #8fe3ff 42%, #b79cff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 28px rgba(56, 189, 248, 0.22));
}

h1 span { letter-spacing: -0.5px; }

h2 {
  margin: 0 0 6px;
  font-size: 34px;
  letter-spacing: -0.6px;
  font-weight: 700;
}

.sub {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 13.5px;
  letter-spacing: 0.4px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(34, 211, 238, 0.35);
  background: rgba(34, 211, 238, 0.08);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.6px;
  padding: 13px 26px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.2s ease, border-color 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.btn:hover { transform: translateY(-1px); background: rgba(34, 211, 238, 0.16); border-color: rgba(34, 211, 238, 0.6); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(180deg, rgba(34, 211, 238, 0.22), rgba(34, 211, 238, 0.10)); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); margin-top: 10px; }
.btn.ghost:hover { color: var(--ink); }

kbd {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(120, 150, 190, 0.28);
  background: rgba(120, 150, 190, 0.08);
  color: var(--muted);
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 26px;
  font-size: 12px;
  color: var(--dim);
}

.controls kbd { margin-right: 3px; }

.meta {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid rgba(80, 110, 150, 0.18);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--dim);
}

.meta b { color: var(--muted); font-weight: 500; }

.sound-toggle,
.lang-toggle {
  appearance: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 1.8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
}

.lang-toggle {
  letter-spacing: 1px;
}

.seed-toggle {
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  margin: -8px 0;
  font: inherit;
  letter-spacing: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
}

.seed-toggle:hover { color: var(--ink); border-color: var(--line); }
.seed-toggle b { color: var(--cyan); }

.sound-toggle:hover { color: var(--ink); border-color: rgba(34, 211, 238, 0.45); }

.sound-toggle[aria-pressed="true"] {
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.5);
}

.btn.ghost.sound-toggle { background: transparent; margin-top: 14px; }

.results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 22px 0 26px;
}

.result {
  padding: 14px 8px;
  border: 1px solid rgba(80, 110, 150, 0.2);
  border-radius: 10px;
  background: rgba(10, 16, 30, 0.5);
}

.result b {
  display: block;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--cyan);
}

.seed-line {
  margin: 18px 0 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--dim);
}

.seed-line b { color: var(--muted); }

.hidden { display: none !important; }
.panel.hidden { display: none !important; }

/* ---------------- touch ---------------- */

.touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 22px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  gap: 16px;
  z-index: 15;
  pointer-events: none;
}

.tbtn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid rgba(34, 211, 238, 0.3);
  background: rgba(10, 18, 32, 0.55);
  color: rgba(226, 240, 255, 0.9);
  font-size: 20px;
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
  user-select: none;
  touch-action: none;
}

.tbtn:active { background: rgba(34, 211, 238, 0.22); }

.tbtn.jump { margin-left: auto; border-color: rgba(167, 139, 250, 0.45); }

.touch .tbtn:nth-child(2) { margin-left: 0; }

/* ---------------- flash / toast ---------------- */

.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(244, 114, 182, 0.0), rgba(244, 114, 182, 0.0));
  z-index: 18;
  transition: background 0.12s ease;
}

.flash.on { background: radial-gradient(circle at 50% 50%, rgba(244, 114, 182, 0.10), rgba(244, 114, 182, 0.34)); }

.toast {
  position: fixed;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -6px);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(34, 211, 238, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 24;
}

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

@media (max-width: 520px) {
  .panel { padding: 26px 22px 24px; }
  .hud { padding: 14px 16px; }
  .stat .value { font-size: 18px; }
  .controls { gap: 12px; font-size: 11px; }
}

/* ---------------- difficulty ---------------- */

.diffs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 20px;
}

.diff {
  appearance: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 18px;
  min-width: 80px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(10, 16, 30, 0.5);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.diff small {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 2px;
  color: var(--dim);
}

.diff:hover { border-color: rgba(34, 211, 238, 0.4); color: var(--ink); }

.diff.active {
  border-color: rgba(34, 211, 238, 0.75);
  color: #eafbff;
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.18), rgba(34, 211, 238, 0.05));
  box-shadow: 0 0 26px rgba(34, 211, 238, 0.16);
}

.diff.active small { color: var(--cyan); }

.hud-diff {
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 2.6px;
  color: var(--muted);
  padding: 4px 12px;
  border: 1px solid rgba(80, 110, 150, 0.25);
  border-radius: 999px;
  background: rgba(8, 13, 24, 0.45);
}

@media (max-width: 520px) {
  .hud-diff { top: 14px; font-size: 8.5px; }
  .diff { padding: 8px 12px; min-width: 64px; font-size: 12px; }
}

/* ---------------- accessibility ---------------- */

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

/* Pause lives above the jump button so one thumb covers both. */
.tbtn.pause {
  position: fixed;
  right: 22px;
  bottom: calc(104px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  font-size: 10px;
  letter-spacing: -1px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
