:root {
  --md-sys-color-primary: #006d44;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #91f7be;
  --md-sys-color-on-primary-container: #002111;
  --md-sys-color-secondary-container: #d0e8d6;
  --md-sys-color-on-secondary-container: #0b1f14;
  --md-sys-color-surface: #f8faf5;
  --md-sys-color-surface-container: #eceee9;
  --md-sys-color-on-surface: #191c1a;
  --md-sys-color-on-surface-variant: #404943;
  --md-sys-color-outline: #707973;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-ref-typeface-brand: 'Roboto', system-ui, sans-serif;
  --md-ref-typeface-plain: 'Roboto', system-ui, sans-serif;
  --sky-top: #87ceeb;
  --sky-bot: #cdeefa;
  --hill-far: #5a9e4a;
  --hill-mid: #6bb35a;
  --grass: #7cc576;
  --grass-dark: #4a8f3a;
  --dirt: #c9a26b;
  --egg-red: #e53935;
  --egg-yellow: #f9a825;
  --egg-blue: #1e88e5;
  --dino-fill: #4caf50;
  --dino-belly: #a5d6a7;
  --dino-spike: #2e7d32;
  --dino-ridge: #1b5e20;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --md-sys-color-primary: #75daa3;
    --md-sys-color-on-primary: #003822;
    --md-sys-color-primary-container: #005233;
    --md-sys-color-on-primary-container: #91f7be;
    --md-sys-color-secondary-container: #364b3d;
    --md-sys-color-on-secondary-container: #d0e8d6;
    --md-sys-color-surface: #111412;
    --md-sys-color-surface-container: #1d201e;
    --md-sys-color-on-surface: #e1e3de;
    --md-sys-color-on-surface-variant: #c0c9c1;
    --md-sys-color-outline: #8a938c;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-error-container: #93000a;
    --sky-top: #1a3344;
    --sky-bot: #2a4a5c;
    --hill-far: #2a5530;
    --hill-mid: #356b3c;
    --grass: #2f6b3a;
    --grass-dark: #1e4a28;
    --dirt: #6b5236;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-family: 'Roboto', system-ui, sans-serif; overflow-x: hidden;
  background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface);
  -webkit-tap-highlight-color: transparent;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  height: 100dvh; max-width: 1100px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

/* ---------- Screens ---------- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.screen.fight { justify-content: stretch; gap: 8px; display: grid; grid-template-rows: auto minmax(0, 1.15fr) minmax(0, 1fr); width: 100%; }

#eggScreen h1, .top-bar h1 {
  margin: 0; font-size: clamp(1.5rem, 5.5vw, 2.2rem); font-weight: 900; color: var(--md-sys-color-primary); text-align: center;
}
.subtitle { margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--md-sys-color-on-surface-variant); text-align: center; }

/* ---------- Eggs ---------- */
.eggs { display: flex; gap: clamp(10px, 4vw, 28px); justify-content: center; flex-wrap: wrap; width: 100%; max-width: 640px; }
.egg-btn {
  position: relative; flex: 1 1 100px; max-width: 180px; min-height: 140px;
  border: none; border-radius: 28px; cursor: pointer; padding: 16px 8px 12px;
  background: var(--md-sys-color-surface-container);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--md-sys-color-outline) 40%, transparent);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: transform .15s, box-shadow .15s;
}
.egg-btn:hover { transform: translateY(-4px) scale(1.04); }
.egg-btn:active { transform: translateY(3px); box-shadow: none; }
.egg-btn:focus-visible { outline: 4px solid var(--md-sys-color-primary); outline-offset: 3px; }
.egg-sprite { font-size: clamp(3.5rem, 12vw, 5.5rem); line-height: 1; position: relative; z-index: 1; filter: drop-shadow(0 4px 0 rgb(0 0 0 / .15)); }
.egg-sprite.big { font-size: clamp(5rem, 22vw, 8rem); }
.egg-tint {
  position: absolute; inset: 18% 22% 28%; border-radius: 50% 50% 45% 45%;
  mix-blend-mode: multiply; opacity: .55; pointer-events: none; z-index: 2;
}
.egg-tint.red, #hatchTint.red { background: var(--egg-red); }
.egg-tint.yellow, #hatchTint.yellow { background: var(--egg-yellow); }
.egg-tint.blue, #hatchTint.blue { background: var(--egg-blue); }
.egg-label { font-weight: 900; font-size: 1.1rem; z-index: 1; }

/* ---------- Hatch ---------- */
.hatch-stage { position: relative; width: min(90vw, 280px); height: min(40dvh, 280px); display: grid; place-items: center; }
.hatch-egg, .hatch-baby { grid-area: 1 / 1; display: grid; place-items: center; position: relative; }
.hatch-egg.shake { animation: egg-shake .5s ease-in-out 3; }
.hatch-egg.crack-open .egg-sprite { animation: egg-pop .4s ease-out forwards; }
.crack { position: absolute; font-size: 3rem; animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
.hatch-baby {
  width: clamp(140px, 36vw, 220px);
  height: clamp(120px, 30vw, 190px);
  animation: pop .6s cubic-bezier(.3, 1.6, .5, 1);
}
.hatch-baby .dino-svg { width: 100%; height: 100%; }
.hatch-msg { font-size: 1.25rem; font-weight: 700; text-align: center; margin: 0; }
@keyframes egg-shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-12deg) translateX(-4px); }
  75% { transform: rotate(12deg) translateX(4px); }
}
@keyframes egg-pop { to { transform: scale(0); opacity: 0; } }
@keyframes pop { from { transform: scale(0); } }

/* ---------- Arena (grassland) ---------- */
.arena {
  position: relative; border-radius: 18px; overflow: hidden; width: 100%;
  min-height: 0; height: 100%;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; padding: 6px 6px 10px; gap: 0;
}
.arena-bg {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
}
.arena-bg .sky {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 55%, var(--grass) 55%, var(--grass) 78%, var(--dirt) 78%);
}
.arena-bg .hills {
  position: absolute; left: 0; right: 0; bottom: 22%; height: 28%;
  width: 100%;
}
.arena-bg .sun-disk {
  position: absolute; top: 6%; right: 10%;
  width: clamp(28px, 6vw, 48px); height: clamp(28px, 6vw, 48px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff9c4, #ffeb3b 40%, #f9a825 80%);
  box-shadow: 0 0 24px rgb(255 235 59 / .55);
}
.arena-bg .cloud-shape {
  position: absolute; background: #fff; border-radius: 50px;
  opacity: .9; animation: drift 22s linear infinite;
  box-shadow: 18px 0 0 -2px #fff, 32px 4px 0 -6px #fff, 8px 8px 0 -4px #fff;
}
.cloud-shape.c1 { top: 10%; width: 36px; height: 16px; }
.cloud-shape.c2 { top: 28%; width: 28px; height: 12px; animation-delay: -11s; opacity: .75; }
@keyframes drift { from { left: 105%; } to { left: -15%; } }
.arena-bg .ground {
  position: absolute; left: 0; right: 0; bottom: 0; height: 22%;
  background: linear-gradient(180deg, var(--grass) 0%, var(--grass) 35%, var(--dirt) 35%);
}
.arena-bg .grass-tufts {
  position: absolute; left: 0; right: 0; bottom: 55%; height: 50%;
  width: 100%;
}

.fighter { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fighter.player { justify-self: start; }
.fighter.opponent { justify-self: end; }

/* Larger SVG dinos */
.dino-sprite {
  width: clamp(100px, min(42vw, 34dvh), 220px);
  height: clamp(110px, min(46vw, 38dvh), 240px);
  max-width: 46vw;
  display: block;
  animation: bob .55s ease-in-out infinite alternate;
  filter: drop-shadow(0 4px 2px rgb(0 0 0 / .28));
  line-height: 0;
}
.dino-sprite .dino-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.dino-sprite.face-left { transform: scaleX(-1); }

/* Colour tints via CSS vars on .dino-svg */
.dino-svg .dino-body { fill: var(--dino-fill); stroke: #222; stroke-width: 1.6; stroke-linejoin: round; }
.dino-svg .dino-belly { fill: var(--dino-belly); stroke: #222; stroke-width: 1.2; }
.dino-svg .dino-spike { fill: var(--dino-spike); stroke: #222; stroke-width: 1.2; stroke-linejoin: round; }
.dino-svg .dino-ridge { stroke: var(--dino-ridge); }
.dino-svg .dino-tooth { fill: #fff; }
.dino-svg .dino-eye-white { fill: #fff; stroke: #222; stroke-width: 1; }
.dino-svg .dino-eye { fill: #1a1a1a; }

.dino-svg.tint-red {
  --dino-fill: #e53935;
  --dino-belly: #ffcdd2;
  --dino-spike: #b71c1c;
  --dino-ridge: #7f0000;
}
.dino-svg.tint-yellow {
  --dino-fill: #f9a825;
  --dino-belly: #fff9c4;
  --dino-spike: #f57f17;
  --dino-ridge: #e65100;
}
.dino-svg.tint-blue {
  --dino-fill: #1e88e5;
  --dino-belly: #bbdefb;
  --dino-spike: #0d47a1;
  --dino-ridge: #01579b;
}
.dino-svg.tint-rival {
  --dino-fill: #8d6e63;
  --dino-belly: #d7ccc8;
  --dino-spike: #5d4037;
  --dino-ridge: #3e2723;
}
.dino-svg.tint-rival-alt {
  --dino-fill: #7e57c2;
  --dino-belly: #d1c4e9;
  --dino-spike: #4527a0;
  --dino-ridge: #311b92;
}
.dino-svg.tint-rival-green {
  --dino-fill: #66bb6a;
  --dino-belly: #c8e6c9;
  --dino-spike: #2e7d32;
  --dino-ridge: #1b5e20;
}

.fighter.player.punch .dino-sprite { animation: punch .45s ease-out; }
.fighter.opponent.punch .dino-sprite.face-left { animation: punch-opp .45s ease-out; }
.fighter.take-hit .dino-sprite { animation: take-hit .45s ease-out; }
.fighter.opponent.take-hit .dino-sprite.face-left { animation: take-hit-opp .45s ease-out; }
.fighter.take-hit { animation: shake .4s; }
@keyframes bob { to { translate: 0 -6px; } }
@keyframes punch {
  30% { translate: 32px -10px; }
  60% { translate: 42px 0; }
  100% { translate: 0 0; }
}
@keyframes punch-opp {
  30% { translate: -32px -10px; transform: scaleX(-1); }
  60% { translate: -42px 0; transform: scaleX(-1); }
  100% { translate: 0 0; transform: scaleX(-1); }
}
@keyframes take-hit {
  20% { translate: -12px 0; filter: brightness(1.35) drop-shadow(0 0 10px #ff5252); }
  50% { translate: 10px 0; }
  100% { translate: 0 0; }
}
@keyframes take-hit-opp {
  20% { translate: 12px 0; transform: scaleX(-1); filter: brightness(1.35) drop-shadow(0 0 10px #ff5252); }
  50% { translate: -10px 0; transform: scaleX(-1); }
  100% { translate: 0 0; transform: scaleX(-1); }
}
@keyframes shake { 25% { translate: -4px 0; } 50% { translate: 4px 0; } 75% { translate: -2px 0; } }

/* Comic POW / BAM / WHAM burst */
.pow-burst {
  position: absolute;
  left: 50%; top: 52%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 5;
  width: clamp(110px, 28dvh, 200px);
  height: clamp(110px, 28dvh, 200px);
  pointer-events: none;
  opacity: 0;
  display: grid; place-items: center;
}
.pow-burst .pow-shape {
  position: absolute; inset: 0; width: 100%; height: 100%;
  filter: drop-shadow(0 4px 0 #111);
}
.pow-burst .pow-text {
  position: relative; z-index: 1;
  font-family: 'Roboto', Impact, sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 5.5dvh, 3rem);
  letter-spacing: .04em;
  color: #fff;
  text-shadow:
    3px 3px 0 #111,
    -2px -2px 0 #111,
    2px -2px 0 #111,
    -2px 2px 0 #111,
    0 0 8px #ff6f00;
  transform: rotate(-12deg);
  line-height: 1;
}
.pow-burst.show {
  animation: pow-pop .7s cubic-bezier(.2, 1.5, .4, 1) forwards;
}
@keyframes pow-pop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.15) rotate(-20deg); }
  25%  { opacity: 1; transform: translate(-50%, -50%) scale(1.25) rotate(4deg); }
  45%  { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(-6deg); }
  70%  { opacity: 1; transform: translate(-50%, -55%) scale(1.1) rotate(2deg); }
  100% { opacity: 0; transform: translate(-50%, -65%) scale(1.35) rotate(-4deg); }
}

.vs {
  z-index: 3; font-weight: 900; font-size: clamp(.9rem, 3vw, 1.3rem);
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary);
  padding: 4px 10px; border-radius: 99px; align-self: center; margin-bottom: 28%;
  position: relative;
}

/* HP bars */
.hp-wrap { display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: clamp(90px, 28vw, 160px); }
.hp-name { font-size: .75rem; font-weight: 700; text-align: center; }
.hp-bar {
  height: 14px; border-radius: 99px; background: rgb(0 0 0 / .18);
  overflow: hidden; border: 2px solid rgb(0 0 0 / .15);
}
.hp-fill {
  height: 100%; width: 100%; border-radius: inherit;
  background: linear-gradient(90deg, #43a047, #81c784);
  transition: width .4s ease;
}
.hp-fill.opp { background: linear-gradient(90deg, #e53935, #ef9a9a); }
.hp-num { font-size: .7rem; font-weight: 700; text-align: center; }

/* ---------- Quiz ---------- */
.quiz {
  min-height: 0; width: 100%; display: grid;
  grid-template-rows: auto auto minmax(0, 1fr); gap: 4px; padding: 10px 12px;
  border-radius: 24px; background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.question { margin: 0; font-size: clamp(2rem, 6.5dvh, 3.6rem); font-weight: 900; letter-spacing: .02em; text-align: center; }
.feedback { margin: 0; min-height: 1.3em; font-size: 1rem; font-weight: 700; text-align: center; }
.feedback.bad { color: var(--md-sys-color-error); }
.feedback.good { color: var(--md-sys-color-primary); }
.choices {
  display: grid; grid-template-columns: repeat(2, 1fr); grid-auto-rows: minmax(56px, 1fr);
  gap: 10px; align-self: end; height: min(100%, 220px);
}
.bubble {
  position: relative; border: none; border-radius: 999px; cursor: pointer; min-height: 56px;
  font: 900 clamp(1.6rem, 5dvh, 2.6rem) 'Roboto', sans-serif;
  color: var(--md-sys-color-on-primary-container);
  background: radial-gradient(circle at 22% 25%, rgb(255 255 255 / .75) 0 7%, transparent 8%), var(--md-sys-color-primary-container);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--md-sys-color-primary) 60%, black);
  transition: transform .15s, opacity .3s;
}
.bubble:nth-child(2) { background-color: #ffe08a; color: #3d2e00; box-shadow: 0 5px 0 #b38b00; }
.bubble:nth-child(3) { background-color: #c7e4ff; color: #001d33; box-shadow: 0 5px 0 #4b7aa6; }
.bubble:nth-child(4) { background-color: #ffd8e8; color: #3b0021; box-shadow: 0 5px 0 #b35c86; }
.bubble .key { position: absolute; right: 14px; top: 6px; font-size: .75rem; font-weight: 700; opacity: .55; display: none; }
.bubble:hover:not(:disabled) { transform: translateY(-3px) scale(1.03); }
.bubble:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.bubble:focus-visible { outline: 4px solid var(--md-sys-color-primary); outline-offset: 3px; }
.bubble:disabled { opacity: .35; cursor: default; transform: scale(.88); text-decoration: line-through; }
.bubble.pop { animation: popb .5s ease-out forwards; }
@keyframes popb {
  50% { transform: scale(1.15); }
  100% { transform: scale(1.05); background-color: var(--md-sys-color-primary); color: #fff; }
}

/* ---------- End dialog ---------- */
dialog {
  border: none; border-radius: 28px; padding: 28px; text-align: center;
  max-width: min(92vw, 420px); background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.end-emoji { font-size: 4.5rem; animation: pop .6s cubic-bezier(.3, 1.6, .5, 1); }

/* Desktop */
@media (min-width: 900px) {
  .app { padding: 16px 24px; }
  .screen.fight { gap: 14px; grid-template-rows: auto minmax(0, 1.15fr) auto; }
  .arena { padding: 12px 24px 20px; }
  .dino-sprite {
    width: clamp(180px, 36dvh, 300px);
    height: clamp(200px, 42dvh, 340px);
    max-width: none;
  }
  .pow-burst {
    width: clamp(160px, 30dvh, 260px);
    height: clamp(160px, 30dvh, 260px);
  }
  .pow-burst .pow-text { font-size: clamp(2.2rem, 5dvh, 3.6rem); }
  .quiz {
    grid-template-columns: auto 1fr; grid-template-rows: auto auto;
    column-gap: 28px; padding: 16px 24px; align-items: center;
  }
  .question { grid-column: 1; grid-row: 1 / span 2; font-size: 3.8rem; align-self: center; }
  .feedback { grid-column: 2; grid-row: 1; text-align: left; }
  .choices {
    grid-column: 2; grid-row: 2; grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 100px; height: auto;
  }
  .bubble .key { display: block; }
  .eggs { gap: 32px; }
  .egg-btn { min-height: 180px; }
}
@media (hover: none) { .bubble .key { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .pow-burst.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
