@font-face {
  font-family: "Nunito";
  src: url("../fonts/nunito-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-600-latin.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f6f7f5;
  --fg: #1a1f1a;
  --accent: #3a8a3a;
  --accent-fg: #ffffff;
  --muted: #6a716a;
  --surface: #ffffff;
  --border: #d5dbd5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1410;
    --fg: #e8ede8;
    --accent: #62b862;
    --accent-fg: #0a0e0a;
    --muted: #8a918a;
    --surface: #1a201a;
    --border: #2a312a;
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Robust pointers (GAME_DESIGN.md Controls): no pans, pull-to-refresh,
     text selection or iOS long-press menu. */
  overscroll-behavior: none;
}

body {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}






button {
  font: inherit;
  cursor: pointer;
}

.btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-weight: 500;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}

.btn.icon {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}


/* ---- gameplay (milestone 1) ------------------------------------------- */

:root {
  --meadow: #5f9e45;
  --deep-grass: #2f6b34;
  --gold: #e7b84a;
  --buttercup: #f4d35e;
  --soil: #7a5a3a;
  --sky-cream: #fbf3df;
  --ink: #2b2a26;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;          /* still read by screen readers; never painted */
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.game-root {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  background: var(--sky-cream);
  color: var(--ink);
}
.game-root[hidden] { display: none; }

.game-canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hud {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  align-items: center;
  pointer-events: none;
  color: var(--ink);
}
.hud[hidden] { display: none; }
/* A paper panel behind the HUD so it always reads on the painting. */
.hud { isolation: isolate; }
.hud::before {
  content: "";
  position: absolute;
  inset: 6px;
  z-index: -1;
  border-radius: 16px;
  background: rgba(251, 243, 223, 0.9) url("../assets/textures/paper.jpg") center / 512px repeat;
  border: 2px solid rgba(43, 42, 38, 0.85);
  box-shadow: 0 4px 14px rgba(43, 42, 38, 0.18);
  pointer-events: none;
}
.hud.landscape {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 20px 18px;
  gap: 14px;
}
.hud > * { pointer-events: auto; }
.hud.landscape .hud-main { flex: none; }
.hud-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.hud-meter-row { display: flex; align-items: center; gap: 6px; }
.hud-meter-row .hud-meter { flex: 1; min-width: 0; }
.hud-flower { position: relative; width: 34px; height: 34px; flex: none; }
.hud-flower img { position: absolute; display: block; pointer-events: none; }
.hud-flower .centre { width: 14px; height: 14px; left: 10px; top: 10px; z-index: 1; }
.hud-flower .petal {
  width: 14px; height: 15px; left: 10px; top: 2px;
  transform-origin: 50% 100%;
  transform: rotate(var(--a)) scale(0.25);
  opacity: 0.55;
  filter: saturate(0.4);
  transition: transform 450ms cubic-bezier(.3,1.6,.5,1), opacity 300ms ease, filter 300ms ease;
}
.hud-flower .p0 { --a: 0deg; } .hud-flower .p1 { --a: 90deg; } .hud-flower .p2 { --a: 180deg; } .hud-flower .p3 { --a: 270deg; }
.hud-flower[data-open="1"] .p0, .hud-flower[data-open="2"] .p0, .hud-flower[data-open="2"] .p1,
.hud-flower[data-open="3"] .p0, .hud-flower[data-open="3"] .p1, .hud-flower[data-open="3"] .p2,
.hud-flower[data-open="4"] .petal { transform: rotate(var(--a)) scale(1); opacity: 1; filter: none; }
html.reduce-motion .hud-flower .petal { transition: none; }
.hud-buttons { display: flex; gap: 8px; }
.hud.landscape .hud-buttons { align-self: flex-start; }
.hud .btn.icon img { width: 30px; height: 30px; display: block; pointer-events: none; }
.hud-mute .icon-off { display: none !important; }
.hud-mute.muted .icon-on { display: none !important; }
.hud-mute.muted .icon-off { display: block !important; }
.hud-name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 17px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}
.hud.landscape .hud-name { white-space: normal; font-size: 16px; text-wrap: balance; }
/* A phone on its side: a tighter panel, so the name fits on one line and the
   meter runs the column's width. */
@media (max-height: 500px) {
  .hud.landscape { padding: 16px 14px; gap: 10px; }
  .hud.landscape .hud-name { font-size: 15px; }
}
.hud-meter {
  --pulse: 0;
  position: relative;
  height: 20px;
  border-radius: 10px;
  background: rgba(43, 42, 38, 0.18);
  box-shadow: inset 0 0 0 2px var(--ink), 0 0 calc(var(--pulse) * 12px) rgba(255, 214, 110, 0.9);
  overflow: hidden;
}
.hud-meter-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #d9a636, var(--gold) 60%, var(--buttercup));
  transition: transform 120ms linear;
}
.hud-meter-line {
  position: absolute;
  right: 0;
  top: -2px;
  bottom: -2px;
  width: 4px;
  background: var(--ink);
}
.hud-meter-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9);
}
.hud-leaf {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 48px;
  font-size: 12px;
  font-weight: 700;
}
.hud.portrait .hud-leaf { flex-direction: column; gap: 0; }
.hud.portrait { padding-top: 15px; padding-bottom: 10px; }
.hud-leaf svg { width: 36px; height: 36px; display: block; }
.hud-leaf .leaf-track { fill: rgba(251, 243, 223, 0.8); stroke: rgba(43, 42, 38, 0.25); stroke-width: 4; }
.hud-leaf .leaf-ring {
  fill: none;
  stroke: var(--meadow);
  stroke-width: 4;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 20px 20px;
  transition: stroke-dashoffset 200ms linear;
}
.hud-leaf .leaf-shape { fill: var(--meadow); stroke: var(--ink); stroke-width: 1.4; }
.hud-leaf.done .leaf-ring { stroke: var(--gold); }
.hud-leaf.done .leaf-shape { fill: var(--gold); }
.hud-leaf-text { white-space: nowrap; }
.hud-pause, .hud-mute {
  background: rgba(251, 243, 223, 0.92);
  border: 2px solid var(--ink);
  color: var(--ink);
  transition: transform 90ms ease;
}
.hud-pause:active, .hud-mute:active, .card .btn:active { transform: scale(0.94); }

.hud-toast {
  position: absolute;
  transform: translate(-50%, -8px);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(251, 243, 223, 0.95);
  border: 2px solid var(--ink);
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease, transform 250ms ease;
  white-space: nowrap;
}
.hud-toast.show { opacity: 1; transform: translate(-50%, 0); }

.card-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  /* Dim the field clearly so the card stands out on bright grass. */
  background: rgba(30, 32, 24, 0.56);
  z-index: 5;
}
.card-layer[hidden] { display: none; }
.card {
  width: min(360px, 100%);
  max-height: 100%;
  overflow: auto;
  box-sizing: border-box;
  padding: 22px 22px 20px;
  border-radius: 18px;
  background: var(--sky-cream) url("../assets/textures/paper.jpg") center / 512px repeat;
  border: 2px solid var(--ink);
  box-shadow: 0 10px 30px rgba(43, 42, 38, 0.3);
  text-align: center;
  color: var(--ink);
  animation: card-in 220ms ease-out;
}
@keyframes card-in { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }
html.reduce-motion .card { animation: none; }
.card-kicker { margin: 0; font-size: 13px; font-weight: 700; color: var(--deep-grass); text-transform: uppercase; letter-spacing: 0.06em; }
.card-title { margin: 4px 0 2px; font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 26px; line-height: 1.2; text-wrap: balance; }
.card-sub { margin: 0 0 14px; color: #5a5548; text-wrap: balance; }
.card-stats { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 14px; text-align: left; }
.card-stats dt { font-weight: 700; }
.card-stats dd { margin: 0; }
.card-headstart {
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(231, 184, 74, 0.3);
  font-weight: 700;
  text-wrap: balance;
}
.card-actions { display: flex; flex-direction: column; gap: 10px; }
.card .btn { border: 2px solid var(--ink); background: #fff; color: var(--ink); }
.card .btn.primary { background: var(--deep-grass); border-color: var(--ink); color: #fff; }


/* ---- milestone 3: toolbar, warnings, ribbon, hint cards ------------------ */

.toolbar {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
  z-index: 2;
}
.toolbar[hidden] { display: none; }
.toolbar.landscape { flex-direction: column; }
.move-btn {
  pointer-events: auto;
  position: relative;
  width: 64px;
  height: 64px;
  padding: 2px 0 0;
  border-radius: 16px;
  border: 2px solid var(--ink);
  background: rgba(251, 243, 223, 0.95) url("../assets/textures/paper.jpg") center / 256px;
  box-shadow: 0 3px 10px rgba(43, 42, 38, 0.22);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  transition: transform 90ms ease, opacity 200ms ease, filter 200ms ease;
}
.move-btn[hidden] { display: none; }
.move-btn img { width: 40px; height: 40px; display: block; pointer-events: none; }
.move-price {
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  margin-top: 1px;
  white-space: nowrap;
  pointer-events: none;
}
/* "needs 37%" on a greyed-out button: one line inside the 64 px button. */
.move-btn.disabled .move-price { font-size: 10px; letter-spacing: -0.2px; }
.move-key {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 9px;
  border: 1.5px solid var(--ink);
  background: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 15px;
  text-align: center;
  pointer-events: none;
}
@media (pointer: coarse) { .move-key { display: none; } }
.move-btn:active { transform: scale(0.94); }
.move-btn.disabled { filter: grayscale(0.9); opacity: 0.55; box-shadow: none; }
.move-btn.armed {
  background: #fff4c9;
  border-color: #8a5a00;
  animation: move-pulse 900ms ease-in-out infinite;
}
@keyframes move-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 184, 74, 0.9), 0 3px 10px rgba(43, 42, 38, 0.22); transform: scale(1); }
  50% { box-shadow: 0 0 0 7px rgba(231, 184, 74, 0.25), 0 3px 10px rgba(43, 42, 38, 0.22); transform: scale(1.06); }
}
html.reduce-motion .move-btn.armed { animation: none; box-shadow: 0 0 0 4px rgba(231, 184, 74, 0.8); }

/* An angry biter: the meter's edge glows red on the side nearest the bug. */
.hud-meter.warn[data-warn-side="left"] {
  box-shadow: inset 0 0 0 2px var(--ink), -8px 0 14px -2px rgba(220, 50, 35, 0.85);
}
.hud-meter.warn[data-warn-side="right"] {
  box-shadow: inset 0 0 0 2px var(--ink), 8px 0 14px -2px rgba(220, 50, 35, 0.85);
}
.hud-meter.warn { animation: warn-glow 600ms ease-in-out infinite alternate; }
@keyframes warn-glow { from { filter: none; } to { filter: drop-shadow(0 0 4px rgba(220, 50, 35, 0.7)); } }
.hud-meter.shake { animation: meter-shake 360ms ease; }
@keyframes meter-shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -5px 0; }
  40% { translate: 5px 0; }
  60% { translate: -3px 0; }
  80% { translate: 3px 0; }
}
html.reduce-motion .hud-meter.warn, html.reduce-motion .hud-meter.shake { animation: none; }
/* A bite: the meter flashes red for a moment (a colour change: kept with reduced motion). */
.hud-meter::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(214, 48, 34, 0.6);
  opacity: 0;
  transition: opacity 450ms ease-out;
  pointer-events: none;
}
.hud-meter.bit::after { opacity: 1; transition: none; }
html.reduce-motion .hud-meter::after { transition: none; }

/* "New friend!" ribbon (drawn in code: a banner with folded tails). */
.ribbon {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 26px 6px 12px;
  transform: translate(-50%, -12px) scale(0.9);
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(#e8657e, #c94a63);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(43, 42, 38, 0.3);
  transition: opacity 260ms ease, transform 320ms cubic-bezier(.3, 1.5, .5, 1);
  white-space: nowrap;
}
.ribbon::before, .ribbon::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 22px;
  height: 100%;
  background: #a63a50;
  border: 2px solid var(--ink);
  z-index: -1;
}
.ribbon::before { left: -16px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 40% 50%); }
.ribbon::after { right: -16px; clip-path: polygon(0 0, 100% 0, 60% 50%, 100% 100%, 0 100%); }
.ribbon.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.ribbon img {
  width: 44px;
  height: 44px;
  margin: -10px 0;
  border-radius: 50%;
  background: rgba(251, 243, 223, 0.95);
  border: 2px solid var(--ink);
  padding: 2px;
}
.ribbon-text { display: flex; flex-direction: column; line-height: 1.1; }
.ribbon-text b { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 18px; text-shadow: 0 1px 0 rgba(43, 42, 38, 0.4); }
.ribbon-text span { font-size: 13px; font-weight: 700; }
html.reduce-motion .ribbon { transition: opacity 120ms linear; }

/* Hint cards: built from in-game art. */
.card-hint { width: min(380px, 100%); animation: hint-in 320ms cubic-bezier(.3, 1.3, .5, 1); }
@keyframes hint-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
html.reduce-motion .card-hint { animation: none; }
/* Phone portrait: the field sits in the middle of the screen, so a hint card
   sits low, leaving the middle of the field (field 2's mown stripe) and the
   HUD in view. */
@media (orientation: portrait) and (max-width: 600px) {
  .card-layer[data-kind="hint"] { align-items: flex-end; }
}
.hint-art {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  min-height: 92px;
  margin: 0 auto 8px;
  padding: 10px 14px 8px;
  border-radius: 14px;
  background: radial-gradient(ellipse at 50% 85%, rgba(122, 90, 58, 0.35), rgba(122, 90, 58, 0.08) 70%, transparent 72%);
}
.hint-art img { display: block; }
.ha-tuft { width: 72px; height: 72px; margin: 0 -8px; }
.ha-tuft-flat { width: 64px; height: 64px; }
.ha-bug { position: relative; display: block; width: 76px; height: 76px; }
.ha-bug img { width: 76px; height: 76px; filter: drop-shadow(2px 5px 2px rgba(43, 42, 38, 0.25)); }
.ha-bug.angry::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3.5px solid rgba(200, 40, 30, 0.8);
  background: rgba(230, 60, 40, 0.12);
  animation: ha-warn 900ms ease-in-out infinite;
}
.ha-bug.angry img { filter: drop-shadow(2px 5px 2px rgba(43, 42, 38, 0.25)) sepia(0.4) saturate(2.2) hue-rotate(-25deg); }
@keyframes ha-warn { 0%, 100% { transform: scale(1); opacity: 0.9; } 50% { transform: scale(1.06); opacity: 0.6; } }
.ha-move { width: 64px; height: 64px; padding: 4px; border-radius: 16px; border: 2px solid var(--ink); background: #fff4c9; box-sizing: border-box; align-self: center; }
.ha-arrow { align-self: center; width: 26px; height: 18px; position: relative; }
.ha-arrow::before { content: ""; position: absolute; left: 0; top: 7px; width: 18px; height: 4px; background: var(--ink); border-radius: 2px; }
.ha-arrow::after { content: ""; position: absolute; right: 0; top: 2px; border: 7px solid transparent; border-left: 10px solid var(--ink); border-right: 0; }
.ha-leaf svg { width: 52px; height: 52px; display: block; }
.ha-swatch { position: relative; display: flex; align-items: flex-end; height: 70px; padding: 0 6px; }
.ha-swatch-tuft { width: 46px; height: 46px; margin: 0 -9px; }
.ha-hand {
  position: absolute;
  width: 62px;
  height: 62px;
  left: 0;
  top: -6px;
  animation: ha-glide 2.6s ease-in-out infinite;
  filter: drop-shadow(2px 4px 2px rgba(43, 42, 38, 0.25));
}
@keyframes ha-glide {
  0% { transform: translateX(-6px); opacity: 0; }
  15% { opacity: 1; }
  70% { transform: translateX(150px); opacity: 1; }
  85%, 100% { transform: translateX(150px); opacity: 0; }
}
html.reduce-motion .ha-hand { animation: none; transform: translateX(70px); }
html.reduce-motion .ha-bug.angry::before { animation: none; }
.hint-text { font-size: 15px; line-height: 1.4; }
.card-foot { margin: 10px 0 0; font-size: 12px; color: #6a6457; }

.card-howto { width: min(440px, 100%); text-align: left; display: flex; flex-direction: column; }
/* The list pages to fit; if even one entry is too tall (a very short
   screen), it scrolls inside the card so the buttons stay on screen. */
.card-howto .howto-list { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
.card-howto > :not(.howto-list) { flex: none; }
@media (min-width: 760px) and (min-height: 521px) {
  .card-howto { width: min(820px, 100%); }
  .howto-list { display: grid !important; grid-template-columns: 1fr 1fr; gap: 12px 18px !important; }
  .howto-list.single { grid-template-columns: 1fr; }
}
.howto-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 0 0 12px; }
.howto-pager[hidden] { display: none; }
.howto-pager .btn { min-height: 44px; padding: 0 16px; }
.howto-pager .btn:disabled { opacity: 0.4; cursor: default; }
.howto-page { font-weight: 700; font-size: 14px; min-width: 56px; text-align: center; }
.card-howto .card-title { text-align: center; }
.howto-list { list-style: none; margin: 8px 0 14px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.howto-item { display: flex; align-items: center; gap: 10px; }
.howto-item .hint-art { flex: none; width: 112px; min-height: 0; margin: 0; padding: 4px; gap: 0; transform-origin: center; }
.howto-item .hint-art > * { transform: scale(0.62); margin: -14px -12px; }
.howto-item .ha-swatch { margin: -14px -40px; }
.howto-text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; line-height: 1.3; text-wrap: pretty; }
.howto-text span { text-wrap: pretty; }
.howto-text strong { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 16px; text-wrap: balance; }

/* ---- milestone 4: the screens ---------------------------------------------- */

:root { color-scheme: light dark; }
/* The painting looks the same in both modes; only what's around it changes
   (the page behind, the loading screen, theme-color, system controls). */
html { background: var(--bg); }

button:focus-visible, a.btn:focus-visible, input:focus-visible, .map-token:focus-visible, .garden-friend:focus-visible {
  outline: 3px solid #e7b84a;
  outline-offset: 3px;
}

#app {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
.screen {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: auto;
  opacity: 1;
  transition: opacity var(--fade, 300ms) ease;
  color: var(--ink);
}
.screen.entering { opacity: 0; }
.screen.leaving { pointer-events: none; }
.screen.fading-out { opacity: 0; }
.screen > div { position: absolute; inset: 0; }

/* Buttons on the painted screens and cards: paper and ink. */
.screen .btn, .modal-card .btn, .card .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid var(--ink);
  background: rgba(251, 243, 223, 0.96);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  box-sizing: border-box;
  transition: transform 90ms ease, background-color 150ms ease;
}
.screen .btn:active, .modal-card .btn:active { transform: scale(0.95); }
.screen .btn.primary, .modal-card .btn.primary, .card .btn.primary { background: var(--deep-grass); color: #fff; }
.screen .btn.icon { padding: 0; width: 52px; height: 52px; border-radius: 16px; }
.btn-icon { width: 26px; height: 26px; display: block; pointer-events: none; }
.btn.icon .btn-icon { width: 34px; height: 34px; }
.btn-label { pointer-events: none; }
.btn-danger { background: #fff1ee !important; color: #8a2a1c !important; border-color: #8a2a1c !important; }
.mute-btn .icon-on, .mute-btn .icon-off { width: 34px; height: 34px; display: block; pointer-events: none; }
.mute-btn .icon-off { display: none; }
.mute-btn.muted .icon-on { display: none; }
.mute-btn.muted .icon-off { display: block; }
@media (hover: hover) {
  .screen .btn:hover, .modal-card .btn:hover { background-color: #fff8e6; }
  .screen .btn.primary:hover, .modal-card .btn.primary:hover, .card .btn.primary:hover { background-color: #3a7c3f; }
}

/* ---- title ---- */
.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: max(7vh, env(safe-area-inset-top)) 20px max(20vh, calc(env(safe-area-inset-bottom) + 120px));
  background: #e9eccf;
  text-align: center;
}
@media (orientation: portrait) {
  .title-screen { padding-top: max(11vh, env(safe-area-inset-top)); }
}
.title-toy { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.scene-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; pointer-events: none; user-select: none; }
.challenge-card, .challenge-screen .title-top { position: relative; z-index: 1; }
.title-top, .title-actions, .title-corner { position: relative; z-index: 1; }
.title-logo {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(3rem, min(13vw, 15vh), 6.2rem);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-shadow: 0 3px 0 rgba(251, 243, 223, 0.95), 0 0 24px rgba(251, 243, 223, 0.9);
  white-space: nowrap;
}
.title-screen .best {
  margin: 10px 0 0;
  font-weight: 800;
  font-size: 1.05rem;
  color: #3d3a31;
  text-shadow: 0 0 10px rgba(251, 243, 223, 1), 0 0 4px rgba(251, 243, 223, 1);
}
.title-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: min(340px, 100%);
}
.btn-play {
  flex-direction: column;
  gap: 0 !important;
  min-height: 72px;
  border-radius: 20px !important;
  font-size: 1.5rem;
  box-shadow: 0 6px 18px rgba(43, 42, 38, 0.25);
}
.btn-sub { font-size: 0.85rem; font-weight: 700; opacity: 0.92; pointer-events: none; }
.title-row { display: flex; gap: 12px; }
.title-row .btn { flex: 1; min-height: 54px; border-radius: 16px; font-size: 1.02rem; padding: 0 10px; box-shadow: 0 4px 12px rgba(43, 42, 38, 0.18); }
.title-corner {
  position: absolute !important;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  gap: 10px;
}
@media (orientation: landscape) and (max-height: 500px) {
  .title-screen { padding-top: max(5vh, env(safe-area-inset-top)); padding-bottom: max(70px, env(safe-area-inset-bottom)); justify-content: flex-start; gap: 4vh; }
  .title-logo { font-size: clamp(2.6rem, 15vh, 4rem); }
  .title-actions { width: min(420px, 100%); }
  .btn-play { min-height: 60px; }
}

/* ---- the top bar of the map, garden and settings ---- */
.screen-bar {
  position: absolute !important;
  inset: 0 0 auto 0 !important;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  margin-top: env(safe-area-inset-top);
  box-sizing: border-box;
  pointer-events: none;
}
.screen-bar > * { pointer-events: auto; }
.screen-bar .btn-back { min-height: 48px; padding: 0 16px 0 10px; border-radius: 14px; }
.back-chev { display: inline-flex; }
.screen-title {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 26px;
  line-height: 1.1;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(251, 243, 223, 0.9), 0 0 14px rgba(251, 243, 223, 0.95);
}
.bar-heading { display: flex; flex-direction: column; min-width: 0; }
/* A paper tab behind the heading, so it reads on any painting. */
.screen-bar > .screen-title, .bar-heading {
  padding: 4px 14px 5px;
  border-radius: 14px;
  background: rgba(251, 243, 223, 0.88);
  border: 2px solid rgba(43, 42, 38, 0.85);
  box-shadow: 0 3px 10px rgba(43, 42, 38, 0.15);
}
.bar-heading .screen-title { text-shadow: none; }
.screen-bar > .screen-title { text-shadow: none; }
.screen-sub { margin: 0; font-size: 13px; font-weight: 800; color: #3d3a31; text-shadow: 0 0 6px rgba(251, 243, 223, 1); white-space: nowrap; }
.bar-right { margin-left: auto; display: flex; gap: 10px; }
.screen-bar .btn.icon { width: 48px; height: 48px; border-radius: 14px; }
@media (max-width: 420px) { .screen-title { font-size: 22px; } }

/* ---- the meadow map ---- */
.map-screen { background: #dfe8c6 url("../assets/scenes/map-16x9.jpg") center / cover no-repeat; }
.map-screen.portrait { background-image: url("../assets/scenes/map-9x16.jpg"); }
.map-path { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.map-path path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.path-edge { stroke: rgba(122, 90, 58, 0.32); }
.path-sand { stroke: rgba(246, 230, 190, 0.92); }
.path-walked { stroke: rgba(214, 160, 50, 0.85); stroke-dasharray: 2 14; }
.map-tokens { position: absolute; inset: 0; }
.map-token {
  position: absolute;
  width: var(--tok);
  height: var(--tok);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  transition: transform 120ms ease;
}
.map-screen .map-token { width: var(--tok); height: var(--tok); }
.map-token:active { transform: scale(0.94); }
.token-art { width: 100%; height: 100%; display: block; border-radius: 50%; pointer-events: none; }
.token-num {
  position: absolute;
  left: -4px;
  top: -4px;
  min-width: 26px;
  height: 26px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 13px;
  border: 2px solid var(--ink);
  background: var(--sky-cream);
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 15px;
  line-height: 22px;
  text-align: center;
  pointer-events: none;
}
.token-best {
  position: absolute;
  left: 50%;
  top: calc(100% + 2px);
  transform: translateX(-50%);
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(251, 243, 223, 0.95);
  border: 1.5px solid var(--ink);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
.token-leaf {
  position: absolute; right: -6px; top: -6px; width: 30px; height: 30px; box-sizing: border-box; padding: 3px;
  border-radius: 50%; background: var(--sky-cream); border: 2px solid var(--ink); pointer-events: none;
}
.token-leaf svg { width: 100%; height: 100%; display: block; }
.map-token.locked .token-art { filter: grayscale(1) brightness(1.08) contrast(0.85); opacity: 0.72; }
.map-token.locked .token-num { background: #e6e2d6; color: #6a6457; border-color: #6a6457; }
.map-token.open { box-shadow: 0 0 0 3px rgba(255, 246, 214, 0.95), 0 0 20px 8px rgba(255, 226, 140, 0.75); animation: token-glow 2.2s ease-in-out infinite; }
.map-token.done { box-shadow: 0 0 0 3px #fbf3df, 0 0 0 6px rgba(214, 160, 50, 0.95), 0 4px 14px rgba(43, 42, 38, 0.3); }
.map-token.next { animation-duration: 1.5s; }
@keyframes token-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 246, 214, 0.95), 0 0 14px 4px rgba(255, 226, 140, 0.6); }
  50% { box-shadow: 0 0 0 4px rgba(255, 246, 214, 1), 0 0 26px 12px rgba(255, 226, 140, 0.9); }
}
.map-token.nudge { animation: token-nudge 360ms ease; }
@keyframes token-nudge { 0%, 100% { translate: 0 0; } 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
html.reduce-motion .map-token.open { animation: none; box-shadow: 0 0 0 4px rgba(255, 246, 214, 1), 0 0 22px 9px rgba(255, 226, 140, 0.85); }
html.reduce-motion .map-token.nudge { animation: none; }

/* ---- the Bug Garden ---- */
.garden-screen { background: #e4ecc8 url("../assets/scenes/garden-16x9.jpg") center / cover no-repeat; }
@media (orientation: portrait) { .garden-screen { background-image: url("../assets/scenes/garden-9x16.jpg"); } }
.garden-jar { position: absolute; inset: 0; }
.garden-friend {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--friend);
  height: var(--friend);
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 50%;
  will-change: transform;
}
.friend-art { width: 100%; height: 100%; display: block; pointer-events: none; filter: drop-shadow(2px 5px 2px rgba(43, 42, 38, 0.28)); }
.garden-friend.unmet { width: calc(var(--friend) * 1.25); height: calc(var(--friend) * 1.25); }
.garden-friend.unmet .friend-art { filter: brightness(0) blur(0.3px); opacity: 0.4; }
.friend-tag[hidden] { display: none; }
.friend-tag {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5000;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(251, 243, 223, 0.88);
  border: 1.5px solid rgba(43, 42, 38, 0.5);
  color: #5a5548;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
.friend-pic {
  width: 96px;
  height: 96px;
  margin: 0 auto 6px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: radial-gradient(circle at 50% 60%, #f3ead0, #e4d7b0);
  display: flex;
  align-items: center;
  justify-content: center;
}
.friend-pic img { width: 80px; height: 80px; }
.friend-pic.unmet img { filter: brightness(0); opacity: 0.3; }
.friend-note { margin: 0 0 12px; font-size: 15px; text-wrap: balance; }
.hearts { display: flex; justify-content: center; gap: 8px; margin: 0 0 12px; }
.hearts .heart svg { width: 30px; height: 30px; display: block; }
.hearts .heart path { fill: #efe2d8; stroke: var(--ink); stroke-width: 1.6; }
.hearts .heart.on path { fill: #e8657e; }

/* ---- settings ---- */
.settings-screen { background: #f3ecd6 url("../assets/scenes/title-16x9.jpg") center / cover no-repeat; }
@media (orientation: portrait) { .settings-screen { background-image: url("../assets/scenes/title-9x16.jpg"); } }
.settings-screen::before { content: ""; position: absolute; inset: 0; background: rgba(251, 243, 223, 0.55); }
.settings-panel {
  position: absolute !important;
  inset: auto !important;
  left: 50% !important;
  top: calc(env(safe-area-inset-top) + 72px) !important;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px)) !important;
  max-height: calc(100% - 84px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  text-align: left;
  padding: 8px 20px 16px !important;
  animation: none !important;
}
.set-group { padding: 10px 0; border-bottom: 1.5px solid rgba(43, 42, 38, 0.15); }
.set-group:last-child { border-bottom: none; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 52px; }
.set-text { min-width: 0; flex: 1 1 auto; }
.set-label { font-weight: 800; font-size: 16px; }
.set-note { margin: 2px 0 0; font-size: 13px; color: #5a5548; line-height: 1.3; text-wrap: pretty; }
.set-control { flex: none; display: flex; align-items: center; gap: 8px; }
.slider-wrap { width: min(220px, 48vw); }
.set-slider { flex: 1; min-width: 0; height: 32px; accent-color: var(--deep-grass); }
.set-value { width: 3.2em; text-align: right; font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.switch {
  position: relative;
  width: 56px;
  height: 32px;
  padding: 0;
  border-radius: 16px;
  border: 2px solid var(--ink);
  background: #e6e0cf;
  transition: background-color 150ms ease;
}
.switch-knob { position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); box-sizing: border-box; transition: transform 150ms ease; }
.switch.on { background: var(--meadow); }
.switch.on .switch-knob { transform: translateX(24px); }
.segmented { display: flex; border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; }
.seg { min-width: 54px; min-height: 44px; padding: 0 10px; border: none; border-left: 2px solid var(--ink); background: #fff; color: var(--ink); font-weight: 800; }
.seg:first-child { border-left: none; }
.seg[aria-checked="true"] { background: var(--deep-grass); color: #fff; }
.set-name {
  width: min(190px, 44vw);
  min-height: 44px;
  box-sizing: border-box;
  padding: 0 12px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
.set-more { display: flex; flex-direction: column; gap: 10px; }
.set-more .btn { min-height: 48px; border-radius: 14px; }
/* "Keys" heads its list: no paragraph margins (they left a big gap under it). */
.set-more > .set-label { margin: 2px 0 -6px; }
/* Rows with a note can wrap to three lines on a phone: keep them apart. */
.set-play .set-row + .set-row { margin-top: 8px; }
.set-keys { margin: 0; padding: 0 0 0 18px; font-size: 14px; color: #3d3a31; line-height: 1.6; }
.set-credits p { margin: 2px 0; font-size: 13px; color: #5a5548; text-wrap: pretty; }
.set-credits .credit-main { font-weight: 800; color: var(--ink); font-size: 14px; }
html.reduce-motion .switch, html.reduce-motion .switch-knob { transition: none; }
/* A phone on its side: two columns, so it all fits without scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  .settings-panel {
    width: min(860px, calc(100% - 24px)) !important;
    top: calc(env(safe-area-inset-top) + 64px) !important;
    max-height: calc(100% - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "sound credits" "play credits" "play more";
    column-gap: 26px;
    padding: 4px 18px 8px !important;
  }
  .set-sound { grid-area: sound; }
  .set-play { grid-area: play; border-bottom: none; }
  .set-more { grid-area: more; align-self: end; border-bottom: none; }
  .set-credits { grid-area: credits; align-self: start; border-bottom: 1.5px solid rgba(43, 42, 38, 0.15); }
  /* Clear data last and quiet: a small outlined button at the bottom. */
  .set-more .btn-danger { align-self: flex-end; min-height: 40px; padding: 0 18px; font-size: 14px; background: transparent !important; border-width: 1.5px !important; }
  .set-group { padding: 6px 0; }
  .set-row { min-height: 46px; }
  .settings-panel .slider-wrap { width: min(200px, 24vw); }
  .settings-panel .set-name { width: min(170px, 20vw); }
}

/* ---- modal cards and the toast ---- */
.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  background: rgba(30, 32, 24, 0.56);
  color: var(--ink);
}
.modal-layer[hidden] { display: none; }
html.modal-open .card-layer > .card { visibility: hidden; }
.modal-card .set-name { width: 100%; margin: 0 0 14px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 70;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: rgba(251, 243, 223, 0.97);
  color: var(--ink);
  font-weight: 800;
  font-size: 15px;
  text-align: center;
  text-wrap: balance;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
html.reduce-motion .toast { transition: none; }
.download-card { width: min(420px, 100%); }
@media (max-height: 520px) {
  .download-card { width: min(660px, 100%); display: grid; grid-template-columns: 1.1fr 1fr; grid-template-areas: "h h" "pic side"; column-gap: 18px; align-items: center; }
  .download-card > .card-title { grid-area: h; }
  .download-card .dl-pic { grid-area: pic; }
  .download-card .dl-side { grid-area: side; }
  .download-card .download-preview { margin: 0; }
  .download-card .card-sub { margin-bottom: 8px; }
  .download-card .download-link-row { margin-bottom: 10px; }
}
.download-preview { width: 100%; height: auto; border-radius: 10px; border: 2px solid var(--ink); margin: 4px 0 10px; display: block; }
.download-link-row { display: flex; gap: 8px; margin: 0 0 14px; }
.download-link-row .btn { flex: none; min-height: 44px; padding: 0 16px; border-radius: 10px; }
.download-card .download-link-row .download-link { margin: 0; flex: 1 1 auto; min-width: 0; }
.download-link { width: 100%; min-height: 44px; box-sizing: border-box; margin: 0 0 14px; padding: 0 10px; border-radius: 10px; border: 2px solid var(--ink); font: inherit; font-size: 14px; -webkit-user-select: text; user-select: text; }
.card a.btn { text-decoration: none; min-height: 48px; border-radius: 12px; }

/* ---- cards over the field (milestone 4 additions) ---- */
.card .btn { min-height: 48px; }
.card-pair { display: flex; gap: 10px; }
.card-pair .btn { flex: 1; }
.card-score { display: flex; flex-direction: column; align-items: center; margin: 4px 0 10px; }
.card-score-label { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--deep-grass); }
.card-score-num { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 46px; line-height: 1.05; }
.card-newbest { margin-top: 2px; padding: 2px 10px; border-radius: 999px; background: #e7b84a; font-weight: 800; font-size: 13px; }
.card-compare { margin: 0 0 12px; padding: 8px 10px; border-radius: 10px; background: rgba(95, 158, 69, 0.18); font-weight: 800; text-wrap: balance; }
.card-compare.won { background: rgba(231, 184, 74, 0.35); }
.card-complete { width: min(380px, 100%); }
.checklist { margin: 6px 0 16px; padding: 0 0 0 20px; text-align: left; line-height: 1.4; font-size: 15px; }
.checklist li { margin: 0 0 6px; text-wrap: pretty; }
@media (max-height: 520px) {
  /* Short screens (a phone on its side): the long cards go two-wide. */
  .card-pause { width: min(520px, 100%); }
  .card-pause .card-title { margin-top: 0; }
  .card-pause .card-sub { margin-bottom: 10px; }
  .card-pause .card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .card-pause .card-actions > .primary, .card-pause .card-actions > .span-row { grid-column: 1 / -1; }
  .card-pause .card-pair { display: contents; }
  .card-complete { display: grid; grid-template-columns: 1fr 1.2fr; column-gap: 22px; align-items: center; }
  .card-complete .card-title { font-size: 22px; }
  .card-complete .card-stats { margin-bottom: 8px; }
  .card-complete .card-headstart { margin-bottom: 8px; padding: 6px 8px; font-size: 14px; }
  .card-complete .card-compare { margin-bottom: 0; }
  .card-checklist { width: min(760px, 100%); }
  .card-checklist .card-title { margin-bottom: 4px; }
  .card-checklist .checklist { columns: 2; column-gap: 28px; font-size: 14px; margin-bottom: 10px; }
  .card-checklist .checklist li { break-inside: avoid; margin-bottom: 4px; }
  /* How to play on a short screen: small pictures, two columns, and the pager
     beside Back on one row, so a page holds more. */
  /* (How to play is opened from the pause card: it may cover the dimmed HUD
     and toolbar, so its columns have room.) */
  .card-layer[data-kind="howto"] { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .card-howto { width: min(820px, 100%); display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto minmax(0, 1fr) auto; column-gap: 12px; }
  .card-howto .card-title { grid-column: 1 / -1; font-size: 22px; margin: 0; }
  .card-howto .howto-list { grid-column: 1 / -1; }
  .card-howto .howto-pager { margin: 0; }
  .card-howto .howto-pager[hidden] + .card-actions { grid-column: 1 / -1; }
  .howto-list { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px 16px !important; margin: 6px 0 10px !important; }
  .howto-list.single { grid-template-columns: 1fr; }
  .howto-item { gap: 8px; }
  .howto-item .hint-art { width: 72px; height: 56px; padding: 0; overflow: visible; }
  .howto-item .hint-art > * { transform: scale(0.5); margin: -18px -17px; }
  .howto-item .ha-swatch { margin: -18px -52px; }
  .howto-text { font-size: 13px; }
  .howto-text strong { font-size: 15px; }
  /* A phone on its side: keep the cards clear of the HUD column. */
  .card-layer { padding-left: calc(var(--hud-w, 0px) + 8px); padding-right: calc(var(--tb-w, 0px) + 8px); }
  .card-hint { width: min(600px, 100%); display: grid; grid-template-columns: 200px 1fr; grid-template-areas: "art title" "art text" "art actions" "art foot"; column-gap: 18px; align-items: center; text-align: left; }
  .card-hint .hint-art { grid-area: art; margin: 0; align-self: stretch; align-items: center; flex-wrap: wrap; }
  .card-hint .card-title { grid-area: title; }
  .card-hint .hint-text { grid-area: text; font-size: 14px; margin-bottom: 10px; }
  .card-hint .card-actions { grid-area: actions; }
  .card-hint .card-foot { grid-area: foot; margin-top: 6px; }
  .card { padding: 14px 18px 14px; }
  .card-score-num { font-size: 36px; }
  .card-stats { margin-bottom: 8px; }
  .card-actions { gap: 8px; }
  .card-complete { width: min(560px, 100%); }
}

/* ---- the ending ---- */
.ending-screen { background: #2a2f4a url("../assets/scenes/ending-16x9.jpg") center / cover no-repeat; color: #fbf3df; }
@media (orientation: portrait) { .ending-screen { background-image: url("../assets/scenes/ending-9x16.jpg"); } }
.ending-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ending-words {
  position: absolute !important;
  inset: auto !important;
  left: 50% !important;
  top: max(9vh, calc(env(safe-area-inset-top) + 16px)) !important;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: ending-words 2.6s ease both;
}
@keyframes ending-words { 0%, 45% { opacity: 0; transform: translate(-50%, 12px); } 100% { opacity: 1; transform: translate(-50%, 0); } }
html.reduce-motion .ending-words { animation: none; }
.ending-line {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.8rem, min(7vw, 9vh), 3.2rem);
  line-height: 1.1;
  text-wrap: balance;
  color: #fff8e4;
  text-shadow: 0 2px 14px rgba(20, 20, 50, 0.85), 0 0 3px rgba(20, 20, 50, 0.6);
}
.ending-line2 { margin: 0 0 6px; font-size: clamp(1.1rem, 4vw, 1.4rem); font-weight: 700; color: #ffe9b0; text-shadow: 0 1px 10px rgba(20, 20, 50, 0.9); text-wrap: balance; }
.ending-total { margin: 4px 0 8px; display: flex; flex-direction: column; align-items: center; }
.ending-total-label { margin-bottom: 2px; padding: 2px 10px; border-radius: 999px; background: rgba(34, 32, 58, 0.62); font-size: 13px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: #fff3cf; }
.ending-total-num { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 40px; line-height: 1.1; color: #fff8e4; text-shadow: 0 2px 12px rgba(20, 20, 50, 0.9); }
.ending-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.ending-actions .btn { min-height: 52px; border-radius: 16px; padding: 0 18px; }
@media (orientation: landscape) and (max-height: 500px) {
  .ending-words { top: max(4vh, env(safe-area-inset-top)) !important; gap: 2px; }
  .ending-total-num { font-size: 30px; }
}

/* ---- a challenge ---- */
.challenge-screen { justify-content: flex-start; gap: 4vh; }
.challenge-card { position: relative; z-index: 1; width: min(400px, 100%); animation: card-in 260ms ease-out; }
.challenge-line { font-size: 24px; }
@media (orientation: landscape) and (max-height: 500px) {
  .challenge-screen .title-logo { font-size: 2.4rem; }
  .challenge-screen { gap: 2vh; padding-bottom: 12px; }
  .challenge-card .card-sub { margin-bottom: 8px; }
}

/* The bug report form: the game's font. */
gh-feedback { font-family: "Nunito", -apple-system, "Segoe UI", sans-serif; }

/* A field's name never breaks at its hyphen ("Five-Stone Lawn"). */
.keep-name { white-space: nowrap; }

/* Title screen links (publishing): small, muted, inside the safe areas. */
.title-link {
  position: absolute;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 3;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(251, 243, 223, 0.72);
  color: #4a4a40;
  font: 600 13px/1.2 "Nunito", sans-serif;
  text-decoration: none;
  pointer-events: auto;
}
.title-link:hover, .title-link:focus-visible { color: var(--ink, #2b2a26); background: rgba(251, 243, 223, 0.92); text-decoration: underline; }
.title-link-gallery { left: calc(10px + env(safe-area-inset-left)); }
.title-link-repo { right: calc(10px + env(safe-area-inset-right)); }
@media (max-width: 480px), (max-height: 480px) {
  .title-link { font-size: 11px; padding: 2px 7px; bottom: calc(6px + env(safe-area-inset-bottom)); }
}
