/* css/base.css — デザイントークン・共通部品・IP ガード（owner=core。SPEC §2・§3-6）
   区画の CSS はこの後に読まれる。ここの class は CORE-API.md に一覧がある。 */

@property --room { syntax: '<color>'; inherits: true; initial-value: #FFE14A; }

:root {
  /* 2-1 色 */
  --paper: #F2EADB; --paper-deep: #E7DBC4; --paper-hi: #FBF6EC;
  --ink: #1C1B33; --ink-soft: #4A4766; --ink-line: rgba(28, 27, 51, .18);
  --do: #FF4B2B; --mi: #FFE14A; --so: #2BC3FF;
  --pop-1: var(--do); --pop-2: #FF9A1F; --pop-3: var(--mi); --pop-4: #43D66B; --pop-5: var(--so); --pop-6: #FF5FCF;
  --clay: #E9826B; --clay-deep: #C9634D;
  --night: #1C1B33; --night-sky: #2A2850; --moon: #FFF3C4;
  --shadow: rgba(28, 27, 51, .28);
  --room: #FFE14A;
  --room-tint: color-mix(in oklab, var(--room) 18%, var(--paper));

  /* 2-2 文字 */
  --f-pop: 'Mochiy Pop One', 'Zen Maru Gothic', system-ui, sans-serif;
  --f-body: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', system-ui, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;
  --f-q: 'Fraunces', Georgia, serif;
  --fs-hero: clamp(2.6rem, 10vw, 7.5rem);
  --fs-logo: clamp(1.5rem, 4.2vw, 3rem);
  --fs-h2: clamp(2rem, 6.4vw, 4.4rem);
  --fs-h3: clamp(1.2rem, 3vw, 1.75rem);
  --fs-lead: clamp(1.05rem, 2.2vw, 1.35rem);
  --fs-body: 1.0625rem;
  --fs-small: .875rem;
  --fs-mono: .8125rem;
  --lh-body: 1.85; --lh-head: 1.25; --tracking-head: .02em;

  /* 2-3 角丸・影 */
  --r-s: 10px; --r-m: 18px; --r-l: 28px; --r-pill: 999px;
  --sh-step: 0 4px 0 var(--ink);
  --sh-step-lg: 0 8px 0 var(--ink);
  --sh-float: 0 18px 24px -14px var(--shadow);
  --line: 3px solid var(--ink);
  --diecut: drop-shadow(0 0 0 #fff) drop-shadow(2px 0 0 #fff) drop-shadow(-2px 0 0 #fff) drop-shadow(0 2px 0 #fff) drop-shadow(0 -2px 0 #fff);
  --diecut-shadow: var(--diecut) drop-shadow(0 6px 0 rgba(28, 27, 51, .22));

  /* 2-4 余白 */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --sp-6: 32px; --sp-7: 48px; --sp-8: 72px; --sp-9: 112px; --sp-10: 160px;
  --gutter: clamp(16px, 4vw, 48px);
  --maxw: 1280px;
  --header-h: 64px;

  /* 重なり順 */
  --z-sec-bg: -2; --z-grain: -1; --z-chara: 5; --z-header: 60; --z-hud: 70; --z-layers: 80; --z-dialog: 90; --z-gate: 100;

  /* 動き（ZOO.motion と同じ値） */
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-soft: cubic-bezier(.22, .61, .36, 1);
  --dur-s: .25s; --dur-m: .6s; --dur-l: 1.1s;

  /* 紙目（6-13）とグレイン（3-40）の SVG */
  --tex-paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .11 0 0 0 0 .1 0 0 0 0 .2 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23p)'/%3E%3C/svg%3E");
  --tex-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.6' numOctaves='1' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)'/%3E%3C/svg%3E");

  color-scheme: light;
}
@media (max-width: 599px) { :root { --fs-body: 1rem; --header-h: 56px; } }

/* ---------- 基本 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: var(--header-h);
  transition: --room .6s var(--ease-soft);
  overflow-x: clip;
}
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image: var(--tex-paper);            /* 6-13 紙目。静的・blend なし */
  background-size: 240px 240px;
  color: var(--ink);
  font-family: var(--f-body);
  font-weight: 500;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'palt' 0;
}
/* 3-40 グレイン: 区画の背景より上・中身（原画）より下。transform の steps で合成レイヤーだけ動かす */
body::before {
  content: '';
  position: fixed;
  inset: -60px;
  z-index: var(--z-grain);
  pointer-events: none;
  background-image: var(--tex-grain);
  background-size: 180px 180px;
  opacity: .028;
  animation: zoo-grain 1s steps(4) infinite;
}
@keyframes zoo-grain {
  0% { transform: translate(0, 0); } 25% { transform: translate(-22px, 14px); }
  50% { transform: translate(18px, -26px); } 75% { transform: translate(-12px, -8px); } 100% { transform: translate(0, 0); }
}
img, svg, canvas { max-width: 100%; }
img { height: auto; }
a { color: inherit; text-underline-offset: .2em; }
button { font: inherit; color: inherit; }
:where(h1, h2, h3, h4) { font-family: var(--f-pop); font-weight: 400; line-height: var(--lh-head); letter-spacing: var(--tracking-head); margin: 0; }
:where(p) { margin: 0 0 1em; }
.mono { font-family: var(--f-mono); font-size: var(--fs-mono); letter-spacing: .04em; }
.qq { font-family: var(--f-q); font-style: italic; font-weight: 700; }
.lead { font-size: var(--fs-lead); line-height: 1.75; }
.small { font-size: var(--fs-small); }
.visually-hidden, .sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* skip link */
.skip {
  position: fixed; left: var(--sp-4); top: var(--sp-3); z-index: calc(var(--z-gate) + 1);
  padding: var(--sp-2) var(--sp-4); background: var(--ink); color: var(--paper-hi);
  border-radius: var(--r-pill); font-weight: 700; text-decoration: none;
  transform: translateY(-160%); transition: transform .2s;
}
.skip:focus-visible { transform: none; }

/* フォーカスリング: 墨の輪＋レモンの外輪。どの地でも見える */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  box-shadow: 0 0 0 7px var(--mi);
  border-radius: var(--r-s);
}
:focus:not(:focus-visible) { outline: none; }

/* ---------- 区画の枠（SPEC §4 共通マークアップ） ---------- */
/* 区画の地は ::before（z -2）に塗る。グレイン（z -1）はその上、中身はさらに上に来る。
   → .sec 自身に z-index / transform / opacity / filter をかけない（重なり順が壊れる）。地の色は --sec-bg で変える */
.sec {
  --sec-bg: var(--room-tint);
  position: relative;
  overflow-x: clip;
  padding: var(--sp-8) var(--gutter);
  scroll-margin-top: var(--header-h);
}
.sec::before { content: ''; position: absolute; inset: 0; z-index: var(--z-sec-bg); background: var(--sec-bg); pointer-events: none; }
@media (min-width: 900px) {
  .sec { padding: var(--sp-10) var(--gutter) var(--sp-10) calc(var(--gutter) + 72px); }
}
.sec-inner, .wrap { max-width: var(--maxw); margin-inline: auto; }

/* 区画の縦帯（900px 以上）／横長の札（900px 未満） */
.area-band {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  padding: var(--sp-2) var(--sp-4);
  background: var(--sec-room, var(--room)); color: var(--ink);
  border: var(--line); border-radius: var(--r-m); box-shadow: var(--sh-step);
}
/* 統合: 部屋の色が暗い区画（夜 #5e008e・退園 #7631ff）は墨の字が沈むので、明るい字にする */
.sec-night .area-band, .sec-exit .area-band { color: var(--paper-hi); }
.area-no { font-family: var(--f-mono); font-size: var(--fs-mono); letter-spacing: .12em; }
.area-name { font-family: var(--f-body); font-weight: 900; }
@media (min-width: 900px) {
  .area-band {
    position: absolute; left: 0; top: 0; bottom: 0; width: 56px; margin: 0;
    flex-direction: column; justify-content: flex-start; gap: var(--sp-5);
    padding: var(--sp-6) 0; border-width: 0 3px 0 0; border-radius: 0; box-shadow: none;
  }
  .area-no { writing-mode: vertical-rl; }
  .area-name { writing-mode: vertical-rl; letter-spacing: .3em; font-size: 1.05rem; }
}

/* ---------- 多色見出し .poptitle（2-2） ---------- */
.poptitle {
  font-family: var(--f-pop); font-size: var(--fs-h2); line-height: 1.15; letter-spacing: var(--tracking-head);
  margin: 0 0 var(--sp-6);
  overflow-wrap: anywhere;
}
.poptitle .ch, .pop .ch {
  display: inline-block;
  -webkit-text-stroke: .09em var(--ink);
  paint-order: stroke fill;
  text-shadow: .05em .06em 0 var(--ink);
}
.poptitle .sp, .pop .sp { display: inline-block; width: .35em; }
.ch[data-c="1"] { color: var(--pop-1); } .ch[data-c="2"] { color: var(--pop-2); } .ch[data-c="3"] { color: var(--pop-3); }
.ch[data-c="4"] { color: var(--pop-4); } .ch[data-c="5"] { color: var(--pop-5); } .ch[data-c="6"] { color: var(--pop-6); }
.poptitle--ink .ch, .poptitle--ink { color: var(--ink) !important; -webkit-text-stroke: 0; text-shadow: none; }
/* 1-4 のマスクせり上げが効くように、見出しの外枠でクリップ */
.mp-heading { overflow: hidden; padding-bottom: .12em; }
.mp-heading .mp-heading-inner { display: inline-block; }

/* ---------- IP ガード（3-6。全ユニットが従う） ---------- */
img.chara { filter: none; mix-blend-mode: normal; image-rendering: auto; max-width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
img.chara--cut { filter: var(--diecut, none); }   /* drop-shadow だけ */
img.chara--cut.is-lifted { filter: var(--diecut-shadow); }
img.chara--tile { border-radius: 0; }
.frame-round {
  display: inline-grid; place-items: center; aspect-ratio: 1; overflow: hidden;
  border-radius: 50%; border: var(--line);
  box-shadow: 0 0 0 6px var(--paper-hi), 0 0 0 9px var(--ink);
  background: var(--paper-hi);
  vertical-align: middle;
}
.frame-round > img.chara { width: 100%; height: 100%; object-fit: cover; }

/* 接地影・台座 */
.chara-stand { position: relative; display: inline-grid; justify-items: center; align-items: end; }
.ground {
  display: block; width: 70%; height: 14px; margin-top: -8px;
  background: radial-gradient(closest-side, rgba(28, 27, 51, .35), transparent);
  transform-origin: 50% 50%; pointer-events: none;
}
.pedestal {
  display: block; width: 86%; height: 22px; margin-top: -12px;
  background: var(--clay); border: var(--line); border-radius: 50%;
  box-shadow: 0 5px 0 var(--clay-deep), 0 5px 0 3px var(--ink);
  transform-origin: 50% 50%;
}

/* ---------- 部品 ---------- */
/* 札（ひも穴つき看板） */
.fuda {
  position: relative; display: inline-block;
  padding: var(--sp-4) var(--sp-5) var(--sp-3);
  background: var(--paper-hi); border: var(--line); border-radius: var(--r-m); box-shadow: var(--sh-step);
  font-weight: 700;
}
.fuda::before {
  content: ''; position: absolute; left: 50%; top: 7px; width: 10px; height: 10px; margin-left: -5px;
  border-radius: 50%; background: var(--paper); border: 2px solid var(--ink);
}
.fuda--room { background: var(--sec-room, var(--room)); }

/* 入園券（左端にミシン目と切り欠き） */
.ticket {
  --notch: 14px;
  position: relative;
  background: var(--paper-hi);
  border: var(--line); border-radius: var(--r-m);
  box-shadow: var(--sh-step-lg);
  padding: var(--sp-5) var(--sp-5) var(--sp-5) calc(var(--sp-5) + 22px);
  background-image:
    radial-gradient(circle, var(--ink) 1.6px, transparent 2.2px);
  background-size: 6px 10px;
  background-repeat: repeat-y;
  background-position: 18px 0;
}
.ticket::before, .ticket::after {
  content: ''; position: absolute; left: 6px; width: calc(var(--notch) * 2); height: var(--notch);
  background: var(--paper); border: var(--line);
}
.ticket::before { top: -3px; border-top: 0; border-radius: 0 0 999px 999px; }
.ticket::after { bottom: -3px; border-bottom: 0; border-radius: 999px 999px 0 0; }

/* スタンプ（1色の丸い判子、版ずれ） */
.stamp {
  --stamp-color: var(--do);
  display: inline-grid; place-items: center;
  width: 84px; aspect-ratio: 1; border-radius: 50%;
  border: 3px double var(--stamp-color); color: var(--stamp-color);
  font-family: var(--f-pop); font-size: .95rem; line-height: 1.1; text-align: center;
  text-shadow: 2px 1px 0 rgba(255, 75, 43, .45);
  transform: rotate(var(--stamp-rot, -6deg));
}
.stamp--ink { --stamp-color: var(--ink); }
.stamp.is-empty { border-style: dashed; border-color: var(--ink-line); color: var(--ink-line); text-shadow: none; }

/* ボタンの基本（ねんど。押すと沈む） */
.btn {
  --btn-bg: var(--paper-hi); --btn-fg: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 48px; padding: var(--sp-2) var(--sp-5);
  background: var(--btn-bg); color: var(--btn-fg);
  border: var(--line); border-radius: var(--r-pill); box-shadow: var(--sh-step);
  font-family: var(--f-body); font-weight: 900; font-size: 1rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; touch-action: manipulation;
  transition: transform .18s var(--ease-spring), box-shadow .18s var(--ease-spring), background-color .2s;
}
.btn:active, .btn[aria-pressed="true"] { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn--clay { --btn-bg: var(--clay); }
.btn--do { --btn-bg: var(--do); --btn-fg: var(--paper-hi); }
.btn--mi { --btn-bg: var(--mi); }
.btn--so { --btn-bg: var(--so); }
.btn--ink { --btn-bg: var(--ink); --btn-fg: var(--paper-hi); }
.btn--sm { min-height: 40px; padding: var(--sp-1) var(--sp-4); font-size: var(--fs-small); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background-color: color-mix(in oklab, var(--btn-bg) 82%, var(--mi)); }
}
/* 「あそぶ」を押した面だけ縦スクロールを奪ってよい */
.is-playing { touch-action: none; }

/* 額（原画・スチルの額縁） */
.gaku {
  display: block; border: var(--line); border-radius: var(--r-s);
  background: var(--paper-hi); padding: 10px; box-shadow: var(--sh-step-lg);
}

/* バッジ（「こえ あり」など） */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border: 2px solid var(--ink); border-radius: var(--r-pill);
  background: var(--mi); font-size: var(--fs-small); font-weight: 700; line-height: 1.5;
}

/* クレヨン波線（6-21。build が区画の間に入れる。動きは chrome） */
.wave-sep { position: relative; height: 40px; margin: -20px 0; pointer-events: none; }
.wave-sep svg { display: block; width: 100%; height: 100%; overflow: visible; }
.wave-sep path { fill: none; stroke-width: 7; stroke-linecap: round; }

/* ---------- dialog の基本 ---------- */
dialog.zoo-dialog, dialog[data-zoo-dialog] {
  width: min(92vw, 880px); max-height: min(88vh, 900px);
  padding: 0; border: var(--line); border-radius: var(--r-l);
  background: var(--paper-hi); color: var(--ink); box-shadow: var(--sh-step-lg), 0 30px 60px -20px var(--shadow);
  overflow: auto; overscroll-behavior: contain;
}
dialog.zoo-dialog::backdrop, dialog[data-zoo-dialog]::backdrop { background: rgba(28, 27, 51, .55); }
.dialog-close {
  position: sticky; top: var(--sp-3); float: right; margin: var(--sp-3);
  width: 48px; height: 48px; border-radius: 50%; border: var(--line); background: var(--mi); box-shadow: var(--sh-step);
  font-weight: 900; cursor: pointer; z-index: 2;
}

/* ---------- 常駐レイヤー #layers（4-18）とトースト（8-32） ---------- */
#layers { position: fixed; inset: 0; z-index: var(--z-layers); pointer-events: none; }
#layers > * { pointer-events: none; }
#layers .toasts {
  position: absolute; left: 50%; bottom: calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
  width: min(92vw, 420px); transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 0;
}
.toast-row { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .32s var(--ease-soft), opacity .32s; }
.toast-row > .toast { overflow: hidden; min-height: 0; }
.toast-row.is-leaving { grid-template-rows: 0fr; opacity: 0; }
.toast {
  margin-top: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  background: var(--ink); color: var(--paper-hi);
  border-radius: var(--r-pill); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--do);
  font-weight: 700; text-align: center; line-height: 1.5;
  animation: zoo-toast-in .42s var(--ease-spring) both;
}
@keyframes zoo-toast-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#layers canvas.confetti { position: fixed; inset: 0; width: 100%; height: 100%; }

/* ---------- 停止（reduced / うごき オフ / 画面外） ---------- */
[data-loop].is-offscreen, [data-loop].is-offscreen * { animation-play-state: paused !important; }
html[data-motion="off"] [data-loop], html[data-motion="off"] [data-loop] *,
html[data-motion="off"] .mp-on-1-28 { animation-play-state: paused !important; }
html[data-motion="off"] body::before { animation: none; }
html[data-motion="off"] [data-mp="cta"] .mp-cta-btn { transition: none; }
html[data-motion="off"] { transition: none; }
html[data-motion="off"] .toast { animation: none; }
/* 統合: 図鑑 2-14（マウス併用パララックス）は起動後に「うごき」を切っても mousemove で動き続ける。スニペットは変えず、見た目の位置だけ止める */
html[data-motion="off"] [data-mp="hero"] .mp-hero-title,
html[data-motion="off"] [data-mp="hero"] .mp-hero-sub { transform: none !important; }
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  [data-loop], [data-loop] *, .mp-on-1-28 { animation-play-state: paused !important; }
  [data-mp="cta"] .mp-cta-btn { transition: none; }
  html { transition: none; scroll-behavior: auto; }
  .toast { animation: none; }
}
/* 読み込み中のローダーはボタンを塞がない（4-25。中身は gate-hero） */
#mp-loader { pointer-events: none; }
