/* なぞって めいろ — 見た目。ライト=うすい みどり・ダーク=夜。外部フォントは使わない(何も送らないため) */
:root {
  --bg: #eef7e6;
  --ink: #2b2433;
  --sub: #5d6a58;
  --floor: #fffef8;
  --floor-sh: #c9dcb4;
  --wall: #2f6f45;
  --card: #ffffff;
  --card-sh: #cfe0bf;
  --gold: #ffb800;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151c1f;
    --ink: #eef5ea;
    --sub: #a8b8a5;
    --floor: #222c31;
    --floor-sh: #0c1113;
    --wall: #86d39a;
    --card: #273238;
    --card-sh: #0d1316;
    --focus: #ffb800;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
svg { overflow: visible; }

/* ---- あそぶ画面 ---- */
.game {
  flex: 1; min-height: 0;
  display: grid; width: 100%; align-items: stretch;
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "top" "status" "board";
  /* 画面の下 15% には 押すものも 盤も置かない(手首が当たる) */
  padding: 10px 16px 15vh; gap: 8px;
}

/* 上の列: めいろの大きさ(左)・いんさつと音(右) */
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sizes, .tools { display: flex; gap: 6px; }
.tool {
  width: 56px; height: 56px; flex: none;
  border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  display: grid; place-items: center;
}
.tool svg { width: 38px; height: 38px; }
.tool:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }
.g-box { fill: var(--floor); stroke: var(--wall); stroke-width: 3; }
.g-line { fill: none; stroke: var(--wall); stroke-width: 2.2; }
/* 320px のスマホでは 56px の5こが入らない(「おと」が右にはみ出す)ので、すこし小さく */
@media (max-width: 339px) {
  .game { padding-left: 10px; padding-right: 10px; }
  .sizes, .tools { gap: 4px; }
  .tool { width: 52px; height: 52px; }
  .tool svg { width: 34px; height: 34px; }
}
.sz[aria-pressed="true"] { background: var(--ink); box-shadow: 0 4px 0 rgba(0, 0, 0, .3); }
.sz[aria-pressed="true"] .g-box { fill: none; stroke: var(--bg); }
.sz[aria-pressed="true"] .g-line { stroke: var(--bg); }
.pr-paper { fill: var(--card); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
.pr-body { fill: var(--ink); opacity: .82; }
.pr-dot { stroke: var(--card); stroke-width: 3; stroke-linecap: round; }
.spk { fill: var(--ink); }
.wave, .slash { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }

/* ようす(だれを どこへ・ゴール)と「つぎ」。高さは かえない(盤の大きさが ゆれないように) */
.status { grid-area: status; display: flex; align-items: center; justify-content: center; gap: 10px; height: 66px; min-width: 0; }
.say {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 0; min-width: 0; font-size: clamp(18px, 5vw, 24px); font-weight: 900;
}
.st-icon { width: 46px; height: 46px; flex: none; }
.st-icon svg, .next-pet svg, .bob svg, .hand-in svg { display: block; width: 100%; height: 100%; }
.st-arrow { width: 32px; height: 16px; flex: none; }
.st-arrow path { fill: none; stroke: var(--sub); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.st-text { line-height: 1.2; word-break: keep-all; overflow-wrap: anywhere; }
.st-sub { display: none; font-size: 16px; font-weight: 800; color: var(--sub); }
.say.done .st-text { animation: pop .45s ease-out; }
.say.done .st-icon { animation: bob 1.2s ease-in-out infinite; }
@media (max-width: 374px) {
  .st-icon { width: 40px; height: 40px; }
  .st-arrow { width: 24px; }
}
@media (min-width: 640px) { .say.done .st-sub { display: inline; } }
.next {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 64px; padding: 0 16px 0 22px; border-radius: 22px;
  font-size: clamp(22px, 6vw, 28px); font-weight: 900;
  background: var(--gold); color: #3a2a00; box-shadow: 0 6px 0 #c98a00;
  animation: pop .35s ease-out;
}
.next:active { transform: translateY(4px); box-shadow: 0 2px 0 #c98a00; }
.next:disabled { opacity: .55; }
.next-pet { width: 40px; height: 40px; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } }

/* ---- めいろの盤 ---- */
.board-wrap { grid-area: board; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board {
  --cell: 40px; --pet: #ff8a3d;
  position: relative; flex: none;
  background: var(--floor);
  border-radius: calc(var(--cell) * .1);
  box-shadow: 0 calc(var(--cell) * .06 + 3px) 0 var(--floor-sh);
  touch-action: none; /* なぞっている あいだ 画面が動かないように */
}
.maze, .glow-svg, .trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.walls { fill: none; stroke: var(--wall); stroke-linecap: round; stroke-linejoin: round; }
.pad-s { fill: var(--pet); opacity: .16; }
.pad-g { fill: var(--gold); opacity: .3; }
/* 線と光は それぞれ 自分の層(かべは 描きなおさない)。光るのは うすさ(opacity)だけで ゆっくり */
.trail, .glow-svg { will-change: transform; }
.line { fill: none; stroke: var(--pet); stroke-linecap: round; stroke-linejoin: round; opacity: .82; }
.glow { fill: none; stroke: var(--gold); stroke-linecap: round; stroke-linejoin: round; }
.glow-svg { opacity: 0; }
.glow-svg.on { animation: glow 1.3s ease-in-out 3 alternate both; }
@keyframes glow { from { opacity: 0; } to { opacity: .85; } }

.pet, .goal, .hand, .poke { position: absolute; left: 0; top: 0; pointer-events: none; will-change: transform; }
.pet { --ps: calc(var(--cell) * .86); width: var(--ps); height: var(--ps); margin: calc(var(--ps) / -2) 0 0 calc(var(--ps) / -2); z-index: 3; }
.bob { width: 100%; height: 100%; }
.pet .bob { animation: bob 1.6s ease-in-out infinite; transition: transform .08s; }
.pet.held .bob { animation: none; transform: scale(1.14); }
.pet.hey .bob { animation: hey .45s ease-out; }
.pet.yay .bob { animation: yay .5s ease-out 3; }
@keyframes bob { 50% { transform: translateY(-5%); } }
@keyframes hey { 30% { transform: rotate(-12deg) scale(1.08); } 65% { transform: rotate(10deg); } }
@keyframes yay { 40% { transform: translateY(-28%) scale(1.06); } 70% { transform: translateY(0) scale(1.08, .92); } }

.goal { --fs: calc(var(--cell) * .8); width: var(--fs); height: var(--fs); margin: calc(var(--fs) / -2) 0 0 calc(var(--fs) / -2); z-index: 2; }
.goal .bob { animation: wiggle 2.4s ease-in-out infinite; }
.goal.eaten { z-index: 4; }
.goal.eaten .bob { animation: eat .45s ease-in forwards; }
@keyframes wiggle { 50% { transform: rotate(-6deg) scale(1.05); } }
@keyframes eat { to { transform: scale(.2); opacity: 0; } }
.hearts { position: absolute; inset: 0; }
.hearts svg { position: absolute; left: 25%; top: -10%; width: 55%; height: 55%; opacity: 0; }
.goal.eaten .hearts svg { animation: heart 1.4s ease-out .1s both; }
.goal.eaten .hearts svg:nth-child(2) { left: -20%; animation-delay: .25s; }
.goal.eaten .hearts svg:nth-child(3) { left: 70%; animation-delay: .4s; }
@keyframes heart {
  0% { opacity: 0; transform: translateY(0) scale(.4); }
  25% { opacity: 1; transform: translateY(-40%) scale(1); }
  100% { opacity: 0; transform: translateY(-120%) scale(.9); }
}

/* 手のお手本: ゆびさきが どうぶつの まんなか */
.hand { --hw: max(46px, calc(var(--cell) * .72)); z-index: 5; opacity: 0; }
.hand-in { position: absolute; left: calc(var(--hw) * -.44); top: calc(var(--hw) * -.04); width: var(--hw); height: var(--hw); transform-origin: 44% 4%; }
.hand.demo { animation: handfade 1.9s ease-in-out both; }
.hand.demo .hand-in { animation: handmove 1.9s ease-in-out both; }
@keyframes handfade { 0% { opacity: 0; } 12%, 82% { opacity: .95; } 100% { opacity: 0; } }
@keyframes handmove {
  0%, 18% { transform: translate(0, 0) scale(1); }
  28% { transform: translate(0, 0) scale(.88); }
  78% { transform: translate(var(--dx), var(--dy)) scale(.88); }
  100% { transform: translate(var(--dx), var(--dy)) scale(1); }
}
/* どうぶつから はなれた所を さわったときの わっか */
.poke { z-index: 4; }
.poke i { position: absolute; width: 56px; height: 56px; left: -28px; top: -28px; border-radius: 50%; border: 4px solid var(--pet); opacity: 0; }
.poke.on i { animation: ring .45s ease-out; }
@keyframes ring { 0% { opacity: .7; transform: scale(.3); } 100% { opacity: 0; transform: scale(1.2); } }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 6; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px;
  animation-name: fall; animation-timing-function: cubic-bezier(.3, .6, .6, 1); animation-fill-mode: forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* ---- いんさつの ようい(おうちの人むけ) ---- */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(5vh, 12px) 16px 0;
  background: rgba(16, 22, 18, .5);
}
.sheet-box {
  width: min(100%, 440px);
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 18px 16px; border-radius: 22px;
  background: var(--card); box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.sheet-title { margin: 0; font-size: 24px; font-weight: 900; }
.sheet-note { margin: 0; font-size: 15px; line-height: 1.6; color: var(--sub); }
.sheet-note span { display: inline-block; } /* 文の とちゅうで 折り返さない(せまいときは 文と文の あいだで) */
.opt { display: flex; flex-direction: column; gap: 6px; }
.opt-label { font-size: 15px; font-weight: 800; }
.segs { display: flex; flex-wrap: wrap; gap: 8px; }
.seg {
  min-height: 48px; padding: 0 14px; border-radius: 999px;
  background: var(--bg); box-shadow: inset 0 0 0 2px var(--card-sh);
  font-size: 16px; font-weight: 800;
}
.seg[aria-pressed="true"] { background: var(--ink); color: var(--bg); box-shadow: none; }
.sheet-act { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.print-go {
  min-height: 56px; padding: 0 22px; border-radius: 18px;
  font-size: 20px; font-weight: 900;
  background: var(--gold); color: #3a2a00; box-shadow: 0 5px 0 #c98a00;
}
.print-go:active { transform: translateY(3px); box-shadow: 0 2px 0 #c98a00; }
.link { min-height: 48px; min-width: 64px; padding: 0 14px; font-size: 16px; color: var(--sub); text-decoration: underline; text-underline-offset: 3px; }

/* スマホを横にしたとき: 盤を左、ボタンと ようすを右の列に */
@media (orientation: landscape) and (max-height: 600px) {
  .game {
    grid-template-columns: minmax(0, 1fr) minmax(196px, 30%);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "board top" "board status";
    padding: 8px 12px 15vh 20px; column-gap: 14px; row-gap: 8px;
  }
  .top { flex-direction: column; align-items: center; }
  .status { flex-direction: column; justify-content: flex-start; height: auto; gap: 10px; }
  .say { flex-wrap: wrap; row-gap: 2px; }
  .st-text, .say.done .st-sub { flex-basis: 100%; text-align: center; }
  .say.done .st-sub { display: block; }
  .sheet { padding-top: 8px; }
  .sheet-box {
    width: min(100%, 660px);
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; row-gap: 8px;
    padding: 12px 16px;
  }
  .sheet-title, .sheet-note, .sheet-act { grid-column: 1 / -1; }
  .sheet-title { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; }
}

/* ---- いんさつ(A4 たて。白黒でも わかる) ---- */
#print { display: none; }
@media print {
  @page { size: A4 portrait; margin: 10mm; }
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; color: #000 !important; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #app { display: none !important; }
  #print { display: block; }
  .pp {
    height: 270mm; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between;
    break-after: page; page-break-after: always;
  }
  .pp:last-child { break-after: auto; page-break-after: auto; }
  .pp-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8mm; padding-bottom: 2mm; border-bottom: .6mm solid #000; }
  .pp-head h1 { margin: 0; font-size: 9mm; line-height: 1.1; }
  .pp-head small { font-size: 5mm; margin-left: 2mm; }
  .pp-name { flex: 0 0 80mm; font-size: 5mm; padding-bottom: 1mm; border-bottom: .4mm solid #000; }
  .pq { display: flex; flex-direction: column; align-items: center; gap: 2mm; }
  .pq-say { margin: 0; display: flex; align-items: center; gap: 1mm; font-size: 5.2mm; font-weight: 800; }
  .pq-icon { display: inline-block; width: 9mm; height: 9mm; }
  .pq-icon svg { display: block; width: 100%; height: 100%; }
  .pq-maze { display: block; width: 190mm; height: 112mm; }
  .pq-label { font-family: inherit; font-weight: 800; fill: #000; }
}
