:root {
  --lilac: #8c53d7;
  --lilac-d: #6a35b4;
  --plum: #5b2c91;
  --honey: #f6b748;
  --honey-d: #c98522;
  --vanilla: #f3e9d2;
  --vanilla-d: #e7dcc1;
  --chestnut: #7d3e23;
  --chestnut-d: #55260f;
  --pink: #f274aa;
  --ink: #402a2b;
  --muted: #8a6c63;
  --mint: #45b58a;
  --danger: #e2504c;
  --cream: #fff8ea;
  --shadow: 0 10px 30px rgba(64, 42, 43, .18);
  --cw: 52px;            /* cell width, set by JS */
  --wrap-pad: 10px; --cab-pad: 10px; --gap-x: 8px; --gap-y: 10px; --bay-pad: 5px;
  --ch: calc(var(--cw) * 1.34);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fw-heavy: 900;   /* titles, buttons, numbers */
  --fw-bold: 800;    /* labels, captions, coach line */
  --fw-text: 700;    /* body and helper text */
  font-family: var(--font);
  font-weight: var(--fw-text);
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--vanilla-d);
  background-image:
    radial-gradient(circle at 25% 25%, rgba(140, 83, 215, .10) 2px, transparent 2.5px),
    radial-gradient(circle at 75% 75%, rgba(246, 183, 72, .18) 2px, transparent 2.5px);
  background-size: 34px 34px;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, b, strong { font-weight: var(--fw-heavy); }
input, select, textarea { font: inherit; }
button:focus-visible, .cell:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }

#app {
  position: relative;
  max-width: 520px; height: 100dvh; margin: 0 auto;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, .55) 0 1.5px, transparent 2px) 0 0 / 28px 28px,
    linear-gradient(#fbf3df, var(--vanilla));
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(125, 62, 35, .15), var(--shadow);
}
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  border: 0; border-radius: 18px; padding: 13px 18px; font-weight: var(--fw-heavy); letter-spacing: .2px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .18); transition: transform .08s, box-shadow .08s, filter .15s;
  min-height: 48px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
.btn-primary { background: linear-gradient(#a36ce6, var(--lilac)); color: #fff; box-shadow: 0 5px 0 var(--plum); }
.btn-primary:active { box-shadow: 0 2px 0 var(--plum); }
.btn-honey { background: linear-gradient(#ffd47e, var(--honey)); color: var(--chestnut-d); box-shadow: 0 5px 0 var(--honey-d); }
.btn-soft { background: #fff; color: var(--plum); box-shadow: 0 4px 0 #d9c9ef; }
.btn-link { background: none; box-shadow: none; color: var(--plum); text-decoration: underline; text-underline-offset: 3px; font-weight: var(--fw-bold); }
.btn-xl { font-size: 21px; padding: 16px 22px; width: 100%; }
.btn-xl span { margin-left: 6px; }
.btn[disabled] { filter: grayscale(.8); opacity: .55; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; background: #fff; color: var(--plum);
  font-size: 22px; font-weight: var(--fw-heavy); box-shadow: 0 3px 0 #d9c9ef; display: grid; place-items: center; flex: none;
}
.icon-btn.ghost { background: rgba(255, 255, 255, .7); }
.pill { background: #fff; border-radius: 99px; padding: 6px 12px; font-weight: var(--fw-heavy); color: var(--plum); box-shadow: 0 2px 0 #d9c9ef; font-size: 14px; white-space: nowrap; }

/* ── Menu ────────────────────────────────────────────── */
#screen-menu { padding: max(16px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom)); justify-content: space-between; overflow-y: auto; }
.menu-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.name-chip {
  border: 0; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; max-width: 70%; padding: 8px 14px;
  border-radius: 99px; background: rgba(255, 255, 255, .75); color: var(--plum); font-weight: var(--fw-heavy); font-size: 15px;
  box-shadow: 0 3px 0 #d9c9ef; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.menu-sign {
  margin: 4px auto 0; text-align: center; width: 100%;
  background: linear-gradient(#a36ce6, var(--lilac)); color: #fff; border-radius: 26px; padding: 18px 16px 20px;
  border: 6px solid var(--chestnut); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .25), 0 8px 0 var(--chestnut-d), var(--shadow);
}
.sign-kicker { font-size: 11px; letter-spacing: 2px; font-weight: var(--fw-heavy); opacity: .85; }
.menu-sign h1 { margin: 6px 0 6px; font-size: clamp(40px, 13vw, 58px); line-height: .92; letter-spacing: -1px; text-shadow: 0 4px 0 var(--plum); }
.menu-sign h1 span { color: var(--honey); }
.menu-sign p { margin: 0; font-weight: var(--fw-text); opacity: .92; font-size: 15px; }
.menu-shelf {
  display: flex; justify-content: center; align-items: flex-end; gap: 4px; padding: 14px 12px 0; margin: 12px 4px 0;
  background: linear-gradient(#fff4dc, #f4e2be); border: 8px solid var(--chestnut); border-bottom-width: 0; border-radius: 18px 18px 0 0;
  position: relative; min-height: 120px;
}
.menu-shelf::after { content: ""; position: absolute; left: -8px; right: -8px; bottom: -14px; height: 16px; border-radius: 4px; background: linear-gradient(#ffcf73, var(--honey) 50%, var(--honey-d)); box-shadow: 0 6px 10px rgba(85, 38, 15, .3); }
.menu-shelf img { width: 19%; max-width: 86px; animation: bob 3.2s ease-in-out infinite; }
.menu-shelf img:nth-child(2n) { animation-delay: -1.1s; }
.menu-shelf img:nth-child(3n) { animation-delay: -2s; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.menu-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.menu-row b:empty, .menu-row b[data-zero] { display: none; }
/* Shorter phones: the menu now has a Daily button, so the sign and shelf give up some height. */
@media (max-height: 860px) {
  .menu-actions { gap: 10px; margin-top: 14px; }
  .menu-actions .btn-link { min-height: 40px; padding: 6px; }
  .menu-sign { margin-top: 2px; }
  .menu-sign { padding: 12px 14px 14px; }
  .menu-sign h1 { font-size: clamp(36px, 11vw, 50px); }
  .menu-shelf { min-height: 96px; padding-top: 10px; }
  .menu-shelf img { max-width: 64px; }
}
.menu-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.menu-row .btn { position: relative; white-space: nowrap; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 9px 4px 8px; font-size: 14px; min-width: 0; }
.menu-row .btn .ic { width: 1.6em; height: 1.6em; }
.menu-row .btn span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.menu-row .lbl-short { display: none; }
/* Narrow phones: "Leaderboard" can't fit a third of 320 px in every font, so it says "Ranking". */
@media (max-width: 359px) { .menu-row { gap: 8px; } .menu-row .btn { font-size: 13px; padding-left: 2px; padding-right: 2px; } .menu-row .lbl-long { display: none; } .menu-row .lbl-short { display: inline; } }
/* Corner badge (like the toolbar's), so a 2–3 digit count never wraps the label onto two lines. */
.menu-row b { position: absolute; top: -7px; right: 8px; background: var(--pink); color: #fff; border-radius: 99px; min-width: 22px; padding: 2px 6px; font-size: 12px; line-height: 1.3; box-shadow: 0 2px 0 #b8457a; }

/* ── Sub screens ─────────────────────────────────────── */
.sub-head { display: flex; align-items: center; gap: 12px; padding: max(14px, env(safe-area-inset-top)) 16px 10px; background: linear-gradient(#a36ce6, var(--lilac)); color: #fff; box-shadow: 0 4px 0 var(--plum); z-index: 2; }
.sub-head h2 { flex: 1; margin: 0; font-size: 22px; text-shadow: 0 2px 0 var(--plum); }
.sub-note { margin: 14px 16px 2px; color: var(--muted); font-weight: var(--fw-text); font-size: 14px; }
.level-grid { padding: 18px 16px 30px; display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 12px; overflow-y: auto; }
.lvl {
  aspect-ratio: 1; border: 0; border-radius: 18px; background: #fff; box-shadow: 0 4px 0 #d9c9ef; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: var(--fw-heavy); font-size: 20px; color: var(--plum); gap: 2px;
}
.lvl small { font-size: 11px; letter-spacing: 1px; color: var(--honey-d); }
.lvl.current { background: linear-gradient(#ffd47e, var(--honey)); color: var(--chestnut-d); box-shadow: 0 4px 0 var(--honey-d); animation: pulse 1.6s ease-in-out infinite; }
.lvl.locked { background: #efe6d4; color: #b8a58c; box-shadow: 0 4px 0 #dcccb0; pointer-events: none; }
.lvl.boss::after { content: "♛"; position: absolute; transform: translate(22px, -24px); font-size: 13px; color: var(--pink); }
@keyframes pulse { 50% { transform: scale(1.05); } }
.collection { overflow-y: auto; padding: 8px 14px 30px; }
.fam { margin-top: 14px; }
.fam h3 { margin: 0 0 6px 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--chestnut); display: flex; justify-content: space-between; }
.fam-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.ccard { background: #fff; border-radius: 12px; padding: 4px 2px 5px; text-align: center; box-shadow: 0 2px 0 #e5d6be; }
.ccard img { width: 100%; aspect-ratio: 110/150; display: block; }
.ccard span { display: block; font-size: 10px; font-weight: var(--fw-bold); line-height: 1.1; min-height: 2.2em; color: var(--ink); padding: 0 2px; }
.ccard.unknown img { filter: brightness(0) opacity(.18); }
.ccard.unknown span { color: #bba98f; }

/* ── HUD ─────────────────────────────────────────────── */
.hud {
  display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(#a36ce6, var(--lilac)); color: #fff; box-shadow: 0 4px 0 var(--plum); z-index: 3;
}
.hud-btn { width: 42px; height: 42px; font-size: 14px; letter-spacing: -2px; }
.hud-mid { flex: 1; min-width: 0; }
.hud-level { font-weight: var(--fw-bold); font-size: 14px; display: flex; gap: 6px; align-items: center; }
.hud-level b { font-size: 18px; }
#hudTag:not(:empty) { background: var(--pink); border-radius: 99px; font-size: 10px; padding: 2px 7px; letter-spacing: .6px; text-transform: uppercase; }
.hud-progress { position: relative; height: 16px; background: rgba(0, 0, 0, .22); border-radius: 99px; margin-top: 4px; overflow: hidden; }
.hud-bar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--honey), #ffd47e); border-radius: 99px; transition: width .4s var(--ease-out); }
.hud-progress span { position: relative; display: block; text-align: center; font-size: 11px; font-weight: var(--fw-heavy); line-height: 16px; text-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
.hud-timer {
  min-width: 70px; text-align: center; font-weight: var(--fw-heavy); font-size: 18px; background: rgba(0, 0, 0, .22); border-radius: 14px; padding: 8px 8px;
  font-variant-numeric: tabular-nums;
}
.hud-timer.warn { background: var(--danger); animation: pulse .9s ease-in-out infinite; }
.hud-timer.paused { opacity: .7; }

.coach {
  /* fixed height (2 lines) so changing messages never push the shelves down */
  --coach-lh: 1.25;
  margin: 10px 12px 0; height: calc(2em * var(--coach-lh) + 20px); flex: none; padding: 8px 14px; border-radius: 14px; background: #fff3dd; border: 2px solid #f3d6a2;
  font-weight: var(--fw-bold); font-size: 14px; line-height: var(--coach-lh); color: var(--chestnut); display: flex; align-items: center; justify-content: center; text-align: center;
  overflow: hidden; transition: background .2s;
}
.coach-in { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.coach.hot { background: #ffe4f0; border-color: #f7b4d1; color: #8c2a5b; }
.coach img { height: 1.5em; vertical-align: -.4em; margin-right: 4px; }

/* ── Board / cabinet ─────────────────────────────────── */
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: var(--wrap-pad); position: relative; }
.board-wrap.scroll {
  overflow-y: auto; align-items: flex-start; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  /* soft top/bottom edges show there are more shelves above/below (instead of a hard cut) */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}
.board-wrap.scroll .bays { touch-action: pan-y; }
.board-wrap.scroll .cabinet { margin-bottom: 14px; }
.cabinet {
  padding: var(--cab-pad) var(--cab-pad) 4px; border-radius: 20px;
  background: linear-gradient(90deg, #6b3219, var(--chestnut) 8%, #96512e 50%, var(--chestnut) 92%, #6b3219);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .25), 0 10px 0 var(--chestnut-d), 0 18px 30px rgba(64, 42, 43, .35);
}
.bays { display: grid; gap: var(--gap-y) var(--gap-x); touch-action: none; }
.bay { position: relative; border-radius: 10px 10px 4px 4px; padding: 6px var(--bay-pad) 0; background: linear-gradient(#5e2b14, #3e1c0d); }
.bay-inner {
  position: relative; border-radius: 7px 7px 0 0; overflow: hidden;
  background: radial-gradient(120% 70% at 50% 0%, #fff6dc, #f3dfb6 60%, #e2c792);
  box-shadow: inset 0 8px 12px -6px rgba(255, 220, 140, .9), inset 6px 0 10px -6px rgba(85, 38, 15, .45), inset -8px 0 12px -6px rgba(85, 38, 15, .6);
  height: calc(var(--ch) * 1.06); width: calc(var(--cw) * 3);
}
.bay-front { position: absolute; left: 0; right: 0; display: grid; grid-template-columns: repeat(3, var(--cw)); justify-content: center; }
.bay-front { bottom: 0; }
.cell {
  position: relative; width: var(--cw); height: var(--ch); border: 0; padding: 0; background: none; display: flex; align-items: flex-end; justify-content: center;
  border-radius: 8px;
}
.cell img.item { width: 94%; height: auto; pointer-events: none; transition: transform .12s var(--ease-out), filter .12s; filter: drop-shadow(0 2px 1px rgba(64, 42, 43, .25)); will-change: transform; }
.cell.empty::after { content: ""; position: absolute; left: 18%; right: 18%; bottom: 4px; height: 6px; border-radius: 50%; background: rgba(125, 62, 35, .14); }
.cell.selected img.item { transform: translateY(calc(var(--ch) * -.1)) scale(1.08); filter: drop-shadow(0 10px 6px rgba(64, 42, 43, .35)) drop-shadow(0 0 6px rgba(255, 255, 255, .9)); }
.cell.lifting img.item { opacity: .28; }
.bay.can-drop .cell.empty::before {
  content: ""; position: absolute; inset: 6px 3px 2px; border-radius: 10px; border: 2.5px dashed var(--mint); background: rgba(69, 181, 138, .14);
  animation: drop-pulse 1s ease-in-out infinite;
}
.bay.can-drop.drop-hover .cell.empty::before { background: rgba(69, 181, 138, .38); border-style: solid; }
.bay.can-drop .bay-inner { box-shadow: inset 0 0 0 3px rgba(69, 181, 138, .7), inset 0 8px 12px -6px rgba(255, 220, 140, .9); }
@keyframes drop-pulse { 50% { opacity: .55; } }
.cell.hint-src img.item { animation: hint-bounce .7s ease-in-out infinite; }
.cell.hint-dst::before {
  content: ""; position: absolute; inset: 6px 3px 2px; border-radius: 10px; border: 3px solid var(--pink); background: rgba(242, 116, 170, .2);
  animation: drop-pulse .7s ease-in-out infinite;
}
@keyframes hint-bounce { 50% { transform: translateY(-10px) scale(1.06); } }

.lip {
  position: relative; height: 18px; margin: 0 calc(-1 * var(--bay-pad)); border-radius: 3px;
  background: linear-gradient(#ffd885, var(--honey) 45%, var(--honey-d));
  box-shadow: 0 4px 6px rgba(40, 15, 5, .45), inset 0 1px 0 rgba(255, 255, 255, .6);
  display: flex; align-items: center; justify-content: center; gap: 3px;
}
.shelf-tag {
  /* price-label style tag on the shelf lip: how many rows are stacked behind */
  padding: 0 6px; border-radius: 3px; background: var(--cream); border: 1px solid var(--chestnut);
  color: var(--chestnut-d); font-size: 11px; font-weight: var(--fw-heavy); line-height: 14px;
  white-space: nowrap; box-shadow: 0 1px 0 rgba(85, 38, 15, .35); font-variant-numeric: tabular-nums;
}
.shelf-tag.pop { animation: tag-pop .5s var(--ease-out); }
@keyframes tag-pop { 0% { transform: scale(1); } 35% { transform: scale(1.3); background: #ffe4f0; } 100% { transform: scale(1); } }

/* modifiers */
.cell.frozen::after {
  content: ""; position: absolute; left: 4%; right: 4%; bottom: 2px; top: 18%; border-radius: 10px;
  background: linear-gradient(160deg, rgba(225, 248, 255, .78), rgba(160, 215, 240, .55)); border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: inset 0 0 8px rgba(80, 160, 210, .6);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3v18M4.2 7.5l15.6 9M4.2 16.5l15.6-9M9.6 4.6 12 7l2.4-2.4M9.6 19.4 12 17l2.4 2.4' fill='none' stroke='%233d8ec2' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E"), linear-gradient(160deg, rgba(225, 248, 255, .78), rgba(160, 215, 240, .55));
  background-repeat: no-repeat; background-size: calc(var(--cw) * .3) auto, auto; background-position: right 3px top 3px, 0 0;
}
.bay.locked .bay-front { filter: grayscale(.6) brightness(.8); }
.lock-tag {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(-45deg, rgba(64, 42, 43, .0) 0 12px, rgba(64, 42, 43, .12) 12px 16px);
}
.lock-tag span {
  background: var(--ink); color: #fff; font-weight: var(--fw-heavy); border-radius: 12px; padding: 6px 10px; font-size: calc(var(--cw) * .27);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .3); border: 2px solid var(--honey);
}
.bay.unlocking .lock-tag { animation: unlock .5s var(--ease-out) forwards; }
@keyframes unlock { to { opacity: 0; transform: scale(1.4); } }

/* animations */
.cell.pop img.item { animation: pop .3s var(--ease-out) forwards; }
@keyframes pop { 40% { transform: scale(1.22) translateY(-8px); filter: brightness(1.4); } 100% { transform: scale(0); opacity: 0; } }
.cell.promote img.item { animation: promote .32s var(--ease-out); }
@keyframes promote { from { transform: translateY(18%) scale(.7); opacity: 0; } }
.cell.shake img.item { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.sparkle { position: fixed; pointer-events: none; z-index: 40; width: 10px; height: 10px; border-radius: 50%; background: var(--honey); box-shadow: 0 0 8px var(--honey); }
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; width: calc(var(--cw) * 1.12); transform: translate(-50%, -62%) scale(1.08); filter: drop-shadow(0 14px 8px rgba(64, 42, 43, .35)); }
.score-float {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); pointer-events: none; font-weight: var(--fw-heavy); font-size: 32px;
  color: #fff; text-shadow: 0 3px 0 var(--plum), 0 0 12px rgba(140, 83, 215, .6); opacity: 0; z-index: 20; white-space: nowrap;
}
.score-float.show { animation: float-up .9s var(--ease-out); }
@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.7); } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -120%) scale(1); } }

/* ── Toolbar ─────────────────────────────────────────── */
.toolbar {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px 12px max(12px, env(safe-area-inset-bottom));
}
.tool {
  position: relative; border: 0; border-radius: 16px; background: #fff; box-shadow: 0 4px 0 #d9c9ef; padding: 7px 4px 6px; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--plum); transition: transform .08s;
}
.tool:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9c9ef; }
.tool .ico { width: 28px; height: 28px; overflow: visible; }
.tool .ico .st { fill: none; stroke: var(--plum); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tool .ico .st.thin { stroke-width: 2; }
.tool .ico .fl { fill: var(--honey); }
.tool .ico .st.fl { fill: var(--honey); }
.tool .ico .hi { fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; opacity: .85; }
.tool .tl { font-size: 12px; font-weight: var(--fw-heavy); }
.tool .badge { position: absolute; top: -6px; right: 6px; background: var(--pink); color: #fff; font-style: normal; font-weight: var(--fw-heavy); font-size: 12px; border-radius: 99px; min-width: 22px; padding: 2px 6px; box-shadow: 0 2px 0 #b8457a; }
.tool[disabled] { opacity: .45; pointer-events: none; }
.tool.empty { opacity: .5; }
.tool.empty .badge { background: #b9a9c9; box-shadow: none; }
.tool.nudge { animation: pulse .8s ease-in-out 3; background: #fff3dd; }

/* ── Modal ───────────────────────────────────────────── */
.modal-back { position: absolute; inset: 0; background: rgba(48, 24, 40, .48); display: grid; place-items: center; z-index: 60; padding: 18px; backdrop-filter: blur(2px); }
.modal-back[hidden] { display: none; }
.modal {
  width: 100%; max-width: 380px; background: var(--cream); border-radius: 26px; border: 6px solid var(--chestnut);
  box-shadow: 0 8px 0 var(--chestnut-d), var(--shadow); overflow: hidden; animation: modal-in .28s var(--ease-out);
  max-height: 92%; display: flex; flex-direction: column;
}
@keyframes modal-in { from { transform: scale(.85); opacity: 0; } }
.modal-head { background: linear-gradient(#a36ce6, var(--lilac)); color: #fff; text-align: center; padding: 14px 16px 12px; }
.modal-head h2 { margin: 0; font-size: 26px; text-shadow: 0 3px 0 var(--plum); }
.modal-head p { margin: 4px 0 0; font-weight: var(--fw-text); opacity: .9; font-size: 14px; }
.modal-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.modal-body p { margin: 0; font-weight: var(--fw-text); text-align: center; line-height: 1.4; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stars { display: flex; justify-content: center; gap: 8px; font-size: 46px; line-height: 1; margin-top: -4px; }
.stars span { color: #e3d4bb; text-shadow: 0 3px 0 #cdb894; }
.stars span.on { color: var(--honey); text-shadow: 0 3px 0 var(--honey-d); animation: star-in .45s var(--ease-out) backwards; }
.stars span.on:nth-child(2) { animation-delay: .15s; }
.stars span.on:nth-child(3) { animation-delay: .3s; }
@keyframes star-in { from { transform: scale(0) rotate(-40deg); } }
.stat-row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.stat { background: #fff; border-radius: 14px; padding: 6px 18px 7px; min-width: 104px; box-shadow: 0 2px 0 #e5d6be; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.stat span { font-size: 11px; font-weight: var(--fw-bold); letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: 24px; line-height: 1.05; color: var(--plum); font-variant-numeric: tabular-nums; }
.new-items { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.new-items figure { margin: 0; width: 64px; text-align: center; font-size: 11px; line-height: 1.2; font-weight: var(--fw-bold); }
.new-items img { width: 100%; }
.muted-sm { font-size: 13px; color: var(--muted); }
.modal-body .reward { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; font-weight: var(--fw-heavy); color: var(--plum); background: #fff3dd; border-radius: 12px; padding: 6px 10px; }
.reward .ic { width: 1.2em; height: 1.2em; }
.muted-xs { font-size: 12px; }
.modal-body .intro-text { text-align: left; font-size: 14px; margin-top: 2px; }
.howto { display: grid; gap: 10px; }
.howto-step { display: grid; grid-template-columns: 54px 1fr; gap: 10px; align-items: center; background: #fff; border-radius: 14px; padding: 8px 10px; box-shadow: 0 2px 0 #e5d6be; }
.howto-step .ill { font-size: 30px; text-align: center; }
.howto-step .ill img { width: 40px; }
.howto-step b { display: block; color: var(--plum); }
.howto-step span { font-size: 13px; font-weight: var(--fw-text); color: var(--muted); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #fff; border-radius: 14px; padding: 10px 12px; box-shadow: 0 2px 0 #e5d6be; font-weight: var(--fw-bold); }
.setting small { display: block; font-weight: var(--fw-text); color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #d9cdbb; border-radius: 99px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch input:checked + span { background: var(--mint); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 3px solid var(--pink); outline-offset: 2px; }
.intro-card { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; text-align: left; }
.intro-card .ill { position: relative; width: 64px; }
.intro-card .ill img { width: 100%; }

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: absolute; left: 50%; bottom: 96px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; font-weight: var(--fw-bold);
  padding: 10px 16px; border-radius: 14px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 70;
  max-width: calc(100% - 32px); text-align: center; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* reduced motion */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
.reduce-motion .cell.hint-src img.item, .reduce-motion .cell.hint-dst::before, .reduce-motion .bay.can-drop .cell.empty::before { animation: none !important; }

@media (min-width: 560px) and (min-height: 700px) {
  body { padding: 18px 0; }
  #app { height: calc(100dvh - 36px); border-radius: 30px; border: 8px solid var(--chestnut); box-shadow: 0 10px 0 var(--chestnut-d), var(--shadow); }
}
/* Installed iPhone app: iOS can lay the page out shorter than the screen (793 of 852 pt on
   iPhone 16), and only the page background paints the strip below. Match the app's bottom
   colour so it reads as part of the toolbar, not a stray band. */
@media (display-mode: standalone) and (max-width: 559px) {
  html, body { background: var(--vanilla); }
}
/* compact phones (set by JS: width < 380 or height < 680) */
.compact { --wrap-pad: 6px; --cab-pad: 6px; --gap-x: 6px; --gap-y: 8px; --bay-pad: 3px; }
.compact .hud { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
.compact .coach { height: calc(2em * var(--coach-lh) + 12px); padding: 4px 10px; font-size: 13px; margin: 6px 8px 0; }
.compact .toolbar { padding-top: 6px; gap: 6px; }
.compact .tool { min-height: 50px; }
@media (max-height: 640px) { .menu-shelf { min-height: 90px; } }

/* landscape phones: use the full width, let the menu scroll */
@media (orientation: landscape) and (max-height: 520px) {
  #app { max-width: none; }
  #screen-menu { overflow-y: auto; justify-content: flex-start; gap: 12px; }
  .menu-shelf { display: none; }
  .menu-actions { margin-top: 0; max-width: 520px; width: 100%; align-self: center; }
  .menu-sign { max-width: 520px; align-self: center; padding: 10px 14px 12px; border-width: 5px; }
  .menu-sign h1 { font-size: 34px; line-height: 1; margin: 4px 0; }
  .menu-sign h1 br { display: none; }
  .menu-sign h1 span { margin-left: .28em; }
  .menu-sign p { font-size: 13px; }
  .menu-actions { gap: 8px; }
  .btn-xl { padding: 11px 18px; font-size: 18px; }
}

/* short screens (landscape phones): compact pop-ups, buttons in one row */
@media (max-height: 520px) {
  .modal-back { padding: 8px; }
  .modal { max-width: 560px; max-height: 96%; }
  .modal-head { padding: 8px 14px; }
  .modal-head h2 { font-size: 20px; }
  .modal-body { padding: 10px 14px 12px; gap: 8px; }
  .stars { font-size: 30px; }
  .stat { padding: 3px 14px 4px; }
  .stat b { font-size: 19px; }
  .new-items figure { width: 50px; font-size: 10px; }
  .modal-actions { flex-direction: row; flex-wrap: wrap; }
  .modal-actions > .btn { flex: 1 1 140px; }
  .modal-actions .row { display: contents; }
  .modal-actions .row > .btn { flex: 1 1 110px; }
  .btn-xl { font-size: 17px; padding: 11px 16px; }
  .btn { min-height: 44px; padding: 10px 14px; }
}

/* touch: no long-press image menu or image dragging */
img { -webkit-user-drag: none; -webkit-touch-callout: none; }
body { -webkit-touch-callout: none; }


/* ── Icon set ────────────────────────────────────────── */
.ic { width: 1.2em; height: 1.2em; vertical-align: -.24em; flex: none; overflow: visible; }
.ic .s { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ic .f { fill: var(--honey); }
.ic .s.f { fill: var(--honey); }
.ic .c { fill: currentColor; }
.ic-lg { width: 22px; height: 22px; }
.ic-xl { width: 34px; height: 34px; }
.ic-xxl { width: 48px; height: 48px; }
.ill-ic { display: grid; place-items: center; color: var(--plum); }
.howto-step .ill { color: var(--plum); }
.icon-btn .ic { width: 24px; height: 24px; }
.lock-tag span { display: inline-flex; align-items: center; gap: 4px; }
.lock-tag .ic { color: #fff; }
.lvl.locked .ic { color: #b8a58c; }
.lvl.locked .ic .f { fill: #e2d4bb; }
.toast .ic { color: var(--honey); }
.toast .ic .f { fill: var(--honey); }
.coach .ic { width: 1.4em; height: 1.4em; vertical-align: -.35em; margin: 0 2px; }

/* ── Daily, player name, leaderboard ─────────────────── */
.btn-daily { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 17px; }
.btn-sm { min-height: 40px; padding: 8px 12px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; flex: none; }

.name-form { display: flex; flex-direction: column; gap: 8px; }
.name-label { font-weight: var(--fw-heavy); color: var(--plum); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.name-label small { font-weight: var(--fw-bold); color: #8a7b97; font-size: 12px; }
.name-input {
  font-size: 18px; /* 16px+ so iOS doesn't zoom in */
  font-weight: var(--fw-heavy); color: var(--ink); padding: 12px 14px; border-radius: 14px;
  border: 2px solid #d9c9ef; background: #fff; -webkit-user-select: text; user-select: text; width: 100%;
}
.name-input:focus { outline: none; border-color: var(--lilac); box-shadow: 0 0 0 3px rgba(140, 83, 215, .2); }
.name-error { color: #c0335f; font-weight: var(--fw-bold); font-size: 13px; min-height: 1.2em; margin: 0; }

.lb { background: #fff; border-radius: 16px; padding: 10px 12px; box-shadow: 0 3px 0 #ecdcc0; text-align: left; }
.lb-title { display: flex; align-items: center; gap: 6px; font-weight: var(--fw-heavy); color: var(--plum); font-size: 15px; }
.lb-note { margin: 6px 0; font-size: 13px; color: #6d5e7a; font-weight: var(--fw-bold); }
.lb-list { list-style: none; margin: 6px 0 0; padding: 0; font-size: 14px; font-weight: var(--fw-bold); }
.lb-list li { display: grid; grid-template-columns: 2.2em 1fr 3.4em 3.4em; gap: 6px; align-items: center; padding: 5px 6px; border-radius: 10px; }
.lb-list li:nth-child(odd):not(.lb-headrow) { background: #faf5ec; }
.lb-list .lb-headrow { font-size: 11px; color: #8a7b97; text-transform: uppercase; letter-spacing: .4px; padding-bottom: 2px; }
.lb-list li.me { background: #fde3ef; color: #9b2a5f; }
.lb-list .lb-gap { display: block; text-align: center; color: #b9a9c9; padding: 0; }
.lb-rank { color: #8a7b97; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-moves, .lb-time { text-align: right; font-variant-numeric: tabular-nums; }
.lb-more { display: block; margin: 4px auto 0; min-height: 40px; }
.lb-full { max-height: 58vh; overflow-y: auto; }

/* ── Leaderboards screen ─────────────────────────────── */
#screen-leaders { overflow: hidden; }
.lb-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 14px 16px 0; padding: 4px; background: #ecdfc6; border-radius: 16px; }
.lb-tab { border: 0; min-height: 44px; border-radius: 12px; background: transparent; color: var(--plum); font-weight: var(--fw-heavy); font-size: 15px; }
.lb-tab.on { background: #fff; box-shadow: 0 3px 0 #d9c9ef; }
.lb-sub { margin: 10px 16px 0; text-align: center; font-size: 13px; color: #6d5e7a; font-weight: var(--fw-bold); }
.lb-all li { grid-template-columns: 2.2em 1fr 3.2em 4.6em; }
.lb-screen { margin: 10px 14px 16px; flex: 1; min-height: 0; overflow-y: auto; }

.lb-rename { margin: 6px auto 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.name-alt { align-self: center; }
.fireworks { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 65; pointer-events: none; }

/* Win screen: progress to the next gift box */
.goal { background: #fff3dd; border-radius: 14px; padding: 8px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.goal.opened { background: linear-gradient(#fff3dd, #ffe2ef); box-shadow: 0 0 0 2px var(--pink) inset; }
.goal-pips { display: flex; gap: 6px; }
.goal-pips i { width: 26px; height: 8px; border-radius: 99px; background: #e9d9bd; }
.goal-pips i.on { background: var(--honey); }
.goal-pips i.gift { background: #f6c6dc; }
.goal-pips i.gift.on { background: var(--pink); }
.modal-body .goal-text { margin: 0; font-weight: var(--fw-heavy); color: var(--plum); font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.modal-body .goal-extra { margin: 0; font-size: 13px; font-weight: var(--fw-bold); color: #6d5e7a; display: flex; gap: 4px; align-items: center; justify-content: center; }
.goal .ic { width: 1.15em; height: 1.15em; }
.lvl { position: relative; }
.lvl .gift-mark { position: absolute; top: -6px; right: -4px; font-style: normal; font-size: 16px; line-height: 1; }

/* Win pop-up: the buttons stay visible at the bottom; the rest scrolls above them on short phones. */
.modal-body .modal-actions.pinned { position: sticky; bottom: -18px; margin: 0 -18px -18px; padding: 10px 18px 18px; background: linear-gradient(rgba(255, 248, 234, 0), var(--cream) 14px); z-index: 1; }
/* Short or narrow phones: stars and stats take less room, so the gift row stays in view. */
@media (max-height: 700px), (max-width: 359px) {
  .stars { font-size: 34px; }
  .stat-row { flex-wrap: nowrap; gap: 6px; }
  .stat { min-width: 0; flex: 1 1 0; padding: 5px 6px 6px; }
  .stat span { font-size: 10px; letter-spacing: .6px; }
  .stat b { font-size: 19px; }
  .modal-body { gap: 9px; }
}
/* Phones: a calmer type scale (titles and big buttons were sized for tablets). */
@media (max-width: 480px) {
  .btn-xl { font-size: 18px; padding: 13px 18px; }
  .btn { font-size: 15px; }
  .btn-daily { font-size: 16px; }
  .menu-sign h1 { font-size: clamp(34px, 11vw, 46px); }
  .menu-sign p { font-size: 14px; }
  .sub-head h2 { font-size: 20px; }
  .modal-head h2 { font-size: 22px; }
  .modal-head p { font-size: 13px; }
  .modal-body p { font-size: 14px; }
  .stat b { font-size: 21px; }
  .hud-level b { font-size: 16px; }
  .hud-timer { font-size: 16px; min-width: 62px; }
  .score-float { font-size: 26px; }
  .coach { font-size: 14px; }
  .lb-list { font-size: 13px; }
  .name-chip { font-size: 14px; }
}
@media (max-width: 359px) {
  .btn-xl { font-size: 17px; }
  .modal-head h2 { font-size: 20px; }
  .menu-sign h1 { font-size: 32px; }
}

/* Coins + shop */
.menu-top-right { display: flex; align-items: center; gap: 8px; }
.coin-pill { border: 0; min-height: 44px; padding: 8px 14px; border-radius: 99px; background: linear-gradient(#ffe6a8, var(--honey)); color: var(--chestnut-d); font-weight: var(--fw-heavy); font-size: 15px; box-shadow: 0 3px 0 var(--honey-d); white-space: nowrap; }
.coin-pill b { font-variant-numeric: tabular-nums; }
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-item { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 8px 10px; box-shadow: 0 2px 0 #e5d6be; }
.shop-ic { color: var(--plum); flex: none; }
.shop-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.shop-txt b { color: var(--plum); font-size: 15px; }
.shop-txt small { color: #6d5e7a; font-weight: var(--fw-bold); font-size: 12px; }
.shop-item .btn-sm { min-width: 76px; justify-content: center; }
.modal-body .shop-note { background: #ffe2ef; color: #9b2a5f; border-radius: 12px; padding: 6px 10px; font-weight: var(--fw-heavy); }

.setting-btns { display: flex; gap: 6px; flex: none; }
.modal-body .backup-code { font-family: ui-monospace, Menlo, monospace; font-size: 15px; font-weight: 700; background: #fff; border: 2px dashed #d9c9ef; border-radius: 12px; padding: 10px; word-break: break-all; user-select: all; -webkit-user-select: all; color: var(--plum); }
.coin-pill { display: inline-flex; align-items: center; gap: 4px; }
.coin-pill .ic, .shop-item .btn-sm .ic { width: 1.2em; height: 1.2em; }
