@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('/assets/fonts/fredoka-latin-v1.woff2') format('woff2');
}

:root {
  --lav: #d3adf0;
  --lav-deep: #a77fd6;
  --straw: #f58fb8;
  --cream: #fff3da;
  --cream-2: #ffe9c2;
  --mint: #9ce3cb;
  --sky: #8ccfed;
  --gold: #d99a24;
  --gold-hi: #ffd56b;
  --plum: #35233f;
  --plum-2: #5b4468;
  --plum-soft: rgba(53, 35, 63, .62);
  --panel: rgba(255, 246, 228, .94);
  --panel-edge: rgba(122, 82, 150, .18);
  --shadow: 0 10px 28px rgba(90, 50, 120, .22), 0 2px 0 rgba(255, 255, 255, .7) inset;
  --r: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  font-weight: 500;
  color: var(--plum);
  background: #c9a5ef;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
img { -webkit-user-drag: none; }
[hidden] { display: none !important; }
.noscript { padding: 2rem; font-size: 1.2rem; }

/* ---------- buttons ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: .7em 1.6em;
  font-weight: 700;
  color: var(--plum);
  background: linear-gradient(#ffe9a6, #ffc84a 55%, #f0a92a);
  box-shadow: 0 5px 0 #b8771a, 0 10px 22px rgba(120, 70, 20, .3), 0 2px 0 rgba(255, 255, 255, .8) inset;
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b8771a, 0 4px 10px rgba(120, 70, 20, .25), 0 2px 0 rgba(255, 255, 255, .8) inset; }
.btn:disabled { filter: grayscale(.6) brightness(.95); cursor: default; }
.btn-soft { background: linear-gradient(#fff, #f6e7ff); box-shadow: 0 4px 0 #b99bd6, 0 8px 18px rgba(90, 50, 120, .18); }
.btn-soft:active { box-shadow: 0 1px 0 #b99bd6; }
.chip {
  border: 0; border-radius: 999px; padding: .45em 1em; font-size: .95rem;
  background: rgba(255, 255, 255, .78); color: var(--plum);
  box-shadow: 0 3px 10px rgba(90, 50, 120, .2);
}
.linkbtn { border: 0; background: none; color: var(--lav-deep); font-weight: 600; padding: .3em .4em; text-decoration: underline; text-underline-offset: 3px; }
.iconbtn {
  position: relative; width: 46px; height: 46px; border: 0; border-radius: 14px;
  background: rgba(255, 255, 255, .8); box-shadow: 0 3px 10px rgba(90, 50, 120, .2);
  display: grid; place-items: center; color: var(--plum-2);
}
.iconbtn img { width: 30px; height: 30px; }
.iconbtn svg { width: 26px; height: 26px; }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--straw); color: #fff; font-size: .75rem; line-height: 20px; font-weight: 700;
}

/* ---------- title page ---------- */
.screen { position: fixed; inset: 0; }
#title { overflow: hidden; display: grid; }
.title-art, .title-art img { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-art img { object-fit: cover; object-position: 60% 0%; animation: kenburns 26s ease-in-out infinite alternate; }
@keyframes kenburns { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.08) translate(-1.2%, -1%); } }
.title-shade { position: absolute; inset: 0; background: radial-gradient(120% 70% at 22% 40%, rgba(255, 243, 230, .55), rgba(255, 243, 230, 0) 60%); }
.title-inner {
  position: relative; z-index: 2; align-self: center;
  width: min(46vw, 640px); margin-left: 5vw;
  display: flex; flex-direction: column; align-items: center; gap: 1.1rem; text-align: center;
}
.title-logo { margin: 0; width: 100%; }
.title-logo img { width: 100%; height: auto; display: block; filter: drop-shadow(0 8px 14px rgba(90, 40, 110, .35)); animation: logoin .9s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes logoin { from { transform: scale(.6) translateY(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
.title-tag {
  margin: 0; font-size: clamp(1.05rem, 2vw, 1.5rem); font-weight: 600; color: var(--plum);
  background: rgba(255, 246, 232, .82); padding: .35em 1em; border-radius: 999px;
  box-shadow: 0 4px 14px rgba(90, 50, 120, .18);
}
.btn-play { font-size: clamp(1.6rem, 3.2vw, 2.3rem); padding: .45em 2.2em .5em; display: flex; flex-direction: column; align-items: center; line-height: 1.05; animation: pulse 2.2s ease-in-out infinite; }
.play-sub { font-size: .5em; font-weight: 600; opacity: .8; }
.play-sub:empty { display: none; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
.title-foot { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; justify-content: center; }
.made-by { font-size: .9rem; color: var(--plum-2); background: rgba(255, 255, 255, .6); padding: .3em .8em; border-radius: 999px; }

@media (max-aspect-ratio: 4/5) {
  .title-art img { object-position: 50% 60%; }
  .title-shade { background: linear-gradient(rgba(255, 243, 230, .45), rgba(255, 243, 230, 0) 38%, rgba(255, 243, 230, 0) 75%, rgba(255, 243, 230, .5)); }
  .title-inner { width: 92vw; margin: 0 auto; align-self: stretch; justify-content: space-between; padding: calc(4vh + var(--safe-t)) 0 calc(3vh + var(--safe-b)); }
  .title-actions { margin-top: auto; margin-bottom: 1rem; }
}

/* ---------- game layout ---------- */
#game {
  display: grid;
  grid-template-columns: minmax(320px, 1.15fr) minmax(270px, .8fr) minmax(360px, 1.1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas: "top top top" "stage mid shop";
  gap: 14px; padding: 10px 14px 14px;
}
.sky {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 40% at 20% 15%, rgba(255, 255, 255, .55), transparent 70%),
    radial-gradient(50% 35% at 85% 25%, rgba(255, 220, 240, .6), transparent 70%),
    linear-gradient(#cfb2f3 0%, #e9c6f0 45%, #ffd9d0 75%, #ffe8c6 100%);
  background-size: cover; background-position: center;
  transition: background-image 1.2s;
}
.sky::after { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(255, 255, 255, 0) 60%, rgba(255, 240, 225, .35)); }

.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-mini { border: 0; background: none; padding: 0; width: clamp(150px, 16vw, 230px); flex: 0 0 auto; }
.logo-mini img { width: 100%; display: block; filter: drop-shadow(0 3px 5px rgba(90, 40, 110, .3)); }
.topstats { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.05; min-width: 0; }
.bank { font-size: clamp(1.6rem, 3vw, 2.3rem); font-weight: 700; display: flex; align-items: center; gap: .25em; color: var(--plum);
  text-shadow: 0 2px 0 rgba(255, 255, 255, .8); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bank .ico { width: 1.15em; height: 1.15em; }
.rate { font-size: clamp(.85rem, 1.3vw, 1.05rem); color: var(--plum-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.rate.boosted { color: #d0457e; }
.topbtns { display: flex; gap: 8px; }

.col { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.col-stage { grid-area: stage; }
.col-mid { grid-area: mid; }
.col-shop { grid-area: shop; }
.panel {
  background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow);
  border: 1.5px solid var(--panel-edge);
  min-height: 0; flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.panel h2 { font-size: 1.15rem; margin: 0; font-weight: 700; color: var(--plum); }
.tabs { display: none; }

/* stage */
.stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; }
.chapter-tag {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  background: rgba(255, 255, 255, .72); padding: .25em .9em; border-radius: 999px; font-size: .95rem; font-weight: 600;
  box-shadow: 0 3px 10px rgba(90, 50, 120, .15); white-space: nowrap;
}
.goat {
  position: relative; border: 0; background: none; padding: 0;
  width: min(92%, 52vh, 460px); aspect-ratio: 799 / 900;
  touch-action: manipulation; cursor: pointer;
}
.goat:focus-visible { outline: none; }
.goat:focus-visible .goat-glow { opacity: 1; }
.goat img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; will-change: transform; transform-origin: 50% 70%;
  filter: drop-shadow(0 18px 18px rgba(110, 60, 140, .28)); }
.goat-glow {
  position: absolute; inset: 8% 4% 2%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, .85), rgba(255, 236, 170, .45) 45%, rgba(255, 255, 255, 0) 75%);
  opacity: .8; transition: opacity .3s;
}
.tapval { margin-top: -6px; font-size: .95rem; font-weight: 600; color: var(--plum-2); background: rgba(255, 255, 255, .6); padding: .15em .8em; border-radius: 999px; }
.effects { position: absolute; bottom: 8px; left: 0; right: 0; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.effect { background: linear-gradient(#fff6, #fff0), var(--straw); color: #fff; font-weight: 700; padding: .35em .9em; border-radius: 999px; box-shadow: 0 4px 12px rgba(200, 60, 120, .35); font-size: .95rem; }
.effect.horn { background: linear-gradient(#fff6, #fff0), var(--gold); }
.delivery {
  position: absolute; left: 0; top: 0; width: 84px; height: 84px; border: 0; padding: 0; background: none;
  touch-action: manipulation; z-index: 5; will-change: transform;
}
.delivery img { width: 100%; height: 100%; filter: drop-shadow(0 0 14px rgba(255, 230, 140, .95)) drop-shadow(0 6px 8px rgba(90, 50, 120, .3)); }
.hint {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%); z-index: 4;
  background: var(--plum); color: #fff; padding: .45em 1em; border-radius: 14px; font-weight: 600; font-size: 1rem;
  box-shadow: 0 6px 16px rgba(53, 35, 63, .35); pointer-events: none; white-space: nowrap;
  animation: bob 1.4s ease-in-out infinite;
}
.hint::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: var(--plum); }
@keyframes bob { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -6px); } }

/* kingdom column */
.panel-head { padding: 12px 16px 6px; display: flex; justify-content: space-between; align-items: baseline; }
.helpers { padding: 4px 12px 8px; display: grid; gap: 8px; }
.helper {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px;
  background: #fff; border-radius: 14px; padding: 6px 10px 6px 6px; border: 2px solid transparent; text-align: left;
  box-shadow: 0 2px 6px rgba(90, 50, 120, .1);
}
.helper.on { border-color: var(--gold); background: linear-gradient(#fffaf0, #fff1cf); }
.helper.locked { opacity: .55; }
.helper .face { width: 52px; height: 52px; border-radius: 12px; background: var(--lav) center / cover no-repeat; }
.helper .nm { font-weight: 700; font-size: .98rem; }
.helper .ds { font-size: .82rem; color: var(--plum-soft); font-weight: 500; line-height: 1.2; }
.helper .tag { font-size: .78rem; font-weight: 700; padding: .25em .6em; border-radius: 999px; background: var(--lav); color: #fff; }
.helper.on .tag { background: var(--gold); }
.helper-slots { font-size: .85rem; color: var(--plum-soft); padding: 0 4px; }
.parade-card { margin: 4px 12px 10px; }
.parade-box {
  border-radius: 14px; padding: 10px 12px; background: linear-gradient(135deg, #fff4d6, #ffe2f0); border: 2px dashed rgba(217, 154, 36, .55);
  display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center;
}
.parade-box img { width: 44px; height: 44px; }
.parade-box .t { font-weight: 700; }
.parade-box .s { font-size: .85rem; color: var(--plum-soft); }
.parade-box.ready { border-style: solid; background: linear-gradient(135deg, #fff1c2, #ffd1e8); }
.parade-box .btn { grid-column: 1 / -1; font-size: 1rem; padding: .5em 1em; }
.kingdom-view { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 12px; display: grid; gap: 6px; align-content: start; }
.krow { display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 4px 8px; background: rgba(255, 255, 255, .55); border-radius: 12px; overflow: hidden; }
.krow .kn { font-size: .78rem; font-weight: 600; color: var(--plum-soft); width: 7.5em; flex: 0 0 auto; line-height: 1.1; }
.krow .kicons { display: flex; flex-wrap: nowrap; }
.krow .ki { width: 30px; height: 30px; margin-right: -10px; border-radius: 8px; background: center / contain no-repeat; flex: 0 0 auto; }
.krow .kmore { font-size: .8rem; font-weight: 700; margin-left: 14px; color: var(--plum-2); }
.empty-note { font-size: .9rem; color: var(--plum-soft); padding: 8px 4px; }

/* shop column */
.upg-head, .shop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 6px; }
.upgrades { padding: 0 12px 6px; display: grid; gap: 6px; }
.upg {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 10px; align-items: center; text-align: left;
  background: #fff; border: 0; border-radius: 14px; padding: 6px 10px 6px 6px; box-shadow: 0 2px 6px rgba(90, 50, 120, .1);
  transition: transform .08s;
}
.upg:active { transform: scale(.98); }
.upg .ui { width: 46px; height: 46px; border-radius: 12px; background: var(--lav) center / cover no-repeat; position: relative; }
.upg .ui[data-frame]::after { content: ''; position: absolute; inset: -2px; border-radius: 13px; border: 3px solid var(--frame, #c98a3a); }
.upg .un { font-weight: 700; font-size: .95rem; line-height: 1.15; }
.upg .ud { font-size: .8rem; color: var(--plum-soft); line-height: 1.2; }
.upg .uc { font-weight: 700; font-size: .95rem; display: flex; align-items: center; gap: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.upg .uc img { width: 18px; height: 18px; }
.upg.cant { background: #f6f0f8; }
.upg.cant .uc { color: var(--plum-soft); }
.upgrades .none { font-size: .88rem; color: var(--plum-soft); padding: 2px 4px 8px; }

.buyamt { display: flex; background: #efe3f7; border-radius: 999px; padding: 3px; }
.buyamt button { border: 0; background: none; padding: .3em .75em; border-radius: 999px; font-weight: 700; font-size: .9rem; color: var(--plum-2); }
.buyamt button[aria-checked="true"] { background: #fff; color: var(--plum); box-shadow: 0 2px 6px rgba(90, 50, 120, .2); }
.buildings { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 12px; display: grid; gap: 7px; align-content: start; overscroll-behavior: contain; }
.bld {
  position: relative; display: grid; grid-template-columns: 62px 1fr auto; gap: 10px; align-items: center; text-align: left;
  min-height: 70px; padding: 5px 12px 5px 5px; border: 0; border-radius: 16px;
  background: linear-gradient(#ffffff, #fff8ee); box-shadow: 0 2px 0 rgba(255, 255, 255, .9) inset, 0 3px 8px rgba(90, 50, 120, .14);
  transition: transform .08s, filter .2s;
}
.bld:active { transform: scale(.985); }
.bld .bi { width: 62px; height: 62px; border-radius: 13px; background: linear-gradient(135deg, #f5dcff, #ffe4f0) center / cover no-repeat; display: grid; place-items: center; font-weight: 700; color: var(--plum-2); font-size: 1.3rem; }
.bld .bn { font-weight: 700; font-size: 1.02rem; line-height: 1.1; }
.bld .bc { display: flex; align-items: center; gap: 4px; font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.bld .bc img { width: 18px; height: 18px; }
.bld .bs { font-size: .78rem; color: var(--plum-soft); line-height: 1.2; }
.bld .bo { font-size: 1.8rem; font-weight: 700; color: rgba(53, 35, 63, .28); font-variant-numeric: tabular-nums; min-width: 1.4em; text-align: right; }
.bld .bm { position: absolute; left: 72px; right: 12px; bottom: 4px; height: 4px; border-radius: 2px; background: #efe3f7; overflow: hidden; }
.bld .bm i { display: block; height: 100%; background: linear-gradient(90deg, var(--straw), var(--gold)); }
.bld.cant { filter: saturate(.55); }
.bld.cant .bc { color: #b0547a; }
.bld.locked .bi { filter: brightness(0) opacity(.35); }
.bld.locked .bn { color: var(--plum-soft); }
.bld.flash { animation: bldflash .5s ease-out; }
@keyframes bldflash { 0% { box-shadow: 0 0 0 0 rgba(255, 200, 80, .9); } 100% { box-shadow: 0 0 0 14px rgba(255, 200, 80, 0); } }

/* sheet (modal) */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(53, 35, 63, .45); display: grid; place-items: center; padding: 16px; animation: fadein .2s; }
@keyframes fadein { from { opacity: 0; } }
.sheet-card {
  position: relative; width: min(680px, 100%); max-height: min(88vh, 900px); overflow-y: auto;
  background: var(--cream); border-radius: 24px; padding: 22px 22px 24px; box-shadow: 0 24px 60px rgba(53, 35, 63, .4);
  animation: popin .28s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes popin { from { transform: scale(.85); opacity: 0; } }
.sheet-card h2 { margin: 0 40px 12px 0; font-size: 1.5rem; }
.sheet-x { position: absolute; top: 10px; right: 12px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(53, 35, 63, .08); font-size: 1.6rem; line-height: 1; }
.sheet p { line-height: 1.4; font-weight: 500; }
.sheet .center { text-align: center; }
.big-num { font-size: 2.4rem; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: .2em; font-variant-numeric: tabular-nums; }
.big-num img { width: 1.1em; height: 1.1em; }
.welcome-art { width: 180px; margin: 0 auto; display: block; animation: snooze 2.4s ease-in-out infinite; }
@keyframes snooze { 0%, 100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(3deg) translateY(-6px); } }
.row-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.stk { background: #fff; border-radius: 14px; padding: 8px 6px; text-align: center; box-shadow: 0 2px 6px rgba(90, 50, 120, .1); }
.stk .si { width: 54px; height: 54px; margin: 0 auto 4px; border-radius: 50%; background: var(--lav) center / cover no-repeat; border: 3px solid var(--gold-hi); }
.stk .sn { font-size: .78rem; font-weight: 700; line-height: 1.1; }
.stk .sd { font-size: .68rem; color: var(--plum-soft); line-height: 1.15; margin-top: 2px; }
.stk.no { background: #f4eef7; }
.stk.no .si { filter: grayscale(1) opacity(.35); border-color: #ddd; }
.stk.no .sn { color: var(--plum-soft); }
.book-sum { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.book-sum .pill { background: #fff; border-radius: 999px; padding: .35em .9em; font-weight: 700; box-shadow: 0 2px 6px rgba(90, 50, 120, .12); }
.settings { display: grid; gap: 10px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: #fff; border-radius: 14px; padding: 10px 14px; }
.toggle { min-width: 84px; border: 0; border-radius: 999px; padding: .45em 1em; font-weight: 700; background: #e5d7ef; color: var(--plum-2); }
.toggle[aria-pressed="true"] { background: var(--mint); color: var(--plum); }
.tree { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.tnode { display: grid; gap: 4px; text-align: left; background: #fff; border: 2px solid transparent; border-radius: 14px; padding: 10px 12px; }
.tnode .tn { font-weight: 700; }
.tnode .td { font-size: .82rem; color: var(--plum-soft); line-height: 1.25; }
.tnode .tc { font-weight: 700; display: flex; align-items: center; gap: 4px; }
.tnode .tc img { width: 20px; height: 20px; }
.tnode.own { border-color: var(--gold); background: #fff7df; }
.tnode.cant { opacity: .6; }
.stats-list { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: .98rem; }
.stats-list dt { color: var(--plum-soft); }
.stats-list dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.credits p { font-size: .95rem; }

/* toast */
.toast {
  position: fixed; left: 50%; top: calc(74px + var(--safe-t)); transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 10px; background: var(--plum); color: #fff;
  padding: .55em 1.1em .55em .6em; border-radius: 16px; box-shadow: 0 10px 24px rgba(53, 35, 63, .4);
  font-weight: 600; max-width: min(92vw, 460px); animation: toastin .35s cubic-bezier(.2, 1.4, .4, 1);
}
.toast img { width: 38px; height: 38px; }
.toast small { display: block; font-weight: 500; opacity: .8; font-size: .82rem; }
@keyframes toastin { from { transform: translate(-50%, -20px); opacity: 0; } }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* ---------- tablet: two columns, tabs on the right ---------- */
@media (max-width: 1099px), (max-height: 560px) and (max-width: 1300px) {
  #game {
    grid-template-columns: minmax(0, 1fr) minmax(330px, 1fr);
    grid-template-rows: 60px minmax(0, 1fr) auto;
    grid-template-areas: "top top" "stage panel" "stage tabs";
  }
  .col-mid, .col-shop { grid-area: panel; }
  .tabs { grid-area: tabs; display: flex; gap: 6px; background: var(--panel); border-radius: 16px; padding: 5px; box-shadow: var(--shadow); }
  .tabs button { flex: 1; border: 0; border-radius: 12px; background: none; padding: .55em .4em; font-weight: 700; color: var(--plum-2); position: relative; min-height: 44px; }
  .tabs button[aria-selected="true"] { background: #fff; color: var(--plum); box-shadow: 0 2px 8px rgba(90, 50, 120, .18); }
  .tabs .dot { position: absolute; top: 6px; right: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--straw); }
  #game[data-tab="mid"] .col-shop { display: none; }
  #game:not([data-tab="mid"]) .col-mid { display: none; }
  #game[data-tab="upg"] .shop-head, #game[data-tab="upg"] .buildings { display: none; }
  #game[data-tab="upg"] .upgrades { overflow-y: auto; flex: 1; min-height: 0; }
  #game[data-tab="upg"] #allUpgBtn { display: none; }
  #game[data-tab="shop"] .upg-head, #game[data-tab="shop"] .upgrades { display: none; }
  #panelKingdom { overflow-y: auto; overscroll-behavior: contain; }
  #panelKingdom .kingdom-view { flex: none; overflow: visible; min-height: 120px; }
}

/* ---------- phone portrait: stacked ---------- */
@media (max-width: 699px) {
  #game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto clamp(170px, 30vh, 270px) minmax(0, 1fr) auto;
    grid-template-areas: "top" "stage" "panel" "tabs";
    gap: 8px; padding: calc(6px + var(--safe-t)) 10px calc(8px + var(--safe-b));
  }
  .topbar { gap: 8px; }
  .logo-mini { width: 92px; }
  .bank { font-size: 1.55rem; }
  .iconbtn { width: 42px; height: 42px; }
  .goat { width: min(62vw, 24vh, 300px); }
  .tapval { display: none; }
  .parade-chip { top: 4px; right: 0; font-size: .85rem; }
  .chapter-tag { font-size: .82rem; }
  .tapval { font-size: .82rem; }
  .delivery { width: 66px; height: 66px; }
  .bld { min-height: 64px; grid-template-columns: 54px 1fr auto; }
  .bld .bi { width: 54px; height: 54px; }
  .bld .bm { left: 64px; }
  .bld .bo { font-size: 1.5rem; }
  .shop-head h2, .upg-head h2 { font-size: 1.02rem; }
  .buyamt button { padding: .3em .6em; font-size: .85rem; }
  .tabs { border-radius: 18px; }
  .sheet { padding: 0; place-items: end stretch; }
  .sheet-card { width: 100%; max-height: 90vh; border-radius: 24px 24px 0 0; padding-bottom: calc(24px + var(--safe-b)); }
}

/* very short landscape phones */
@media (max-height: 460px) and (orientation: landscape) {
  #game { grid-template-rows: 48px minmax(0, 1fr) auto; padding: 6px 10px; gap: 8px; }
  .logo-mini { width: 120px; }
  .bank { font-size: 1.4rem; }
  .goat { width: min(80%, 62vh); }
  .chapter-tag { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .title-art img, .btn-play, .hint, .welcome-art { animation: none !important; }
}
body.reduced .title-art img, body.reduced .btn-play, body.reduced .hint, body.reduced .welcome-art { animation: none !important; }
.small { font-size: .9rem; color: var(--plum-soft); }

/* delivery tag, parade chip */
.delivery .dtag { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); white-space: nowrap; font-size: .78rem; font-weight: 700;
  background: rgba(255, 255, 255, .92); color: var(--plum); padding: .15em .6em; border-radius: 999px; box-shadow: 0 2px 8px rgba(90, 50, 120, .25); }
.parade-chip { position: absolute; top: 40px; right: 6px; z-index: 6; display: flex; align-items: center; gap: 6px; border: 0; border-radius: 999px;
  padding: .35em .9em .35em .4em; font-weight: 700; background: linear-gradient(#fff3c4, #ffd36a); box-shadow: 0 4px 0 #c8902a, 0 8px 18px rgba(120, 70, 20, .3);
  animation: pulse 1.8s ease-in-out infinite; }
.parade-chip img { width: 28px; height: 28px; }

/* kingdom goals + landmarks */
.goals { padding: 0 12px; }
.goal-card { background: #fff; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 2px 6px rgba(90, 50, 120, .1); }
.goal-card .gt { font-size: .95rem; margin-bottom: 6px; }
.goal-card .gl { display: flex; align-items: center; gap: 8px; font-size: .88rem; padding: 3px 0; color: var(--plum-2); }
.goal-card .gl.ok { color: #2f8f6c; }
.goal-card .gk { width: 20px; height: 20px; border-radius: 6px; border: 2px solid #d9c7e6; display: grid; place-items: center; font-size: .8rem; font-weight: 700; flex: 0 0 auto; }
.goal-card .gl.ok .gk { background: var(--mint); border-color: #5fcfa8; color: #fff; }
.goal-card .gp { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--plum-soft); }
.goal-card .gr { font-size: .78rem; color: var(--plum-soft); margin-top: 4px; }
.landmarks { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.landmarks .lm { background: linear-gradient(#fff7e0, #ffe9b8); border: 1.5px solid rgba(217, 154, 36, .5); border-radius: 999px; padding: .2em .7em; font-size: .8rem; font-weight: 700; }
.landmarks .lm-bonus { font-size: .8rem; font-weight: 700; color: #2f8f6c; }

/* kingdom islands */
.kingdom-view { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 4px; }
.kingdom-view .empty-note { grid-column: 1 / -1; }
.ktile { position: relative; aspect-ratio: 1; display: grid; place-items: center; }
.ktile .kimg { width: 100%; height: 100%; background: center / contain no-repeat; display: grid; place-items: center; font-weight: 700; color: var(--plum-2);
  filter: drop-shadow(0 4px 6px rgba(90, 50, 120, .25)); animation: float 4s ease-in-out infinite; }
.ktile:nth-child(2n) .kimg { animation-delay: -1.3s; }
.ktile:nth-child(3n) .kimg { animation-delay: -2.6s; }
@keyframes float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
.ktile .kcount { position: absolute; right: 2px; bottom: 4px; background: var(--plum); color: #fff; font-size: .75rem; font-weight: 700; padding: 0 .45em; border-radius: 999px; }
.ktile .kstars { position: absolute; left: 2px; top: 2px; color: var(--gold); font-size: .7rem; text-shadow: 0 1px 0 #fff; letter-spacing: -1px; }
body.reduced .ktile .kimg { animation: none; }
@media (prefers-reduced-motion: reduce) { .ktile .kimg { animation: none; } }

/* helpers: a compact portrait row */
.helpers { padding: 6px 12px 4px; display: block; border-top: 1.5px solid var(--panel-edge); }
.helper-head { display: flex; justify-content: space-between; align-items: baseline; }
.helper-head h3 { margin: 0; font-size: 1rem; }
.helper-head span { font-size: .8rem; color: var(--plum-soft); }
.helper-row { display: flex; gap: 6px; margin: 6px 0 4px; flex-wrap: wrap; }
.hchip { width: 62px; border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hchip .face { width: 54px; height: 54px; border-radius: 50%; background: #fff center / 86% no-repeat; border: 3px solid #e6d8ef; box-shadow: 0 2px 6px rgba(90, 50, 120, .15); transition: transform .12s; }
.hchip.on .face { border-color: var(--gold); background-color: #fff6dc; box-shadow: 0 0 0 3px rgba(255, 213, 107, .5), 0 3px 8px rgba(120, 70, 20, .25); }
.hchip:active .face { transform: scale(.94); }
.hchip .hn { font-size: .72rem; font-weight: 700; color: var(--plum-2); }
.hchip.locked .face { filter: brightness(0) opacity(.22); }
.helper-desc { font-size: .8rem; color: var(--plum-2); line-height: 1.3; }
.helper-next { font-size: .75rem; color: var(--plum-soft); margin-top: 2px; }
.kingdom-view { padding-top: 4px; }
.bld { padding-bottom: 15px; }
.bld .bm { bottom: 5px; }
.col-stage > .helpers { flex: 0 0 auto; border-top: 0; background: rgba(255, 246, 228, .78); border-radius: var(--r); box-shadow: var(--shadow); padding: 8px 12px; margin-top: 6px; }
.col-stage > .helpers .helper-row { margin-bottom: 2px; }
.bld .bm { left: auto; right: 12px; width: 52px; bottom: 9px; }
.bld { padding-bottom: 5px; }
@media (min-width: 1100px) and (min-height: 561px) { .chapter-tag { display: none; } }
.bld .bo { padding-bottom: 10px; line-height: 1; }
.bld .bt { min-width: 0; }
.bld .bs { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 699px) {
  .toast { top: calc(58px + var(--safe-t)); font-size: .9rem; padding: .45em .9em .45em .5em; }
  .toast img { width: 30px; height: 30px; }
  .toast small { font-size: .78rem; }
}
.bld.nudge { animation: nudge 1.3s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(245, 143, 184, .0), 0 3px 8px rgba(90, 50, 120, .14); } 50% { box-shadow: 0 0 0 5px rgba(245, 143, 184, .75), 0 3px 8px rgba(90, 50, 120, .14); } }
.delivery { width: 96px; height: 100px; }
.delivery img { object-fit: contain; }
@media (max-width: 699px) { .delivery { width: 70px; height: 74px; } }
.sky { background-size: cover; background-position: 50% 70%; }

/* round-3 review: readability, hierarchy, materials */
.bld .bs, .upg .ud { font-size: .86rem; color: var(--plum-2); }
.bld .bo { color: rgba(53, 35, 63, .55); }
.welcome-art { width: 100px; }
.sheet .big-num { font-size: 2.6rem; }
.made-by { background: none; box-shadow: none; text-shadow: 0 1px 0 rgba(255, 255, 255, .8); }
.parade-confirm .pc-head { background: linear-gradient(135deg, #fff4d6, #ffe0ef); border-radius: 18px; padding: 10px 12px 12px; margin-bottom: 8px; }
.parade-confirm .pc-mult { font-size: 1.15rem; }
.parade-confirm p { max-width: 48ch; margin-left: auto; margin-right: auto; }
.pc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; font-size: .9rem; }
.pc-col { border-radius: 14px; padding: 10px 12px; line-height: 1.35; }
.pc-col b { display: block; margin-bottom: 2px; }
.pc-col.reset { background: #fdeef3; }
.pc-col.keep { background: #e8f8f1; }
.sheet .tree + .row-btns { position: sticky; bottom: -24px; background: linear-gradient(rgba(255, 243, 218, 0), var(--cream) 30%); padding: 18px 0 8px; margin-bottom: -8px; }
.upg.best { box-shadow: 0 0 0 3px var(--gold-hi), 0 2px 6px rgba(90, 50, 120, .1); }
.upg.best .un::after { content: 'Best pick'; margin-left: 6px; font-size: .7rem; vertical-align: 2px; background: var(--gold); color: #fff; padding: .1em .5em; border-radius: 999px; }
.hchip.locked .face { filter: none; background: #efe4f6; display: grid; place-items: center; font-weight: 700; font-size: 1.4rem; color: #b49bc8; border-style: dashed; }
.stickers { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
.stk .si { width: 64px; height: 64px; }
.stk .sn { font-size: .85rem; }
.stk .sd { font-size: .74rem; }
.stk.new { box-shadow: 0 0 0 3px var(--straw), 0 4px 12px rgba(245, 143, 184, .35); }
.stk.new::before { content: 'New!'; display: block; font-size: .7rem; font-weight: 700; color: var(--straw); }
.bank { cursor: pointer; }
/* confectionery panels: a wafer edge and an icing highlight */
.panel, .col-stage > .helpers { border-bottom: 5px solid #e6c48c; box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 10px 24px rgba(90, 50, 120, .18); }
.topstats { background: rgba(255, 246, 228, .82); border-radius: 18px; padding: 4px 22px 6px; flex: 0 1 auto; margin: 0 auto; box-shadow: 0 3px 10px rgba(90, 50, 120, .15); border-bottom: 3px solid #e6c48c; }
@media (min-width: 1100px) and (min-height: 561px) {
  .toast { left: 14px; transform: none; top: 74px; max-width: min(37vw, 470px); }
  @keyframes toastin { from { transform: translateY(-16px); opacity: 0; } }
}
@media (max-width: 699px) {
  .tapval { display: block; position: absolute; bottom: 2px; font-size: .78rem; }
  .topstats { padding: 2px 12px 4px; }
}
/* QA round 1 */
.goat:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; border-radius: 40%; }
.btn:focus-visible { outline-color: var(--plum); }
.hint { top: auto; bottom: 6%; }
.hint::after { bottom: auto; top: -8px; border-top: 0; border-bottom: 8px solid var(--plum); }
.effects { bottom: auto; top: 4px; }
.credits a { color: var(--lav-deep); font-weight: 700; }
.logo-mini { padding: 10px 0; }
@media (max-width: 699px) {
  .iconbtn { width: 44px; height: 44px; }
  .chapter-tag { left: 0; transform: none; top: 0; }
  .effects { top: 26px; }
}
@media (max-width: 699px) { .hint { bottom: 24px; } }
/* the Goatacorn is sized by the stage's real height so the per-tap label never spills onto the helpers */
.stage { position: relative; }
.goat { width: auto; height: min(calc(100% - 40px), 470px); max-width: 94%; aspect-ratio: 799 / 900; }
.tapval { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); margin: 0; white-space: nowrap; }
@media (max-width: 699px) { .goat { height: calc(100% - 26px); width: auto; } .tapval { bottom: 0; } }
@media (max-height: 460px) and (orientation: landscape) { .goat { height: calc(100% - 30px); width: auto; } }
/* the kingdom as a scene: staggered islands, landmarks first and bigger */
.kingdom-view { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); row-gap: 0; }
.ktile:nth-child(even) { transform: translateY(10px); }
.lmtile { grid-column: span 2; grid-row: span 2; transform: none !important; }
.lmtile .lmname { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: .72rem; font-weight: 700;
  background: linear-gradient(#fff3c4, #ffd36a); padding: .15em .7em; border-radius: 6px; box-shadow: 0 2px 6px rgba(120, 70, 20, .3); }
/* painted upgrade icons */
.upg .ui.pic { background-color: #fff6e8; background-size: contain; position: relative; overflow: visible; }
.upg .ui.tapic, .upg .ui.flv { background-color: #fff3d6; background-size: 82%; }
.upg .ui .seal { position: absolute; right: -6px; bottom: -6px; width: 26px; height: 26px; background: center / contain no-repeat; filter: drop-shadow(0 1px 2px rgba(90, 50, 120, .4)); }
.lm-strip { grid-column: 1 / -1; display: flex; gap: 4px; justify-content: center; padding: 2px 0 10px; }
.lm-strip .lmtile { position: relative; flex: 0 1 92px; aspect-ratio: 1; grid-column: auto; grid-row: auto; }
.lm-strip .kimg { display: block; width: 100%; height: 100%; background: center / contain no-repeat; filter: drop-shadow(0 4px 6px rgba(90, 50, 120, .25)); }
.lm-strip .lmname { bottom: -2px; font-size: .64rem; padding: .1em .45em; }
.save-warn { position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); z-index: 60; max-width: 92vw;
  background: #fff1f3; color: #8a1f45; border: 2px solid #f58fb8; border-radius: 14px; padding: .5em 1em; font-weight: 600; font-size: .9rem; box-shadow: 0 8px 20px rgba(53, 35, 63, .25); }
.lm-strip .lmname { white-space: normal; text-align: center; width: max-content; max-width: 104%; line-height: 1.05; bottom: -4px; }
/* phone: toasts are a snackbar above the tabs, never over the Goatacorn or the chapter name */
@media (max-width: 699px) {
  .toast { top: auto; bottom: calc(76px + var(--safe-b)); }
  @keyframes toastin { from { transform: translate(-50%, 20px); opacity: 0; } }
}
/* QA round 2: tap targets and badges */
.buyamt button { min-height: 34px; }
.parade-chip { min-height: 44px; }
.ktile .kstars { font-size: .62rem; top: 0; }
@media (max-width: 699px) { .logo-mini { min-height: 44px; display: flex; align-items: center; } .buyamt button { min-height: 38px; padding: .3em .7em; } }
