:root {
  --bg: #101322;
  --panel: rgba(18, 20, 34, 0.86);
  --text: #f4f6ff;
  --muted: rgba(244, 246, 255, 0.62);
  --accent: #ff6b6b;
  --accent-2: #ffd166;
  --radius: 18px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ---------- menu ---------- */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px 32px;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(255, 107, 107, 0.25), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(31, 162, 255, 0.25), transparent 60%),
    var(--bg);
  animation: fade-in 0.5s ease both;
}

.menu-head { text-align: center; margin: 24px 0 18px; width: min(1040px, 100%); }
.menu-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.account-name { font-weight: 700; }
.account-role {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-2);
  background: rgba(255, 209, 102, 0.12);
  border-radius: 999px;
  padding: 6px 10px;
}
.wallet-chip {
  margin: 10px auto 0;
  display: inline-block;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
}
.lane {
  width: min(1040px, 100%);
  margin: 10px 0 28px;
}
.lane-head { margin-bottom: 14px; text-align: left; }
.lane-head h2 {
  margin: 0 0 4px;
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 800;
}
.lane-head p { margin: 0; color: var(--muted); font-size: 14px; }
.load-more { margin: 14px auto 0; display: block; }
.level-card.locked { opacity: 0.92; }
.level-card .price {
  font-weight: 800;
  color: var(--accent-2);
  font-size: 13px;
}
.level-card .price.free { color: #7dffa0; }
.review-panel {
  width: min(1040px, 100%);
  margin: 0 0 28px;
  padding: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
}
.review-panel h2 { margin: 0 0 12px; font-size: 20px; }
.review-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.appsoln-copy { margin-top: 8px; font-weight: 700; letter-spacing: 0.02em; }
.logo { display: inline-flex; align-items: center; gap: 16px; }
.logo h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 60px);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #ffd166 60%, #ff6b6b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo-line {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, #ff6b6b, #ffd166);
  box-shadow: 0 10px 30px rgba(255, 107, 107, 0.45);
  position: relative;
  animation: bob 2.2s ease-in-out infinite;
}
.logo-line::after {
  content: ""; position: absolute; left: 14px; top: -34px; width: 16px; height: 44px;
  border-radius: 8px 8px 0 0; background: rgba(255, 255, 255, 0.35);
}
.tagline { margin: 12px 0 0; color: var(--muted); font-size: 15px; }

.level-grid {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}

.lane-loader {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 160px;
  padding: 28px 16px;
  border-radius: var(--radius);
  background: rgba(18, 20, 34, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.lane-loader p { margin: 0; }
.lane-loader .spinner { margin-bottom: 8px; }

.level-card {
  position: relative;
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  background: var(--card-bg, linear-gradient(145deg, #2a2f52, #171a2f));
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}
.level-card:hover, .level-card:focus-visible { transform: translateY(-4px); box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55); }
.level-card .num {
  position: absolute; right: 16px; top: 12px;
  font-size: 54px; font-weight: 800; opacity: 0.12; line-height: 1;
}
.level-card h3 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.level-card .meta { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.level-card .swatch {
  height: 6px; border-radius: 3px; margin: 14px 0;
  background: var(--swatch, linear-gradient(90deg, #ff6b6b, #ffd166));
}
.level-card .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.difficulty { display: inline-flex; gap: 4px; }
.difficulty i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); display: inline-block; }
.difficulty i.on { background: var(--accent-2); }
.best { font-size: 13px; color: var(--muted); }
.best strong { color: var(--text); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.card-actions .btn { padding: 10px 16px; font-size: 14px; }
.card-actions .btn.sync, .card-actions .btn.auto { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.level-card.synced { box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.45), var(--shadow); }

.sync-bar {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  z-index: 40;
  pointer-events: auto;
  background: rgba(10, 12, 24, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 14px 16px 12px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.sync-bar p { margin: 0 0 8px; font-weight: 600; font-size: 15px; }
.sync-row { display: flex; align-items: center; gap: 10px; }
.sync-actions { margin-top: 10px; }
.sync-bpm { min-width: 78px; font-size: 18px; }
.sync-bar input[type="range"] { flex: 1; accent-color: var(--accent-2); }
#sync-cancel { margin-top: 6px; width: 100%; }

.level-card.custom-card {
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 0 8px, transparent 8px 16px),
    linear-gradient(145deg, #243049, #141824);
  border-style: dashed;
}
.level-card .blurb { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.custom-panel { text-align: left; }
.custom-panel h2, .custom-panel .btn-col { text-align: center; }
.wave {
  display: block;
  width: 100%;
  height: 96px;
  margin: 14px 0 6px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
}
.field { margin-top: 14px; }
.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.field input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 12px 14px;
  user-select: text;
  -webkit-user-select: text;
}
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px 8px;
  cursor: pointer;
}
.seg button.on { background: linear-gradient(135deg, var(--accent), #ff9f68); color: #1a1020; border-color: transparent; }
label.btn { display: block; text-align: center; }

.credits { margin-top: 36px; max-width: 760px; text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.credits a { color: var(--text); text-decoration: none; border-bottom: 1px solid rgba(255, 255, 255, 0.25); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 13px 22px; border-radius: 14px;
  cursor: pointer; transition: transform 0.12s ease, background 0.2s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff9f68); border-color: transparent; color: #1a1020; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

.icon-btn {
  font: inherit; font-size: 14px; color: var(--text);
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 12, 24, 0.35); backdrop-filter: blur(6px);
  cursor: pointer; pointer-events: auto;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0; pointer-events: none;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
}
.progress {
  position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: rgba(255, 255, 255, 0.12);
}
#progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px var(--accent);
  transition: width 0.12s linear;
}
.hud-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 12px; min-width: 120px; }
.hud-right { justify-content: flex-end; }
#hud-title { font-weight: 600; font-size: 14px; opacity: 0.85; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); }
#hud-percent {
  font-size: 30px; font-weight: 800; letter-spacing: -0.02em;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  transform-origin: center; transition: transform 0.08s ease;
}
.gem-counter { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 16px; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); }
.gem-icon {
  width: 12px; height: 12px; display: inline-block; transform: rotate(45deg);
  background: linear-gradient(135deg, #fff, var(--accent-2)); border-radius: 2px;
  box-shadow: 0 0 10px var(--accent-2);
}
.toast {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  background: rgba(10, 12, 24, 0.55); backdrop-filter: blur(6px);
  padding: 10px 20px; border-radius: 999px; font-weight: 600;
  animation: toast 1.6s ease both;
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(8, 9, 18, 0.42);
  backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease both;
}
.overlay.tapzone { background: transparent; backdrop-filter: none; cursor: pointer; }
.panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.panel.wide { width: min(640px, 100%); }
.panel.subtle { background: transparent; border: none; box-shadow: none; }
.panel h2 { margin: 0 0 6px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.muted { color: var(--muted); margin: 6px 0; font-size: 14px; }
.big-stat { margin: 18px 0 6px; display: flex; flex-direction: column; align-items: center; }
.big-stat span { font-size: 64px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.big-stat small { color: var(--muted); font-size: 13px; margin-top: 6px; }

.start-card {
  text-align: center;
  background: rgba(8, 9, 18, 0.4);
  backdrop-filter: blur(8px);
  padding: 28px 34px; border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  animation: pop-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.start-card h2 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.tap-hint { margin-top: 20px; display: inline-flex; align-items: center; gap: 10px; font-weight: 600; }
.pulse-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent-2); animation: pulse 1s ease-in-out infinite; }

textarea {
  width: 100%; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text); background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 12px; padding: 12px; resize: vertical;
  user-select: text; -webkit-user-select: text;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(255, 255, 255, 0.1); padding: 1px 6px; border-radius: 6px; }

.spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent-2);
  animation: spin 0.9s linear infinite;
}

/* ---------- animations ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: 0.55; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  15%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

@media (max-width: 520px) {
  .hud-left { display: none; }
  #hud-percent { font-size: 26px; }
  .panel { padding: 24px 20px; }
  .big-stat span { font-size: 54px; }
}
