:root {
  --bg-0: #05050f;
  --bg-1: #0a0a1f;
  --bg-2: #11102a;
  --ink: #e8f1ff;
  --ink-dim: #8a92b8;
  --cyan: #38e8ff;
  --magenta: #ff4ad1;
  --violet: #8b5cff;
  --gold: #ffd166;
  --danger: #ff5577;
  --glow-cyan: 0 0 16px rgba(56, 232, 255, 0.55), 0 0 36px rgba(56, 232, 255, 0.25);
  --glow-magenta: 0 0 16px rgba(255, 74, 209, 0.55), 0 0 36px rgba(255, 74, 209, 0.25);
  --glow-violet: 0 0 16px rgba(139, 92, 255, 0.55), 0 0 36px rgba(139, 92, 255, 0.25);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 800px at 80% -10%, rgba(139, 92, 255, 0.25), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(56, 232, 255, 0.18), transparent 60%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 40%, var(--bg-2));
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.orb {
  position: absolute;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: float 18s ease-in-out infinite;
}
.orb-cyan { background: radial-gradient(circle, var(--cyan), transparent 60%); top: -160px; left: -120px; }
.orb-magenta { background: radial-gradient(circle, var(--magenta), transparent 60%); bottom: -180px; right: -140px; animation-delay: -6s; animation-duration: 22s; }
.orb-violet { background: radial-gradient(circle, var(--violet), transparent 60%); top: 30%; right: 20%; opacity: 0.32; animation-delay: -12s; animation-duration: 26s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -50px) scale(1.08); }
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(56, 232, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 232, 255, 0.06) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
}

.stage {
  position: relative;
  z-index: 1;
  width: min(720px, 96vw);
  max-height: 100vh;
  padding: 14px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.hud-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 10px;
}

.hud-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hud-score {
  background: linear-gradient(180deg, rgba(56, 232, 255, 0.12), rgba(139, 92, 255, 0.08));
  border-color: rgba(56, 232, 255, 0.35);
  box-shadow: var(--glow-cyan);
}

.hud-label {
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.hud-value {
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 1px;
  text-shadow: 0 0 12px rgba(56, 232, 255, 0.5);
}

.hud-score .hud-value {
  font-size: 26px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
}

.lives {
  display: inline-flex;
  gap: 6px;
  text-shadow: none;
}
.lives i {
  width: 14px;
  height: 14px;
  display: inline-block;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--cyan), var(--magenta));
  box-shadow: var(--glow-cyan);
  transition: opacity 0.2s, transform 0.2s;
}
.lives i.lost {
  opacity: 0.18;
  background: #2a2a44;
  box-shadow: none;
  transform: scale(0.85);
}

.hud-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.hud-tag {
  font-size: 12px;
  color: var(--ink-dim);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.hud-tag.best {
  color: var(--gold);
  border-color: rgba(255, 209, 102, 0.3);
  background: rgba(255, 209, 102, 0.08);
}
.hud-tag.diff-tag {
  color: var(--magenta);
  border-color: rgba(255, 74, 209, 0.35);
  background: rgba(255, 74, 209, 0.08);
  font-weight: 700;
}
.hud-tag.diff-tag[data-diff="easy"]   { color: #7ad9ff; border-color: rgba(122,217,255,0.4); background: rgba(122,217,255,0.08); }
.hud-tag.diff-tag[data-diff="normal"] { color: #8b5cff; border-color: rgba(139,92,255,0.4); background: rgba(139,92,255,0.08); }
.hud-tag.diff-tag[data-diff="hard"]   { color: #ff4ad1; border-color: rgba(255,74,209,0.4); background: rgba(255,74,209,0.08); }
.hud-tag.diff-tag[data-diff="hell"]   { color: #ff5577; border-color: rgba(255,85,119,0.5); background: rgba(255,85,119,0.1); }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 720 / 900;
  border-radius: 20px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(139, 92, 255, 0.22), transparent 60%),
    linear-gradient(180deg, #0c0c22 0%, #06061a 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(56, 232, 255, 0.05),
    0 0 50px rgba(56, 232, 255, 0.08);
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background:
    radial-gradient(circle at 50% 40%, rgba(20, 20, 50, 0.6), rgba(5, 5, 15, 0.92));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 5;
  animation: fadeIn 0.3s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.overlay-modal {
  position: fixed;
  z-index: 60;
}

.overlay.hidden { display: none; }
.overlay > .overlay-card { margin: auto; flex-shrink: 0; position: relative; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  z-index: 2;
}
.modal-close:hover {
  background: rgba(255, 74, 209, 0.16);
  border-color: rgba(255, 74, 209, 0.5);
  transform: rotate(90deg);
}
.modal-close:active { transform: rotate(90deg) scale(0.92); }

.result-badge {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1.5px;
  padding: 11px 22px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #06091a;
  box-shadow: var(--glow-cyan), 0 8px 20px rgba(0, 0, 0, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  animation: badgeFloat 2.2s ease-in-out infinite;
}
.result-badge:hover { filter: brightness(1.12); }
.result-badge:active { transform: translateX(-50%) translateY(1px); }
.result-badge.hidden { display: none; }

.icon-trophy {
  display: inline-block;
  width: 14px;
  height: 14px;
  background:
    radial-gradient(circle at center, currentColor 35%, transparent 36%) center / 14px 14px no-repeat;
  position: relative;
}
.icon-trophy::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 8px;
  height: 3px;
  background: currentColor;
  border-radius: 1px;
  transform: translateX(-50%);
}

@keyframes badgeFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(1.02); }
  to { opacity: 1; transform: scale(1); }
}

.overlay-card {
  width: 100%;
  max-width: 440px;
  padding: 28px 26px 26px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(56, 232, 255, 0.22);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 30px 60px rgba(0, 0, 0, 0.5),
    0 0 80px rgba(56, 232, 255, 0.15);
  text-align: center;
}
.overlay-card.small { max-width: 320px; padding: 22px 22px 20px; }

.title {
  margin: 0 0 10px;
  font-size: clamp(28px, 6vw, 42px);
  line-height: 1.05;
  letter-spacing: 4px;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.title-line { display: block; }
.title-cyan {
  background: linear-gradient(90deg, var(--cyan), #6dffe5);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(56, 232, 255, 0.45));
}
.title-magenta {
  background: linear-gradient(90deg, var(--magenta), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 74, 209, 0.45));
}

.title-sm {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 2px;
  font-weight: 800;
}
.title-sm.cyan {
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 0 0 18px;
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.6;
}

.diff-picker {
  margin: 18px 0 14px;
  padding: 14px 12px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.diff-title {
  display: block;
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.diff-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.diff-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  border-radius: 12px;
  padding: 10px 4px 8px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: transform 0.15s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
}
.diff-btn .diff-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--ink);
}
.diff-btn .diff-sub {
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--ink-dim);
  line-height: 1.2;
}
.diff-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(56, 232, 255, 0.3);
}
.diff-btn.active[data-diff="easy"] {
  background: linear-gradient(135deg, rgba(122,217,255,0.2), rgba(56,232,255,0.1));
  border-color: rgba(122,217,255,0.7);
  box-shadow: 0 0 18px rgba(122,217,255,0.35);
}
.diff-btn.active[data-diff="normal"] {
  background: linear-gradient(135deg, rgba(139,92,255,0.22), rgba(56,232,255,0.1));
  border-color: rgba(139,92,255,0.7);
  box-shadow: 0 0 18px rgba(139,92,255,0.35);
}
.diff-btn.active[data-diff="hard"] {
  background: linear-gradient(135deg, rgba(255,74,209,0.22), rgba(139,92,255,0.1));
  border-color: rgba(255,74,209,0.7);
  box-shadow: 0 0 18px rgba(255,74,209,0.35);
}
.diff-btn.active[data-diff="hell"] {
  background: linear-gradient(135deg, rgba(255,85,119,0.28), rgba(255,74,209,0.12));
  border-color: rgba(255,85,119,0.85);
  box-shadow: 0 0 22px rgba(255,85,119,0.45);
}
.diff-btn.active .diff-name { color: #fff; }
.diff-desc {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
  line-height: 1.5;
  min-height: 32px;
}

.howto {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-dim);
}
.howto li { line-height: 1.5; }
.howto strong { color: var(--ink); }
.howto kbd {
  display: inline-block;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  padding: 2px 8px;
  margin: 0 2px;
  border-radius: 6px;
  background: rgba(56, 232, 255, 0.12);
  border: 1px solid rgba(56, 232, 255, 0.3);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 2px;
  padding: 12px 26px;
  border-radius: 12px;
  margin: 4px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.15); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #06091a;
  border: none;
  box-shadow: var(--glow-cyan);
  padding: 14px 30px;
  font-size: 16px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.end-score, .end-best {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.end-value {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 22px;
}
.end-value.cyan { color: var(--gold); text-shadow: 0 0 12px rgba(255, 209, 102, 0.5); }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 4px;
}
.controls .btn { padding: 10px 18px; font-size: 13px; letter-spacing: 1.5px; }
.controls .hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-dim);
}

.icon-pause, .icon-restart {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
}
.icon-pause {
  background:
    linear-gradient(currentColor, currentColor) left top / 4px 12px no-repeat,
    linear-gradient(currentColor, currentColor) right top / 4px 12px no-repeat;
}
.icon-restart {
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  transform: rotate(45deg);
}

.icon-share {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 2px solid currentColor;
  border-radius: 50%;
  position: relative;
}
.icon-share::before {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  background: currentColor;
  border-radius: 50%;
  left: -3px;
  top: 2px;
}
.icon-share::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  background: currentColor;
  border-radius: 50%;
  right: -3px;
  top: 2px;
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.end-actions .btn { margin: 0; }

.share-card {
  max-width: 460px;
  padding: 22px 22px 18px;
}

.share-preview {
  position: relative;
  margin: 8px 0 14px;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(56, 232, 255, 0.18);
  box-shadow: 0 0 30px rgba(56, 232, 255, 0.12);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.share-preview img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 16px;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
  pointer-events: auto;
  touch-action: auto;
}
.share-preview img:not([src]),
.share-preview img[src=""] { display: none; }
.share-preview {
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
  touch-action: auto;
}

.share-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  font-size: 13px;
  letter-spacing: 2px;
  background: rgba(0, 0, 0, 0.3);
  pointer-events: none;
  transition: opacity 0.2s;
}
.share-loading.hidden { display: none; }

.share-hint {
  margin: 4px 0 10px;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
  line-height: 1.5;
}
.share-hint.hidden { display: none; }

.share-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.share-actions.two-col { grid-template-columns: 1fr 1fr; }
.share-actions .hidden-btn { display: none; }
.share-actions .btn {
  margin: 0;
  padding: 11px 8px;
  font-size: 13px;
  letter-spacing: 1px;
}

.share-toast {
  display: block;
  min-height: 18px;
  color: var(--cyan);
  font-size: 12px;
  text-align: center;
  margin-bottom: 6px;
  opacity: 0;
  transition: opacity 0.25s;
}
.share-toast.show { opacity: 1; }

.link-close {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 10px;
  letter-spacing: 1px;
}
.link-close:hover { color: var(--ink); }

@media (max-width: 540px) {
  .share-actions:not(.two-col) { grid-template-columns: 1fr 1fr; }
  .share-actions:not(.two-col) .btn:first-child { grid-column: 1 / -1; }
}

@media (max-width: 540px) {
  .stage { padding: 8px 8px 12px; gap: 8px; }
  .hud-card { padding: 8px 10px; border-radius: 12px; }
  .hud-value { font-size: 18px; }
  .hud-score .hud-value { font-size: 22px; }
  .controls .hint { display: none; }
  .controls { justify-content: space-between; }
  .controls .btn { flex: 1; padding: 10px 12px; }
  .howto { font-size: 12px; }
  .title { letter-spacing: 2px; font-size: clamp(22px, 5.5vw, 32px); }

  .overlay { padding: 12px; }
  .overlay-card { padding: 18px 18px 16px; border-radius: 18px; }
  .overlay-card.small { padding: 16px 16px 14px; }
  .subtitle { font-size: 12.5px; margin-bottom: 12px; }

  .diff-picker { margin: 12px 0 10px; padding: 10px 8px 8px; border-radius: 14px; }
  .diff-title { margin-bottom: 8px; letter-spacing: 2px; }
  .diff-grid { gap: 4px; }
  .diff-btn { padding: 8px 2px 6px; border-radius: 10px; }
  .diff-btn .diff-name { font-size: 13px; }
  .diff-btn .diff-sub { font-size: 9px; }
  .diff-desc { font-size: 11px; min-height: 28px; margin-top: 8px; }

  .howto { margin: 0 0 14px; gap: 6px; }
  .howto li { line-height: 1.4; }

  .btn-primary { padding: 12px 24px; font-size: 15px; }

  .modal-close { width: 32px; height: 32px; font-size: 20px; top: 8px; right: 10px; }
  .result-badge { padding: 9px 18px; font-size: 12px; bottom: 12px; }

  .share-card { padding: 16px 16px 14px; }
  .share-preview { min-height: 180px; margin: 6px 0 10px; }
  .share-hint { font-size: 11px; margin: 2px 0 8px; }
  .share-actions .btn { padding: 10px 6px; font-size: 12px; letter-spacing: 0.5px; }
  .end-score, .end-best { padding: 8px 12px; }
  .end-value { font-size: 18px; }
}

@media (max-width: 380px) {
  .howto { display: none; }
  .title { font-size: clamp(20px, 5vw, 28px); }
  .subtitle { margin-bottom: 8px; }
  .diff-btn .diff-sub { display: none; }
  .diff-btn { padding: 10px 2px; }
}

@media (min-width: 900px) {
  .stage { width: 760px; }
}

@media (max-height: 760px) and (min-width: 541px) {
  .stage { padding: 10px; }
  .hud-row-meta { display: none; }
}
