/* 幻想繪卷 — shared look: antique storybook, cream washi, dusty blue, rose, muted gold */
:root {
  --cream: #fbf5ea;
  --paper: #f6eddc;
  --ink: #3b335e;
  --ink-soft: #6a6288;
  --navy: #2b3560;
  --blue: #7f93c4;
  --rose: #d9798d;
  --rose-soft: #f2c6cf;
  --gold: #b8862f;
  --gold-soft: #e7cf96;
  --font-display: Georgia, serif;
  --top: 56px; /* top bar height */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #efe3cf; touch-action: none; user-select: none; -webkit-user-select: none; }
body {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,.7), transparent 60%),
    repeating-linear-gradient(17deg, rgba(160,130,90,.025) 0 2px, transparent 2px 7px),
    #efe3cf;
  font-family: var(--font-display);
  color: var(--ink);
}
#app { position: fixed; top: 0; left: 0; transform-origin: 0 0; overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255,255,255,.85), transparent 55%),
    repeating-linear-gradient(103deg, rgba(150,120,80,.03) 0 1px, transparent 1px 5px),
    var(--cream);
}
#screens, #modals, #fx { position: absolute; inset: 0; }
#modals { pointer-events: none; z-index: 40; }
#modals > * { pointer-events: auto; }
#fx { pointer-events: none; z-index: 60; }
.screen { position: absolute; inset: 0; overflow: hidden; display: flex; flex-direction: column; }
.screen.enter { animation: scrIn .3s cubic-bezier(.2,1.2,.4,1) both; }
.screen.leave { animation: scrOut .24s ease-in both; pointer-events: none; }
@keyframes scrIn { from { opacity: 0; transform: translateY(18px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes scrOut { to { opacity: 0; transform: translateY(-10px); } }

/* studio canvas stage (persistent, the studio places it) */
#studio-stage { position: absolute; display: none; z-index: 5; }
#studio-stage.on { display: block; }
#paint-view { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- display type ---------- */
.display, .panel-title, h1, h2, h3 { font-family: var(--font-display); font-weight: 900; color: var(--navy);
  paint-order: stroke fill; -webkit-text-stroke: 4px #fffaf0; text-shadow: 0 2px 0 rgba(217,121,141,.35); margin: 0; }
.panel-title { font-size: 22px; text-align: center; margin: 2px 0 10px; letter-spacing: .02em; }

/* ---------- 9-slice panel and button ---------- */
.panel {
  position: relative;
  border-style: solid; border-width: 24px;
  border-image: url(../assets/ui-panel.webp) 12% fill / 24px stretch;
  filter: drop-shadow(0 6px 14px rgba(60, 40, 70, .22));
}
.panel-inner { position: relative; padding: 8px; }
.btn {
  appearance: none; -webkit-appearance: none; background: none; cursor: pointer;
  min-height: 46px; min-width: 46px; padding: 0 10px;
  border-style: solid; border-width: 12px 22px;
  border-image: url(../assets/ui-button.webp) 30% 22% fill / 12px 22px stretch;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-display); font-weight: 900; font-size: 16px; color: #fffaf3;
  paint-order: stroke fill; -webkit-text-stroke: 3px #8e4058; letter-spacing: .02em;
  transition: transform .12s cubic-bezier(.3,1.6,.5,1), filter .15s;
  filter: drop-shadow(0 3px 0 rgba(120, 60, 80, .25));
}
.btn:hover { filter: drop-shadow(0 3px 0 rgba(120,60,80,.25)) brightness(1.06); transform: translateY(-1px) scale(1.02); }
.btn:active { transform: scale(.93); }
.btn[disabled], .btn.disabled { filter: grayscale(.8) opacity(.6); pointer-events: none; }
.btn-small { min-height: 44px; font-size: 14px; border-width: 10px 16px; border-image-width: 10px 16px; padding: 0 4px; }
.btn-icon { width: 24px; height: 24px; object-fit: contain; -webkit-text-stroke: 0; }
.btn-label { white-space: nowrap; }
.btn.btn-blue { filter: hue-rotate(195deg) saturate(.7) drop-shadow(0 3px 0 rgba(40,50,100,.25)); -webkit-text-stroke-color: #2b3560; }
.btn.btn-gold { filter: hue-rotate(35deg) saturate(.9) brightness(1.05) drop-shadow(0 3px 0 rgba(120,90,30,.25)); -webkit-text-stroke-color: #7a5212; }
.btn.btn-gold[disabled], .btn.btn-blue[disabled], .btn[disabled] { filter: grayscale(1) opacity(.45); pointer-events: none; }
.nav-focus { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 14px; animation: navPulse 1s ease-in-out infinite; }
@keyframes navPulse { 50% { outline-color: var(--rose); } }

/* ---------- top bar + gold pill ---------- */
.topbar { position: relative; height: var(--top); flex: none; display: flex; align-items: center; gap: 8px; padding: 0 70px 0 10px; z-index: 3; }
.gold-pill { appearance: none; border: 0; cursor: pointer; height: 44px; min-width: 88px; padding: 0 14px 0 6px; display: inline-flex; align-items: center; gap: 4px;
  border-radius: 20px; background: linear-gradient(#fffaf2, #f3e6cd); box-shadow: inset 0 0 0 2px var(--gold-soft), 0 2px 6px rgba(80,50,40,.15);
  font-family: var(--font-display); font-weight: 900; font-size: 18px; color: var(--navy); }
.gold-pill img { width: 30px; height: 30px; object-fit: contain; }
.gold-pill:active { transform: scale(.95); }

/* ---------- ribbon bookmark (shared by every tab bar) ---------- */
.ribbon { position: relative; appearance: none; border: 0; background: none; cursor: pointer; padding: 0; width: 64px; height: 74px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 8px;
  background: linear-gradient(90deg, rgba(0,0,0,.08), transparent 18%, transparent 82%, rgba(0,0,0,.08)), var(--rb, #7f93c4);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 84%, 0 100%);
  box-shadow: inset 0 0 0 2px rgba(255,236,190,.6);
  transform-origin: top center; transition: height .25s cubic-bezier(.3,1.5,.5,1), filter .15s;
  font-family: var(--font-display); font-weight: 900; font-size: 12px; color: #fffaf2; -webkit-text-stroke: 2px rgba(40,30,60,.55); paint-order: stroke fill; }
.ribbon::before { content: ""; position: absolute; inset: 3px 4px 10px; border: 1px dashed rgba(255,236,190,.75); clip-path: inherit; pointer-events: none; }
.ribbon img { width: 30px; height: 30px; object-fit: contain; margin-bottom: 2px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.ribbon.active { height: 90px; filter: brightness(1.08) saturate(1.1); }
.ribbon:active { filter: brightness(.95); }

/* ---------- modal ---------- */
.modal-back { position: absolute; inset: 0; background: rgba(40, 30, 60, .42); display: flex; align-items: center; justify-content: center; padding: 14px; animation: fadeIn .18s both; }
.modal-back.out { animation: fadeOut .2s both; }
.modal-panel { width: 100%; max-width: 372px; max-height: 92%; overflow: auto; animation: popIn .26s cubic-bezier(.2,1.4,.4,1) both; }
.modal-x { position: absolute; top: -6px; right: -6px; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 40% 35%, #fff, #f1dfc4); box-shadow: 0 0 0 2px var(--gold-soft), 0 2px 6px rgba(0,0,0,.2);
  font-size: 18px; color: var(--navy); font-weight: 900; z-index: 2; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.8); } 70% { transform: scale(1.03); } to { opacity: 1; transform: none; } }

.help-text p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--ink); }

/* ---------- toasts / subtitles ---------- */
#toasts { position: absolute; left: 0; right: 0; top: 64px; display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 70; pointer-events: none; }
.toast { background: rgba(59, 51, 94, .92); color: #fffaf2; padding: 9px 18px; border-radius: 20px; font-size: 15px; font-weight: 700; box-shadow: 0 0 0 2px var(--gold-soft);
  animation: popIn .25s both; max-width: 86%; text-align: center; transition: opacity .3s, transform .3s; }
.toast.out { opacity: 0; transform: translateY(-8px); }
.subtitle { position: absolute; left: 14px; right: 14px; bottom: 120px; z-index: 65; pointer-events: none; text-align: center;
  font-size: 16px; font-weight: 700; color: #fffaf2; background: rgba(43,53,96,.82); border-radius: 14px; padding: 9px 12px;
  box-shadow: 0 0 0 2px rgba(231,207,150,.8); opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
.subtitle.show { opacity: 1; transform: none; }

/* ---------- intro ---------- */
.intro { position: absolute; inset: 0; z-index: 80; background: #f6eddc url(../assets/cover-bg.webp) center / cover no-repeat; }
.intro.out { animation: fadeOut .3s both; }
.intro-video { width: 100%; height: 100%; object-fit: cover; display: block; background: transparent; }
.intro-skip { position: absolute; right: 16px; bottom: 28px; min-width: 96px; }

/* ---------- effects ---------- */
.vfx-canvas { position: absolute; pointer-events: none; }
.fly-coin { position: absolute; width: 28px; height: 28px; pointer-events: none; transform: translate(-50%, -50%); }
.guide-canvas { display: block; pointer-events: none; }
.scroll-y { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-y; scrollbar-width: none; }
.scroll-y::-webkit-scrollbar { display: none; }
