/* Board-first layout. Compact controls on phones; a separate order rail on wide screens.
   layout() measures the remaining board area, including safe-area padding. */

@font-face {
  font-family: 'Lilita';
  src: url(./assets/fonts/LilitaOne-Regular.ttf) format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'KuaiLe';
  src: url(./assets/fonts/kuaile.woff2) format('woff2');
  font-display: swap;
}

:root {
  --ink: #2a2346;
  --night: #1a1030;
  --pink: #ff5fa2;
  --pink-deep: #e0337f;
  --pink-soft: #ffd3e8;
  --gold: #ffc83d;
  --gold-deep: #f5a623;
  --cream: #fff6e6;
  --mint: #5fe39a;
  --green: #22a55b;
  --cell: 52px;
  --orders-h: 96px;
  --col: min(100vw, 560px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --display: 'Lilita', 'KuaiLe', "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --body: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-family: var(--display);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  /* Keep Safari's document from panning behind the game's own scroll containers. */
  position: fixed;
  inset: 0;
  width: 100%;
  background: #2a1d3d url(./assets/ui/bg-board.webp) center top / cover no-repeat;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(26, 16, 48, .55) 0%, rgba(26, 16, 48, .15) 22%, rgba(26, 16, 48, .25) 60%, rgba(26, 16, 48, .8) 100%);
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; touch-action: manipulation; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
img { -webkit-user-drag: none; user-select: none; pointer-events: none; }
[hidden] { display: none !important; }

/* Outlined game numbers and labels. */
.num, .stroke { color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; letter-spacing: .5px; }

#app {
  position: relative;
  /* Allow the order rail to pan, but do not turn play gestures into page zoom. */
  touch-action: pan-x pan-y;
  width: var(--col);
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 4px) 6px calc(var(--safe-bottom) + 8px);
  gap: 5px;
}

/* ---------- HUD ---------- */
#hud { flex: 0 0 44px; display: flex; align-items: center; gap: 6px; padding-left: 4px; }
.pill {
  position: relative; height: 34px; display: flex; align-items: center; padding: 0 10px 0 30px; margin-left: 12px;
  background: linear-gradient(180deg, #43315f, #261a3d); border: 2.5px solid var(--night); border-radius: 17px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .18), 0 3px 0 rgba(0, 0, 0, .35);
}
.pill-icon { position: absolute; left: -14px; top: 50%; width: 42px; height: 42px; transform: translateY(-50%); filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .35)); }
.pill-val { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.pill b { font-size: 19px; font-weight: 400; }
.pill small { font-family: var(--body); font-size: 9px; font-weight: 700; color: #ffe8a3; margin-top: 1px; min-height: 9px; }
#hud-energy { flex: 0 0 auto; }
#hud-energy .plus {
  font-style: normal; width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; margin-left: 6px;
  background: linear-gradient(180deg, #7cf0b0, var(--green)); border: 2px solid var(--night); color: #fff; font-size: 15px; line-height: 1;
  -webkit-text-stroke: 2px var(--night); paint-order: stroke fill;
}
#hud-coins { flex: 1 1 auto; min-width: 72px; }
.pill.small { height: 30px; }
.pill.small .pill-icon { width: 36px; height: 36px; left: -12px; }
.hud-level { flex: 0 1 132px; min-width: 96px; display: flex; align-items: center; position: relative; }
.level-badge {
  position: relative; z-index: 2; flex: 0 0 auto; width: 44px; height: 44px; display: grid; place-items: center;
  background: url(./assets/ui/star.webp) center/contain no-repeat; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .35));
}
.level-badge b { font-size: 17px; margin-top: 3px; }
.xp-track {
  position: relative; flex: 1 1 auto; height: 20px; margin-left: -12px; border-radius: 0 10px 10px 0; overflow: hidden;
  background: #1f1533; border: 2.5px solid var(--night); box-shadow: inset 0 2px 3px rgba(0, 0, 0, .4);
}
.xp-track i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(180deg, #ffa2cd, var(--pink) 60%, #d63a82); transition: width .5s cubic-bezier(.3, 1.4, .5, 1); }
.xp-track em { position: absolute; inset: 0; display: grid; place-items: center; font-style: normal; font-size: 12px; -webkit-text-stroke: 3px var(--night); padding-left: 8px; }
.round-btn {
  flex: 0 0 36px; height: 36px; border-radius: 18px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(180deg, #43315f, #261a3d); border: 2.5px solid var(--night); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .18), 0 3px 0 rgba(0, 0, 0, .35);
}
.round-btn svg { width: 22px; height: 22px; }
.bump { animation: bump .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 40% { transform: scale(1.18); } }

/* ---------- Orders ---------- */
#goals { flex: 0 0 54px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; min-height: 0; }
.goal { display: flex; align-items: center; gap: 5px; padding: 3px 6px; border: 2px solid var(--night); border-radius: 13px; background: #fff4df; color: var(--ink); text-align: left; min-width: 0; box-shadow: 0 2px 0 var(--night); }
.goal img { width: 38px; height: 38px; object-fit: contain; flex-shrink: 0; }
.goal span { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.goal b { font-size: 14px; font-weight: 400; white-space: nowrap; }
.goal small, .goal em { font: 700 10px/1.25 var(--body); white-space: nowrap; }
.goal small { color: #776181; }
.goal em { color: #9e365e; }
.collection-goal { background: #ffe2ee; }
.weekly-goal { display: none; }
.goal:active { transform: translateY(2px); }
#order-panel { flex: 0 0 118px; min-width: 0; min-height: 0; }
.order-heading { height: 22px; display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 0 4px; }
.order-heading b { font-size: 13px; font-weight: 400; }
.order-heading span { font: 700 11px var(--body); color: #ffe29a; }
.order-heading small { font: 10px var(--body); color: #ead9ec; }
#orders {
  height: var(--orders-h); display: flex; gap: 7px; overflow-x: auto; overflow-y: hidden; align-items: flex-start;
  scrollbar-width: none; touch-action: pan-x; padding: 2px 2px 5px; scroll-snap-type: x proximity;
}
#orders::-webkit-scrollbar { display: none; }
.order {
  --w: 158px;
  --who: 32px;
  position: relative; flex: 0 0 var(--w); height: 86px; border-radius: 14px; scroll-snap-align: start;
  background: linear-gradient(180deg, #fffdf7 0%, #ffeccf 100%); color: var(--ink); border: 3px solid var(--night);
  box-shadow: 0 4px 0 var(--night), inset 0 -4px 0 rgba(214, 150, 90, .25);
  display: flex; flex-direction: column; justify-content: flex-end; padding: 3px 5px 3px 38px;
  transition: transform .15s;
}
.order:active { transform: translateY(2px); }
.order .who {
  position: absolute; left: 4px; top: 10px; width: var(--who); height: var(--who); z-index: 2;
  filter: drop-shadow(0 3px 0 rgba(26, 16, 48, .35));
}
.order .who img { width: 100%; height: 100%; object-fit: contain; }
.order .name {
  position: absolute; left: 3px; top: 45px; z-index: 3; font-size: 10px; padding: 0 3px; border-radius: 8px;
  background: var(--ink); color: #fff; white-space: nowrap; line-height: 16px;
}
.order .needs { flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0; }
.need {
  --n: 42px;
  position: relative; width: var(--n); height: var(--n); border-radius: 12px;
  background: radial-gradient(circle at 50% 40%, #fff, #f3e3cc); box-shadow: inset 0 -2px 0 rgba(160, 110, 70, .25);
}
.need img { width: 100%; height: 100%; padding: 2px; }
.needs.n2 .need { width: calc(var(--n) - 4px); height: calc(var(--n) - 4px); }
.order:has(.needs.n3) { --w: 184px; }
.needs.n3 .need { width: 40px; height: 40px; border-radius: 9px; }
.needs.n3 { gap: 1px; }
.need.have::after {
  content: '✓'; position: absolute; right: -4px; bottom: -4px; width: 18px; height: 18px; border-radius: 9px; background: var(--green); color: #fff;
  font-size: 12px; display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 0 rgba(0, 0, 0, .3);
}
.need .lv { position: absolute; left: -3px; bottom: -4px; font-size: 10px; min-width: 16px; height: 16px; line-height: 13px; text-align: center; color: #fff; background: var(--ink); border-radius: 8px; border: 1.5px solid #fff; }
.order .reward { display: flex; align-items: center; justify-content: center; gap: 2px; font-size: 13px; height: 18px; margin-top: 4px; }
.order .reward img { width: 17px; height: 17px; }
.order .reward span { margin-right: 3px; }
.order.ready { background: linear-gradient(180deg, #f2fff6 0%, #b8f5cf 100%); box-shadow: 0 4px 0 #0f5a31, 0 0 0 3px rgba(95, 227, 154, .6), inset 0 -4px 0 rgba(34, 165, 91, .25); border-color: #0f5a31; }
.order-status { font: 700 10px/14px var(--body); color: #776181; text-align: center; }
.order.ready .order-status { color: #146c3a; }
.order .go {
  position: absolute; right: -6px; top: -8px; z-index: 3; padding: 1px 9px; border-radius: 12px; font-size: 13px;
  background: linear-gradient(180deg, #7cf0b0, var(--green)); color: #fff; border: 2.5px solid #0f5a31; box-shadow: 0 2px 0 #0f5a31;
  -webkit-text-stroke: 3px #0f5a31; paint-order: stroke fill; white-space: nowrap; animation: pulse 1s ease-in-out infinite;
}
.order.empty { background: rgba(255, 255, 255, .08); border: 2px dashed rgba(255, 255, 255, .28); box-shadow: none; align-items: center; justify-content: center; }
.order.empty .wait { font-size: 12px; color: rgba(255, 255, 255, .75); }
.order.empty .wait::before { content: ''; display: block; width: 26px; height: 26px; margin: 0 auto 4px; background: url(./assets/ui/coin.webp) center/contain no-repeat; opacity: .6; animation: spin 1.4s linear infinite; }
.order .bubble {
  position: absolute; left: 50%; top: -30px; z-index: 4; background: #fff; color: var(--ink); font-size: 12px; transform: translateX(-50%);
  padding: 3px 10px; border-radius: 12px; border: 2.5px solid var(--night); white-space: nowrap; animation: bubble 1.9s forwards;
}
@keyframes hop { 50% { transform: translate(-50%, -68%); } }
@keyframes pulse { 50% { transform: scale(1.1) rotate(4deg); } }
@keyframes spin { to { transform: rotateY(360deg); } }
@keyframes bubble { 0% { opacity: 0; transform: translateX(-50%) scale(.6); } 12% { opacity: 1; transform: translateX(-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Board ---------- */
#board-wrap { flex: 1 1 0; display: flex; align-items: center; justify-content: center; min-height: 0; touch-action: none; }
#board {
  position: relative; display: grid; grid-template-columns: repeat(7, var(--cell)); grid-auto-rows: var(--cell);
  padding: 4px; border-radius: 18px;
  background: linear-gradient(180deg, #ffa9d0 0%, #f47fb5 45%, #d9579a 100%);
  border: 3px solid var(--night);
  box-shadow: 0 6px 0 var(--night), 0 14px 24px rgba(10, 4, 24, .45), inset 0 3px 0 rgba(255, 255, 255, .5), inset 0 -3px 0 rgba(120, 20, 70, .35);
}
#board::before {
  content: ''; position: absolute; inset: 5px; border-radius: 17px; pointer-events: none;
  background: #ffe7c7; box-shadow: inset 0 3px 6px rgba(150, 70, 40, .25);
}
.cell { position: relative; width: var(--cell); height: var(--cell); }
.cell::before {
  content: ''; position: absolute; inset: 1.5px; border-radius: calc(var(--cell) * .2);
  background: linear-gradient(180deg, #fffaf1, #fff0dc); box-shadow: inset 0 -2px 0 rgba(200, 140, 90, .22);
}
.cell:nth-child(even)::before { background: linear-gradient(180deg, #ffeed6, #ffe3c0); }
.cell .piece {
  position: absolute; inset: 3px; display: grid; place-items: center; touch-action: none; z-index: 1;
  transition: transform .12s;
}
.cell .piece::after {
  content: ''; position: absolute; left: 20%; right: 20%; bottom: 3%; height: 14%; border-radius: 50%; z-index: -1;
  background: radial-gradient(ellipse at center, rgba(90, 40, 40, .28), rgba(90, 40, 40, 0) 70%);
}
.cell .piece img { width: 100%; height: 100%; object-fit: contain; }
.cell.gen::before { background: radial-gradient(circle at 50% 55%, #fff6c9 0%, #ffd66b 60%, #ffbf3d 100%); box-shadow: inset 0 -3px 0 rgba(180, 100, 20, .35), 0 0 0 2px rgba(255, 200, 61, .6); }
.cell.gen .piece { animation: breathe 2.4s ease-in-out infinite; }
.cell.gen.tired .piece { animation: none; filter: saturate(.4) brightness(.9); }
.cell .cost {
  position: absolute; right: 0; top: 0; z-index: 2; display: flex; align-items: center; height: 15px; padding: 0 3px 0 1px; border-radius: 8px;
  background: var(--ink); font-size: 10px; color: #ffe27a; pointer-events: none; border: 1.5px solid #fff;
}
.cell .cost img { width: 13px; height: 13px; }
@keyframes breathe { 50% { transform: scale(1.05) translateY(-1px); } }
.cell .lv {
  position: absolute; right: 0; bottom: 0; z-index: 2; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 8px;
  background: var(--ink); color: #fff; font-size: 11px; line-height: 13px; text-align: center; pointer-events: none; border: 1.5px solid #fff;
}
.cell .lv.max { background: linear-gradient(180deg, #ffe07a, var(--gold-deep)); color: var(--ink); }
.cell .charges { position: absolute; left: 50%; bottom: 1px; transform: translateX(-50%); display: flex; gap: 2px; pointer-events: none; z-index: 2; }
.cell .charges i { width: 6px; height: 6px; border-radius: 3px; background: rgba(42, 35, 70, .25); border: 1px solid rgba(255, 255, 255, .7); }
.cell .charges i.on { background: #2cb3f0; }
.cell .cooldown {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); font-size: 10px; color: #fff; z-index: 2;
  background: var(--ink); border-radius: 7px; padding: 0 5px; pointer-events: none; font-family: var(--body); font-weight: 800;
}
.cell .want {
  position: absolute; left: 0; top: 0; z-index: 2; width: 17px; height: 17px; border-radius: 9px; background: var(--green); border: 2px solid #fff;
  color: #fff; font-size: 10px; display: grid; place-items: center; pointer-events: none; box-shadow: 0 1px 0 rgba(0, 0, 0, .25);
}
.cell.selected::after {
  content: ''; position: absolute; inset: 0; border-radius: calc(var(--cell) * .22); pointer-events: none; z-index: 3;
  border: 3px solid #fff; box-shadow: 0 0 0 2px var(--pink), 0 0 14px 2px rgba(255, 95, 162, .8); animation: sel 1.1s ease-in-out infinite;
}
.cell.target::after {
  content: ''; position: absolute; inset: 0; border-radius: calc(var(--cell) * .22); pointer-events: none; z-index: 3;
  background: rgba(95, 227, 154, .35); border: 3px solid var(--green); box-shadow: 0 0 14px rgba(95, 227, 154, .9);
}
.cell .preview {
  position: absolute; left: 50%; bottom: 88%; width: 86%; height: 86%; margin-left: -43%; z-index: 20; pointer-events: none;
  background: radial-gradient(circle, #fff 0 45%, rgba(255, 255, 255, 0) 70%); border-radius: 50%; animation: preview .5s ease-in-out infinite alternate;
}
.cell .preview img { width: 100%; height: 100%; }
.cell .preview::after { content: '↓'; position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); font-size: 14px; color: var(--green); -webkit-text-stroke: 3px #fff; paint-order: stroke fill; }
@keyframes preview { from { transform: translateY(0) scale(.92); } to { transform: translateY(-5px) scale(1.04); } }
.cell.dragging .piece { opacity: .25; }
.cell.hint .piece { animation: wiggle .7s ease-in-out 2; }
.cell.flash .piece { animation: flash .9s ease-in-out 2; }
@keyframes sel { 50% { box-shadow: 0 0 0 2px var(--pink), 0 0 4px 0 rgba(255, 95, 162, .5); } }
@keyframes wiggle { 25% { transform: rotate(-10deg) scale(1.08); } 75% { transform: rotate(10deg) scale(1.08); } }
@keyframes flash { 50% { transform: scale(1.2); filter: brightness(1.3); } }
.ghost { position: fixed; z-index: 60; pointer-events: none; transform: translate(-50%, -62%) scale(1.2); filter: drop-shadow(0 8px 6px rgba(26, 16, 48, .45)); }
.ghost img { width: 100%; height: 100%; }
.ring { position: fixed; z-index: 61; pointer-events: none; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 0 12px #fff, inset 0 0 12px #ffe07a; }

/* ---------- Info bar ---------- */
#info {
  flex: 0 0 44px; min-height: 0; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 6px; border-radius: 14px; color: var(--ink);
  background: linear-gradient(180deg, #fffdf7, #ffeccf); border: 3px solid var(--night); box-shadow: 0 4px 0 var(--night);
}
#info .icon-wrap { position: relative; flex: 0 0 auto; width: 36px; height: 36px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #fff, #f3e0c4); box-shadow: inset 0 -2px 0 rgba(160, 110, 70, .3); }
#info .icon-wrap img { width: 100%; height: 100%; padding: 3px; }
#info .icon-wrap .book {
  position: absolute; right: -6px; bottom: -6px; width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center;
  background: var(--pink); color: #fff; border: 2px solid #fff; font-size: 11px; font-family: var(--body); font-weight: 900; box-shadow: 0 1px 0 rgba(0, 0, 0, .3);
}
#info .text { flex: 1 1 auto; min-width: 0; line-height: 1.25; }
#info .text b { display: block; font-size: 16px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#info .text b small { font-size: 12px; color: #8a6b8f; margin-left: 4px; }
#info .text small.sub { display: block; font-family: var(--body); font-size: 11px; font-weight: 700; color: #7d6f86; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#info .tip { font-family: var(--body); font-size: 12px; font-weight: 700; color: #6d5d78; line-height: 1.35; }
#info .nice { width: 36px; height: 36px; object-fit: contain; flex: 0 0 auto; }

.btn {
  flex: 0 0 auto; height: 38px; padding: 0 14px; border-radius: 13px; font-size: 16px; color: #fff; font-weight: 400;
  background: linear-gradient(180deg, #ff9cc8 0%, var(--pink) 45%, var(--pink-deep) 100%);
  border: 2.5px solid var(--night); box-shadow: 0 4px 0 var(--night), inset 0 2px 0 rgba(255, 255, 255, .45);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap;
  -webkit-text-stroke: 3px rgba(42, 35, 70, .85); paint-order: stroke fill; transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--night), inset 0 2px 0 rgba(255, 255, 255, .45); }
.btn.green { background: linear-gradient(180deg, #8ff5bd 0%, var(--mint) 45%, var(--green) 100%); }
.btn.gold { background: linear-gradient(180deg, #fff0a6 0%, var(--gold) 45%, var(--gold-deep) 100%); }
.btn.gray { background: linear-gradient(180deg, #b0a9c9 0%, #8a84a6 45%, #625c82 100%); }
.btn[disabled] { filter: grayscale(.7) brightness(.85); pointer-events: none; }
.btn img { width: 22px; height: 22px; }
.btn.big { height: 52px; font-size: 21px; padding: 0 30px; border-radius: 18px; box-shadow: 0 5px 0 var(--night), inset 0 3px 0 rgba(255, 255, 255, .45); }

/* ---------- Dock ---------- */
#nav {
  flex: 0 0 56px; min-height: 0; display: flex; gap: 4px; padding: 0 6px; border-radius: 16px; margin-top: 4px;
  background: linear-gradient(180deg, #4a3470, #2a1d45); border: 3px solid var(--night);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4), inset 0 3px 0 rgba(255, 140, 200, .35);
}
#nav button { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 5px; }
#nav .nav-icon { position: absolute; top: -5px; width: 36px; height: 36px; transition: transform .15s; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .4)); }
#nav .nav-icon img { width: 100%; height: 100%; }
#nav .nav-label { font-size: 13px; -webkit-text-stroke: 3px var(--night); paint-order: stroke fill; }
#nav button:active .nav-icon { transform: scale(.9); }
#nav button.attn .nav-icon { animation: nav-bob 1.1s ease-in-out infinite; }
@keyframes nav-bob { 50% { transform: translateY(-4px) rotate(-6deg); } }
.badge {
  position: absolute; right: 8%; top: -14px; min-width: 20px; height: 20px; border-radius: 10px; background: linear-gradient(180deg, #ff6b86, #e8264b); border: 2px solid #fff;
  font-size: 11px; font-style: normal; display: grid; place-items: center; padding: 0 4px; z-index: 2; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); font-family: var(--body); font-weight: 900;
}

/* ---------- Base screen ---------- */
.screen {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  background: #8fd6ff url(./assets/build/sky.webp) center top / cover no-repeat; overflow: hidden;
  padding: 0 0 calc(var(--safe-bottom) + 8px);
  animation: screen-in .3s ease-out;
}
@keyframes screen-in { from { opacity: 0; transform: scale(1.04); } }
.screen-head {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 6; width: var(--col); max-width: 100%;
  display: flex; align-items: center; gap: 8px; height: calc(var(--safe-top) + 50px); padding: calc(var(--safe-top) + 6px) 10px 0;
}
.screen-head h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 400; text-align: center; -webkit-text-stroke: 5px var(--night); paint-order: stroke fill; }
.back {
  height: 34px; padding: 0 14px 0 10px; border-radius: 17px; font-size: 16px; display: flex; align-items: center; gap: 2px;
  background: linear-gradient(180deg, #43315f, #261a3d); border: 2.5px solid var(--night); box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}
.back span { font-size: 24px; line-height: 1; margin-top: -2px; }
#base-progress {
  position: absolute; top: calc(var(--safe-top) + 58px); left: 50%; transform: translateX(-50%); z-index: 6; width: var(--col); max-width: 100%;
  padding: 0 12px; color: var(--ink); pointer-events: none;
}
#base-progress .bp-top { display: flex; justify-content: space-between; font-size: 14px; color: #fff; -webkit-text-stroke: 4px var(--night); paint-order: stroke fill; }
#base-progress .bar { height: 14px; background: rgba(255, 255, 255, .7); border: 2.5px solid var(--night); border-radius: 8px; overflow: hidden; margin-top: 2px; }
#base-progress .bar i { display: block; height: 100%; background: linear-gradient(180deg, #ffa2cd, var(--pink) 60%, #d63a82); }
#base-progress .chips { display: flex; gap: 6px; margin-top: 6px; }
#base-progress .chips span {
  flex: 1; text-align: center; font-size: 12px; padding: 3px 2px; border-radius: 10px; color: var(--ink);
  background: rgba(255, 255, 255, .8); border: 2px solid rgba(42, 35, 70, .35); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#base-progress .chips span.done { background: #c2f7d6; border-color: var(--green); }
#base-progress .chips span.now { background: var(--pink-soft); border-color: var(--pink); }
#park-wrap {
  position: absolute; inset: 0; overflow: auto hidden; scrollbar-width: none; touch-action: pan-x; cursor: grab;
  display: flex; align-items: flex-end;
}
#park-wrap::-webkit-scrollbar { display: none; }
#park {
  position: relative; flex: 0 0 auto; width: var(--park, 100vw); aspect-ratio: 1; margin: 0 auto var(--park-bottom, 150px);
  background: url(./assets/build/ground.webp) center/cover;
  -webkit-mask-image: radial-gradient(ellipse 72% 70% at 50% 52%, #000 72%, transparent 100%);
          mask-image: radial-gradient(ellipse 72% 70% at 50% 52%, #000 72%, transparent 100%);
}
.plot { position: absolute; width: 27%; aspect-ratio: 1; transform: translate(-50%, -62%); }
.plot img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 5px 3px rgba(20, 40, 10, .3)); }
.plot.next img { filter: grayscale(1) brightness(1.7) opacity(.5); }
.plot.next .pin {
  position: absolute; left: 50%; top: 10%; transform: translateX(-50%); display: flex; align-items: center; gap: 3px;
  background: linear-gradient(180deg, #ff9cc8, var(--pink-deep)); color: #fff; font-size: 13px;
  padding: 3px 10px 3px 4px; border-radius: 14px; border: 2.5px solid var(--night); white-space: nowrap; animation: bob 1.2s ease-in-out infinite;
  box-shadow: 0 3px 0 var(--night); -webkit-text-stroke: 3px var(--night); paint-order: stroke fill;
}
.plot.next .pin img { width: 20px; height: 20px; }
.plot.built, .plot.keeper { cursor: pointer; }
.plot.drop img { animation: drop .8s cubic-bezier(.3, 1.6, .5, 1); }
.plot.keeper { width: 14%; transform: translate(-50%, -85%); }
.plot.keeper img { animation: breathe 2.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(-50%, -6px); } }
@keyframes drop { from { transform: translateY(-80%) scale(.4); opacity: 0; } 55% { opacity: 1; } }
.walker { position: absolute; width: 9%; aspect-ratio: 1; transform: translate(-50%, -88%); transition: left 3.2s linear, top 3.2s linear; cursor: pointer; }
.walker img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 1px rgba(20, 40, 10, .35)); }
.walker.moving img { animation: waddle .32s ease-in-out infinite alternate; }
.walker.flip img { transform: scaleX(-1); }
.walker.flip.moving img { animation-name: waddle-flip; }
@keyframes waddle { from { transform: rotate(-6deg) translateY(0); } to { transform: rotate(6deg) translateY(-8%); } }
@keyframes waddle-flip { from { transform: scaleX(-1) rotate(-6deg) translateY(0); } to { transform: scaleX(-1) rotate(6deg) translateY(-8%); } }
#project-card {
  position: relative; z-index: 6; flex: 0 0 auto; width: calc(var(--col) - 16px); max-width: calc(100% - 16px); padding: 12px 12px 14px; border-radius: 20px; color: var(--ink);
  background: linear-gradient(180deg, #fffdf7, #ffeccf); border: 3px solid var(--night); box-shadow: 0 5px 0 var(--night);
  display: grid; grid-template-columns: 84px 1fr; gap: 2px 10px; align-items: center;
}
#project-card .thumb { grid-row: span 3; width: 84px; height: 84px; margin-top: -30px; filter: drop-shadow(0 4px 2px rgba(0, 0, 0, .25)); }
#project-card .chapter { font-size: 13px; color: var(--pink-deep); }
#project-card h3 { margin: 0; font-size: 22px; font-weight: 400; }
#project-card .dots { display: flex; gap: 4px; }
#project-card .dots i { width: 18px; height: 7px; border-radius: 4px; background: rgba(42, 35, 70, .18); }
#project-card .dots i.on { background: var(--pink); }
#project-card .row { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#project-card .row .btn { flex: 1; height: 50px; font-size: 20px; }
#project-card .need-more { grid-column: 1 / -1; font-family: var(--body); font-weight: 700; font-size: 12px; text-align: center; color: #7d6f86; margin-top: 6px; }
.say {
  position: absolute; z-index: 50; transform: translate(-50%, -100%); background: #fff; color: var(--ink); font-size: 13px;
  padding: 4px 11px; border-radius: 13px; border: 2.5px solid var(--night); white-space: nowrap; animation: say 2.4s forwards; pointer-events: none;
}
.say::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--night); border-bottom: 0; }
@keyframes say { 0% { opacity: 0; transform: translate(-50%, -80%) scale(.6); } 10% { opacity: 1; transform: translate(-50%, -100%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Title ---------- */
#title {
  position: fixed; inset: 0; z-index: 58; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 30px) 20px calc(var(--safe-bottom) + 40px); background: #7fc8ff; overflow: hidden;
}
/* title.webp is the poster with its sky extended upward (build-assets.sh), so phones of any height see all seven
   characters at the bottom; wide screens show it at full height on the matching sky blue. */
#title .title-art {
  position: absolute; inset: 0; transform-origin: 50% 100%; animation: title-zoom 18s ease-in-out infinite alternate;
  background: #1c93ef url(./assets/ui/title.webp) center bottom / cover no-repeat;
}
@media (min-aspect-ratio: 1/2) { #title .title-art { background-size: auto 100%; } }
#title .title-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(40, 90, 180, .1) 40%, rgba(26, 16, 48, .55) 100%); }
@keyframes title-zoom { to { transform: scale(1.06); } }
#title .floaty { position: absolute; width: 64px; animation: floaty 4s ease-in-out infinite; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .18)); }
@keyframes floaty { 50% { transform: translateY(-12px) rotate(6deg); } }
#title .title-logo { position: relative; margin-top: min(16vh, 140px); width: min(84vw, 420px); animation: logo-in .8s cubic-bezier(.3, 1.5, .5, 1) both, logo-float 3s .8s ease-in-out infinite; }
@keyframes logo-in { from { transform: scale(.4) rotate(-6deg); opacity: 0; } }
@keyframes logo-float { 50% { transform: translateY(-6px) rotate(-1deg); } }
#title .title-start { position: relative; animation: pulse2 1.2s ease-in-out infinite; }
@keyframes pulse2 { 50% { transform: scale(1.06); } }
#title .title-foot { position: absolute; bottom: calc(var(--safe-bottom) + 10px); margin: 0; font-size: 13px; -webkit-text-stroke: 3px var(--night); paint-order: stroke fill; }

/* ---------- Bottom sheet (album, tasks, rank, settings) ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(10, 6, 24, .62); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet-body {
  position: relative; width: var(--col); max-width: 100%; max-height: 86%; display: flex; flex-direction: column; color: var(--ink);
  background: var(--cream); border: 3px solid var(--night); border-bottom: 0; border-radius: 26px 26px 0 0;
  padding: 0 12px calc(var(--safe-bottom) + 14px); animation: sheet-in .28s cubic-bezier(.3, 1.3, .5, 1);
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .35);
}
@keyframes sheet-in { from { transform: translateY(40%); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: center; height: 30px; }
.sheet-head h2 {
  margin: -18px 0 0; padding: 4px 28px; font-size: 20px; font-weight: 400; color: #fff; border-radius: 14px; border: 3px solid var(--night);
  background: linear-gradient(180deg, #ff9cc8, var(--pink-deep)); box-shadow: 0 3px 0 var(--night); -webkit-text-stroke: 4px var(--night); paint-order: stroke fill;
}
.close {
  position: absolute; right: 10px; top: -14px; width: 36px; height: 36px; border-radius: 18px; color: #fff; font-size: 24px; line-height: 1;
  background: linear-gradient(180deg, #ff8a8a, #e23d52); border: 3px solid var(--night); box-shadow: 0 3px 0 var(--night);
}
#sheet-content { overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; min-height: 0; padding: 12px 2px 4px; }

.collection-intro { background: #f9dfed; border: 2px solid #e2afcc; border-radius: 16px; padding: 12px; margin-bottom: 10px; }
.collection-intro h3 { display: flex; justify-content: space-between; margin: 4px 0; font-size: 21px; font-weight: 400; }
.collection-intro h3 b { color: #b32b73; }
.collection-intro small, .collection-intro p { font: 12px/1.5 var(--body); margin: 4px 0; }
.collection-balance { display: flex; align-items: center; gap: 6px; font: 700 13px var(--body); margin-top: 8px; }
.collection-balance b { font-size: 20px; color: #b32b73; }
.text-link { color: #9d2a65; text-decoration: underline; font: 700 12px var(--body); min-height: 36px; }
.collection-balance .text-link { margin-left: auto; }
.collection-milestones { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-bottom: 12px; }
.collection-step { text-align: center; background: #fff; border: 2px solid #e6d7cf; border-radius: 12px; padding: 7px 3px 3px; }
.collection-step.ready { border-color: #e6ab32; background: #fff5cf; }
.collection-step b, .collection-step small { display: block; }
.collection-step b { font-size: 17px; font-weight: 400; }
.collection-step small { font: 10px/1.5 var(--body); }
.milestone-reward { display: flex; flex-direction: column; align-items: center; margin: 5px 0; }
.milestone-reward span { display: flex; align-items: center; font-size: 13px; }
.milestone-reward img { width: 20px; height: 20px; }
.collection-step button, .craft-card { min-height: 36px; width: 100%; border-radius: 8px; background: #653b82; color: white; font: 700 11px var(--body); }
.collection-step button:disabled, .craft-card:disabled { background: #eee6ee; color: #817184; cursor: default; }
.collection-rules { font: 12px/1.6 var(--body); margin: 0 0 12px; padding: 10px; border-radius: 10px; background: #eee6ee; user-select: text; }
.collection-rules summary { cursor: pointer; font-weight: 700; }
.album-card { min-width: 0; }
.craft-card { margin-top: 6px; }
.card-owned { display: block; text-align: center; font: 11px/36px var(--body); color: #288055; }

.album-sum { font-family: var(--body); font-weight: 700; font-size: 12px; margin-bottom: 10px; color: #7d6f86; }
.album-sum b { font-family: var(--display); font-size: 18px; font-weight: 400; color: var(--pink-deep); }
.album-row { background: #fff; border: 2.5px solid rgba(42, 35, 70, .14); border-radius: 16px; padding: 8px; margin-bottom: 10px; box-shadow: 0 3px 0 rgba(42, 35, 70, .08); }
.album-row header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 16px; }
.album-row header img { width: 34px; height: 34px; object-fit: contain; }
.album-row header small { font-family: var(--body); font-weight: 700; color: #8a7f96; font-size: 11px; }
.album-row header .btn { margin-left: auto; height: 30px; font-size: 13px; padding: 0 10px; box-shadow: 0 3px 0 var(--night); }
.album-row header .done { margin-left: auto; font-size: 13px; color: var(--green); }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.card {
  position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; border: 3px solid var(--ink);
  background: linear-gradient(160deg, #fff, #e8e2f5); display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 0 rgba(42, 35, 70, .25);
}
.card::before { content: ''; position: absolute; z-index: 1; inset: 3px; border-radius: 8px; border: 1.5px solid rgba(255, 255, 255, .8); pointer-events: none; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card img.ph { position: static; width: 46%; height: auto; opacity: .35; }
.card .title { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; font-size: 10px; text-align: center; background: rgba(42, 35, 70, .88); color: #fff; padding: 3px 0 2px; }
.card .rar { position: absolute; z-index: 2; left: 4px; top: 3px; font-size: 12px; -webkit-text-stroke: 3px #fff; paint-order: stroke fill; }
.card .count { position: absolute; z-index: 2; right: 3px; top: 3px; font-size: 10px; background: var(--ink); color: #fff; border-radius: 6px; padding: 0 4px; }
.card.missing { background: repeating-linear-gradient(45deg, #efeaf7, #efeaf7 6px, #e5def1 6px, #e5def1 12px); box-shadow: none; }
.card.missing .ph { filter: grayscale(1); }
.card.N { border-color: #8a84a6; }
.card.N .rar { color: #6d6789; }
.card.R { border-color: #3aa0ff; background: linear-gradient(160deg, #fff, #d6ecff); }
.card.R .rar { color: #1c7fe0; }
.card.SR { border-color: #b35cff; background: linear-gradient(160deg, #fff, #ecd8ff); }
.card.SR .rar { color: #9a3cf0; }
.card.UR { border-color: var(--gold-deep); background: linear-gradient(160deg, #fffbe8, #ffe39a); }
.card.UR .rar { color: #d98800; }
.card.missing .rar { opacity: .6; }
.card.UR:not(.missing)::after { content: ''; position: absolute; z-index: 1; inset: 0; background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .75) 45%, transparent 60%); animation: shine 2.5s infinite; }
@keyframes shine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.task { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px; padding: 10px; margin-bottom: 8px; border: 2.5px solid rgba(42, 35, 70, .12); box-shadow: 0 3px 0 rgba(42, 35, 70, .08); }
.task.done { opacity: .6; }
.task .t-main { flex: 1; min-width: 0; }
.task .t-main b { font-size: 16px; font-weight: 400; }
.task .t-main small { font-family: var(--body); font-weight: 700; font-size: 11px; color: #8a7f96; }
.bar { height: 12px; border-radius: 6px; background: rgba(42, 35, 70, .12); overflow: hidden; margin: 5px 0 2px; box-shadow: inset 0 2px 2px rgba(0, 0, 0, .12); }
.bar i { display: block; height: 100%; background: linear-gradient(180deg, #8ff5bd, var(--green)); border-radius: 6px; }
.task .rw { display: flex; align-items: center; gap: 2px; font-size: 14px; }
.task .rw img { width: 24px; height: 24px; }
.task img.t-icon { width: 44px; height: 44px; }
.task .btn { height: 34px; font-size: 14px; padding: 0 12px; }
.claimed { font-size: 14px; color: var(--green); }
.sub { font-family: var(--body); font-weight: 700; font-size: 12px; color: #7d6f86; margin: 0 2px 10px; }

.rank-me { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; margin-bottom: 10px; color: #fff; font-size: 16px;
  background: linear-gradient(135deg, #ff9cc8, var(--pink-deep)); border: 3px solid var(--night); box-shadow: 0 3px 0 var(--night); -webkit-text-stroke: 3px var(--night); paint-order: stroke fill; }
.rank-me img { width: 46px; height: 46px; }
.rank-me b { font-size: 26px; font-weight: 400; margin-left: auto; }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fff; border-radius: 14px; margin-bottom: 6px; font-size: 15px; border: 2px solid rgba(42, 35, 70, .08); }
.rank-list li.me { background: #ffe0ef; border: 2.5px solid var(--pink); }
.rank-list .r { width: 30px; text-align: center; font-size: 18px; }
.rank-list .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--body); font-weight: 800; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.stat-grid div { background: #fff; border-radius: 14px; padding: 10px; text-align: center; border: 2px solid rgba(42, 35, 70, .08); }
.stat-grid b { display: block; font-size: 24px; font-weight: 400; color: var(--pink-deep); }
.stat-grid small { font-family: var(--body); font-weight: 700; color: #8a7f96; font-size: 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; font-size: 16px; }
.toggle { width: 54px; height: 32px; border-radius: 16px; background: #c9c3dd; position: relative; transition: background .2s; border: 2.5px solid var(--night); }
.toggle::after { content: ''; position: absolute; left: 2px; top: 2px; width: 23px; height: 23px; border-radius: 12px; background: #fff; transition: transform .2s; box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.toggle.on { background: var(--green); }
.toggle.on::after { transform: translateX(21px); }

/* ---------- Modal (level up, cards, messages) ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: radial-gradient(circle at 50% 45%, rgba(60, 30, 90, .7), rgba(10, 6, 24, .85)); display: grid; place-items: center; padding: 20px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal-box {
  position: relative; z-index: 1; width: min(340px, 100%); padding: 20px 16px 18px; border-radius: 24px; background: linear-gradient(180deg, #fffdf7, #ffeccf); color: var(--ink);
  border: 3px solid var(--night); box-shadow: 0 6px 0 var(--night), 0 20px 40px rgba(0, 0, 0, .4); text-align: center; animation: pop-in .4s cubic-bezier(.3, 1.5, .5, 1);
}
.rays {
  position: fixed; left: 50%; top: 50%; width: 640px; height: 640px; margin: -380px 0 0 -320px; z-index: 0; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255, 224, 122, .5) 0 9deg, rgba(255, 224, 122, 0) 9deg 20deg);
  -webkit-mask-image: radial-gradient(circle, #000 15%, transparent 62%); mask-image: radial-gradient(circle, #000 15%, transparent 62%);
  animation: rays 14s linear infinite;
}
@keyframes rays { to { transform: rotate(360deg); } }
@keyframes pop-in { from { transform: scale(.6); opacity: 0; } }
.modal-box h2 { margin: 0 0 6px; font-size: 24px; font-weight: 400; }
.modal-box p { margin: 6px 0; font-family: var(--body); font-weight: 700; font-size: 14px; color: #5d4f6b; }
.modal-box p b { color: var(--pink-deep); }
.modal-box .hero { width: 160px; height: 160px; object-fit: contain; margin: -90px auto 0; display: block; filter: drop-shadow(0 5px 0 rgba(0, 0, 0, .2)); }
.ribbon {
  position: relative; display: inline-block; margin: 4px 0 8px; padding: 6px 26px; font-size: 22px; color: #fff;
  background: linear-gradient(180deg, #ff9cc8, var(--pink-deep)); border: 3px solid var(--night); border-radius: 12px; transform: rotate(-2deg);
  box-shadow: 0 4px 0 var(--night); -webkit-text-stroke: 4px var(--night); paint-order: stroke fill;
}
.rewards { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.rewards span { display: flex; align-items: center; gap: 2px; background: #fff; border-radius: 14px; padding: 4px 10px 4px 4px; font-size: 17px; border: 2.5px solid rgba(42, 35, 70, .15); box-shadow: 0 3px 0 rgba(42, 35, 70, .1); animation: pop-in .4s both; }
.rewards span:nth-child(2) { animation-delay: .1s; }
.rewards span:nth-child(3) { animation-delay: .2s; }
.rewards span:nth-child(4) { animation-delay: .3s; }
.rewards img { width: 32px; height: 32px; }
.unlock { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 6px 10px; margin: 6px 0; text-align: left; border: 2px dashed var(--pink); }
.unlock img { width: 52px; height: 52px; }
.unlock b { font-size: 16px; font-weight: 400; }
.unlock small { display: block; font-family: var(--body); font-weight: 700; color: #8a7f96; font-size: 11px; }
.card-reveal { perspective: 800px; width: 190px; height: 253px; margin: 6px auto 12px; }
.card-reveal .inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; animation: flip .9s .2s cubic-bezier(.3, 1.3, .5, 1) both; }
.card-reveal .face, .card-reveal .backface { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 16px; }
.card-reveal .backface { background: radial-gradient(circle at 50% 40%, #ff9cc8, #7a3cff); border: 4px solid var(--night); display: grid; place-items: center; }
.card-reveal .backface img { width: 60%; }
.card-reveal .face { transform: rotateY(180deg); }
.card-reveal .face.card { width: 100%; height: 100%; aspect-ratio: auto; border-width: 4px; border-radius: 16px; }
.card-reveal .face.card .title { font-size: 14px; padding: 5px 0; }
.card-reveal .face.card .rar { font-size: 18px; }
@keyframes flip { from { transform: rotateY(0) scale(.9); } to { transform: rotateY(180deg) scale(1); } }
.new-tag { display: inline-block; background: linear-gradient(180deg, #ff6b86, #e8264b); color: #fff; padding: 2px 12px; border-radius: 10px; font-size: 15px; border: 2px solid var(--night); }
.chain-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 14px; }
.chain-grid div { position: relative; background: #fff; border-radius: 12px; padding: 4px 2px 3px; border: 2px solid rgba(42, 35, 70, .1); }
.chain-grid div.cur { border-color: var(--pink); box-shadow: 0 0 0 2px var(--pink-soft); }
.chain-grid img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.chain-grid div.unknown img { filter: brightness(0) opacity(.18); }
.chain-grid span { display: block; font-size: 11px; line-height: 1.2; min-height: 26px; }
.chain-grid i { position: absolute; left: 4px; top: 2px; font-style: normal; font-size: 12px; color: var(--pink-deep); }
.chain-gen { display: flex; align-items: center; gap: 8px; text-align: left; background: #fff4d0; border-radius: 14px; padding: 6px 10px; }
.chain-gen img { width: 48px; height: 48px; }
.chain-gen small { display: block; font-family: var(--body); font-weight: 700; font-size: 11px; color: #8a7f96; }

/* ---------- Dialogue ---------- */
.dialog { position: fixed; inset: 0; z-index: 55; background: linear-gradient(180deg, rgba(10, 6, 24, 0) 25%, rgba(10, 6, 24, .8)); display: flex; align-items: flex-end; justify-content: center; }
.dialog-box { position: relative; width: var(--col); max-width: 100%; padding: 0 12px calc(var(--safe-bottom) + 20px); }
.dialog .speaker { display: block; height: 200px; max-width: 62%; object-fit: contain; margin: 0 0 -26px 6px; filter: drop-shadow(0 5px 0 rgba(0, 0, 0, .3)); animation: speaker .35s cubic-bezier(.3, 1.5, .5, 1); }
.dialog .speaker.right { margin-left: auto; margin-right: 6px; }
@keyframes speaker { from { transform: translateY(24px) scale(.9); opacity: 0; } }
.dialog .line {
  position: relative; background: linear-gradient(180deg, #fffdf7, #ffeccf); color: var(--ink); border: 3px solid var(--night); border-radius: 20px; padding: 18px 18px 22px;
  min-height: 100px; box-shadow: 0 6px 0 var(--night); font-family: var(--body); font-size: 16px; font-weight: 800; line-height: 1.55;
}
.dialog .line b {
  position: absolute; top: -18px; left: 16px; font-family: var(--display); font-weight: 400; color: #fff; padding: 2px 16px; border-radius: 12px; font-size: 17px;
  background: linear-gradient(180deg, #ff9cc8, var(--pink-deep)); border: 3px solid var(--night); -webkit-text-stroke: 3px var(--night); paint-order: stroke fill;
}
.dialog .line.right b { left: auto; right: 16px; background: linear-gradient(180deg, #8fd6ff, #2c8fe0); }
.dialog .more { position: absolute; right: 16px; bottom: 6px; font-size: 12px; color: #a898b2; animation: bob2 1s infinite; font-style: normal; }
@keyframes bob2 { 50% { transform: translateY(3px); } }

/* ---------- Coach, toast, fx ---------- */
#coach { position: fixed; z-index: 45; pointer-events: none; left: 0; top: 0; }
#coach .hand { position: absolute; font-size: 40px; transform: translate(-30%, -10%); filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .45)); }
#coach .coach-text {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 140px); width: min(92vw, 420px);
  color: var(--ink); border: 3px solid var(--night); border-radius: 18px; padding: 8px 12px 8px 64px; font-size: 16px;
  min-height: 56px; display: flex; align-items: center; box-shadow: 0 5px 0 var(--night);
  background: url(./assets/chars/nice-idle.webp) 4px 60% / 56px no-repeat, linear-gradient(180deg, #fffdf7, #ffeccf);
}
#coach .coach-text.top { bottom: auto; top: calc(var(--safe-top) + 225px); }
#coach .coach-text:empty { display: none; }
#toast { position: fixed; left: 50%; top: calc(var(--safe-top) + 170px); transform: translateX(-50%); z-index: 70; pointer-events: none; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#toast div {
  background: linear-gradient(180deg, #43315f, #261a3d); border: 2.5px solid var(--night); color: #fff; font-size: 15px; padding: 6px 16px 6px 8px;
  border-radius: 16px; display: flex; align-items: center; gap: 6px; animation: toast 2.2s forwards; white-space: nowrap; box-shadow: 0 4px 0 rgba(0, 0, 0, .35);
}
#toast img { width: 32px; height: 32px; }
@keyframes toast { 0% { opacity: 0; transform: translateY(10px) scale(.9); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 65; pointer-events: none; }
.flyer { position: fixed; z-index: 62; pointer-events: none; object-fit: contain; }
.float-text { position: fixed; z-index: 63; pointer-events: none; font-size: 22px; color: #fff; -webkit-text-stroke: 4px var(--night); paint-order: stroke fill; white-space: nowrap; }
.float-text.gold { color: var(--gold); }
.float-text.pink { color: #ff9ccb; }
.float-text.big { font-size: 30px; }

/* ---------- Upgrade pass: generator stars, upgrade modal, styles, pass, tabs ---------- */
.cell .glv {
  position: absolute; left: 50%; bottom: -1px; transform: translateX(-50%); z-index: 2; font-size: 10px; line-height: 12px; letter-spacing: -1px;
  color: var(--gold); -webkit-text-stroke: 2.5px var(--night); paint-order: stroke fill; pointer-events: none;
}
.upg { display: flex; align-items: center; gap: 6px; margin: 8px 0; }
.upg > div { flex: 1; background: #fff; border-radius: 14px; padding: 8px 6px; border: 2px solid rgba(42, 35, 70, .12); }
.upg > div.to { border-color: var(--gold-deep); background: #fff7d6; }
.upg small { display: block; font-size: 12px; color: var(--gold-deep); }
.upg b { font-family: var(--body); font-weight: 800; font-size: 13px; }
.upg i { font-style: normal; font-size: 28px; color: var(--pink-deep); }

.style-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.style-opt { background: #fff; border-radius: 16px; padding: 6px 6px 10px; text-align: center; border: 2.5px solid rgba(42, 35, 70, .12); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.style-opt.cur { border-color: var(--pink); box-shadow: 0 0 0 3px var(--pink-soft); }
.style-opt.locked img { filter: grayscale(1) opacity(.5); }
.style-opt img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.style-opt b { font-size: 15px; font-weight: 400; }
.style-opt small { font-family: var(--body); font-weight: 700; font-size: 10px; color: #8a7f96; min-height: 13px; }
.style-opt .btn { height: 32px; font-size: 14px; padding: 0 10px; }
.style-opt .btn img { width: 18px; height: 18px; }
.style-opt .lock { font-family: var(--body); font-weight: 800; font-size: 11px; color: #8a7f96; min-height: 32px; display: grid; place-items: center; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; background: rgba(42, 35, 70, .08); padding: 4px; border-radius: 14px; }
.tabs button { position: relative; flex: 1; height: 34px; border-radius: 11px; font-size: 15px; color: #7d6f86; }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 0 rgba(42, 35, 70, .15); }
.tabs .dot { position: absolute; right: 10px; top: 6px; min-width: 18px; height: 18px; border-radius: 9px; background: #e8264b; color: #fff; font-style: normal; font-size: 11px; display: grid; place-items: center; font-family: var(--body); font-weight: 900; }

.pass-banner { position: relative; border-radius: 16px; overflow: hidden; border: 3px solid var(--night); margin-bottom: 10px; aspect-ratio: 16 / 7; background: #2a1d45; }
.pass-banner img { width: 100%; height: 100%; object-fit: cover; }
.pass-banner .pb-text { position: absolute; left: 10px; bottom: 8px; display: flex; flex-direction: column; }
.pass-banner b { font-size: 26px; font-weight: 400; color: #fff; -webkit-text-stroke: 5px var(--night); paint-order: stroke fill; }
.pass-banner small { font-size: 12px; color: #fff; -webkit-text-stroke: 3px var(--night); paint-order: stroke fill; }
.pass-head { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px; padding: 8px 10px; margin-bottom: 10px; border: 2.5px solid rgba(42, 35, 70, .12); }
.pass-lv { text-align: center; }
.pass-lv small { display: block; font-size: 11px; color: #8a7f96; }
.pass-lv b { font-size: 20px; font-weight: 400; color: var(--pink-deep); }
.pass-bar { flex: 1; min-width: 0; }
.pass-bar .bar i { background: linear-gradient(180deg, #ffa2cd, var(--pink)); }
.pass-bar small { display: block; font-family: var(--body); font-weight: 700; font-size: 10px; color: #8a7f96; line-height: 1.3; }
.tiers { display: flex; flex-direction: column; gap: 6px; }
.tier { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 14px; padding: 6px 10px 6px 6px; border: 2.5px solid rgba(42, 35, 70, .1); }
.tier .tn { flex: 0 0 34px; height: 34px; border-radius: 17px; display: grid; place-items: center; font-style: normal; font-size: 16px; color: #fff; background: #b8b1cc; -webkit-text-stroke: 3px rgba(42, 35, 70, .6); paint-order: stroke fill; }
.tier .tr { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.tier .tr span { display: flex; align-items: center; gap: 1px; font-size: 15px; }
.tier .tr img { width: 30px; height: 30px; }
.tier.got { opacity: .55; }
.tier.ready { border-color: var(--gold-deep); background: #fff7d6; }
.tier.ready .tn, .tier.got .tn { background: linear-gradient(180deg, #ffe07a, var(--gold-deep)); }
.tier.now { border-color: var(--pink); }
.tier.now .tn { background: linear-gradient(180deg, #ff9cc8, var(--pink-deep)); }
.tier.final { background: linear-gradient(135deg, #fffbe8, #ffe39a); border-color: var(--gold-deep); }
.tier .rdy { font-size: 13px; color: var(--gold-deep); }
.tier .pts { font-size: 13px; color: var(--pink-deep); }
.tier .lk { font-size: 14px; opacity: .6; }
#nav .nav-icon img[src*="cheer-8"] { transform: scale(.92); }

/* On a wide viewport the board gets its own column rather than a phone-sized strip. */
@media (min-width: 900px) and (min-height: 600px) {
  #app { width: min(1100px, 100vw); display: grid; grid-template-columns: 340px minmax(0, 1fr); grid-template-rows: 48px 138px minmax(0, 1fr) 58px; gap: 14px 28px; padding: 16px 24px 20px; }
  #hud { grid-column: 1; grid-row: 1; }
  #goals { grid-column: 1; grid-row: 2; grid-template-rows: 64px 64px; }
  .weekly-goal { display: flex; grid-column: 1 / -1; }
  #order-panel { grid-column: 1; grid-row: 3; overflow: hidden; }
  .order-heading { height: 30px; }
  .order-heading small { display: none; }
  #orders { height: calc(100% - 30px); flex-direction: column; overflow-y: auto; padding: 4px 5px 8px; touch-action: pan-y; }
  .order { width: 100%; flex: 0 0 96px; padding-left: 78px; padding-right: 14px; }
  .order .who { --who: 52px; left: 14px; top: 10px; }
  .order .name { left: 18px; top: 64px; font-size: 12px; }
  .need, .needs.n2 .need, .needs.n3 .need { width: 46px; height: 46px; }
  .order-status { font-size: 12px; }
  #board-wrap { grid-column: 2; grid-row: 1 / 4; }
  #info { grid-column: 2; grid-row: 4; }
  #nav { grid-column: 1; grid-row: 4; margin: 0; }
  #coach .coach-text.top { top: 80px; left: calc(50% + 184px); }
}
@media (max-height: 700px) and (max-width: 899px) {
  #app { gap: 4px; }
  #hud { flex-basis: 40px; }
  #goals { flex-basis: 44px; }
  .goal img { width: 30px; height: 30px; }
  .goal b { font-size: 12px; }
  .goal small, .goal em { font-size: 9px; }
  #order-panel { flex-basis: 88px; }
  .order-heading { height: 18px; }
  #orders { --orders-h: 70px; }
  .order { height: 62px; }
  .order .who { top: 3px; }
  .order .name { top: 35px; }
  .need, .needs.n2 .need, .needs.n3 .need { width: 32px; height: 32px; }
  .order .reward { margin-top: 1px; height: 16px; }
  .order-status { display: none; }
  .order.ready .reward::after { content: '交付'; color: #146c3a; font-size: 10px; }
  #info { flex-basis: 40px; }
  #info .tip { font-size: 10px; }
  #nav { flex-basis: 48px; }
  #nav .nav-icon { width: 30px; height: 30px; }
}

/* Respect reduced-motion: keep feedback, drop looping and decorative motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-iteration-count: 1 !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
