:root {
  --ink: #1a1020;
  --paper: #fffdf3;
  --bg: #241a5c;
  --bg-dots: rgba(255, 255, 255, 0.08);
  --space-1: #3d2f86;
  --space-2: #120d2e;
  --caption: #ffe45c;
  --best: #ff9f1c;
  --correct: #3ddc84;
  --wrong: #ff4d5e;
  --jupiter: #f4a259;
  --saturn: #f6d365;
  --uranus: #7fdbda;
  --neptune: #6b9bff;
  --font-display: "Bangers", "Impact", "Arial Black", sans-serif;
  --font-body: "Comic Neue", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  --border: 4px solid var(--ink);
  --pop: 5px 5px 0 var(--ink);
  --radius: 10px;
  --gap: clamp(0.6rem, 2vh, 1rem);
  --bubble-height: 7.6rem;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dots) 1.6px, transparent 1.8px);
  background-size: 14px 14px;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

button {
  touch-action: manipulation; /* no double-tap zoom */
}

/*
 * App layout: the game fills the screen and every row has a fixed size, so
 * nothing moves between rounds. Only the comic panel is flexible and the moon
 * drawing scales to fit the space that is left. The speech bubble is only as
 * large as its text and sits at the top of its row, the rest of the row is
 * left empty above the buttons.
 */
.game {
  height: 100vh;
  height: 100dvh;
  max-height: 54rem;
  min-height: 34rem;
  width: 100%;
  max-width: 34rem;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--bubble-height) auto;
  gap: var(--gap);
  padding:
    calc(env(safe-area-inset-top, 0px) + 0.8rem)
    calc(env(safe-area-inset-right, 0px) + 1rem)
    calc(env(safe-area-inset-bottom, 0px) + 0.8rem)
    calc(env(safe-area-inset-left, 0px) + 1rem);
}

@media (min-height: 54rem) {
  body { display: grid; align-items: center; }
}

/* --- header --- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.9rem, 8vw, 3rem);
  letter-spacing: 0.04em;
  line-height: 1;
  white-space: nowrap;
  color: var(--caption);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-3deg);
}

.scores {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.score {
  width: 4.6rem;
  padding: 0.25rem 0.4rem 0.15rem;
  text-align: center;
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--ink);
}

.score .label {
  display: block;
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.score .value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.7rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.score.best { background: var(--best); }

.score .value.bump { animation: bump 0.35s ease; }

@keyframes bump {
  50% { transform: scale(1.35) rotate(-6deg); }
}

/* --- comic panel --- */

.panel {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.4rem 1rem 0.7rem;
  text-align: center;
  background: radial-gradient(circle at 50% 42%, var(--space-1), var(--space-2) 72%);
  border: var(--border);
  border-radius: 4px;
  box-shadow: 7px 7px 0 var(--ink);
  overflow: hidden;
}

.caption {
  position: absolute;
  top: -4px;
  left: -4px;
  margin: 0;
  padding: 0.3rem 0.75rem;
  font-weight: 700;
  font-size: 0.9rem;
  background: var(--caption);
  border: var(--border);
  z-index: 2;
}

.art {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

.art svg {
  display: block;
  height: 100%;
  max-height: 17rem;
  aspect-ratio: 1;
  max-width: 100%;
}

.art.enter svg { animation: enter 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes enter {
  from { transform: scale(0.4) rotate(-20deg); opacity: 0; }
}

.moon {
  flex: none;
  height: 1.1em;
  margin: 0.3rem 0 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.3rem, 10vw, 3.4rem);
  letter-spacing: 0.05em;
  line-height: 1.1;
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 4px 4px 0 var(--ink);
}

/* --- POW! burst --- */

.burst {
  position: absolute;
  top: 0.5rem;
  right: 0.4rem;
  width: 7.5rem;
  aspect-ratio: 1;
  z-index: 3;
  filter:
    drop-shadow(3px 0 0 var(--ink)) drop-shadow(-3px 0 0 var(--ink))
    drop-shadow(0 3px 0 var(--ink)) drop-shadow(0 -3px 0 var(--ink))
    drop-shadow(4px 4px 0 var(--ink));
  animation: burst 0.35s cubic-bezier(0.2, 1.8, 0.4, 1);
  pointer-events: none;
}

.burst-shape {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: var(--caption);
  clip-path: polygon(
    100% 50%, 85.1% 64.6%, 85.4% 85.4%, 64.6% 85.1%, 50% 100%, 35.4% 85.1%,
    14.6% 85.4%, 14.9% 64.6%, 0% 50%, 14.9% 35.4%, 14.6% 14.6%, 35.4% 14.9%,
    50% 0%, 64.6% 14.9%, 85.4% 14.6%, 85.1% 35.4%
  );
}

.burst.wrong .burst-shape { background: var(--wrong); color: #fff; }

.burst-shape span {
  font-family: var(--font-display);
  font-size: 1.7rem;
  letter-spacing: 0.04em;
  transform: rotate(-12deg);
}

@keyframes burst {
  from { transform: scale(0) rotate(-40deg); }
}

/* --- speech bubble (sized to its text, at the top of a fixed row) --- */

.bubble {
  position: relative;
  justify-self: start;
  align-self: start;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.9rem;
  background: var(--paper);
  border: var(--border);
  border-radius: 20px;
  box-shadow: var(--pop);
}

.bubble.show { animation: pop 0.25s ease-out; }

/* scrolls only if a text is ever too long for the bubble row */
.bubble-body {
  min-height: 0;
  overflow-y: auto;
}

.bubble::before,
.bubble::after {
  content: "";
  position: absolute;
  left: 2.5rem;
  border-style: solid;
  border-color: transparent;
}

.bubble::before {
  top: -22px;
  border-width: 0 0 22px 22px;
  border-bottom-color: var(--ink);
}

.bubble::after {
  top: -14px;
  left: calc(2.5rem + 4px);
  border-width: 0 0 15px 15px;
  border-bottom-color: var(--paper);
}

@keyframes pop {
  from { transform: scale(0.94); }
}

.fact {
  margin: 0;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
}

.bubble:not(.show) .fact { font-size: 1.1rem; }

.fact .verdict {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.2rem;
  letter-spacing: 0.04em;
  margin-right: 0.3rem;
}

.fact .verdict.correct { color: #11994f; }
.fact .verdict.wrong { color: #d11a2e; }

.meta {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  line-height: 1.3;
  opacity: 0.8;
}

/* --- planet buttons --- */

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.planet {
  height: 3.6rem;
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--pop);
  padding: 0.2rem 0.5rem 0;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}

.planet.jupiter { background: var(--jupiter); }
.planet.saturn { background: var(--saturn); }
.planet.uranus { background: var(--uranus); }
.planet.neptune { background: var(--neptune); }

@media (hover: hover) {
  .planet:hover:not(:disabled) { filter: brightness(1.08); transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--ink); }
}
.planet:active:not(:disabled) { transform: translate(4px, 4px); box-shadow: 1px 1px 0 var(--ink); }
.planet:focus-visible { outline: 3px dashed #fff; outline-offset: 4px; }
.planet:disabled { cursor: default; }
.answers.answered .planet:not(.correct):not(.wrong) { filter: grayscale(0.7) brightness(0.75); }

.planet.correct { background: var(--correct); }
.planet.correct::after { content: " ✓"; }
.planet.wrong { background: var(--wrong); color: #fff; animation: shake 0.4s; }
.planet.wrong::after { content: " ✗"; }

@keyframes shake {
  20%, 60% { transform: translateX(-6px) rotate(-2deg); }
  40%, 80% { transform: translateX(6px) rotate(2deg); }
}

kbd {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  vertical-align: middle;
  margin-right: 0.45rem;
  opacity: 0.55;
}

/* --- countdown to the next moon (bottom right of the panel) --- */

.timer {
  position: absolute;
  right: 0.6rem;
  bottom: 0.6rem;
  width: 3.2rem;
  height: 3.2rem;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: var(--border);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  z-index: 2;
}

.timer[hidden] { display: none; }

.timer svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer circle {
  fill: none;
  stroke-width: 5;
}

.timer-track { stroke: rgba(26, 16, 32, 0.12); }

.timer-ring {
  stroke: var(--best);
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
}

.timer.run .timer-ring { animation: drain var(--delay, 3s) linear forwards; }

@keyframes drain {
  to { stroke-dashoffset: 100; }
}

.timer-count {
  position: relative;
  font-family: var(--font-display);
  font-size: 1.4rem;
  line-height: 1;
  padding-top: 0.1rem;
  font-variant-numeric: tabular-nums;
}

.timer:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.timer:focus-visible { outline: 3px dashed #fff; outline-offset: 4px; }

/* touch devices: no keyboard hints */
@media (hover: none) {
  kbd { display: none; }
}

@media (max-width: 420px) {
  :root { --bubble-height: 8.4rem; }
  .planet { font-size: 1.4rem; }
  .burst { width: 6rem; }
  .burst-shape span { font-size: 1.35rem; }
  .fact { font-size: 0.95rem; }
  .meta { font-size: 0.8rem; }
}

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