/* 論理サイズ 1280x720 の枠を JS が画面に合わせて拡縮する。ここの px は論理 px。
   本文 26px（iPad 横 1180px で約 24px）、ボタンは高さ 76px 以上。 */
:root {
  --bg: #0b0a1c;
  --panel: #1c1a3a;
  --line: #4a4478;
  --ink: #f4f1ff;
  --soft: #c9c3ee;
  --accent: #ffd36e;
  --ok: #9fe0b4;
  --info: #bfe6ff;
  --body: 26px;
  --btn-h: 76px;
  --fs-head: 40px; /* けっか画面の文字の3段：見出し */
  --fs-body: 28px; /* 本文 */
  --fs-cap: 22px; /* 補足（これより小さい文字は作らない） */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--band, var(--bg)); /* 3D の間だけ、かいの暗い岩の色（render3d/band-fill.js）。2D・ほかの画面は --bg */
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: var(--body);
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#frame {
  position: absolute;
  left: 0;
  top: 0;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  transform-origin: 0 0;
  background: var(--bg);
}

#stage { position: absolute; inset: 0; width: 1280px; height: 720px; }
/* 一人称3Dの WebGL キャンバス。#stage（透明にして HUD などを重ね描き）の下に敷く */
#gl { position: absolute; inset: 0; width: 1280px; height: 720px; }
#gl[hidden] { display: none; }

/* ---- 画面 ---- */
.screen { position: absolute; inset: 0; display: none; padding: 36px 56px; z-index: 1; }
.screen.active { display: block; }
.screen.opaque { background: radial-gradient(ellipse at 50% 20%, #26224a 0%, var(--bg) 75%); }
.screen.clear { pointer-events: none; }
.screen.clear .btn { pointer-events: auto; }

h1 { margin: 56px 0 8px; font-size: 68px; letter-spacing: 0.06em; text-align: center; color: var(--accent); }
h2 { margin: 0 0 16px; font-size: 42px; letter-spacing: 0.04em; }
.lead { text-align: center; color: var(--soft); margin: 0 0 28px; }
.keys { position: absolute; left: 56px; right: 56px; bottom: 20px; margin: 0; text-align: center; color: var(--soft); font-size: 24px; }
.msg { min-height: 40px; color: var(--info); margin: 8px 0 16px; }
.big { font-size: 38px; text-align: center; margin: 8px 0; }
.soft { color: var(--soft); }
.center { position: absolute; left: 56px; right: 56px; top: 150px; text-align: center; }
.side { position: absolute; left: 736px; right: 40px; top: 110px; }

/* ---- ボタン ---- */
.buttons { display: flex; gap: 16px; }
.buttons.column { flex-direction: column; align-items: center; }
.row { display: flex; gap: 16px; justify-content: center; margin-top: 16px; }
.row.bottom { position: absolute; left: 56px; right: 56px; bottom: 28px; }

.btn {
  min-width: 76px;
  min-height: var(--btn-h);
  padding: 0 36px;
  font: inherit;
  font-size: 30px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 24px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 5px solid var(--info); outline-offset: 3px; }
.btn.primary { background: var(--accent); color: #2a2208; border-color: var(--accent); font-weight: bold; }
.btn.on { background: #2d4a45; border-color: var(--ok); color: #eafff1; }
.btn[hidden] { display: none; }
.screen.opaque .buttons.column .btn { width: 560px; }
.side .buttons.column .btn { width: 100%; }

/* ---- ゲーム画面のボタン ---- */
.corner { position: absolute; bottom: 20px; opacity: 0.85; }
.corner.left { left: 24px; }
.corner.right { right: 24px; }
.floating { position: absolute; left: 0; right: 0; bottom: 120px; margin: 0; padding: 0 160px; text-align: center; color: var(--soft); font-size: 30px; white-space: pre-line; text-shadow: 0 2px 6px #000; }

/* ---- カメラ映像（鏡像）と枠の重ね描き ---- */
#camwrap { position: absolute; z-index: 2; aspect-ratio: 4 / 3; background: #000; border-radius: 16px; overflow: hidden; }
#camwrap.cam-off { display: none; }
#camwrap.cam-full { left: 56px; top: 110px; width: 640px; height: 480px; border: 3px solid var(--line); }
#camwrap.cam-mini { right: 16px; top: 16px; height: auto; border: 3px solid var(--line); opacity: 0.95; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; transform: scaleX(-1); }
#camover { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---- ③ ---- */
.arrow { font-size: 150px; line-height: 1.1; color: var(--accent); }
.progress { width: 640px; height: 18px; margin: 20px auto 32px; background: rgba(255, 255, 255, 0.14); border-radius: 9px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--ok); }

/* ---- 結果・図鑑 ---- */
.grid { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 8px; }
.grid .cell { position: relative; width: 150px; text-align: center; font-size: 24px; }
.grid .cell canvas { width: 112px; height: 112px; }
.grid .cell .new { position: absolute; top: 0; right: 6px; color: var(--accent); font-weight: bold; }
.grid.zukan .cell { width: 180px; }
.helper { position: absolute; left: 56px; right: 56px; bottom: 124px; font-size: 24px; }
.helper summary { cursor: pointer; min-height: 48px; color: var(--soft); }
.helper pre { max-height: 160px; overflow: auto; margin: 8px 0; padding: 12px; background: var(--panel); border-radius: 12px; font: 22px/1.5 inherit; white-space: pre-wrap; user-select: text; }
#zukan-count { font-size: 30px; color: var(--soft); }

/* ---- 設定 ---- */
.form { height: 520px; overflow-y: auto; padding-right: 12px; touch-action: pan-y; }
.form .item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.form .item .label { flex: 0 0 400px; }
.form .item .controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.form .value { min-width: 90px; text-align: center; font-size: 34px; }
.form input[type="range"] { width: 360px; height: var(--btn-h); accent-color: var(--accent); }

/* ---- 帯・デバッグ・横向き案内 ---- */
#band { position: absolute; left: 56px; right: 56px; bottom: 112px; z-index: 5; padding: 14px 24px; border-radius: 16px; background: rgba(28, 26, 58, 0.94); border: 2px solid var(--info); text-align: center; font-size: 24px; }
#band[data-tone="error"] { border-color: var(--accent); }
#band[hidden], #debug[hidden] { display: none; }
#debug { position: absolute; left: 8px; bottom: 8px; z-index: 6; margin: 0; padding: 8px 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.7); color: #d8ffd8; font: 18px/1.4 ui-monospace, Consolas, monospace; pointer-events: none; }

#rotate { position: fixed; inset: 0; z-index: 99; display: none; align-items: center; justify-content: center; background: var(--bg); color: var(--accent); font-size: 56px; font-weight: bold; text-align: center; }
body.portrait #rotate { display: flex; }
body.portrait #frame { visibility: hidden; }

/* ---- タイトル（洞窟の絵は #stage に描く。ロゴは Canvas 側に描くので h1 の文字は見せない）---- */
#screen-title { background: none; }
#screen-title h1 { color: transparent; user-select: none; }
#screen-title .lead { text-shadow: 0 2px 8px #000, 0 0 16px #000; }
#screen-title .keys { text-shadow: 0 2px 6px #000; }

/* ---- けっか（左: たからもの / 右: いちばん しずか・なかま・かけら）----
   文字は 3段だけ：見出し --fs-head(40) / 本文 --fs-body(28) / 補足 --fs-cap(22)。22px 未満の文字を作らない。
   縦の割り当て（論理 720）：見出し → 「つぎは」の吊るし → たからもの・かけら → 24px 以上あけて 「おうちの ひと」→ ボタン */
#screen-result { padding-top: 24px; }
#screen-result h2 { margin: 0 0 6px; font-size: var(--fs-head); line-height: 1.2; }
.result-cols { display: flex; gap: 32px; height: 420px; }
.grid.result { flex: 0 0 600px; align-content: flex-start; justify-content: flex-start; margin-top: 0; max-height: 420px; overflow-y: auto; touch-action: pan-y; }
.grid.result .cell { width: 136px; font-size: var(--fs-cap); line-height: 1.3; }
.grid.result .cell canvas { width: 96px; height: 96px; }
.result-side { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.result-top { display: flex; gap: 20px; align-items: flex-start; }
.result-box .cap { margin: 0 0 4px; font-size: var(--fs-cap); line-height: 1.3; color: var(--soft); }
.result-box[hidden] { display: none; }
.result-box.quiet { flex: 0 0 270px; }
.result-box.quiet .cell { position: relative; width: 190px; font-size: var(--fs-cap); line-height: 1.3; text-align: center; }
.result-box.quiet .cell canvas { width: 150px; height: 150px; }
.result-box.met { flex: 1; }
.grid.faces { justify-content: flex-start; gap: 4px; margin-top: 0; }
.grid.faces .cell { width: 78px; font-size: var(--fs-cap); }
.grid.faces .cell canvas { width: 72px; height: 72px; }
.grid.faces .cell > div { display: none; }
.shards-line { margin: 0; font-size: var(--fs-body); }
.shards-line b { margin: 0 8px; font-size: var(--fs-head); color: var(--accent); }
.shard-bar { width: 100%; height: 22px; margin: 10px 0; border-radius: 11px; }
.shard-bar i { background: linear-gradient(90deg, #ffd36e, #fff4c2); width: 0; }
.next-line { margin: 0; font-size: var(--fs-body); color: var(--info); }
.got-line { margin: 6px 0 0; font-size: var(--fs-body); font-weight: bold; color: var(--accent); }
.got-line[hidden] { display: none; }
.helper[open] { z-index: 2; background: var(--bg); }
#screen-result .helper { bottom: 128px; font-size: var(--fs-cap); } /* ボタン（高さ 92）の上 12px。たからものの ます目とは 24px 以上あく */
/* ボタン：「もういちど」を主役（高さ 92・幅も最大）、あとの2つは一回り小さく */
#screen-result .row.bottom { bottom: 24px; align-items: center; gap: 20px; }
#screen-result .row.bottom .btn { min-width: 200px; min-height: var(--btn-h); padding: 0 28px; font-size: var(--fs-body); }
#screen-result .row.bottom .btn.primary { min-width: 380px; min-height: 92px; font-size: var(--fs-head); }

/* ---- ずかん ---- */
.zukan-head { display: flex; align-items: center; justify-content: space-between; }
.zukan-head h2 { margin: 0; }
.zukan-head .row { margin-top: 0; }

/* けっか：NEW! を縁取りの上に重ねない */
.grid .cell .new { top: -10px; right: 0; padding: 0 8px; font-size: var(--fs-cap); line-height: 1.3; background: var(--bg); border-radius: 12px; }
.result-box .cap { word-break: keep-all; }
.grid .cell > div { word-break: keep-all; }
.grid.result { padding-top: 14px; }
.grid.faces { padding-top: 0; }
.grid.faces .cell { width: 100px; }
.grid.faces .cell canvas { width: 96px; height: 96px; }

/* ガイドの文：ほぼ白の字に、暗い半透明の下地（暗い背景でも明るい背景でも読める） */
#play-msg.floating {
  color: #f4f1ff;
  width: fit-content;
  max-width: 90%;
  margin-left: auto;
  margin-right: auto;
  padding: 0.35em 1.1em;
  border-radius: 28px;
  background: rgba(6, 6, 16, 0.62);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
#play-msg.floating:empty { display: none; }

/* ---- ちず（canvas に全部描く。ボタンだけ DOM）---- */
#map-canvas { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; pointer-events: none; }

/* ---- けっか：「つぎは」の吊るし（lastExpedition がある時だけ。screen に has-adv が付く）---- */
.result-adv { display: flex; gap: 18px; align-items: center; margin: 4px 0 10px; min-height: 104px; padding: 10px 18px; background: rgba(255, 255, 255, 0.09); border: 2px solid rgba(255, 234, 166, 0.38); border-radius: 18px; }
.result-adv[hidden] { display: none; }
.adv-sign { flex: 0 0 80px; width: 80px; height: 80px; }
.adv-stones { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; }
.adv-stones canvas { display: block; } /* 大きさは result.js が config の値で決める（見える大きさ = キャンバスの大きさ） */
.adv-lines { flex: 1; min-width: 0; }
.adv-line { margin: 0; font-size: var(--fs-cap); line-height: 1.22; color: var(--info); }
.adv-line.next { font-size: var(--fs-body); font-weight: bold; color: var(--accent); }
.adv-line.new { font-size: var(--fs-body); font-weight: bold; color: var(--accent); }
.adv-line[hidden] { display: none; }
.adv-stones .adv-line { margin-top: 2px; font-size: var(--fs-body); color: var(--accent); font-weight: bold; white-space: nowrap; }
/* 5つ そろった回：カードの後ろに あたたかい光を敷く（固定。点滅しない。明るさは result.js が --lit に 0→1 で ゆっくり入れる） */
.result-adv.all-stones { min-height: 136px; background: rgba(255, 226, 170, 0.16); border-color: rgba(255, 226, 160, 0.7); }
#screen-result::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: 0; background: radial-gradient(ellipse 860px 380px at 50% 215px, rgba(255, 214, 140, 0.5) 0%, rgba(255, 184, 96, 0.24) 45%, rgba(255, 160, 70, 0) 100%); }
#screen-result.lantern-lit::before { opacity: var(--lit, 1); }
.has-adv .result-cols { height: 320px; }
.has-adv.lantern-lit .result-cols { height: 288px; }
.has-adv .grid.result { max-height: 320px; gap: 12px; }
.has-adv.lantern-lit .grid.result { max-height: 288px; }
.has-adv .result-side { gap: 8px; }
.has-adv .result-top { gap: 16px; }
.has-adv .result-box .cap { margin: 0 0 2px; line-height: 1.2; white-space: nowrap; }
.has-adv .result-box.quiet { flex: 0 0 auto; }
.has-adv .result-box.quiet .cell { width: 170px; line-height: 1.25; }
.has-adv .result-box.quiet .cell canvas { width: 84px; height: 84px; }
.has-adv .grid.faces .cell canvas { width: 56px; height: 56px; }
.has-adv .grid.faces .cell { width: 64px; }
.has-adv .shards-line b { font-size: var(--fs-head); line-height: 1.1; }
.has-adv .shard-bar { height: 16px; margin: 4px 0; }
.has-adv .next-line, .has-adv .got-line { margin: 4px 0 0; line-height: 1.25; }
.has-adv .next-line { font-size: var(--fs-cap); }
.has-adv .grid.result .cell { width: 108px; line-height: 1.2; }
.has-adv .grid.result .cell canvas { width: 72px; height: 72px; }
