/* ころころそうち — 見た目。ライト=あおい つくえ・ダーク=よる。外部フォントは使わない(何も送らないため) */
:root {
  --bg: #eef6ff;
  --ink: #2b2433;
  --sub: #55607a;
  --card: #ffffff;
  --card-sh: #c4d6ec;
  --paper: #ffffff;
  --dot: #d9e4f2;
  --gold: #ffc53d;
  --focus: #2f7cf6;
  --on: #2b2433;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c2130;
    --ink: #eef2fa;
    --sub: #aab4c8;
    --card: #2c3346;
    --card-sh: #0e111a;
    --paper: #262d3e;
    --dot: #3a4358;
    --focus: #ffc53d;
    --on: #ffc53d;
  }
}

* { 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 { display: block; width: 100%; height: 100%; overflow: visible; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; }

.big { background: var(--card); border-radius: 22px; box-shadow: 0 6px 0 var(--card-sh); transition: transform .06s; }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--card-sh); }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 56px; min-width: 56px; padding: 0 16px 0 10px;
  border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  font-weight: 800; font-size: 18px; flex-shrink: 0;
}
.back span { font-size: 32px; line-height: 1; margin-top: -5px; }
.back .lbl { font-style: normal; }
.back:active, .snd:active, .rst:active, .pick:active, .close:active, .tool:active, .undo:active, .boardBtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }

/* ---- はじめの画面 ---- */
.menu { padding: 3vh 16px 15vh; gap: 3vh; overflow-y: auto; }
.menu > .logo { margin-top: auto !important; }
.menu > .opts { margin-bottom: auto; }
.logo { display: flex; align-items: center; gap: 12px; margin: 0; font-size: clamp(30px, 8.6vw, 50px); font-weight: 900; letter-spacing: .02em; }
.logo-ball { width: .9em; height: .9em; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 12%, #ff5a6e 40%); border: 3px solid var(--ink); flex-shrink: 0; }
/* ばん 9まい(3×3)。たかさで おさまる はばに する(下15%に かからない) */
.boards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 460px, calc(57vh - 70px)); }
.boardBtn { position: relative; aspect-ratio: 3 / 4; border-radius: 16px; background: var(--card); box-shadow: 0 5px 0 var(--card-sh); padding: 5px; }
.boardBtn canvas { width: 100%; height: 100%; display: block; }
.boardBtn b { position: absolute; left: 5px; bottom: 5px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #3a2a00; font-size: 18px; }
.opts { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.link { min-height: 48px; padding: 0 14px; font-size: 16px; color: var(--sub); text-decoration: underline; text-underline-offset: 3px; }

/* ---- つくる・ころがす 画面 ---- */
.game {
  display: grid; width: 100%; align-items: stretch; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: 10px 12px 15vh; gap: 8px;
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
/* おだい(絵だけ。さわると つぎへ) */
.quest { display: inline-flex; align-items: center; justify-content: center; gap: 2px; min-width: 56px; height: 56px; padding: 0 10px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); color: var(--sub); position: relative; }
.quest:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }
.q-icons { display: flex; align-items: center; gap: 1px; }
.quest .qi { width: 28px; height: 28px; flex-shrink: 0; }
.quest .qa { width: 18px; height: 18px; flex-shrink: 0; margin: 0 1px; }
.quest .q6 { display: grid; grid-template-columns: repeat(3, 16px); gap: 0 1px; }
.quest .q6 .qi { width: 16px; height: 16px; }
.quest .qs { position: absolute; right: -8px; top: -10px; width: 30px; height: 30px; animation: stamp .45s ease-out; }
.quest.done { box-shadow: 0 0 0 4px var(--gold), 0 4px 0 var(--card-sh); }
.quest.none { opacity: .7; }
@keyframes stamp { 0% { transform: scale(2.2) rotate(-30deg); opacity: 0; } 60% { transform: scale(.9) rotate(6deg); opacity: 1; } }
.right { display: flex; gap: 8px; flex-shrink: 0; }
.snd, .rst { width: 56px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; flex-shrink: 0; }
.snd svg, .rst svg { width: 34px; height: 34px; }
.rst { color: var(--ink); }
.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; }

.stage { position: relative; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.bubble {
  position: absolute; top: 8px; left: 10px; right: 10px; width: fit-content; margin: 0 auto; z-index: 2;
  padding: 6px 18px; border-radius: 18px; background: var(--gold); color: #3a2a00; box-shadow: 0 4px 0 #c98a00;
  font-size: clamp(22px, 6.4vw, 32px); font-weight: 900; pointer-events: none;
}
.bubble:empty { display: none; }
/* もとに もどす: みほん・まっさら を えで えらぶ */
/* 画面 ぜんたいに かぶせる(うしろの ばん・どうぐは おせない)。えらぶ ものは 下15% より うえ */
.sheet { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 8px 8px calc(15vh + 8px); background: rgba(43, 36, 51, .45); }
.sheet-in { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 14px; border-radius: 22px; background: var(--card); box-shadow: 0 6px 0 var(--card-sh); max-width: 100%; max-height: 100%; }
.picks { display: flex; gap: 12px; }
.pick { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 6px 4px; border-radius: 16px; background: var(--bg); box-shadow: 0 4px 0 var(--card-sh); }
.pick canvas { display: block; width: min(31vw, 132px, calc((100vh - 330px) * .75)); min-width: 72px; aspect-ratio: 3 / 4; }
.pick b { font-size: 17px; font-weight: 900; }
.close { width: 56px; height: 56px; padding: 10px; border-radius: 16px; background: var(--bg); box-shadow: 0 4px 0 var(--card-sh); color: var(--ink); }
.bubble.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.1); } }

.tray { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.tools { display: flex; justify-content: center; gap: 6px; }
/* どうぐ 6つが 1れつに おさまる おおきさ(せまい 画面は 3つずつ 2れつ) */
.tool { width: clamp(48px, calc((100vw - 54px) / 6), 68px); height: clamp(48px, calc((100vw - 54px) / 6), 68px); padding: 7px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
/* たての スマホ: もどるは «‹» だけ(よこに もとに もどす・おと が ならぶ。よめなくても わかる) */
@media (max-width: 419px) and (orientation: portrait) {
  .back { width: 56px; padding: 0; justify-content: center; }
  .back .lbl { display: none; }
}
@media (max-width: 379px) and (orientation: portrait) {
  .quest { padding: 0 6px; }
  .quest .qi { width: 24px; height: 24px; }
  .quest .qa { width: 14px; height: 14px; }
}
@media (max-width: 349px) and (orientation: portrait) {
  .game { padding-left: 8px; padding-right: 8px; }
  .top, .right { gap: 6px; }
  .quest .qi { width: 20px; height: 20px; }
  .quest .qa { width: 12px; height: 12px; }
  .tools { display: grid; grid-template-columns: repeat(3, 56px); }
  .tools .tool { width: 56px; height: 56px; }
}
.tool[aria-pressed="true"] { box-shadow: 0 0 0 4px var(--on), 0 4px 0 var(--card-sh); }
.acts { display: flex; align-items: center; gap: 10px; }
.acts .tool, .undo { width: clamp(52px, 16vw, 64px); height: clamp(52px, 16vw, 64px); }
.undo { padding: 12px; border-radius: 18px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); color: var(--ink); }
.undo:disabled { opacity: .4; }
.go {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 70px; min-width: min(46vw, 240px); padding: 0 20px;
  font-size: clamp(24px, 7vw, 32px); font-weight: 900; background: var(--gold); color: #3a2a00; box-shadow: 0 6px 0 #c98a00;
}
.go:active { box-shadow: 0 2px 0 #c98a00; }
.go-ball { width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 12%, #ff5a6e 40%); border: 3px solid #3a2a00; flex-shrink: 0; }

/* スマホを横にしたとき: どうぐは みぎに */
@media (orientation: landscape) and (max-height: 600px) {
  .menu { flex-direction: row; flex-wrap: wrap; justify-content: center; align-content: center; gap: 2vh 24px; padding-top: 2vh; }
  .menu > .logo { margin-top: 0 !important; width: 100%; justify-content: center; font-size: 30px; }
  .menu > .opts { margin-bottom: 0; }
  .boards { width: auto; grid-template-columns: repeat(5, auto); gap: 10px; }
  .boardBtn { height: min(180px, calc((81vh - 50px) / 2)); }
  .game { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto 1fr; padding-top: 6px; gap: 6px 12px; }
  .top { grid-column: 1 / -1; }
  .tray { justify-content: center; }
  .tray { gap: 8px; }
  .tools { display: grid; grid-template-columns: repeat(3, 1fr); }
  .tool, .acts .tool, .undo { width: 56px; height: 56px; }
  .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; justify-items: center; }
  .go { grid-column: 1 / -1; min-height: 60px; min-width: 150px; font-size: 24px; }
}
/* よこで ひくい 画面(ブラウザの 帯が ある スマホ・たかさ 360px 以下): もどる・おとは ばんの よこに */
@media (orientation: landscape) and (max-height: 360px) {
  .menu .opts { display: none; }
  .menu { gap: 8px 20px; }
  .boardBtn { height: calc((83vh - 56px) / 2); }
  .game { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: 1fr; padding-top: 6px; }
  .top { grid-column: 1; flex-direction: column; justify-content: flex-start; }
  .tray { justify-content: flex-start; }
  .tool, .acts .tool { width: 50px; height: 50px; padding: 6px; }
  .tools { gap: 6px; }
  .go { min-height: 54px; min-width: 140px; font-size: 22px; }
  .undo { width: 50px; height: 50px; padding: 9px; }
  .quest { padding: 0 6px; }
  .quest .qi { width: 22px; height: 22px; }
  .quest .qa { width: 14px; height: 14px; }
  .right { flex-direction: column; }
}
/* よこの スマホ: もとに もどす の えらびは よこに ならべる */
@media (orientation: landscape) and (max-height: 600px) {
  .sheet-in { flex-direction: row; }
  .pick canvas { width: min(26vw, 132px, calc((85vh - 110px) * .75)); }
}

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