/* ——— Home: your kingdom (js/kingdom.js, js/screens/home.js) ———
   The island is a stage with a fixed shape that fits the screen: wide on
   landscape screens, tall on portrait ones. Everything on it is placed in the
   layout's own units (--W × --H) and sized in cqw, so it scales as one. */

.screen:has(.view-home) { padding-bottom: 12px; }

.km {
  --W: 1600;
  --H: 1100;
  position: relative;
  left: 50%;
  translate: -50% 0;
  /* --km-drop (js/screens/home.js clearGreeting): room made under the
     greeting when it would reach the island. The island moves down by it and
     shrinks to match, so it still fits the screen. */
  margin-top: var(--km-drop, 0px);
  width: min(100vw - 20px, max(620px, (100vh - 112px - var(--km-drop, 0px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1600 / 1100));
  width: min(100vw - 20px, max(620px, (100dvh - 112px - var(--km-drop, 0px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1600 / 1100));
  aspect-ratio: 1600 / 1100;
  container-type: inline-size;
}
.km-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.km-land { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.km-land-tall { display: none; }

/* A place, a character, or a season's touch, anchored by its bottom middle.
   No transform or z-index here: they'd trap the signs underneath nearer
   places. Instead the island lists them back to front. */
.km-at {
  --x: var(--wx);
  --y: var(--wy);
  --w: var(--ww);
  position: absolute;
  left: calc((var(--x) - var(--w) / 2) * 100% / var(--W));
  bottom: calc((var(--H) - var(--y)) * 100% / var(--H));
  width: calc(var(--w) * 100% / var(--W));
}

.km-place {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  transform-origin: 50% 100%;
  animation: km-rise 0.6s var(--bounce) backwards;
  animation-delay: calc(var(--i) * 60ms + 80ms);
}
.km-art {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 6px 0 rgba(91, 58, 110, 0.12));
  transition: transform 0.25s var(--bounce);
}
@media (hover: hover) {
  .km-place:hover .km-art { transform: translateY(-1.5%) scale(1.04); }
}
.km-place:active .km-art,
.km-place.km-chosen .km-art { transform: scale(0.95); }
.km-place:focus-visible { outline: none; }
html.kbd .km-place:focus-visible .km-sign { outline: 4px solid var(--lilac); outline-offset: 3px; }

/* The sign in front of each place. */
.km-sign {
  --accent: #f3c3dc;
  --accent-deep: var(--pink-deep);
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 3;
  translate: -50% 60%;
  display: grid;
  justify-items: center;
  padding: 0.28em 0.95em 0.34em;
  border-radius: 999px;
  border: 3px solid var(--outline);
  background: #fff;
  box-shadow: 0 4px 0 var(--accent);
  font-size: max(12px, 1.1cqw);
  line-height: 1.12;
  white-space: nowrap;
}
.km-sign b { font-size: 1.25em; font-weight: 700; color: var(--ink); }
.km-sign small { font-size: 0.95em; font-weight: 600; color: var(--accent-deep); }
.km-school .km-sign { --accent: #ffc9b6; --accent-deep: #e0603e; }
.km-race .km-sign { --accent: #dccbff; --accent-deep: var(--lilac-deep); }
.km-shop .km-sign { --accent: #ffe08f; --accent-deep: #c27c00; }
.km-palace .km-sign { --accent: #f7c3e3; --accent-deep: var(--pink-deep); }
.km-dressing .km-sign { --accent: #ffc9e3; --accent-deep: #d24f97; }
.km-garden .km-sign { --accent: #bfe9c4; --accent-deep: #2f9a5c; }
.km-bank .km-sign { --accent: #b9ecf2; --accent-deep: #1f97a8; }

/* News over a place: a new class, a ready jar, a room to open… */
.km-ribbon {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 4;
  translate: -50% -35%;
  padding: 0.3em 0.85em;
  border-radius: 999px;
  border: 3px solid #fff;
  background: var(--pink);
  color: #fff;
  font-size: max(12px, 1.05cqw);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 0 var(--pink-deep), var(--shadow);
  animation: ribbon-bob 1.4s ease-in-out infinite;
}

/* The greeting floats in the sky over the island. It stays where it is when
   the island drops to make room (--km-drop). Only its cards and buttons catch
   taps: a tap on the empty sky around them reaches the place underneath.
   On a screen wider than the island, the greeting also takes the sky to its
   left (up to a fifth of the island's width), keeping its right edge, so it's
   wider and shorter. */
.km-greet {
  --gl: min(2.4%, max(-50vw + 50% + 16px, -20%));
  position: absolute; z-index: 6; left: var(--gl); top: calc(1.4% - var(--km-drop, 0px)); width: calc(38.4% - var(--gl));
  pointer-events: none;
}
.km-greet :is(button, .day-path, .week-crown, .fq) { pointer-events: auto; }
.km-greet h1 { font-size: max(26px, 2.9cqw); line-height: 1.05; }
.km-greet p { margin-top: 0.3em; font-size: max(14px, 1.28cqw); font-weight: 500; color: var(--ink-soft); }
/* "How to play" is a round ❓ beside the hello, so the column stays short. */
.km-hello { display: flex; align-items: center; gap: 0.5em; }
.km-greet .km-help { flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin: 0; padding: 0; font-size: 20px; }
/* Today's Path, the Week Crown, and the Family Quest share one wrapping area:
   the path's card on top, the two chips side by side under it when they fit.
   Together they stay above the School and the Flower Garden. */
.km-goals { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45em; margin-top: 0.6em; }
.km-goals:empty { display: none; }
.km-goals > * { margin: 0 !important; }
.km-goals > .day-path { flex: 1 1 100%; }
/* With the Family Quest beside it, the crown is just 👑 and its slots (it
   still reads out its name), so the two chips fit on one row. */
.km-goals:has(.fq) .week-crown :is(b, small) { display: none; }

/* Sprinkles and you, in the town square. */
.km-cast { pointer-events: none; }
.km-cast > * { pointer-events: auto; }
.km-sprinkles .mascot { display: block; width: 100%; }
.km-you .look-hero { --w: 100% !important; }
.km-you .look-cta { width: 100%; padding: 10% 4%; font-size: max(12px, 1.02cqw); }
.km-you .look-cta-icon { font-size: 2.4em; }

/* The season's touches stand either side of the fountain. */
.km-season { aspect-ratio: 5 / 1; pointer-events: none; }
.km-season .sn-spot.l { right: auto; left: 0; }
.km-season .sn-spot.r { left: auto; right: 0; }
.km-season .sn-spot.fly { left: 30%; top: -150%; bottom: auto; height: 60%; }
.km .sn-sky { z-index: 1; }
.km .lp-snow { z-index: 7; }

/* Life on the island. */
.km-flag { animation: lp-flagwave 1.4s ease-in-out infinite alternate; }
.km-bell { animation: km-ring 5s ease-in-out infinite; }
.km-tick { animation: km-tick 4s steps(8) infinite; }
.km-wheel { animation: km-tick 14s linear infinite; }
.km-twinkle { transform-box: fill-box; transform-origin: center; animation: twinkle 0.9s ease-in-out infinite alternate; }
.km-twinkle.late { animation-delay: 0.45s; }
.km-water { animation: km-splash 1.4s ease-in-out infinite alternate; }
.km-flutter { transform-box: fill-box; transform-origin: center; animation: km-flutter 3.4s ease-in-out infinite; }
.km-gem, .km-coin { transform-box: fill-box; transform-origin: center; animation: km-gleam 3.2s ease-in-out infinite; }
.km-bloom { transform-box: fill-box; transform-origin: 50% 100%; animation: km-sway 2.6s ease-in-out infinite alternate; }
.km-bloom:nth-child(even) { animation-delay: -1.3s; }

/* Evening (always, on Hoshiland's home): the dusk sky behind the island,
   navy at the top, lilac, then a warm glow at the horizon, with the moon and
   stars out. Night (by the clock) also lights the windows and lamps. */
.km-dusk {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(var(--dusk), var(--dusk-mid) 38%, #7a63c8 68%, #c7a2e0 86%, var(--glow));
  animation: fade-in 0.8s ease both;
}
.km-moon, .km-star, .km-glow, .km-lit { opacity: 0; }
.km-evening .km-sun { opacity: 0; }
.km-evening .km-moon { opacity: 1; }
.km-evening .km-star { opacity: 1; transform-box: fill-box; transform-origin: center; animation: twinkle 1.8s ease-in-out infinite alternate; }
.km-evening .km-greet h1 { color: #fff; }
.km-evening .km-greet p { color: #e6dafc; }
.km-night .km-glow, .km-night .km-lit { opacity: 1; }
.km-night .km-win { fill: #ffe27a; filter: drop-shadow(0 0 5px #ffd54d); }
.km-night .km-surface, .km-night .km-art { filter: brightness(0.86) saturate(0.92); }

/* Tapping a place zooms into it. */
.km.km-enter { animation: km-zoom 0.38s cubic-bezier(0.5, 0, 0.9, 0.4) forwards; pointer-events: none; }

/* Portrait screens: the tall island. */
@media (orientation: portrait) {
  .km {
    --W: 1000;
    --H: 1800;
    width: min(100vw - 20px, max(340px, (100vh - 112px - var(--km-drop, 0px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1000 / 1800));
    width: min(100vw - 20px, max(340px, (100dvh - 112px - var(--km-drop, 0px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1000 / 1800));
    aspect-ratio: 1000 / 1800;
  }
  .km-land-wide { display: none; }
  .km-land-tall { display: block; }
  .km-at { --x: var(--tx); --y: var(--ty); --w: var(--tw); }
  .km-sign { font-size: max(11px, 2.05cqw); border-width: 2.5px; }
  .km-ribbon { translate: -50% 50%; font-size: max(11px, 2cqw); }
  /* The tall island is narrower than the screen; the greeting uses the whole
     width (the sky either side), so the goals fit on one row above the palace. */
  .km-greet { left: max(-50vw + 50% + 16px, -40%); top: calc(1% - var(--km-drop, 0px)); width: min(100vw - 32px, 180%); }
  /* Path, crown, and quest all on one row: the quest keeps just its faces. */
  .km-goals:has(.week-crown) .fq-title b { display: none; }
  .km-greet h1 { font-size: max(24px, 6cqw); }
  .km-greet p { font-size: max(13px, 3cqw); }
  .km-you .look-cta { font-size: max(11px, 2.2cqw); }
}

/* A small island (phones): signs keep just the place's name, and Today's Path
   and the Family Quest keep just their pictures, so they share one row. */
@container (max-width: 520px) {
  .km-sign small { display: none; }
  .km-goals:has(.fq) :is(.dp-title b, .fq-title b) { display: none; }
  /* The crown keeps its 👑 and slots (its aria-label still names it), so it
     stays on the goals' row and never sits on the island (Pebblebrook). */
  .km-goals .week-crown b { display: none; }
  .km-greet:has(.km-goals > *) > p { display: none; }
  .km-sign { padding: 0.25em 0.8em; }
  .km-ribbon { padding: 0.2em 0.6em; border-width: 2px; }
}

@keyframes km-rise { from { opacity: 0; transform: translateY(8%) scale(0.7); } }
@keyframes km-ring { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(14deg); } 82% { transform: rotate(-12deg); } 88% { transform: rotate(8deg); } 94% { transform: rotate(-4deg); } }
@keyframes km-tick { to { transform: rotate(360deg); } }
@keyframes km-splash { from { opacity: 0.7; transform: translateY(2px); } to { opacity: 1; transform: translateY(-3px); } }
@keyframes km-flutter { 0%, 100% { transform: translate(0, 0) rotate(-6deg); } 50% { transform: translate(-18px, -10px) rotate(8deg); } }
@keyframes km-gleam { 0%, 80%, 100% { transform: scale(1) rotate(0); } 88% { transform: scale(1.15) rotate(-8deg); } 94% { transform: scale(1.05) rotate(5deg); } }
@keyframes km-sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes km-zoom { to { transform: scale(2.2); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .km-place, .km-flag, .km-bell, .km-tick, .km-wheel, .km-twinkle, .km-water, .km-flutter,
  .km-gem, .km-coin, .km-bloom, .km-evening .km-star { animation: none; }
}

/* Today's Path (js/daily.js): three stops under the greeting. */
.day-path { margin-top: 0.7em; padding: 0.55em 0.7em 0.65em; border: 3px solid var(--outline); border-radius: 22px; background: var(--card); box-shadow: var(--shadow); font-size: max(13px, 1.05cqw); }
.dp-title { margin: 0 0 0.45em !important; font-size: 1em !important; color: var(--ink) !important; }
.dp-title small { margin-left: 0.3em; font-size: 0.85em; font-weight: 500; color: var(--ink-soft); }
.dp-stops { display: flex; align-items: center; }
.dp-stop {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 0.15em;
  padding: 0.4em 0.2em; border: 2.5px solid var(--outline); border-radius: 16px; background: #fff;
  font: inherit; font-size: 0.92em; font-weight: 600; color: var(--ink); cursor: pointer;
  animation: km-rise 0.45s var(--bounce) backwards; animation-delay: calc(var(--i) * 90ms + 200ms);
  transition: transform 0.15s var(--bounce);
}
.dp-stop:hover { transform: translateY(-2px) scale(1.04); }
.dp-stop:active { transform: scale(0.96); }
.dp-icon { font-size: 1.6em; line-height: 1; }
.dp-label { line-height: 1.1; text-align: center; overflow-wrap: anywhere; }
.dp-stop.done { background: #eafbf1; border-color: var(--mint-deep); color: #1f7a4d; }
.dp-dash { flex: 0 0 0.6em; height: 0; border-top: 3px dashed var(--outline); opacity: 0.45; }
.day-path.all-done { background: linear-gradient(135deg, #fff6c2, #eafbf1); }
.km-evening .dp-title b { color: var(--ink); }
/* Portrait: one short row (title, then icon-only stops) so the island shows.
   The plan's stops (a skill, the first round) keep a short name under the
   picture, cut short with an ellipsis when the row is tight. */
@media (orientation: portrait) {
  .day-path { display: flex; align-items: center; gap: 0.6em; width: fit-content; max-width: 100%; padding: 0.35em 0.6em; font-size: max(12px, 3cqw); }
  .km-goals > .day-path { flex: 0 1 auto; }
  .dp-title { margin: 0 !important; white-space: nowrap; }
  .dp-stops { min-width: 0; }
  .dp-title small, .dp-label { display: none; }
  .dp-stop { flex: 0 0 auto; padding: 0.25em 0.45em; border-radius: 999px; }
  .dp-stop.dp-plan { flex: 0 1 auto; min-width: 2.6em; gap: 0; padding: 0.2em 0.5em 0.25em; border-radius: 14px; }
  .dp-plan .dp-label { display: block; max-width: min(7.5em, 100%); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; overflow-wrap: normal; font-size: 0.8em; }
  .dp-icon { font-size: 1.35em; }
  .dp-plan .dp-icon { font-size: 1.15em; }
  .dp-dash { flex-basis: 0.5em; }
  /* The path never shrinks past its stops (the Week Crown or the Family
     Quest used to slide over them, so they couldn't be tapped): when the row
     is full, the chips wrap under it, and the island drops to make room. */
  .km-goals:has(.fq) > .day-path { flex: 1 1 0; }
}
/* The narrowest phones: no room for a name beside the quest's faces, so pictures only, as before. */
@media (orientation: portrait) and (max-width: 370px) {
  .km-goals:has(.fq) .dp-plan .dp-label { display: none; }
}

/* The class picker's sparkle meter: bright pips are full-gem rounds left. */
.sparkle-meter { display: inline-flex; gap: 1px; margin-left: 0.45em; font-size: 0.72em; vertical-align: middle; }
.sparkle-meter i { font-style: normal; }
.sparkle-meter i.used { filter: grayscale(1); opacity: 0.35; }

/* A child who can't read yet (js/guide.js): a finger bobs over the place to tap. */
.km-point {
  position: absolute;
  left: 50%;
  top: 22%;
  z-index: 5;
  translate: -50% -50%;
  font-size: max(52px, 6.5cqw);
  filter: drop-shadow(0 3px 2px rgba(60, 30, 80, 0.3));
  animation: km-point 0.9s ease-in-out infinite;
  pointer-events: none;
}
@keyframes km-point { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(12px); } }
@media (prefers-reduced-motion: reduce) { .km-point { animation: none; } }


/* ——— Plan first (js/screens/home.js): today's plan round before the island ———
   One card under the greeting with the next round's ▶, and every place on the
   island dimmed under a 🔒 until the plan's rounds are played. */
.pf-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.45em;
  margin-top: 0.7em; padding: 0.6em 0.75em 0.7em; width: fit-content; max-width: 100%;
  border: 3px solid var(--outline); border-radius: 22px; background: var(--card); box-shadow: var(--shadow);
  font-size: max(14px, 1.15cqw);
}
.pf-go {
  display: flex; align-items: center; gap: 0.55em; max-width: 100%;
  padding: 0.35em 0.5em 0.35em 0.35em; border: 4px solid #fff; border-radius: 999px;
  background: linear-gradient(180deg, var(--pink), var(--pink-deep)); color: #fff;
  font: inherit; font-size: 1.25em; line-height: 1.1; text-align: left; cursor: pointer;
  box-shadow: 0 6px 0 var(--outline), var(--shadow);
  animation: pop-in 0.5s var(--bounce) 0.3s backwards;
}
.pf-go:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--outline), var(--shadow); }
.pf-icon { flex: none; display: grid; place-items: center; width: 1.9em; height: 1.9em; border-radius: 50%; background: #fff; font-size: 1em; }
.pf-text { min-width: 0; display: flex; flex-direction: column; }
.pf-text small { font-size: 0.68em; font-weight: 600; opacity: 0.92; }
.pf-text b { font-weight: 700; overflow-wrap: anywhere; }
.pf-play { flex: none; margin-left: 0.2em; font-size: 1.3em; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.pf-dots { display: flex; gap: 0.35em; padding-left: 0.3em; }
.pf-dots i { width: 0.7em; height: 0.7em; border-radius: 50%; background: var(--outline); opacity: 0.25; }
.pf-dots i.on { background: var(--mint-deep); opacity: 1; }
.pf-then { margin: 0 !important; padding-left: 0.3em; font-size: 0.95em !important; font-weight: 600; color: var(--ink-soft) !important; }
.km-evening .pf-then { color: var(--ink-soft) !important; }
.pf-bounce { animation: pf-bounce 0.6s var(--bounce); }
@keyframes pf-bounce {
  0%, 100% { transform: none; }
  30% { transform: translateY(-10px) scale(1.06); }
  60% { transform: translateY(2px) scale(0.98); }
}
.km-place.km-wait .km-art { filter: grayscale(0.55) brightness(0.92); opacity: 0.75; }
.km-wait-lock {
  position: absolute; left: 50%; top: 38%; z-index: 4; translate: -50% -50%;
  display: grid; place-items: center; width: 1.8em; height: 1.8em;
  border: 3px solid #fff; border-radius: 50%; background: var(--card); box-shadow: var(--shadow);
  font-size: max(16px, 1.6cqw); pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  .pf-go, .pf-bounce { animation: none; }
}

/* Paused (js/screens/home.js): a plan from before the new setup waits for a
   grown-up. The same card, a question first, and "Get a grown-up". */
.pf-ask { margin: 0 !important; padding: 0 0.3em; font-size: 1.05em !important; font-weight: 700; color: var(--ink) !important; }
.pf-grownup { background: linear-gradient(180deg, var(--lilac, #b9a2ff), var(--lilac-deep, #8f6fe8)); }
.pf-offline { font-weight: 500; }
.pf-grownup { position: relative; }
