[hidden] { display: none !important; }
/* 静的な文言は日英とも置き、<html lang> で片方を伏せる（src/lang.js が描く前に決める） */
html[lang="ja"] [lang="en"], html[lang="en"] [lang="ja"] { display: none !important; }
:root {
  --bg: #f3ece0;
  --paper: #fffaf1;
  --ink: #3b2f25;
  --sub: #85735f;
  --line: #e2d5c0;
  --accent: #c8322b;
  --accent-ink: #fff;
  --ar: calc(800 / 760);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
svg.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

#site-header { display: flex; align-items: center; gap: 12px; max-width: 1200px; margin: 0 auto; padding: 10px 16px; }
#site-header .apps-link { color: var(--sub); text-decoration: none; font-size: 14px; display: inline-flex; align-items: center; min-height: 40px; white-space: nowrap; }
#site-header .name { font-weight: 800; font-size: 18px; letter-spacing: 0.04em; margin: 0; min-width: 0; }
.header-sub { margin-left: 6px; font-size: 12px; font-weight: 500; letter-spacing: 0; color: var(--sub); }
.langsw { margin-left: auto; display: inline-flex; flex-shrink: 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--paper); }
.langsw button { font-size: 12px; padding: 0 12px; min-height: 44px; min-width: 44px; border: 0; background: none; color: var(--sub); }
.langsw button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 800; }

#app { padding: 0 16px; }
/* 場面は縦横比を保ったまま、画面の高さの 72% までに収める */
#stage { width: min(100%, calc(72svh * var(--ar))); margin: 0 auto; }
#board { position: relative; border-radius: 14px; overflow: hidden; box-shadow: 0 6px 24px rgba(80, 50, 20, 0.18); user-select: none; -webkit-user-select: none; }
#scene { display: block; width: 100%; aspect-ratio: 800 / 760; touch-action: none; }

/* ── 上の帯 ── */
#topbar { display: flex; align-items: center; gap: 8px; padding: 0 0 8px; }
#topbar button { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); font-size: 14px; white-space: nowrap; }
#topbar button:hover { border-color: #cdb99a; background: #fff; }
#topbar button.ghost { background: transparent; border-color: transparent; color: var(--sub); }
#topbar button.ghost:hover { color: var(--ink); background: rgba(255, 255, 255, 0.6); }
#topbar button.icon { min-width: 40px; padding: 0 8px; font-size: 18px; }
.who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
#title { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dots, .dots { display: inline-flex; gap: 5px; }
#dots i, .dots i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #c9b495; display: block; }
#dots i.on, .dots i.on { background: var(--accent); border-color: var(--accent); }
#seek { font-size: 13px; color: var(--accent); font-weight: 700; white-space: nowrap; }

/* ── 場面の中 ── */
.item { cursor: grab; }
.item.held { cursor: grabbing; }
.ghost { fill: rgba(255, 255, 255, 0.28); stroke: #fff; stroke-width: 3; stroke-dasharray: 10 7; }
.ghost-dot { fill: rgba(255, 255, 255, 0.75); stroke: rgba(60, 40, 20, 0.35); stroke-width: 2; }
.ghost-dot.full { fill: rgba(255, 255, 255, 0.35); }
.ring { fill: none; stroke: #fff6c8; stroke-width: 5; }
.arm { stroke: #fbf8f2; stroke-width: 18; stroke-linecap: round; }
.stamp text { font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; font-size: 70px; font-weight: 800; fill: #c8322b; }
.cat .tail { transform-box: fill-box; transform-origin: 0% 100%; animation: tail 2.6s ease-in-out infinite; }
.cat.asleep .tail { animation-duration: 6s; }
@keyframes tail { 50% { transform: rotate(-12deg); } }
.zzz { font: 800 28px system-ui, sans-serif; fill: #8a7a6a; animation: zzz 2.4s ease-in-out infinite; }
@keyframes zzz { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

#tut { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(40, 28, 18, 0.78); color: #fff; padding: 8px 16px; border-radius: 99px; font-size: 14px; white-space: nowrap; pointer-events: none; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(-50%, -4px); } }
#toast { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(40, 28, 18, 0.85); color: #fff; padding: 8px 16px; border-radius: 99px; font-size: 14px; white-space: nowrap; pointer-events: none; }

/* ── 重なる板 ── */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(50, 34, 20, 0.32); animation: fade 0.25s ease-out; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--paper); border-radius: 16px; padding: 22px 24px; box-shadow: 0 10px 40px rgba(60, 35, 10, 0.3); width: min(100%, 380px); max-height: 100%; overflow: auto; text-align: center; }
.sheet h2 { margin: 0 0 6px; font-size: 22px; }
.sheet .count { margin: 0 0 8px; color: var(--sub); font-size: 13px; }
/* 片付いた板は下に置き、並べた結果を隠さない */
#done { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; padding: 14px; pointer-events: none; animation: rise 0.3s ease-out; }
#done .sheet { pointer-events: auto; width: min(100%, 420px); padding: 16px 20px; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
#done-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
#done-list li { padding: 4px 12px; border-radius: 99px; border: 1px dashed #c9b495; color: var(--sub); font-size: 14px; }
#done-list li.on { border: 1px solid var(--accent); color: var(--accent); background: #fff1ee; font-weight: 700; }
#done-list li.now { background: var(--accent); color: #fff; }
.sheet .acts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.sheet button { min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 15px; }
.sheet button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 800; }
.sheet button.ghost { background: transparent; border-color: transparent; color: var(--sub); }

.hint-sheet { width: auto; padding: 14px; }
.hint-pic { position: relative; margin: 0 auto; max-width: 100%; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
#hint-svg { display: block; width: 100%; aspect-ratio: 800 / 760; filter: grayscale(1) sepia(0.35) contrast(0.8) brightness(1.12); }
#scratch { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.hint-sheet .note { margin: 10px 0; color: var(--sub); font-size: 13px; }

/* 場面の一覧は盤の下に出しっぱなし（遊び方と同じ幅） */
#levels { max-width: 760px; margin: 28px auto 0; background: var(--paper); border-radius: 14px; padding: 16px; box-shadow: 0 2px 10px rgba(80, 50, 20, 0.1); scroll-margin-top: 12px; }
#stage { scroll-margin-top: 8px; }
.menu-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.menu-head h2 { margin: 0; font-size: 18px; }
#menu-count { color: var(--sub); font-size: 13px; }
#chapters { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
#chapters button { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 13px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; }
#chapters button small { font-weight: 400; color: var(--sub); font-size: 11px; }
#chapters button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#chapters button[aria-selected="true"] small { color: #ffe3df; }
#chapters button.full:not([aria-selected="true"]) { border-color: var(--accent); }
#cards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.card .nm { line-height: 1.3; overflow-wrap: anywhere; }
.card { display: flex; flex-direction: column; gap: 6px; align-items: stretch; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: #fff; text-align: left; min-width: 0; }
.card:hover { border-color: #cdb99a; }
.card.now { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card svg { width: 100%; aspect-ratio: 800 / 760; border-radius: 8px; display: block; }
.card .nm { font-weight: 800; font-size: 14px; }

#guide-section { max-width: 760px; margin: 28px auto 0; padding: 0 4px; line-height: 1.8; font-size: 15px; }
#guide-section h2 { font-size: 18px; margin: 0 0 6px; }
#guide-section h3 { font-size: 15px; margin: 14px 0 4px; }
#guide-section ul { margin: 0; padding-left: 1.3em; }
.related-apps, #ad-section { max-width: 760px; margin: 28px auto 0; padding: 0 4px; }
.related-apps-title { font-size: 18px; margin: 0 0 10px; }
.related-apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(180px, calc(50% - 5px)), 1fr)); gap: 10px; }
.related-app-link.ra-card { display: flex; flex-direction: column; overflow: hidden; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); text-decoration: none; transition: transform 0.15s, border-color 0.15s; }
.related-app-link.ra-card:hover { transform: translateY(-2px); border-color: #cdb99a; }
.ra-card .ra-thumb { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: var(--line); }
.ra-card .ra-name { display: block; padding: 8px 12px 10px; font-size: 13px; font-weight: 700; line-height: 1.4; }
#site-footer { max-width: 760px; margin: 0 auto; padding: 24px 16px 40px; color: var(--sub); font-size: 13px; text-align: center; }
.footer-links { display: flex; justify-content: center; gap: 10px; align-items: center; }
.footer-link { color: var(--sub); text-decoration: none; display: inline-flex; align-items: center; min-height: 40px; }
.footer-refs, .footer-copy { margin: 6px 0 0; }
.footer-refs a { color: var(--sub); }

@media (max-width: 600px) {
  .header-sub { display: none; }
  /* スマホでは 2 段: 上に題名と丸、下にボタン */
  #topbar { gap: 4px; flex-wrap: wrap; }
  #topbar .who { order: -1; flex-basis: 100%; padding: 0 2px; }
  #topbar #menu-btn { margin-right: auto; }
  #topbar button { padding: 0 12px; font-size: 13px; }
  #title { font-size: 15px; }
  .who { gap: 6px; }
  #seek { display: none; }
  #tut { font-size: 12px; padding: 6px 12px; }
  .sheet { padding: 16px; }
  .sheet h2 { font-size: 18px; }
  #done { padding: 8px; }
  #done .sheet { padding: 10px 12px; }
  #done .sheet h2 { font-size: 16px; margin-bottom: 2px; }
  #done-list { margin-bottom: 8px; }
  #done-list li { font-size: 12px; padding: 3px 10px; }
  .sheet button { min-height: 40px; font-size: 14px; padding: 0 14px; }
  /* 30 問を 3 列で並べると縦に長すぎるので 4 列。章のタブは «31〜60» が 2 行に割れないよう 1 行に */
  #chapters { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  #chapters button { font-size: 12px; white-space: nowrap; padding: 0 2px; }
  #cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .card { padding: 4px; gap: 4px; border-radius: 10px; }
  .card .nm { font-size: 12px; }
  #levels { padding: 12px; }
  .menu-head { flex-wrap: wrap; }
}
