/* Mate App screens: shell, first run, home, set, end of set, popups.
   Uses the tokens and base components from base.css. Hint visuals live in hints.css. */

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  font-family: var(--font-nunito);
}
body { min-height: 100dvh; }
button { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:focus-visible { outline: 4px solid rgb(115 87 191 / 0.45); outline-offset: 3px; }
.icon { display: block; width: 100%; height: 100%; }

#app { position: fixed; inset: 0; overflow: hidden; }
#screen-host { position: absolute; inset: 0; }

/* ---------- backdrop ---------- */
.sky { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.sky::before, .sky::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(2px); opacity: 0.8;
}
.sky::before {
  width: 62vmax; height: 62vmax; left: -22vmax; top: -30vmax;
  background: radial-gradient(circle, rgb(255 226 240 / 0.8), transparent 65%);
}
.sky::after {
  width: 70vmax; height: 70vmax; right: -30vmax; bottom: -34vmax;
  background: radial-gradient(circle, rgb(205 236 255 / 0.85), transparent 66%);
}

.boot { position: absolute; inset: 0; display: grid; place-items: center; z-index: 99; background: var(--page); color: var(--ink-soft); font: 700 20px var(--font-fredoka); transition: opacity 0.5s; }
.boot.is-gone { opacity: 0; pointer-events: none; }
.boot span { width: 46px; height: 46px; border-radius: 50%; border: 6px solid var(--lavender); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.boot:not(:empty) span { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0;
  padding: max(16px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  animation: screen-in 0.5s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes screen-in { from { opacity: 0; transform: translateY(14px) scale(0.99); } to { opacity: 1; transform: none; } }

h1, h2 { font-family: var(--font-fredoka); margin: 0; }

/* ---------- shared pieces ---------- */
.star-counter {
  display: inline-flex; align-items: center; gap: 10px; height: 64px; padding: 0 24px 0 14px;
  border-radius: 999px; background: rgb(255 255 255 / 0.85); border: 3px solid #eadfb5;
  box-shadow: 0 4px 0 #eadfb5, 0 10px 20px rgb(var(--shadow-color) / 0.06);
  font: 700 34px/1 var(--font-fredoka); color: #6b5217;
}
.star-counter > :first-child { width: 40px; height: 40px; }
.lock-btn {
  display: grid; place-items: center; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 50%;
  background: rgb(255 255 255 / 0.6); color: #9a90b3; cursor: pointer;
}
.lock-btn .icon { width: 30px; height: 30px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 10px; min-height: 64px; padding: 0 24px 0 18px; cursor: pointer;
  border: 3px solid #c9c1dc; border-radius: 999px; background: #fff; box-shadow: 0 4px 0 #c9c1dc;
  font: 700 21px/1 var(--font-fredoka); color: var(--ink); transition: transform 120ms, box-shadow 120ms;
}
.pill-btn > span { width: 28px; height: 28px; display: block; }
.pill-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9c1dc; }
.pill-btn--help { border-color: #e0b04f; background: #fff3c9; box-shadow: 0 4px 0 #e0b04f; }
.pill-btn--help:active { box-shadow: 0 1px 0 #e0b04f; }
.speech-bubble { font-family: var(--font-fredoka); font-weight: 500; }
.big-button { font-family: var(--font-fredoka); }
.big-button:disabled, .big-button.is-disabled { opacity: 0.45; pointer-events: none; filter: grayscale(0.3); }
.link-btn { border: 0; background: none; padding: 12px 16px; min-height: 48px; color: var(--ink-soft); font: 600 18px var(--font-nunito); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }

/* ---------- rainbow week ---------- */
.week-panel {
  width: 100%; padding: 12px 14px 10px; border-radius: 32px; background: rgb(255 255 255 / 0.72);
  box-shadow: var(--shadow-sm); border: 2px solid rgb(255 255 255 / 0.9);
}
.week-title { font-size: 17px; font-weight: 600; color: var(--ink-soft); text-align: center; margin-bottom: 4px; letter-spacing: 0.02em; }
.rainbow-week { width: 100%; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.rainbow-day {
  min-height: 0; padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-radius: 22px; transition: background 0.4s, box-shadow 0.4s;
}
.rainbow-day.is-repaired::after { content: none; }
.rb-arc { display: block; width: 100%; }
.rb-svg { display: block; width: 100%; height: auto; overflow: visible; }
.rb-label { font: 700 16px/1 var(--font-fredoka); color: var(--ink-soft); }
.rainbow-day.is-today .rb-label { color: var(--lavender-dark); }
.rb-track { fill: none; stroke: #e6dff3; stroke-width: 6.4; stroke-linecap: round; }
.rb-band { fill: none; stroke: var(--c); stroke-width: 6.4; stroke-linecap: round; stroke-dasharray: 1 1; stroke-dashoffset: 0; opacity: 0; }
.is-done .rb-band, .is-repaired .rb-band { opacity: 1; }
.is-missed .rb-band { opacity: calc(1 - var(--i) * 0.12); stroke: #d3cedd; }
.is-missed .rb-track { stroke: #e7e3ee; }
.is-future .rb-track, .is-before-start .rb-track { opacity: 0.7; }
.is-before-start .rb-track { opacity: 1; stroke: #d9d1ea; stroke-width: 2.4; stroke-dasharray: 0.1 5.2; }
.is-before-start .rb-label { opacity: 0.45; }
.rainbow-day.is-future { opacity: 0.8; }
.rb-patch { opacity: 0; transition: opacity 0.5s; }
.rb-patch circle { fill: #fff7d6; stroke: #c98f26; stroke-width: 1.4; stroke-dasharray: 3 2.4; }
.rb-patch path { fill: #ffd56c; stroke: #c98f26; stroke-width: 1; stroke-linejoin: round; }
.is-repaired .rb-patch { opacity: 1; }
.rb-svg.is-unfilled .rb-band, .is-unfilled .rb-band { opacity: 0; }
.is-unfilled .rb-patch { opacity: 0; }
.rainbow-day.is-today { background: #fff; box-shadow: inset 0 0 0 3px var(--lavender), 0 6px 14px rgb(115 87 191 / 0.14); }
.rainbow-day.is-today.is-unfilled .rb-track { animation: track-pulse 1.6s ease-in-out infinite; }
@keyframes track-pulse { 50% { stroke: #ddd0fb; } }
.is-filled-now .rb-band { animation: rb-draw 0.75s cubic-bezier(.4,.1,.3,1) both; animation-delay: calc(var(--i) * 130ms); }
.is-filled-now .rb-patch { transition-delay: 0.9s; }
@keyframes rb-draw { from { stroke-dashoffset: 1; opacity: 1; } to { stroke-dashoffset: 0; opacity: 1; } }

/* ---------- first run ---------- */
.fr { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(100%, 780px); margin: 0 auto; }
.fr-top { flex: 0 1 auto; display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 6px; }
.fr-bubble { max-width: 520px; text-align: center; font-size: 26px; transition: opacity 0.2s, transform 0.2s; }
.fr-bubble::before, .fr-bubble::after { left: 50%; margin-left: -18px; }
.fr-bubble::after { margin-left: -15px; }
.fr-bubble.is-swap { opacity: 0; transform: translateY(6px); }
.fr-uni { width: clamp(150px, 31dvh, 330px); }
.fr-uni.is-arriving { animation: uni-arrive 1s cubic-bezier(.2,1.3,.4,1) both; }
@keyframes uni-arrive { 0% { transform: scale(0.2) translateY(80px) rotate(-12deg); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; opacity: 1; } }
.fr-bottom { flex: 1 1 0; min-height: 0; width: 100%; display: flex; flex-direction: column; align-items: center; }
.fr-pane { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; animation: pane-in 0.5s ease both; }
@keyframes pane-in { from { opacity: 0; transform: translateY(10px); } }
.fr-step-name .fr-pane--color, .fr-step-color .fr-pane--name { display: none; }
.fr-title { font-size: 32px; font-weight: 600; color: var(--ink); text-align: center; }
.name-field {
  display: flex; align-items: center; justify-content: center; gap: 4px; width: min(100%, 520px); height: 84px;
  border-radius: 30px; background: #fff; border: 3px solid var(--lavender); box-shadow: 0 0 0 6px rgb(184 161 247 / 0.2), var(--shadow-sm);
  font: 600 50px/1 var(--font-fredoka); color: var(--ink);
}
.nf-placeholder { color: #bdb4d3; }
.nf-caret { width: 4px; height: 52px; border-radius: 2px; background: var(--lavender-dark); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.name-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.name-chip {
  min-height: 56px; padding: 0 24px; border: 3px solid #d8c5f2; border-radius: 999px; background: #f5edff; box-shadow: 0 4px 0 #d8c5f2;
  font: 600 24px var(--font-fredoka); color: var(--lavender-dark); cursor: pointer; transition: transform 120ms;
}
.name-chip.is-picked { background: var(--lavender); border-color: #5f489e; box-shadow: 0 4px 0 #5f489e; color: #2f2546; transform: translateY(-2px); }
.fr-or { margin: 0; color: var(--ink-soft); font-size: 16px; font-weight: 600; }
.letter-keyboard { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.lk-row { display: flex; justify-content: center; gap: 7px; width: 100%; }
.lk-key {
  flex: 0 1 66px; min-width: 0; height: 64px; padding: 0; border: 3px solid #c9c1dc; border-radius: 18px; background: #fff;
  box-shadow: 0 4px 0 #c9c1dc; font: 600 27px var(--font-fredoka); color: var(--ink); cursor: pointer; transition: transform 100ms, box-shadow 100ms;
}
.lk-key:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9c1dc; background: #f5edff; }
.lk-key--wide { flex-basis: 108px; display: grid; place-items: center; color: var(--rose-dark); }
.lk-key--wide .icon { width: 34px; height: 34px; }
.fr-next, .fr-go { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-width: 280px; font-size: 28px; margin-top: 4px; }
.bb-arrow { width: 26px; height: 26px; transform: rotate(180deg); }
.fr-back { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; min-height: 48px; padding: 8px 16px; font: 600 19px var(--font-nunito); color: var(--ink-soft); cursor: pointer; }
.fr-back span { width: 22px; height: 22px; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px 26px; padding: 8px 0 4px; }
.swatch {
  position: relative; width: 112px; height: 112px; border-radius: 50%; border: 6px solid #fff; cursor: pointer;
  background: radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--sw) 55%, #fff), var(--sw) 62%);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--sw) 60%, #302a43), 0 12px 22px rgb(var(--shadow-color) / 0.14); transition: transform 160ms;
}
.swatch .sw-check { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; opacity: 0; transform: scale(0.5); transition: 200ms; filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.3)); }
.swatch .sw-check .icon { width: 46px; height: 46px; }
.swatch.is-picked { transform: translateY(-6px) scale(1.06); box-shadow: 0 0 0 5px var(--lavender-dark), 0 6px 0 color-mix(in srgb, var(--sw) 60%, #302a43), 0 16px 26px rgb(var(--shadow-color) / 0.2); }
.swatch.is-picked .sw-check { opacity: 1; transform: none; }
.fr-colorname { margin: 0; min-height: 28px; font: 600 24px var(--font-fredoka); color: var(--lavender-dark); }
.fr-step-color .fr-uni { width: clamp(180px, 38dvh, 400px); }
.fr-step-color .fr-title { font-size: 32px; }

/* ---------- home ---------- */
.home { flex: 1; min-height: 0; display: flex; flex-direction: column; width: min(100%, 760px); margin: 0 auto; gap: 8px; padding-bottom: 14px; }
.topbar { display: flex; justify-content: space-between; align-items: center; flex: none; }
.home-stage::before {
  content: ""; position: absolute; left: 50%; top: 56%; width: min(100%, 64vh); aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; z-index: -1;
  background: radial-gradient(circle, rgb(255 255 255 / 0.95) 0 36%, rgb(255 240 250 / 0.7) 56%, transparent 70%); pointer-events: none;
}
.home-stage { position: relative; isolation: isolate; flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 6px; }
.home-bubble { flex: none; max-width: 500px; text-align: center; font-size: 24px; animation: bubble-pop 0.6s 0.25s cubic-bezier(.2,1.4,.4,1) both; }
.home-bubble::before, .home-bubble::after { left: 50%; margin-left: -18px; }
.home-bubble::after { margin-left: -15px; }
@keyframes bubble-pop { from { opacity: 0; transform: scale(0.85) translateY(8px); } }
.home-uni-wrap { position: relative; flex: 1 1 0; min-height: 0; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.home-uni { position: relative; flex: 1 1 0; min-height: 0; aspect-ratio: 420 / 400; max-width: 100%; cursor: pointer; }
.home-uni .character { width: 100%; height: 100%; }
.name-tag {
  position: relative; flex: none; margin-top: -4px; display: inline-flex; align-items: center; gap: 10px; padding: 8px 22px 8px 16px; border-radius: 999px;
  background: #fff; border: 3px solid #e3d9f6; box-shadow: 0 4px 0 #e3d9f6; font: 600 24px var(--font-fredoka); color: var(--lavender-dark);
}
.nt-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--mane, var(--lavender)); box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.15); }
.home-bottom { position: relative; z-index: 1; flex: none; display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; padding-top: 2px; }
.skill-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: min(100%, 680px); }
.start-button { display: flex; align-items: center; gap: 20px; width: min(100%, 580px); min-height: 104px; padding: 14px 38px 18px 16px; text-align: left; }
.skill-choice .start-button { width: 100%; min-width: 0; padding-right: 18px; }
.skill-choice .start-button .sb-main { font-size: 28px; }
.set-top-spacer { width: 118px; }
.start-button .sb-icon {
  flex: none; display: grid; place-items: center; width: 76px; height: 76px; border-radius: 50%; background: rgb(255 255 255 / 0.85);
  font: 700 58px/1 var(--font-fredoka); color: #5f489e; box-shadow: inset 0 -4px 0 rgb(95 72 158 / 0.18);
}
.start-button .sb-icon svg { width: 44px; height: auto; }
.start-button .sb-icon--mul { font-size: 104px; line-height: 0.7; padding-bottom: 4px; }
.start-button .sb-text { display: flex; flex-direction: column; gap: 4px; }
.start-button .sb-main { font-size: 38px; font-weight: 700; line-height: 1.05; }
.start-button .sb-sub { font: 700 20px var(--font-nunito); opacity: 0.8; }
.start-button--add { border-color: #3f8a73; background: linear-gradient(180deg, #c4f0e1 0%, var(--mint) 100%); box-shadow: 0 6px 0 #3f8a73, 0 13px 28px rgb(40 110 90 / 0.18); }
.start-button--add .sb-icon { color: #2e7762; }
.start-button--add:active { box-shadow: 0 2px 0 #3f8a73, 0 6px 16px rgb(40 110 90 / 0.14); }
.start-button { animation: start-bob 2.4s ease-in-out 1.4s 3; }
@keyframes start-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
.repair-chip { display: flex; align-items: center; gap: 10px; padding: 8px 20px 8px 12px; border-radius: 999px; background: #fff3c9; border: 3px dashed #d9a93b; font: 700 18px var(--font-nunito); color: #6b5217; text-align: left; }
.repair-chip > span { width: 28px; height: 28px; flex: none; }
.goal-row { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font: 700 17px var(--font-nunito); }
.goal-pips { display: inline-flex; gap: 4px; }
.pip { width: 28px; height: 28px; opacity: 0.35; filter: grayscale(1); }
.pip.is-on { opacity: 1; filter: none; }

/* ---------- set ---------- */
.set { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; width: min(100%, 760px); margin: 0 auto; }
.set-left, .set-right { display: contents; }
.set-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none; }
.set-counter { font: 700 30px var(--font-fredoka); color: var(--ink); }
.progress-cells { width: 100%; flex: none; gap: 8px; }
.progress-cell { position: relative; min-height: 52px; border-radius: 18px; background: rgb(255 255 255 / 0.8); display: grid; place-items: center; transition: background 0.3s, border-color 0.3s; }
.progress-cell svg { width: 86%; height: 86%; }
.progress-cell.is-done { background: #fff5e6; border-color: #f0b476; }
.progress-cell.is-new svg { animation: cell-pop 0.55s cubic-bezier(.2,1.6,.4,1); }
@keyframes cell-pop { 0% { transform: scale(0.3); } 100% { transform: scale(1); } }
.progress-cell.is-current { animation: cell-pulse 1.8s ease-in-out infinite; }
@keyframes cell-pulse { 50% { box-shadow: 0 0 0 8px rgb(184 161 247 / 0.15); } }
.set-uni-wrap { position: relative; flex: none; height: clamp(96px, 17.4dvh, 200px); margin-bottom: -12px; pointer-events: none; z-index: 0; }
.set-uni { position: absolute; left: 10px; bottom: 0; width: clamp(110px, 18.4dvh, 214px); }
.set-uni .character { width: 100%; }
.set-reaction {
  position: absolute; left: calc(clamp(110px, 18.4dvh, 214px) + 26px); top: 46%; max-width: min(340px, calc(100% - clamp(110px, 18.4dvh, 214px) - 44px)); padding: 12px 20px; font-size: 21px; line-height: 1.25;
  border-radius: 24px; opacity: 0; transform: translateY(-50%) scale(0.85); transform-origin: left center; transition: opacity 0.25s, transform 0.3s cubic-bezier(.2,1.4,.4,1);
}
.set-reaction.is-on { opacity: 1; transform: translateY(-50%) scale(1); }
.speech-bubble--side::before, .speech-bubble--side::after { bottom: auto; border-color: transparent; border-style: solid; }
.speech-bubble--side::before { left: -22px; top: 50%; margin-top: -11px; border-width: 11px 22px 11px 0; border-right-color: var(--ink); }
.speech-bubble--side::after { left: -15px; top: 50%; margin-top: -9px; border-width: 9px 17px 9px 0; border-right-color: var(--white); }

.card-host { position: relative; z-index: 1; flex: none; container-type: inline-size; }
.tc { min-height: clamp(150px, 23dvh, 250px); width: 100%; padding: 22px 28px; transition: transform 0.4s; }
.tc::before, .tc::after { content: none; }
.tc[data-tone="peach"] { background: #ffe8d7; border-color: #f0c3a2; }
.tc[data-tone="mint"] { background: #dcf5e8; border-color: #a6dcc3; }
.tc[data-tone="lavender"] { background: #ebe5ff; border-color: #c9bcf3; }
.tc[data-tone="sky"] { background: #def0fb; border-color: #a9d6ee; }
.tc[data-tone="lemon"] { background: #fff4c7; border-color: #ecd77c; }
.tc[data-tone="rose"] { background: #ffe3eb; border-color: #f0b5c8; }
.tc[data-font="andika"] { font-family: var(--font-andika); }
.tc[data-font="atkinson-hyperlegible"] { font-family: var(--font-atkinson); }
.tc[data-font="lexend"] { font-family: var(--font-lexend); }
.tc[data-font="nunito"] { font-family: var(--font-nunito); }
.tc[data-font="fredoka"] { font-family: var(--font-fredoka); }
.tc-size-large { font-size: clamp(46px, 12cqw, 76px); }
.tc-size-larger { font-size: clamp(50px, 14cqw, 92px); }
.tc-size-largest { font-size: clamp(54px, 16cqw, 108px); }
.tc-line { position: relative; z-index: 1; display: flex; align-items: baseline; justify-content: center; gap: 0.2em; white-space: nowrap; line-height: 1; }
.tc-layout-high .tc-line { transform: translateY(-14px); }
.tc-layout-low .tc-line { transform: translateY(14px); }
.tc-op, .tc-eq { opacity: 0.8; font-weight: 700; }
.tc-op.is-dot { display: inline-block; transform: scale(1.35); margin: 0 0.12em; opacity: 0.9; }
.tc-q { color: var(--lavender-dark); }
.tc-frame { position: absolute; inset: 0; pointer-events: none; }
.tc-deco { position: absolute; width: var(--s); color: #fff; filter: drop-shadow(0 1px 0 rgb(48 42 67 / 0.12)); opacity: 0.95; }
.tc-star.is-warm { color: #ffd56c; }
.tc-star { animation: twinkle 3s ease-in-out infinite; animation-delay: var(--d); }
.tc-deco svg { display: block; width: 100%; height: auto; }
.tc-cloud { opacity: 0.9; }
@keyframes twinkle { 50% { transform: scale(0.75); opacity: 0.6; } }
.tc.is-entering { animation: card-in 0.5s cubic-bezier(.2,1.2,.4,1) both; }
@keyframes card-in { from { opacity: 0; transform: translateY(26px) scale(0.92); } }
.tc.is-leaving { animation: card-away 0.5s cubic-bezier(.5,0,.8,.4) forwards; }
@keyframes card-away { to { opacity: 0; transform: translateY(-70px) scale(0.86) rotate(-3deg); } }
.tc.is-nudge { animation: card-nudge 0.5s ease both; }
@keyframes card-nudge { 25% { transform: translateX(-8px); } 55% { transform: translateX(7px); } 80% { transform: translateX(-3px); } }

.answer-box {
  position: relative; flex: none; align-self: center; display: flex; align-items: center; justify-content: center; gap: 6px; width: min(100%, 300px); height: 84px;
  border-radius: 28px; background: #fff; border: 3px solid #c9c1dc; box-shadow: inset 0 4px 0 rgb(48 42 67 / 0.05), 0 4px 0 #c9c1dc;
  font: 700 62px/1 var(--font-atkinson); color: var(--ink); letter-spacing: 0.04em;
}
.answer-box.is-pop .ab-digits { animation: digit-pop 0.2s ease; }
@keyframes digit-pop { 0% { transform: scale(0.82); } 100% { transform: none; } }
.ab-caret { width: 4px; height: 52px; border-radius: 2px; background: var(--lavender); animation: blink 1s steps(2) infinite; }
.set .numeric-keypad { flex: none; align-self: center; width: min(100%, 440px); gap: 12px; }
.keypad-key { font-family: var(--font-atkinson); }
.keypad-key .key-icon { display: block; width: 38px; height: 38px; margin: 0 auto; }
.keypad-key--back { color: var(--rose-dark); border-color: #ecc3d1; box-shadow: 0 5px 0 #ecc3d1, 0 10px 20px rgb(var(--shadow-color) / 0.08); background: #fff7fa; }
.keypad-key--confirm { color: #2c6b58; }
.keypad-key.is-disabled, .keypad-key:disabled { opacity: 0.45; box-shadow: 0 2px 0 #4d977f; transform: translateY(3px); pointer-events: none; }

.fly-food { position: fixed; left: 0; top: 0; z-index: 90; pointer-events: none; filter: drop-shadow(0 6px 6px rgb(48 42 67 / 0.2)); }
.fly-food svg { width: 100%; height: 100%; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgb(60 48 96 / 0.34); backdrop-filter: blur(5px); opacity: 0; transition: opacity 0.25s;
}
.overlay.is-open { opacity: 1; }
.overlay.is-closing { opacity: 0; }
.overlay-sheet {
  width: min(100%, 780px); height: min(100%, 980px); min-height: 0; overflow: hidden; border-radius: 40px; background: #fffdfa; border: 3px solid #e3d9f6;
  box-shadow: var(--shadow-lg); transform: translateY(30px) scale(0.97); transition: transform 0.35s cubic-bezier(.2,1.2,.4,1);
}
.overlay.is-open .overlay-sheet { transform: none; }
.overlay-body { height: 100%; min-height: 0; }
.hint-fallback { height: 100%; display: grid; place-content: center; gap: 20px; padding: 30px; text-align: center; font-size: 24px; }

.overlay--popup { z-index: 70; }
.popup-card {
  position: relative; width: min(100%, 560px); padding: 26px 30px 30px; border-radius: 44px; background: #fffdfa; border: 3px solid #f0d98d; box-shadow: 0 10px 0 #e9c768, 0 30px 60px rgb(48 42 67 / 0.25);
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; transform: scale(0.7) rotate(-2deg); transition: transform 0.5s cubic-bezier(.2,1.5,.4,1);
}
.overlay--popup.is-open .popup-card { transform: none; }
.popup-stage { position: relative; display: grid; place-items: center; min-height: 150px; width: 100%; }
.popup-stage.has-hero { width: min(100%, 300px); }
.popup-stage .character { width: 100%; }
.popup-title { font-size: 36px; font-weight: 700; line-height: 1.15; color: var(--ink); }
.popup-sub { margin: 0; font: 600 21px/1.3 var(--font-nunito); color: var(--ink-soft); }
.popup-ok { margin-top: 10px; min-width: 240px; font-size: 28px; }
.popup-spark { position: absolute; width: 38px; height: 38px; animation: spark 1.8s ease-in-out infinite; }
.popup-spark--a { left: 28px; top: 28px; }
.popup-spark--b { right: 30px; top: 60px; width: 28px; height: 28px; animation-delay: 0.5s; }
.popup-spark--c { right: 70px; top: 14px; width: 22px; height: 22px; animation-delay: 1s; }
@keyframes spark { 0%, 100% { transform: scale(0.6) rotate(0); opacity: 0.6; } 50% { transform: scale(1.15) rotate(20deg); opacity: 1; } }
.popup-badge {
  display: grid; place-items: center; width: 170px; height: 170px; border-radius: 50%; position: relative; font: 700 84px/1 var(--font-fredoka); color: #fff;
  background: radial-gradient(circle at 32% 26%, #d9c9ff, #a58bf0 62%); box-shadow: 0 8px 0 #7357bf, 0 18px 30px rgb(115 87 191 / 0.3); animation: badge-bounce 1.4s ease-in-out infinite;
}
.popup-badge--add { background: radial-gradient(circle at 32% 26%, #c9f2e3, #6fd0b0 62%); box-shadow: 0 8px 0 #3f8a73, 0 18px 30px rgb(40 110 90 / 0.3); }
.popup-badge--rainbow { background: #fff; box-shadow: 0 8px 0 #e3d9f6, 0 18px 30px rgb(48 42 67 / 0.18); }
.pb-rainbow { width: 124px; display: block; margin-top: 6px; }
.pb-rainbow svg { width: 100%; display: block; }
.popup-badge--mul .pb-main { font-size: 76px; }
.popup-badge--add .pb-main { font-size: 110px; }
.pb-star { position: absolute; width: 56px; height: 56px; right: 14px; bottom: 16px; }
@keyframes badge-bounce { 50% { transform: translateY(-8px) rotate(2deg); } }

/* ---------- end of set ---------- */
.end { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(100%, 760px); margin: 0 auto; }
.end-head { flex: none; margin-bottom: 30px; display: grid; justify-items: center; align-items: center; min-height: 168px; width: 100%; }
.end-head > * { grid-area: 1 / 1; }
.end-bubble { font-size: 28px; transition: opacity 0.4s, transform 0.4s; align-self: start; margin-top: 30px; }
.end-bubble::before, .end-bubble::after { left: 50%; margin-left: -18px; }
.end-bubble::after { margin-left: -15px; }
.end-title { font-size: clamp(40px, 8vw, 58px); font-weight: 700; color: var(--lavender-dark); text-align: center; align-self: start; margin-top: 18px; opacity: 0; transform: scale(0.6); transition: opacity 0.4s, transform 0.6s cubic-bezier(.2,1.6,.4,1); }
.end-stars { align-self: end; display: inline-flex; align-items: center; gap: 10px; padding: 6px 30px 6px 16px; border-radius: 999px; background: #fff3c9; border: 3px solid #e0b04f; box-shadow: 0 5px 0 #e0b04f; font: 700 48px/1 var(--font-fredoka); color: #6b5217; opacity: 0; transform: translateY(14px) scale(0.7); transition: opacity 0.4s 0.35s, transform 0.6s 0.35s cubic-bezier(.2,1.6,.4,1); }
.end-stars > :first-child { width: 52px; height: 52px; }
.is-celebrating .end-bubble { opacity: 0; transform: scale(0.8); pointer-events: none; }
.is-celebrating .end-title { opacity: 1; transform: none; }
.is-celebrating .end-stars { opacity: 1; transform: none; }
.end-uni-wrap { flex: 1 1 0; min-height: 0; width: 100%; display: flex; justify-content: center; }
.end-uni { height: 100%; aspect-ratio: 420 / 400; max-width: 100%; }
.end-uni .character { width: 100%; height: 100%; }
.end-week { flex: none; }
.end-foot { flex: none; display: flex; align-items: center; justify-content: center; gap: 24px; padding-top: 6px; opacity: 0; transform: translateY(16px); pointer-events: none; transition: opacity 0.5s, transform 0.5s; }
.is-celebrating .end-foot { opacity: 1; transform: none; pointer-events: auto; }
.end-total { display: inline-flex; align-items: center; gap: 8px; height: 64px; padding: 0 22px 0 12px; border-radius: 999px; background: rgb(255 255 255 / 0.85); border: 3px solid #eadfb5; font: 700 30px var(--font-fredoka); color: #6b5217; }
.end-total > :first-child { width: 36px; height: 36px; }
.end-done { min-width: 240px; font-size: 30px; }

/* ---------- parent placeholder ---------- */
.parent-placeholder { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; max-width: 480px; }
.pp-icon { width: 72px; height: 72px; color: var(--lavender-dark); }
.parent-placeholder p { margin: 0; color: var(--ink-soft); font-size: 20px; }

/* ---------- landscape tablets ---------- */
@media (orientation: landscape) and (min-width: 800px) {
  .fr { flex-direction: row; width: 100%; gap: 34px; align-items: center; }
  .fr-top { flex: 0 0 40%; justify-content: center; }
  .fr-bottom { flex: 1 1 0; justify-content: center; height: 100%; }
  .fr-uni, .fr-step-color .fr-uni { width: min(100%, 52dvh); }
  .fr-pane { gap: 10px; }
  .fr-title { font-size: 28px; }
  .name-field { height: 72px; }
  .lk-key { height: 58px; flex-basis: 56px; }
  .swatch { width: 96px; height: 96px; }
  .screen { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .home { width: 100%; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto minmax(0, 1fr); column-gap: 36px; }
  .topbar { grid-column: 1 / -1; }
  .home-stage { grid-column: 1; grid-row: 2; padding-top: 0; gap: 14px; }
  .home-bottom { grid-column: 2; grid-row: 2; justify-content: center; align-self: center; gap: 18px; }
  .home-bubble { font-size: 22px; }
  .set { width: 100%; flex-direction: row; gap: 34px; }
  .set-left, .set-right { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; min-height: 0; gap: 12px; }
  .set-right { justify-content: center; }
  .set-uni-wrap { flex: 1 1 0; min-height: 0; height: auto; margin: 0; clip-path: none; display: flex; justify-content: center; align-items: flex-end; }
  .set-uni { position: relative; left: auto; bottom: auto; width: auto; height: 100%; max-width: 100%; aspect-ratio: 420 / 400; }
  .set-uni .character { height: 100%; }
  .set-uni-wrap { padding-top: 78px; }
  .set-reaction { left: 0; right: auto; top: 0; max-width: 78%; transform: translateY(0) scale(0.85); transform-origin: bottom left; }
  .set-reaction.is-on { transform: none; }
  .speech-bubble--side::before, .speech-bubble--side::after { content: none; }
  .tc { min-height: clamp(150px, 24dvh, 230px); }
  .end { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto; align-content: center; column-gap: 30px; row-gap: 26px; width: 100%; }
  .end-head { grid-column: 2; grid-row: 1; }
  .end-uni-wrap { grid-column: 1; grid-row: 1 / 4; align-items: center; }
  .end-uni { height: auto; width: min(100%, 70dvh); }
  .end-week { grid-column: 2; grid-row: 2; padding: 16px 16px 12px; }
  .end-head { margin-bottom: 0; }
  .end-foot { grid-column: 2; grid-row: 3; }
}

/* ---------- phones ---------- */
@media (max-width: 620px) {
  .screen { padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
  .star-counter { height: 52px; font-size: 28px; padding-right: 18px; }
  .star-counter > :first-child { width: 32px; height: 32px; }
  .lock-btn { width: 52px; height: 52px; }
  .home-bubble { font-size: 19px; padding: 14px 18px; }
  .name-tag { font-size: 20px; padding: 6px 18px 6px 12px; }
  .start-button { min-height: 84px; gap: 14px; padding: 10px 24px 14px 12px; }
  .start-button .sb-icon { width: 58px; height: 58px; font-size: 44px; }
  .start-button .sb-icon--mul { font-size: 80px; }
  .start-button .sb-main { font-size: 28px; }
  .start-button .sb-sub { font-size: 16px; }
  .skill-choice { gap: 8px; }
  .skill-choice .start-button { min-height: 76px; padding-right: 8px; }
  .skill-choice .start-button .sb-icon { width: 48px; height: 48px; }
  .skill-choice .start-button .sb-icon--mul { font-size: 66px; }
  .skill-choice .start-button .sb-main { font-size: 20px; }
  .skill-choice .start-button .sb-sub { font-size: 13px; }
  .week-panel { padding: 8px 6px 6px; border-radius: 24px; }
  .rainbow-day { border-radius: 14px; }
  .rb-label { font-size: 13px; }
  .repair-chip { font-size: 15px; }
  .fr-bubble { font-size: 20px; padding: 14px 18px; }
  .fr-title { font-size: 25px; }
  .name-field { height: 66px; font-size: 38px; }
  .nf-caret { height: 40px; }
  .lk-row { gap: 4px; }
  .lk-key { height: 50px; font-size: 22px; border-radius: 12px; border-width: 2px; box-shadow: 0 3px 0 #c9c1dc; }
  .lk-key--wide { flex-basis: 70px; }
  .name-chip { min-height: 48px; font-size: 20px; padding: 0 16px; }
  .swatch { width: 84px; height: 84px; }
  .set-counter { font-size: 24px; }
  .pill-btn { min-height: 52px; font-size: 18px; padding: 0 16px 0 12px; }
  .progress-cell { min-height: 36px; border-radius: 10px; border-width: 2px; }
  .answer-box { height: 66px; font-size: 48px; }
  .ab-caret { height: 40px; }
  .set .numeric-keypad { gap: 8px; }
  .set { gap: 8px; }
  .tc { padding: 14px 16px; border-radius: 30px; }
  .set-reaction { font-size: 17px; padding: 8px 14px; }
  .popup-title { font-size: 28px; }
  .end-bubble { font-size: 22px; }
  .end-stars { font-size: 38px; }
  .swatches { gap: 14px 18px; }
}
@media (max-width: 620px) and (max-height: 900px) { :root { --key-size: 64px; } }
@media (max-width: 620px) {
  .fr-top { gap: 14px; }
  .fr-uni { width: clamp(110px, 20dvh, 330px); }
  .fr-step-color .fr-uni { width: clamp(120px, 25dvh, 400px); }
  .fr-pane { gap: 8px; }
  .name-chips { gap: 6px; flex-wrap: nowrap; }
  .name-chip { padding: 0 11px; font-size: 18px; min-height: 44px; border-width: 2px; box-shadow: 0 3px 0 #d8c5f2; }
  .fr-next, .fr-go { min-width: 220px; font-size: 24px; min-height: 56px; padding: 10px 24px 12px; }
  .fr-or { font-size: 14px; }
  .swatch { width: 76px; height: 76px; border-width: 4px; }
  .fr-colorname { min-height: 22px; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .home-bubble, .fr-uni.is-arriving, .start-button { animation: none !important; }
  .tc.is-leaving { animation: fade-out 0.3s forwards !important; }
  @keyframes fade-out { to { opacity: 0; } }
}
