:root {
  --ink: #fdf3e4;
  --ink-soft: #e8d8c4;
  --plum: #2a1d2e;
  --plum-2: #3b2a40;
  --wood: #5a3a2a;
  --wood-2: #7a5038;
  --gold: #f2c46b;
  --poppy: #e0533d;
  --mint: #4aa3df;
  --thorn: #4caf6a;
  --honey: #f2b531;
  --moon: #9b6fd6;
  --panel: rgba(32, 21, 34, 0.86);
  --serif: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #140d16; color: var(--ink); font-family: var(--sans); overscroll-behavior: none; }
body { display: flex; justify-content: center; }
button { font-family: inherit; }

#app {
  position: relative; width: 100%; max-width: 480px; height: 100dvh; overflow: hidden;
  background: var(--plum);
  user-select: none; -webkit-user-select: none;
}

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 14px 26px; font-size: 17px; font-weight: 800; cursor: pointer;
  transition: transform .12s ease, filter .12s ease; color: var(--plum);
}
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(180deg, #ffd88a, #f0a94a); box-shadow: 0 6px 0 #a8642a, 0 10px 24px rgba(0,0,0,.35); }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 2px solid rgba(253,243,228,.35); }
.btn.skip { background: rgba(253,243,228,.1); color: var(--ink-soft); font-size: 14px; font-weight: 600; padding: 13px 18px; min-height: 44px; border: 1px solid rgba(253,243,228,.22); }

/* ---------- title ---------- */
.title-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(242,196,107,.25) 0 2px, transparent 3px) 0 0/60px 60px,
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.18) 0 1.5px, transparent 2.5px) 0 0/90px 90px,
    radial-gradient(ellipse at 50% 110%, #7a3e2c 0%, transparent 60%),
    radial-gradient(ellipse at 50% -10%, #4c3361 0%, transparent 60%),
    linear-gradient(180deg, #2a1d3a, #22162a 60%, #2f1b1e);
}
.title-bg.end { filter: hue-rotate(-20deg) brightness(.9); }
.title-inner { position: relative; margin: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.logo { font-family: var(--serif); font-weight: 700; font-size: 64px; margin: 0; letter-spacing: .5px; color: var(--gold);
  text-shadow: 0 2px 0 #7a4a20, 0 0 30px rgba(242,196,107,.35); }
.small-logo { font-size: 48px; }
.tagline { font-size: 17px; line-height: 1.5; color: var(--ink-soft); margin: 0 0 10px; }
.small { font-size: 12px; color: rgba(253,243,228,.55); margin-top: 6px; }
.eyebrow { text-transform: uppercase; letter-spacing: 3px; font-size: 12px; color: var(--ink-soft); margin: 0; }
.logo-cup { width: 120px; height: 120px; }
.recap { font-size: 14px; color: var(--ink-soft); background: rgba(0,0,0,.25); border-radius: 14px; padding: 12px 16px; line-height: 1.6; }

/* ---------- story ---------- */
.story-bg { position: absolute; inset: 0; transition: background 0.6s ease; }
.story-day {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  font-family: var(--serif); font-size: 22px; font-style: italic; color: var(--gold);
  background: rgba(0,0,0,.3); padding: 4px 18px; border-radius: 999px; z-index: 2;
}
/* portraits: painted art sits behind the dialogue box (waist hidden), visual-novel style */
.portrait {
  position: absolute; left: 0; right: 0; top: 56px; bottom: 150px; z-index: 1; pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.portrait.out { opacity: 0; transform: translateY(14px); }
.p-stage { position: absolute; inset: 0; }
.p-layer {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: flex-end;
  opacity: 0; transition: opacity .3s ease, transform .35s cubic-bezier(.2,.8,.3,1);
}
/* soft ground shadow instead of a per-frame drop-shadow filter (cheaper on phones) */
.p-stage::after { content: ''; position: absolute; left: 15%; right: 15%; bottom: -10px; height: 40px; border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.45), transparent 70%); }
.p-layer.enter { transform: translateX(24px); }
.p-layer.swap { opacity: 1; transition: none; }
.p-layer.on { opacity: 1; transform: none; }
.p-layer.hop.on { animation: hop .38s ease; }
.p-layer img, .p-layer svg { height: 100%; width: auto; max-width: 100%; object-fit: contain; object-position: bottom; }
.p-layer img { animation: breathe 4.6s ease-in-out infinite; transform-origin: 50% 100%; will-change: transform;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 7%, #000 93%, transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 7%, #000 93%, transparent 100%); }
.p-layer.small img, .p-layer.small svg { height: 46%; -webkit-mask-image: none; mask-image: none; }
.p-layer .duo { display: flex; justify-content: center; align-items: flex-end; height: 92%; width: 100%; }
.p-layer .duo img, .p-layer .duo svg { max-width: 50%; height: 100%; }
.p-layer .duo img + img { animation-delay: -2.3s; }
@keyframes breathe { 0%, 100% { transform: scale(1) translateY(0); } 50% { transform: scale(1.012) translateY(-3px); } }
@keyframes hop { 0% { transform: translateY(0); } 35% { transform: translateY(-10px); } 100% { transform: translateY(0); } }

/* character particles */
.p-fx { position: absolute; inset: 0; overflow: hidden; z-index: 2; }
.pt { position: absolute; display: block; pointer-events: none; }
.pt.snow { top: -10px; width: 7px; height: 7px; border-radius: 50%; background: #eaf6ff; box-shadow: 0 0 6px #bfe6ff; animation: fall linear forwards; opacity: .9; }
.pt.leaf { top: -14px; width: 12px; height: 8px; border-radius: 0 100% 0 100%; background: linear-gradient(135deg, #9ccf6a, #4f8a3a); animation: leaf linear forwards; }
.pt.ember { top: 75%; width: 5px; height: 5px; border-radius: 50%; background: #ffb35c; box-shadow: 0 0 8px 2px rgba(255,140,60,.7); animation: rise ease-out forwards; }
/* transform-only animations (no layout work per frame) */
@keyframes fall { to { transform: translate(var(--drift), 70vh); opacity: .2; } }
@keyframes leaf { 0% { transform: translate(0, 0) rotate(0); } 100% { transform: translate(var(--drift), 70vh) rotate(540deg); opacity: .3; } }
@keyframes rise { 0% { opacity: 0; transform: translate(0, 0); } 15% { opacity: 1; } 100% { transform: translate(var(--drift), -45vh); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .p-layer img { animation: none; }
  .p-layer, .p-layer.hop.on { transition: opacity .2s; animation: none !important; transform: none !important; }
  .p-fx { display: none; }
}

.modal-box .earned { font-size: 22px; font-weight: 800; color: var(--gold); }

/* shop restoration */
#screen-shop { background: linear-gradient(180deg, #2a1d3a, #22162a 60%, #2f1b1e); }
.shop-head { display: flex; justify-content: space-between; align-items: center; padding: max(12px, env(safe-area-inset-top)) 16px 6px; z-index: 2; }
.shop-head strong { display: block; font-family: var(--serif); font-size: 26px; color: var(--gold); }
.stars-pill { background: rgba(0,0,0,.35); border: 1px solid rgba(242,196,107,.5); border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 18px; }
.stars-pill.pop { animation: hop .4s ease; }
.shop-stage { position: relative; flex: 1; min-height: 0; margin: 0 12px; border-radius: 20px; overflow: hidden; box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.shop-layer { position: absolute; inset: 0; transition: opacity .9s ease; }
.shop-layer svg, .shop-layer img { width: 100%; height: 100%; object-fit: cover; object-position: center 40%; display: block; }
.shop-layer.fade { opacity: 0; }
.shop-fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.spark { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: #fff3c4; box-shadow: 0 0 10px 3px rgba(255,210,120,.8); animation: spark 1s ease-out forwards; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
.shop-panel { position: relative; padding: 12px 16px max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.shop-ivy { position: absolute; left: 8px; bottom: calc(100% - 46px); width: 76px; height: 100px; pointer-events: none; }
.shop-ivy img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; border-radius: 16px; }
.shop-bubble { align-self: stretch; margin-left: 80px; min-height: 48px; background: var(--panel); border: 1px solid rgba(242,196,107,.4); border-radius: 16px; padding: 10px 14px; font-size: 16px; line-height: 1.4; }
.shop-progress { font-size: 13px; color: var(--ink-soft); letter-spacing: .5px; }

/* title art */
.title-art { position: absolute; left: 50%; top: 0; height: 64%; transform: translateX(-50%); max-width: 115%; object-fit: contain; object-position: top;
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent 98%); mask-image: linear-gradient(to bottom, #000 55%, transparent 98%); opacity: .95; }
#screen-title .title-inner { margin: auto auto max(28px, env(safe-area-inset-bottom)); }
.dialogue {
  position: absolute; left: 12px; right: 12px; bottom: max(16px, env(safe-area-inset-bottom)); min-height: 180px;
  background: var(--panel); border: 1px solid rgba(242,196,107,.35); border-radius: 20px; padding: 18px 20px 30px;
  backdrop-filter: blur(6px); z-index: 2; cursor: pointer;
}
.speaker { font-weight: 800; font-size: 15px; letter-spacing: .5px; text-transform: uppercase; margin-bottom: 6px; min-height: 18px; }
.line { font-size: 18px; line-height: 1.5; animation: fadeIn .25s ease; }
.line.narr { font-family: var(--serif); font-size: 21px; font-style: italic; color: #f1e3cf; }
.line em { color: var(--gold); font-style: italic; }
.next-hint { position: absolute; right: 18px; bottom: 10px; font-size: 13px; color: rgba(253,243,228,.5); animation: pulse 1.4s infinite; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .3; } }

.taps {
  position: absolute; left: 12px; right: 12px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 3;
  background: var(--panel); border: 1px solid rgba(242,196,107,.5); border-radius: 20px; padding: 18px;
  display: flex; flex-direction: column; gap: 10px; animation: fadeIn .25s ease;
}
.taps-prompt { font-family: var(--serif); font-size: 22px; font-weight: 700; color: var(--gold); text-align: center; }
#taps-options { display: flex; flex-direction: column; gap: 10px; }
.tap-opt {
  background: rgba(253,243,228,.08); color: var(--ink); border: 1px solid rgba(253,243,228,.3); border-radius: 14px;
  padding: 14px 16px; font-size: 16px; text-align: left; cursor: pointer; line-height: 1.35;
}
.tap-opt:active { background: rgba(242,196,107,.25); }

.choice-card {
  position: absolute; left: 12px; right: 12px; top: 64px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 3;
  background: var(--panel); border: 1px solid rgba(242,196,107,.5); border-radius: 22px; padding: 20px 18px;
  display: flex; flex-direction: column; gap: 14px; animation: fadeIn .3s ease; overflow-y: auto;
}
.choice-card h3 { font-family: var(--serif); font-size: 28px; margin: 0; text-align: center; color: var(--gold); }
.choice-opt { display: flex; gap: 12px; align-items: center; border-radius: 16px; padding: 12px; background: rgba(253,243,228,.06); border: 2px solid var(--c); }
.choice-opt .face { width: 72px; height: 84px; flex: none; }
.choice-opt .face svg { width: 100%; height: 100%; }
.face { overflow: hidden; border-radius: 14px; }
.face .face-img, .choice-opt .face .face-img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 6%; display: block; }
.choice-opt .face { width: 84px; height: 100px; background: rgba(0,0,0,.25); }
.choice-opt img { width: 40px; height: 40px; flex: none; }
.choice-opt b { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 15px; color: var(--c); text-transform: uppercase; letter-spacing: .5px; }
.choice-opt span { font-size: 15px; line-height: 1.35; color: var(--ink-soft); }
.choice-card .rule { text-align: center; font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--ink); margin: 0; }
.choice-card .btn { align-self: center; margin-top: auto; }

/* backgrounds */
.bg-shop-rain { background:
  repeating-linear-gradient(105deg, rgba(180,200,255,.08) 0 1px, transparent 1px 14px),
  radial-gradient(ellipse at 50% 30%, rgba(255,190,110,.35), transparent 55%),
  linear-gradient(180deg, #2d2236 0%, #4a2f2a 55%, #2a1a16 100%); }
.bg-shop-day { background:
  radial-gradient(circle at 80% 18%, rgba(255,236,190,.55), transparent 35%),
  repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 46px),
  linear-gradient(180deg, #8a5a3e 0%, #a8714b 45%, #5a3a2a 100%); }
.bg-garden-night { background:
  radial-gradient(circle at 75% 15%, #f7f0d0 0 22px, rgba(247,240,208,.15) 23px, transparent 70px),
  radial-gradient(circle at 20% 70%, rgba(180,140,255,.5) 0 4px, transparent 5px) 0 0/80px 70px,
  linear-gradient(180deg, #1b2140 0%, #233a3a 60%, #142a1e 100%); }
.bg-garden-dark { background:
  radial-gradient(circle at 75% 15%, rgba(247,240,208,.35) 0 18px, transparent 40px),
  linear-gradient(180deg, #11121f 0%, #1a1f24 60%, #0f1712 100%); }
.bg-garden-dusk { background:
  radial-gradient(ellipse at 50% 100%, rgba(255,140,90,.4), transparent 60%),
  linear-gradient(180deg, #3b2c55 0%, #7a4a5a 55%, #2a2a22 100%); }
.bg-office-night { background:
  repeating-linear-gradient(0deg, rgba(160,200,230,.06) 0 2px, transparent 2px 60px),
  radial-gradient(ellipse at 30% 30%, rgba(170,220,255,.3), transparent 50%),
  linear-gradient(180deg, #1c2633 0%, #2b3a4a 60%, #161d26 100%); }
.bg-market-night { background:
  radial-gradient(circle at 30% 40%, rgba(220,255,140,.8) 0 2px, transparent 3px) 0 0/50px 46px,
  radial-gradient(circle at 70% 20%, rgba(255,220,120,.6) 0 2px, transparent 3px) 0 0/70px 64px,
  linear-gradient(180deg, #142218 0%, #23402c 55%, #1a1a2e 100%); }
.bg-street-day { background:
  radial-gradient(circle at 50% 10%, rgba(255,250,230,.5), transparent 45%),
  repeating-linear-gradient(90deg, rgba(0,0,0,.1) 0 3px, transparent 3px 70px),
  linear-gradient(180deg, #8fa3b8 0%, #b8a58c 55%, #6b5a4a 100%); }

/* ---------- play ---------- */
#screen-play { background:
  radial-gradient(ellipse at 50% 0%, rgba(242,196,107,.18), transparent 50%),
  linear-gradient(180deg, #3a2533, #2a1d2e 40%, #1f1622); }
.hud { padding: max(10px, env(safe-area-inset-top)) 14px 6px; display: flex; flex-direction: column; gap: 8px; }
.hud-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: rgba(0,0,0,.28); border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 18px; cursor: pointer; }
.lvl { display: flex; flex-direction: column; }
.lvl span { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--ink-soft); }
.lvl strong { font-family: var(--serif); font-size: 24px; color: var(--gold); line-height: 1.1; }
.moves { background: linear-gradient(180deg, #ffd88a, #f0a94a); color: var(--plum); border-radius: 16px; padding: 4px 14px;
  display: flex; flex-direction: column; align-items: center; box-shadow: 0 4px 0 #a8642a; min-width: 70px; }
.moves span { font-size: 28px; font-weight: 800; line-height: 1.05; }
.moves small { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.moves.low { animation: pulse .8s infinite; }
.goals { display: flex; gap: 8px; flex-wrap: wrap; }
.goal { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.28); border-radius: 999px; padding: 4px 12px 4px 6px; font-weight: 800; font-size: 16px; }
.goal img, .goal .gi { width: 30px; height: 30px; }
.goal.done { background: rgba(76,175,106,.35); }
.goal.done::after { content: '✓'; color: #b8f5c6; }
.gauge { background: rgba(0,0,0,.28); border-radius: 14px; padding: 8px 10px; }
.gauge-labels { display: flex; justify-content: space-between; font-size: 13px; font-weight: 800; margin-bottom: 5px; }
.gauge-bar { position: relative; height: 14px; border-radius: 999px; overflow: hidden; display: flex; background: rgba(255,255,255,.1); }
.gauge-bar div { height: 100%; transition: width .3s ease; }
.gauge-mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: #fff; opacity: .7; }
.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 4px 10px; min-height: 0; }
.board-frame {
  width: min(100%, calc(100dvh - var(--reserve, 250px))); aspect-ratio: 1; max-width: 460px;
  background: linear-gradient(180deg, #6b4532, #4e3123); border-radius: 22px; padding: 8px;
  box-shadow: inset 0 0 0 3px #8a5a3e, 0 12px 30px rgba(0,0,0,.45);
}
#board { width: 100%; height: 100%; }
#board canvas { display: block; touch-action: none; }
.play-bottom { display: flex; justify-content: center; padding: 6px 12px max(12px, env(safe-area-inset-bottom)); }

/* ---------- modal & toast ---------- */
.modal { position: absolute; inset: 0; background: rgba(10,6,12,.6); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 20px; animation: fadeIn .2s ease; }
.modal-box { background: linear-gradient(180deg, #3b2a40, #2a1d2e); border: 1px solid rgba(242,196,107,.5); border-radius: 24px; padding: 24px 20px; width: 100%; max-width: 380px;
  text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.modal-box h3 { font-family: var(--serif); font-size: 32px; margin: 0; color: var(--gold); }
.modal-box p { margin: 0; font-size: 16px; line-height: 1.45; color: var(--ink-soft); }
.modal-box .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.modal-box .face { width: 110px; height: 128px; }
.modal-box .face svg { width: 100%; height: 100%; }
.modal-box .pick { display: flex; gap: 10px; width: 100%; }
.modal-box .pick button { flex: 1; border-radius: 16px; padding: 12px 8px; border: 2px solid var(--c); background: rgba(255,255,255,.06); color: var(--ink); font-weight: 800; font-size: 15px; cursor: pointer; }
.modal-box .pick img { width: 40px; height: 40px; display: block; margin: 0 auto 6px; }
.toast { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); background: var(--panel); border: 1px solid rgba(242,196,107,.5);
  padding: 12px 18px; border-radius: 16px; font-weight: 700; z-index: 25; text-align: center; max-width: 86%; animation: fadeIn .2s ease; }

.lvl em { font-size: 13px; color: var(--ink-soft); }
.lvl em:empty { display: none; }
.rotate { display: none; position: absolute; inset: 0; z-index: 50; background: var(--plum); align-items: center; justify-content: center; text-align: center; font-size: 48px; }
.rotate p { font-size: 18px; color: var(--ink-soft); margin: 8px 24px 0; }
@media (orientation: landscape) and (max-height: 500px) {
  .rotate { display: flex; }
}

@media (max-height: 680px) {
  .portrait { bottom: 170px; }
  .dialogue { min-height: 160px; }
  .line { font-size: 17px; }
  .line.narr { font-size: 19px; }
  .logo { font-size: 52px; }
}

/* ---------- privacy notice & install ---------- */
.link { background: none; border: 0; padding: 10px 6px; min-height: 44px; color: var(--ink-soft); text-decoration: underline; font-size: 13px; cursor: pointer; }
.small.links { margin: 0; }
.privacy-note { width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid rgba(242,196,107,.4); border-radius: 18px; padding: 12px 14px; text-align: center; animation: fadeIn .3s ease; }
.privacy-note p { margin: 0 0 6px; font-size: 13px; line-height: 1.4; color: var(--ink-soft); }
.privacy-note .row { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }
.btn.small-btn { padding: 10px 20px; font-size: 15px; min-height: 44px; }
.privacy-text { max-height: 46dvh; overflow-y: auto; padding-right: 10px; text-align: left; display: flex; flex-direction: column; gap: 8px; user-select: text; -webkit-user-select: text; }
.modal-box .privacy-text p { font-size: 14px; line-height: 1.45; }
.modal-box .hint { font-size: 13px; opacity: .8; }
.toggle { display: flex; align-items: center; gap: 10px; font-weight: 700; min-height: 44px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--gold); }
.ios-share { display: inline-block; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: 13px; }
