/* コエキット 共通デザイントークン（正典: docs/screens.md 1節） */

/* フォント自前配置（T-002）— M PLUS Rounded 1c を woff2 で assets/fonts/ に配置。
   Google Fonts CDN は使わない（オフライン対応）。使用文字だけにサブセット済み。
   ライセンス: SIL OFL 1.1（assets/fonts/LICENSE.txt）。
   url() は本CSSの位置基準で解決されるため、/koekit/ 配下でもそのまま動作する。
   font-display: swap により、読込前・読込失敗時はフォールバック書体で表示される。 */
@font-face {
  font-family: "M PLUS Rounded 1c";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./assets/fonts/MPLUSRounded1c-Regular.subset.woff2") format("woff2");
}
@font-face {
  font-family: "M PLUS Rounded 1c";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./assets/fonts/MPLUSRounded1c-Bold.subset.woff2") format("woff2");
}

:root {
  /* フォント — 自前配置した M PLUS Rounded 1c を最優先、以降はフォールバック。
     font-family は必ず指定する（無指定でOS依存の sans-serif に任せない）。 */
  --font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN",
                 "Yu Gothic UI", "Meiryo", sans-serif;

  /* 色 */
  --color-bg: #f2f6fb;
  --color-fg: #223c60;
  --color-accent: #f4c64e;
  --color-primary: #284f85;
  --color-confirm: #16816e;
  --color-muted: #5c6e83;
  --color-line: #dce5ef;

  /* 基準値（docs/screens.md 1節・【想定】） */
  --base-size: 16px;
  --line-height: 1.6;
  --tap-min: 48px;   /* 最小タップ領域 */
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--base-size);
  line-height: var(--line-height);
  color: var(--color-fg);
  background: var(--color-bg);
  min-height: 100vh;
}

/* ===== 共有UIコンポーネント（ピタリズム／メモリズム 共通） =====
   src/ui/* のビューが前提とするクラス。各アプリの index.html は同じIDで組む。 */
.hidden { display: none !important; }
.screen { display: none; min-height: 100svh; }
.screen.active { display: flex; flex-direction: column; }

.btn-round { border: none; background: var(--color-primary); color: #fff; width: clamp(80px, 25vw, 124px); flex-shrink: 0;
  aspect-ratio: 1/1; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 5px 0 #173960, 0 12px 22px #284f8520; cursor: pointer; transition: transform .15s; }
.btn-round:active { transform: scale(.97); }
.btn-round svg { width: 45%; height: 45%; fill: #fff; }
.btn-round.confirm { background: var(--color-confirm); box-shadow: 0 5px 0 #0d6152, 0 12px 22px #16816e20; }
/* 非活性（選択前の確定ボタン）。レイアウトは保持したまま押せない・薄い表示。 */
.btn-round:disabled { opacity: .28; box-shadow: none; cursor: default; }
.btn-round:disabled:active { transform: none; }
.icon-btn { border: none; background: #fff; color: var(--color-fg); padding: 10px; min-width: var(--tap-min);
  min-height: var(--tap-min); border-radius: 12px; cursor: pointer; }
.icon-btn svg { width: 28px; height: 28px; }
.icon-btn:active { background: rgba(0,0,0,.06); }
.lv-btn { width: 52px; height: 52px; border-radius: 14px; border: 1px solid var(--color-line);
  background: #fff; color: var(--color-fg); font-family: var(--font-family); font-size: 1.3rem;
  font-weight: 700; cursor: pointer; display: grid; place-items: center; }
.lv-btn:active { background: #fff8e6; }
.lv-btn svg { width: 26px; height: 26px; fill: var(--color-accent); }

#game { padding: 0; }
#game .topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; }
/* コントロール行は常に一定の高さを確保する。ボタンの表示/非表示（スタート↔確定↔つぎ、
   惰性中の空表示）で行が縮まず、盤面が上下に動かないようにする。 */
#game .controls { display: flex; gap: 20px; justify-content: center; align-items: center;
  padding: 16px 0 max(24px, env(safe-area-inset-bottom)); min-height: calc(clamp(80px, 25vw, 124px) + 48px); }
#stage { flex: 1; min-height: 0; margin: 6px 12px; padding: 14px 6px; border-radius: 32px; border: 3px solid transparent; background: #fff;
  display: grid; place-items: center; position: relative; transition: border-color .15s, box-shadow .15s; }
#stage.listening { border-color: var(--color-accent); box-shadow: 0 0 0 6px rgba(255,179,0,.18) inset; }
#stage.restarting { border-color: #ffd980; }

#board { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: clamp(8px, 2.5vw, 14px); width: min(80vw, 460px, max(290px, calc(100svh - 260px)) ); aspect-ratio: 1/1; }
.card { border-radius: 22%; background: var(--color-accent); box-shadow: inset 0 -5px 0 #dba72d, inset 0 2px 0 #ffe9a0, 0 5px 8px #223c6010;
  display: grid; place-items: center; position: relative; min-width: 0; }
.card.focus { outline: 6px solid var(--color-primary); outline-offset: -3px; }
/* 認識/選択した位置は、カード自体をはっきりフォーカス（矢印は使わない）。 */
.card.selected { outline: 6px solid var(--color-confirm); outline-offset: -3px;
  box-shadow: 0 0 0 6px #16816e25, 0 6px 16px rgba(0,0,0,.22);
  transform: scale(1.05); z-index: 3; transition: transform .1s; }
.card.flipped { background: #fff; border: 2px solid var(--color-line); box-shadow: 0 4px 8px #223c6010; }
/* 前面（絵/文字/赤丸）はめくった時だけ見せる。裏向き(.card:not(.flipped))では隠す。 */
.card .front { width: 100%; height: 100%; display: none; place-items: center; overflow: hidden; }
.card.flipped .front { display: grid; }
.card .front img { width: 100%; height: 100%; min-height: 0; padding: 6%; object-fit: contain; } /* メモリズムの絵：縦横比維持・トリミングなし */
.card-dot { width: 62%; aspect-ratio: 1; border-radius: 50%; background: #e23b3b; } /* 正解の赤丸プレースホルダ */

/* 認識結果の図示は、盤面上部の「トースト」として出す。
   pointer-events:none で下の盤面・ボタンを塞がない（言い直しの札タップ・確定が可能）。 */
#figure { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: none; align-items: center; justify-content: center; padding: 6px 14px;
  background: rgba(255,255,255,.96); border: 2px solid var(--color-confirm); border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,.18); pointer-events: none; }
#figure.show { display: flex; animation: toastIn .18s ease both; }
#figure svg { width: 44px; height: 44px; transition: transform .12s; }
#figure .arrow { fill: var(--color-confirm); }
#figure .dot { fill: var(--color-confirm); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.mic { width: 34px; height: 34px; }
.mic .body { fill: #c9c9c9; transition: fill .15s; }
.mic .slash { stroke: #d33; stroke-width: 6; display: none; }
.mic-state.listening .mic .body { fill: var(--color-accent); }
.mic-state.denied .mic .body { fill: #bbb; }
.mic-state.denied .mic .slash { display: block; }
.mic-state.restarting .mic .body { fill: var(--color-accent); animation: blink .6s steps(2, end) infinite; }
@keyframes blink { 50% { opacity: .3; } }
.finger { width: 30px; height: 30px; display: none; }
.mic-state.denied ~ .finger { display: inline-block; }

#cert { align-items: center; justify-content: center; gap: 26px; padding: 24px; text-align: center; position: relative; overflow: hidden; }
.medal { width: 46vw; max-width: 220px; aspect-ratio: 1/1; border-radius: 50%;
  display: grid; place-items: center; box-shadow: 0 8px 20px rgba(0,0,0,.18); position: relative; z-index: 2; }
.medal.clear { background: radial-gradient(circle at 50% 38%, #ffe08a, #ffb300); }
.medal.over { background: radial-gradient(circle at 50% 38%, #d8d8d8, #a8a8a8); }
.medal svg { width: 56%; height: 56%; }
#cert-stars { display: flex; gap: 6px; z-index: 2; }
#cert-stars svg { width: 30px; height: 30px; }

/* クリア演出：メダルが弾んで出て、星が順に光る。クリア時のみ後光＋きらめき。 */
#cert.active .medal { animation: medalPop .5s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes medalPop { 0% { transform: scale(0) rotate(-35deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(6deg); } 100% { transform: scale(1) rotate(0); opacity: 1; } }
#cert.active #cert-stars svg { animation: starPop .35s ease both; transform: scale(0); }
#cert.active #cert-stars svg:nth-child(1) { animation-delay: .45s; }
#cert.active #cert-stars svg:nth-child(2) { animation-delay: .55s; }
#cert.active #cert-stars svg:nth-child(3) { animation-delay: .65s; }
#cert.active #cert-stars svg:nth-child(4) { animation-delay: .75s; }
#cert.active #cert-stars svg:nth-child(5) { animation-delay: .85s; }
#cert.active #cert-stars svg:nth-child(6) { animation-delay: .95s; }
@keyframes starPop { 0% { transform: scale(0) rotate(-20deg); } 70% { transform: scale(1.3); } 100% { transform: scale(1) rotate(0); } }
/* クリア時だけメダル背後に広がる後光 */
#cert[data-kind="clear"].active .medal::after {
  content: ""; position: absolute; inset: -22%; border-radius: 50%; z-index: -1;
  background: radial-gradient(circle, rgba(255,214,102,.55), rgba(255,214,102,0) 70%);
  animation: halo 1.2s ease-out .2s both; }
@keyframes halo { 0% { transform: scale(.4); opacity: 0; } 40% { opacity: 1; } 100% { transform: scale(1.15); opacity: .5; } }
#cert .cert-next-wrap { z-index: 2; }

/* 共通の見え方：青い操作ボタン、黄色の札、緑の確定。 */
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 5px; }
.play-app { background: var(--color-bg); }
.play-app .screen { max-width: 600px; margin-inline: auto; }
#title { align-items: center; justify-content: center; gap: 24px; padding: 76px 24px 60px; position: relative; }
#title .app-title { font-size: clamp(25px, 6.5vw, 36px); letter-spacing: -.04em; margin: 0; }
#title .home, #title .gear { position: absolute; top: max(16px, env(safe-area-inset-top)); color: var(--color-muted); }
#title .home { left: 20px; text-decoration: none; }
#title .gear { right: 20px; }
.level-picker { text-align: center; margin-top: 6px; }
.level-picker p { margin: 0 0 12px; color: var(--color-muted); font-size: .8rem; }
#level-select { display: grid; grid-template-columns: repeat(4, 48px); gap: 10px; justify-content: center; }
.kioku #level-select { grid-template-columns: repeat(3, 48px); }
.lv-btn { width: 48px; height: 48px; box-shadow: 0 3px 0 #dce5ef; }
.lv-btn svg { fill: var(--color-primary); }
.title-footer { margin-top: 12px; text-align: center; font-size: .7rem; color: var(--color-muted); }
#game { min-height: 100svh; padding-top: env(safe-area-inset-top); }
#game .topbar { padding: 12px 20px; }
.mic-state { border-radius: 50%; padding: 8px; display: grid; place-items: center; background: #fff; }
.mic-state.listening { background: #fff1bc; }
.card:not(.flipped)::before { content: ''; width: 25%; aspect-ratio: 1; border: 3px solid #fff8; border-radius: 50%; }
.card.selected::after, .card.correct::after { content: ''; position: absolute; top: 9%; right: 9%; width: 18%; height: 10%; border-left: 4px solid var(--color-confirm); border-bottom: 4px solid var(--color-confirm); transform: rotate(-45deg); }
.card.correct { outline: 5px solid var(--color-confirm); outline-offset: -2px; }
#figure { background: #fff; border-width: 1px; box-shadow: 0 8px 28px #223c6020; }
#countdown { background: var(--color-primary); color: #fff; border-radius: 50%; width: 64px; height: 64px; display: grid; place-items: center; font-size: 2rem; text-shadow: none; z-index: 6; }
#target-prompt { border-radius: 26px; }
#panel { background: #fff; }

/* 開始案内：ネイティブdialogで背面への操作・フォーカス移動を防ぐ。 */
#level-intro { color: var(--color-fg); border: 0; padding: 0; border-radius: 30px; width: min(440px, calc(100% - 32px)); max-height: calc(100svh - 32px); background: #fff; box-shadow: 0 24px 90px #102d4c40; overflow: auto; overscroll-behavior: contain; }
#level-intro::backdrop { background: #17345166; backdrop-filter: blur(8px); }
#level-intro[open] { animation: introIn .22s ease-out; }
.intro-card { padding: 24px; }
.intro-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.intro-badge { color: var(--color-primary); background: #eaf1fa; border-radius: 10px; padding: 5px 12px; font-size: .8rem; font-weight: 700; }
.intro-back { color: var(--color-muted); border: 0; border-radius: 10px; background: transparent; min-height: 48px; min-width: 48px; cursor: pointer; font-size: .8rem; }
#intro-heading { margin: 12px 0 8px; font-size: clamp(20px, 5vw, 25px); line-height: 1.5; letter-spacing: -.045em; }
.intro-text { margin: 0; color: var(--color-muted); font-size: 1rem; line-height: 1.8; }
.intro-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 360px; margin: 20px auto; }
.preview-tile, .preview-empty { min-height: 60px; min-width: 0; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: clamp(13px, 4vw, 18px); line-height: 1.5; text-align: center; word-break: keep-all; }
.preview-tile { padding: 8px; background: #fff0b7; color: #594316; box-shadow: 0 3px 0 #ead598; }
.preview-empty { border: 1px dashed #dce5ef; }
.practice-preview { align-items: center; padding-block: 8px; }
.preview-number { display: grid; place-items: center; height: 74px; border-radius: 18px; font-size: 2rem; background: #eaf1fa; color: var(--color-primary); }
.preview-number:nth-child(2) { background: var(--color-accent); color: var(--color-fg); transform: rotate(-8deg); box-shadow: 0 5px 0 #dbad37; }
.intro-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; counter-reset: step; }
.intro-steps li { display: grid; grid-template-columns: 24px 1fr; column-gap: 10px; align-items: center; counter-increment: step; }
.intro-steps li::before { content: counter(step); grid-row: span 2; align-self: start; margin-top: 7px; font-size: .75rem; font-weight: 700; color: var(--color-muted); }
.intro-steps strong { justify-self: start; background: #edf3fb; color: var(--color-primary); border-radius: 12px 12px 12px 3px; padding: 6px 12px; font-size: 1.125rem; }
.intro-steps li:last-child strong { background: #e3f3ed; color: #126553; }
.intro-steps span { font-size: .95rem; color: var(--color-muted); padding-top: 4px; }
.intro-family { border-top: 1px solid var(--color-line); margin-top: 20px; padding-top: 14px; color: var(--color-muted); font-size: .95rem; line-height: 1.8; }
.intro-family strong { font-weight: 700; }
.intro-family p { margin: 4px 0 14px; }
.intro-start { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 56px; border: 0; border-radius: 16px; color: #fff; background: var(--color-primary); font-weight: 700; box-shadow: 0 4px 0 #173960; cursor: pointer; }
.intro-start svg { width: 24px; height: 24px; fill: currentColor; }
.intro-start:active { transform: translateY(2px); box-shadow: 0 2px 0 #173960; }
@keyframes introIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@media (max-height: 700px) {
  #title { gap: 16px; padding-top: 64px; }
  .intro-card { padding: 16px 22px 22px; }
  #intro-heading { margin-top: 4px; margin-bottom: 6px; }
  .intro-text { line-height: 1.7; }
  .intro-preview { margin-block: 12px; gap: 5px; }
  .intro-steps { gap: 8px; }
  .intro-steps li { grid-template-columns: 18px minmax(0, 1fr); column-gap: 8px; }
  .intro-steps strong { padding: 6px 9px; }
  .intro-family { margin-top: 14px; padding-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* 一覧は、動物の絵そのものを入口にする。 */
.page { max-width: 720px; margin: 0 auto; min-height: 100svh; padding: 48px 24px 24px; display: flex; flex-direction: column; }
.site-header { margin-bottom: 36px; }
.site-title { display: flex; align-items: center; gap: 2px; margin: -12px 0 0 -14px; font-size: 1.35rem; letter-spacing: -.04em; }
.site-lead { font-size: clamp(25px, 6.5vw, 40px); font-weight: 700; margin: 32px 0 8px; letter-spacing: -.045em; }
.site-note { color: var(--color-muted); margin: 0; font-size: .88rem; }
.app-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; }
.app-card { position: relative; min-height: 172px; display: flex; gap: 22px; align-items: center; background: #fff; color: var(--color-fg); text-decoration: none; padding: 24px 22px; border-radius: 28px; border: 1px solid #e2eaf2; box-shadow: 0 5px 0 #223c6007; }
.app-info { flex: 1; }
.app-name { font-size: clamp(18px, 4.7vw, 25px); font-weight: 700; letter-spacing: -.04em; }
.app-desc { text-align: center; margin-top: 0; font-size: .8rem; line-height: 1.8; color: var(--color-muted); }
.app-open { color: var(--color-primary); font-size: 18px; }
.app-card:active { transform: translateY(2px); box-shadow: none; }
.family-note { margin: 30px 0; color: var(--color-muted); font-size: .8rem; line-height: 1.9; text-align: center; }
.site-footer { margin-top: auto; padding-top: 20px; font-size: .7rem; color: var(--color-muted); text-align: center; }
@media (max-width: 420px) {
  .page { padding: 32px 20px 20px; }
  .app-card { padding: 20px 16px; gap: 18px; min-height: 156px; }
  .app-open { position: absolute; right: 20px; bottom: 14px; font-size: 12px; }
}

/* ロゴ：コエキットのみシンボル、各小品は文字ロゴ。 */
.brand-symbol { display: block; flex-shrink: 0; }
.wordmark { display: block; width: 100%; height: auto; object-fit: contain; }
#title .app-title { width: min(340px, 86vw); margin: 12px 0 20px; }
.app-card .app-name { width: min(260px, 100%); margin-inline: auto; }
.app-card .wordmark { height: 88px; object-position: center; }
.app-card .app-info { min-width: 0; }
@media (max-width: 420px) {
  .app-card { padding: 16px 22px 24px; }
  .app-card .wordmark { height: 76px; }
  .app-open { bottom: 22px; }
}

/* レベル境界：文字を読まずに押せる、音声と並ぶ大きな操作。 */
.intro-navigation { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }
.intro-navigation .intro-start { width: min(100%, 224px); min-height: 104px; margin: 0; border-radius: 28px; background: var(--color-confirm); color: white; box-shadow: 0 6px 0 #247345, 0 10px 24px #32835322; }
.intro-navigation .intro-start svg { width: 56px; height: 56px; }
.intro-voice-hint { margin: 14px 0 0; text-align: center; font-size: .8rem; line-height: 1.8; color: #66736e; }
.navigation-mic { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; background: #eff3ef; }
.navigation-mic.listening { background: #fff1c9; }
#cert .level-next { width: clamp(136px, 42vw, 184px); height: clamp(112px, 34vw, 144px); border-radius: 34px; z-index: 2; }
#cert .level-next svg { width: 58px; height: 58px; }
.card-reveal { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; border-radius: inherit; background: #fff9eeea; pointer-events: none; }
.card-reveal-hero { width: min(78%, 330px); max-height: 88%; aspect-ratio: 1; display: grid; place-items: center; padding: 18px; border-radius: 24%; background: #fff; border: 5px solid #ebc270; box-shadow: 0 18px 44px #82612a24, 0 0 0 10px #f7e5bd66; }
.card-reveal-hero img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }

/* 説明カードと操作を分け、一画面で案内を読み終えられる配置。 */
#level-intro { width: min(480px, calc(100% - 16px)); max-width: none; max-height: none; border-radius: 0; background: transparent; box-shadow: none; overflow: visible; }
.intro-card { padding: 0; display: flex; flex-direction: column; gap: 12px; }
.intro-details { padding: 12px 16px 16px; border-radius: 26px; background: #fff; box-shadow: 0 16px 50px #102d4c30; }
.intro-top { min-height: 44px; }
.intro-back { min-height: 44px; }
#intro-heading { margin: 2px 0 6px; font-size: 20px; line-height: 1.4; }
.intro-text { font-size: 15px; line-height: 1.6; }
.intro-preview { margin: 12px auto; gap: 6px; }
.preview-tile, .preview-empty { min-height: 48px; }
.preview-number { height: 60px; }
.intro-steps { gap: 6px; }
.intro-steps li { grid-template-columns: 14px max-content minmax(0, 1fr); gap: 6px; }
.intro-steps li::before { grid-row: auto; margin-top: 5px; }
.intro-steps strong { font-size: 15px; line-height: 1.35; padding: 3px 7px; }
.intro-steps span { font-size: 14px; padding: 0; line-height: 1.4; }
.intro-family { margin-top: 10px; padding-top: 8px; font-size: 14px; line-height: 1.5; }
.intro-family p { margin: 0; }
.intro-navigation { margin-top: 0; }
.intro-voice-hint { margin: 0; color: #fff; font-size: 14px; line-height: 1.5; text-shadow: 0 1px 4px #173451; }
@media (max-height: 650px) {
  .intro-card { gap: 8px; }
  .intro-details { padding: 6px 12px 10px; }
  #intro-heading { font-size: 18px; margin: 0 0 4px; }
  .intro-text { font-size: 14px; }
  .intro-preview { margin-block: 8px; gap: 5px; }
  .preview-tile, .preview-empty { min-height: 42px; }
  .intro-steps { gap: 4px; }
  .intro-steps strong { font-size: 14px; }
  .intro-steps span { font-size: 13px; }
  .intro-voice-hint { font-size: 13px; line-height: 1.4; }
  .intro-family { margin-top: 6px; padding-top: 6px; }
}

/* 自動フォーカスする非操作の見出しには枠を出さず、文字周囲に余白を置く。 */
#intro-heading { padding: 2px 4px; text-align: center; }
#intro-heading:focus { outline: none; }

/* プレイ中・認定書の途中終了。操作領域を常に確保する。 */
.quit-btn { min-width: 52px; min-height: 52px; color: #8c5144; }
#cert-quit { position: absolute; top: 12px; left: 20px; z-index: 3; }
