:root {
  color-scheme: dark;
  --ink: #f8f3df;
  --muted: #9da2bd;
  --panel: #191d3b;
  --line: #34395b;
  --mint: #6ff0ce;
  --gold: #ffc857;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: #0b0e20;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, a { color: inherit; font: inherit; }

.app {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 88px minmax(0, 1fr);
  background:
    radial-gradient(circle at 50% 22%, #273061 0, #131733 34%, transparent 67%),
    linear-gradient(110deg, #0a0d1e, #11142c 55%, #090c1b);
}

.topbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-width: 0;
  padding: 4px clamp(10px, 3vw, 26px);
  border-bottom: 1px solid #34395b;
  background: rgb(10 13 31 / 88%);
  box-shadow: 0 8px 32px #05071370;
  backdrop-filter: blur(14px);
}

.home-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: #b4b8ce;
  font-size: .62rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover { color: white; }
.home-mark { color: var(--mint); font-size: 1.55rem; font-weight: 500; line-height: .5; }

.quota {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 170px;
  padding: 3px 11px 3px 5px;
  border: 1px solid #3c4267;
  border-radius: 99px;
  background: #151936;
  color: white;
  box-shadow: inset 0 1px #ffffff10, 0 5px 18px #05071355;
}
.quota canvas { width: 72px; height: 72px; flex: 0 0 auto; filter: drop-shadow(0 0 9px #ffffff30); }
.quota > div { display: grid; align-items: baseline; line-height: 1; }
.quota-label { grid-column: 1 / -1; color: #8f96b4; font-size: .43rem; font-weight: 900; letter-spacing: .14em; }
.quota strong { margin-top: 3px; color: var(--gold); font-size: .84rem; font-weight: 950; font-variant-numeric: tabular-nums; }
.quota.match { animation: quota-hit .34s ease; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.actions { justify-self: end; display: flex; align-items: center; gap: 7px; }
.counter { display: grid; min-width: 34px; justify-items: center; line-height: 1; }
.counter strong { color: var(--gold); font-size: .95rem; font-variant-numeric: tabular-nums; }
.counter span { margin-top: 2px; color: #8e94af; font-size: .43rem; font-weight: 900; letter-spacing: .13em; }

.icon-button {
  display: grid;
  width: 35px;
  height: 35px;
  padding: 0;
  place-items: center;
  border: 1px solid #454b70;
  border-radius: 50%;
  background: #1a1e3c;
  color: #d9dbee;
  font-size: .9rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 1px #ffffff12;
}

.icon-button:hover, .icon-button:focus-visible { border-color: var(--mint); color: white; outline: none; }
.icon-button.active { border-color: var(--mint); background: #204443; color: var(--mint); }

.game-shell {
  position: relative;
  min-height: 0;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
}

.game-shell::before, .game-shell::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(transparent, #4b5077 15%, #4b5077 85%, transparent);
  opacity: .55;
}
.game-shell::before { left: 0; }
.game-shell::after { right: 0; }

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

.hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 16%;
  display: grid;
  justify-items: center;
  gap: 2px;
  translate: -50% 0;
  color: #f8f3df;
  font-size: .58rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-shadow: 0 2px 7px #000;
  pointer-events: none;
  animation: hint-bob 1.2s ease-in-out infinite;
  transition: opacity .25s ease;
}
.hint b { color: var(--mint); font-size: 1.4rem; }
.hint.hidden { opacity: 0; }

.toast {
  position: absolute;
  z-index: 3;
  top: 16px;
  left: 50%;
  max-width: 80%;
  padding: 7px 12px;
  border: 1px solid #72789b;
  border-radius: 99px;
  background: rgb(17 21 48 / 90%);
  color: #e9e6da;
  font-size: .59rem;
  font-weight: 850;
  letter-spacing: .1em;
  opacity: 0;
  translate: -50% -8px;
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; translate: -50% 0; }

.help-card[hidden], .success-card[hidden] { display: none; }
.help-card, .success-card {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  width: min(100% - 28px, 430px);
  height: max-content;
  margin: auto;
  padding: 27px;
  place-items: center;
  border: 1px solid #62698f;
  border-radius: 25px;
  background: linear-gradient(150deg, #24294e 0, #151936 68%);
  box-shadow: 0 30px 100px #030511dd, inset 0 1px #ffffff18;
  text-align: center;
}
.help-card::before, .success-card::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 88px 0 0;
  background: #050714a8;
  backdrop-filter: blur(5px);
}
.help-card .eyebrow, .success-card .eyebrow { margin: 17px 0 8px; color: var(--mint); font-size: .57rem; font-weight: 900; letter-spacing: .16em; }
.help-card h1, .success-card h1 { margin: 0; font-size: clamp(1.8rem, 7vw, 2.7rem); line-height: .95; letter-spacing: -.055em; }
.help-card > p:not(.eyebrow), .success-card > p:not(.eyebrow) { max-width: 330px; margin: 13px auto 0; color: #bec2d6; font-size: .88rem; line-height: 1.5; }
.help-key { margin-top: 17px; color: #969cb8; font-size: .55rem; font-weight: 850; letter-spacing: .11em; }
.help-key span { margin: 0 5px; color: var(--gold); }
.help-card button, .success-card button {
  width: 100%;
  margin-top: 20px;
  padding: 13px 18px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(100deg, #6ff0ce, #a1f5b9);
  color: #10142b;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 8px 28px #65e8c33d;
}
.help-card button:hover, .success-card button:hover { filter: brightness(1.08); }
.help-art { display: flex; align-items: center; gap: 12px; height: 50px; }
.demo-marble { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 32% 25%, white 0 8%, transparent 9%), repeating-linear-gradient(45deg, #ffcf55 0 4px, #ef557d 5px 9px); box-shadow: 0 4px 10px #05071499; }
.demo-arrow { color: var(--mint); font-size: 1.3rem; }
.demo-track { width: 55px; height: 10px; border: 2px solid #6ff0ce; border-radius: 8px; background: #f8f3df; rotate: 90deg; box-shadow: 0 0 12px #6ff0ce55; }

.success-card { overflow: hidden; }
.success-card::after {
  content: "✦  ·  ✦  ·  ✦";
  position: absolute;
  top: 21px;
  color: #ffc85780;
  font-size: 1.1rem;
  letter-spacing: .35em;
}
.success-seal {
  display: grid;
  width: 65px;
  height: 65px;
  margin-top: 16px;
  place-items: center;
  border: 2px solid #a6f5d9;
  border-radius: 50%;
  background: #24554e;
  color: #b8ffe7;
  font-size: 2rem;
  font-weight: 950;
  box-shadow: 0 0 30px #6ff0ce55, inset 0 0 20px #6ff0ce22;
}
.success-actions { display: grid; width: 100%; grid-template-columns: 1fr 1fr; gap: 8px; }
.success-card button.secondary { border: 1px solid #50577e; background: #24294b; color: #d9dbea; box-shadow: none; }

@keyframes hint-bob { 50% { translate: -50% 7px; } }
@keyframes quota-hit { 50% { border-color: var(--mint); box-shadow: 0 0 24px #6ff0ce55, inset 0 1px #ffffff18; scale: 1.045; } }

@media (max-width: 520px) {
  .app { grid-template-rows: 84px minmax(0, 1fr); }
  .topbar { padding: 4px 9px; }
  .home-link > span:last-child { display: none; }
  .home-link { width: 35px; }
  .quota { min-width: 150px; padding-right: 8px; }
  .quota canvas { width: 68px; height: 68px; }
  .quota strong { font-size: .78rem; }
  .counter { display: none; }
  .icon-button { width: 33px; height: 33px; }
  .help-card::before, .success-card::before { inset-block-start: 84px; }
  .success-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
  .toast, .hint { transition: none; }
}
