:root {
  --bg: #12121a;
  --panel: #1c1c28;
  --panel-2: #262636;
  --text: #f4f4f8;
  --muted: #9a9ab0;
  --good: #3ddc84;
  --bad: #ff5a5f;
  --accent: #b18cff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.15s;
}
body.flash-good { background: #15261d; }
body.shake .stage { animation: shake 0.3s; }

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  padding: 16px 24px;
  padding-top: max(16px, env(safe-area-inset-top));
}
.lives { font-size: 26px; letter-spacing: 4px; color: var(--bad); }
.heart.lost { color: #3a3a4a; }
.hud-mid { position: absolute; left: 50%; transform: translateX(-50%); }
/* The streak hangs to the right of the level so it never shifts the level off center. */
.streak { position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%); white-space: nowrap; }
.level { color: var(--muted); font-size: 15px; }
.streak { color: var(--accent); font-weight: 600; font-size: 15px; }
.hard-badge {
  position: absolute; right: calc(100% + 12px); top: 50%; transform: translateY(-50%); white-space: nowrap;
  padding: 2px 8px; line-height: 1.4; border-radius: 999px; font-size: 13px; font-weight: 700;
  color: #ffb36b; background: rgba(255, 179, 107, 0.14);
}
.hard-badge[hidden] { display: none; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.score-box {
  display: flex; flex-direction: column; align-items: flex-end;
  line-height: 1.1; margin-right: 6px;
}
.score-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.score { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.best-label { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.mute {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--panel-2);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 0 16px 40px;
  position: relative;
}

.banner {
  position: absolute;
  top: 0;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--accent);
  font-weight: 600;
  opacity: 0;
}
.banner.show { animation: banner 2.4s ease forwards; }

.prompt-wrap { width: min(720px, 100%); text-align: center; }
.prompt {
  min-height: 1.4em;
  font-size: clamp(36px, 7vw, 68px);
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0 0.28em;
}
.prompt.pop { animation: pop 0.18s ease-out; }
.prompt .op { color: var(--muted); font-weight: 600; }
.prompt .paren { color: var(--muted); font-weight: 400; }
.prompt .word { white-space: nowrap; display: inline-flex; align-items: center; }
.prompt .symbol { display: inline-flex; align-items: center; line-height: 1; }
/* Sized to the text so shapes sit level with words at every font size. */
.prompt .symbol svg { width: 0.8em; height: 0.8em; }

.timer {
  margin: 22px auto 0;
  height: 8px;
  width: min(480px, 100%);
  background: var(--panel);
  border-radius: 999px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
}
.timer-bar.low { background: var(--bad); }

.feedback { height: 24px; margin-top: 14px; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.pad {
  display: grid;
  grid-template-areas: ". up ." "left down right";
  grid-template-columns: repeat(3, 110px);
  gap: 10px;
}
.tile {
  height: 104px;
  cursor: pointer;
  touch-action: none;
  background: var(--panel);
  border: 2px solid var(--panel-2);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.15s, background-color 0.15s;
}
.tile .arrow { font-size: 18px; color: var(--muted); line-height: 1; }
.tile .label { font-size: 12px; color: var(--muted); }
.tile.pressed { animation: press 0.16s ease-out; }
.tile.shuffled { animation: shuffle 0.5s ease-out; }
.tile.hit { border-color: var(--good); background: #1b2a22; }
.tile.miss { border-color: var(--bad); background: #2c1a1d; }
.tile.valid { border-color: var(--good); border-style: dashed; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 16, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay[hidden] { display: none; }
.card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 18px;
  padding: 28px 32px;
  line-height: 1.55;
  max-height: 100%;
  overflow-y: auto;
}
.card h1 { margin: 0 0 12px; font-size: 40px; }
.strike { text-decoration: line-through; color: var(--muted); }
.rules { padding-left: 20px; color: var(--muted); }
.rules code { color: var(--text); background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.final { font-size: 24px; font-weight: 700; }
.hard-toggle {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin: 14px 0 4px; padding: 10px 12px; text-align: left;
  background: var(--panel-2); color: var(--text); border: 1px solid transparent; border-radius: 12px;
  font: inherit; cursor: pointer;
}
.hard-toggle.on { border-color: #ffb36b; }
.switch {
  flex: none; position: relative; width: 40px; height: 22px; border-radius: 999px;
  background: #3a3a4a; transition: background-color 0.15s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform 0.15s;
}
.hard-toggle.on .switch { background: #ffb36b; }
.hard-toggle.on .switch::after { transform: translateX(18px); }
.share-preview {
  margin: 12px 0; padding: 12px 14px; border-radius: 12px;
  background: var(--panel-2); font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; user-select: text;
}
.share {
  background: var(--accent); color: #14101f; border: 0; border-radius: 10px;
  padding: 10px 18px; font: inherit; font-weight: 700; cursor: pointer;
}
.share-status { margin-left: 10px; color: var(--good); font-weight: 600; }
.pause-note { min-height: 1.2em; margin: 4px 0 12px; color: #ffb36b; }
.version { margin-top: 4px; opacity: 0.7; }
.small { color: var(--muted); font-size: 13px; }
body.is-paused .prompt { filter: blur(14px); }
.hint { color: var(--accent); font-weight: 600; animation: pulse 1.6s ease-in-out infinite; }

/* Below this width the sides would collide with a centered level, so it moves to its own row. */
@media (max-width: 820px) {
  .hud { flex-wrap: wrap; row-gap: 8px; }
  .hud-mid { position: relative; left: auto; transform: none; order: 3; width: 100%; display: flex; justify-content: center; }
  .hud-mid .level { position: relative; }
  .streak { left: auto; right: 16px; }
  .hard-badge { right: auto; left: 16px; }
}

@media (max-width: 560px) {
  .hud { padding: 12px 16px; }
  .lives { font-size: 22px; }
  .score { font-size: 22px; }
  .best-label { display: none; }
  .mute { padding: 6px 8px; }
  .stage { gap: 24px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .pad { grid-template-columns: repeat(3, min(30vw, 120px)); }
  .tile { height: min(28vw, 116px); }
  .tile .label { font-size: 11px; }
  .card { padding: 22px 20px; }
  .card h1 { font-size: 32px; }
}

@keyframes shuffle { 0% { transform: rotateY(90deg); } 60% { transform: rotateY(-12deg); } 100% { transform: none; } }
@keyframes pop { from { transform: scale(0.92); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
@keyframes press { 50% { transform: scale(0.92); } }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes banner { 0% { opacity: 0; transform: translateY(-6px); } 12%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes pulse { 50% { opacity: 0.55; } }

.debug {
  position: fixed; top: 80px; right: 12px; z-index: 5; width: 230px;
  max-height: calc(100vh - 100px); overflow-y: auto;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--panel-2);
  background: rgba(18, 18, 26, 0.92); color: var(--text);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.debug[hidden] { display: none; }
.debug h2 { margin: 0 0 8px; font-size: 13px; display: flex; justify-content: space-between; }
.debug h2 span { color: var(--muted); font-weight: 400; }
.debug dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; }
.debug dt { color: var(--muted); }
.debug dd { margin: 0; }
.debug table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.debug td { padding: 1px 0; }
.debug td:last-child { text-align: right; color: var(--accent); }
.debug-bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.debug-bar span { display: block; height: 100%; background: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
