: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; }
/* Badge, level and streak are centered together as one group. */
.hud-mid { position: absolute; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.streak:empty { display: none; }
.level { color: var(--muted); font-size: 15px; }
.streak {
  position: relative; overflow: hidden; color: var(--accent); font-weight: 600; font-size: 15px;
  padding: 2px 10px; border-radius: 999px; border: 1.5px solid transparent; line-height: 1.4;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}
.streak.bump { animation: streak-bump 0.25s ease-out; }
/* 10: bronze trim. 20: silver with a shine sweep. 30: gold. 40: glowing gold. 50+: shifting rainbow. */
.streak.tier-1 { color: #ffb36b; border-color: #a8693a; background: rgba(255, 179, 107, 0.08); }
.streak.tier-2 { color: #eef1ff; border-color: #b9c2e8; background: rgba(185, 194, 232, 0.12); }
.streak.tier-3 { color: #ffe27a; border-color: #ffd23f; background: rgba(255, 210, 63, 0.14); }
.streak.tier-4 { color: #ffe27a; border-color: #ffd23f; background: rgba(255, 210, 63, 0.18); animation: streak-glow 1.4s ease-in-out infinite; }
.streak.tier-5 {
  color: #fff; border-color: transparent;
  background: linear-gradient(#1c1c28, #1c1c28) padding-box, linear-gradient(90deg, #ff5a5f, #ffd23f, #3ddc84, #4da3ff, #b18cff, #ff5a5f) border-box;
  background-size: 100% 100%, 300% 100%; animation: streak-rainbow 2.4s linear infinite, streak-glow 1.4s ease-in-out infinite;
}
.streak.tier-2::after, .streak.tier-3::after, .streak.tier-4::after, .streak.tier-5::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(110deg, transparent 35%, rgba(255, 255, 255, 0.45) 50%, transparent 65%);
  transform: translateX(-120%); animation: streak-shine 2.2s ease-in-out infinite;
}
.streak.milestone { animation: streak-milestone 0.8s cubic-bezier(0.2, 1.6, 0.4, 1); }
.combo {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); pointer-events: none; white-space: nowrap; z-index: 1;
  font-size: clamp(15px, 2.6vw, 20px); font-weight: 700; letter-spacing: 0; opacity: 0; color: #ffb36b;
}
.combo.tier-2 { color: #eef1ff; }
.combo.tier-3, .combo.tier-4 { color: #ffe27a; }
.combo.tier-5 {
  background: linear-gradient(90deg, #ff5a5f, #ffd23f, #3ddc84, #4da3ff, #b18cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.combo.show { animation: combo-burst 1.8s ease-out forwards; }
.hard-badge {
  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: center; justify-content: center;
  min-width: 56px; line-height: 1.15; margin-right: 6px; text-align: center;
}
.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 kbd { margin: 0 0 0 6px; font-size: 10px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 6px 9px; }
.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 var(--banner-time, 2.4s) ease forwards; }

.prompt-wrap { position: relative; 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 and nudged down onto the words' baseline, since lowercase text sits low in its line. */
.prompt .symbol svg { width: 0.72em; height: 0.72em; transform: translateY(0.05em); }

.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(--text);
  opacity: 0.85;
  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; }
.steps { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 10px; font-size: 15px; }
.steps li { display: flex; align-items: flex-start; gap: 10px; line-height: 1.45; }
.step-n {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); color: var(--accent); font-size: 13px; font-weight: 700; margin-top: 1px;
}
.pause-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pause-actions .mute { padding: 10px 14px; font-size: 14px; }
.legend {
  display: grid; grid-template-areas: ". up ." "left down right"; grid-template-columns: repeat(3, 76px);
  gap: 6px; justify-content: center; margin: 0 0 18px;
}
.legend-key {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  background: var(--panel-2); border-radius: 10px; line-height: 1.1;
}
.legend-key .arrow { font-size: 13px; color: var(--muted); }
.legend-key .label { font-size: 10px; color: var(--muted); text-align: center; }
.examples {
  list-style: none; padding: 0; margin: 0 0 4px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.examples li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--panel-2);
}
.examples li.wide { grid-column: 1 / -1; }
.examples code { font: 600 13px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); }
.c-red { color: #ff5a5f; } .c-green { color: #3ddc84; } .c-blue { color: #4da3ff; } .c-yellow { color: #ffd23f; }
.ex-keys { display: inline-flex; align-items: center; gap: 3px; flex: none; }
.ex-keys .mini { display: inline-flex; }
.ex-keys .plus, .ex-keys .or { color: var(--muted); font-size: 11px; }
.ex-icon { font-size: 16px; color: var(--muted); line-height: 1; }
kbd {
  display: inline-block; padding: 0 6px; margin-right: 2px; border-radius: 5px; border: 1px solid #3a3a4a;
  border-bottom-width: 2px; background: var(--panel-2); color: var(--text); font: 11px/1.6 ui-monospace, monospace;
}
.keys-hint .dot { margin: 0 6px; }
.keys-hint kbd ~ kbd { margin-left: 10px; }
.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;
  display: inline-flex; align-items: center; gap: 8px;
}
.share-status { margin-left: 10px; color: var(--good); font-weight: 600; }
.pause-help { margin: 10px 0 4px; }
.pause-help .legend { margin-bottom: 12px; }
.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 the centered group, 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%; justify-content: center; }
}

@media (max-width: 560px) {
  .hud { padding: 12px 16px 4px; row-gap: 14px; }
  .timer { width: min(320px, calc(100% - 48px)); height: 6px; }
  /* Room for two lines is always reserved, so a wrapping prompt doesn't push the keys down. */
  .prompt { font-size: 30px; line-height: 1.2; min-height: 2.4em; align-content: center; }
  .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; }
  .examples { grid-template-columns: 1fr; }
}

@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); } 6%, 88% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes streak-bump { 40% { transform: scale(1.18); } }
@keyframes streak-glow { 50% { box-shadow: 0 0 14px 2px rgba(255, 210, 63, 0.45); } }
@keyframes streak-rainbow { to { background-position: 0 0, 300% 0; } }
@keyframes streak-shine { 0%, 55% { transform: translateX(-120%); } 85%, 100% { transform: translateX(120%); } }
@keyframes streak-milestone { 0% { transform: scale(1); } 35% { transform: scale(1.2); } 65% { transform: scale(0.97); } 100% { transform: scale(1); } }
@keyframes combo-burst {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px); }
  15% { opacity: 0.9; transform: translateX(-50%); }
  55% { opacity: 0.9; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}
@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; }
}
.toggle-note { color: var(--muted); font-size: 13px; }

/* Touch screens have no Esc or R, so keyboard hints give way to tap instructions. */
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .kb-only { display: none !important; }
  .touch-only { display: inline; }
}

.intro-card { text-align: center; }
.intro-tag { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.intro-card h2 { margin: 0 0 8px; font-size: 26px; }
.intro-body { margin: 0 0 18px; color: var(--muted); }
.intro-example {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  margin: 0 0 18px; padding: 16px; border-radius: 12px; background: var(--panel-2);
}
.intro-prompt { font-size: 26px; font-weight: 800; display: inline-flex; align-items: center; gap: 0.3em; }
.intro-prompt .op, .intro-prompt .paren, .intro-prompt .comma { color: var(--muted); font-weight: 600; }
.intro-arrow { color: var(--muted); font-size: 20px; }
.intro-keys { display: inline-flex; align-items: center; gap: 6px; }
.intro-keys .or { color: var(--muted); }
.intro-none { color: var(--muted); font-weight: 600; }
.intro-icon { font-size: 40px; line-height: 1; }
.card h1.title { display: flex; align-items: center; gap: 0.25em; }
.title-dog { width: 1.35em; height: 1.35em; object-fit: contain; flex: none; }
.hard-toggle[hidden] { display: none; }

/* The secret nightmare switch lives in the corner once found, above every card. */
.nightmare-toggle {
  position: fixed; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 20;
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px;
  background: rgba(28, 28, 40, 0.92); border: 1px solid #3a2030; color: var(--text); cursor: pointer; font: inherit;
}
.nightmare-toggle[hidden] { display: none; }
.nightmare-icon { font-size: 18px; line-height: 1; filter: grayscale(1); opacity: 0.6; transition: filter 0.2s, opacity 0.2s; }
.nightmare-toggle .switch { width: 34px; height: 20px; }
.nightmare-toggle .switch::after { width: 14px; height: 14px; }
.nightmare-toggle.on { border-color: #b3122f; box-shadow: 0 0 14px rgba(179, 18, 47, 0.45); }
.nightmare-toggle.on .nightmare-icon { filter: none; opacity: 1; }
.nightmare-toggle.on .switch { background: #b3122f; }
.nightmare-toggle.on .switch::after { transform: translateX(14px); }
.hard-badge.nightmare { color: #ff6b81; background: rgba(179, 18, 47, 0.2); }
