/* おばけクエスト CCDV-F：見た目（色は :root のトークン）
   たて向き。画面ぜんたいを #stage にして、その中に画面（.scr）を重ねる。窓は昔の RPG ふうの「黒地に白い枠」 */
:root {
  --bg: #000000;
  --win: #000000;
  --win-line: #f4f4f4;
  --ink: #ffffff;
  --ink-dim: #b8b8c8;
  --gold: #ffd25a;
  --hp: #6ee06a;
  --hp-low: #ff6a5a;
  --ok: #6ee06a;
  --ng: #ff6a5a;
  --sel: #ffd25a;
  --accent: #8ab8ff;
  --boss: #ff8a7a;
  --code-bg: #24242e;
  --splash-bg: #ffffff;
  --font-ui: "DotGothic16", "Hiragino Kaku Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  --font-text: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --text-size: 15px;
  --ctrl-h: 178px;
  color-scheme: dark;
}
:root.big-text { --text-size: 17px; }

/* 起動時の制作会社ロゴ（platform.js の PF.splash が消す） */
#splash {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--splash-bg);
  transition: opacity 0.5s ease;
}
#splash img { width: min(66vh, 66vw); height: auto; animation: splash-in 0.8s ease-out both; }
#splash.out { opacity: 0; pointer-events: none; }
@keyframes splash-in { from { opacity: 0; transform: translateY(8px) scale(0.96); } to { opacity: 1; transform: none; } }

/* iPhone のノッチ・ホームバーの分だけ内側に寄せる */
html {
  box-sizing: border-box;
  height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}
*, *::before, *::after { box-sizing: inherit; }
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

#stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
  background: var(--bg);
}
.scr { position: absolute; inset: 0; overflow: hidden; }

/* ---- 窓 ---- */
.win {
  background: var(--win);
  border: 3px solid var(--win-line);
  border-radius: 10px;
  box-shadow: 0 0 0 2px #000, inset 0 0 0 2px #000;
  color: var(--ink);
}
.win.mini { font-size: 13px; line-height: 1.45; padding: 5px 9px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 14px;
  border: 2px solid var(--win-line);
  border-radius: 10px;
  background: #101018;
  font-family: var(--font-ui);
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { background: #2a2a3a; transform: translateY(1px); }
.btn:disabled { opacity: 0.4; }
.btn.primary { border-color: var(--sel); color: var(--sel); }
.btn:focus-visible { outline: 3px solid var(--sel); outline-offset: 2px; }

/* 一覧の窓（コマンド・お店など） */
.menu { display: grid; gap: 2px; padding: 8px 6px; }
.menu button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 42px;
  padding: 6px 10px 6px 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 17px;
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
}
.menu button::before { content: ''; position: absolute; left: 8px; }
.menu button:hover::before, .menu button:focus-visible::before, .menu button.on::before { content: '▶'; font-size: 12px; color: var(--sel); }
.menu button:active { background: #1f1f2c; }
.menu button:disabled { opacity: 0.45; }
.menu .r { margin-left: auto; color: var(--gold); font-size: 15px; }
.menu .sub { display: block; font-size: 12px; color: var(--ink-dim); }

/* ---- タイトル ---- */
#title-cv { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-box { position: absolute; left: 0; right: 0; top: 9%; text-align: center; text-shadow: 0 3px 0 #000, 0 0 12px rgba(0,0,0,0.8); }
.title-box h1 { margin: 6px 0 0; font-weight: 400; font-size: 44px; letter-spacing: 0.06em; color: var(--gold); line-height: 1.1; }
.title-box h1 span { display: block; font-size: 30px; color: #fff; letter-spacing: 0.12em; }
.title-sub { margin: 0; font-size: 12px; color: #d8d8f0; letter-spacing: 0.04em; }
.title-sub2 { margin: 8px 0 0; font-size: 15px; color: #f0e8ff; }
.title-menu { position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%); width: min(280px, 80%); }
.title-note { position: absolute; left: 12px; right: 12px; bottom: 10px; margin: 0; font-family: var(--font-text); font-size: 10px; line-height: 1.5; color: #c8c8d8; text-align: center; text-shadow: 0 1px 2px #000; }

/* ---- 主人公えらび ---- */
#make { padding: 14px; overflow-y: auto; touch-action: pan-y; }
.make-h { margin: 6px 0 10px; text-align: center; font-weight: 400; font-size: 20px; color: var(--gold); }
.heroes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-c { display: grid; justify-items: center; gap: 2px; padding: 8px 4px; border: 2px solid #555; border-radius: 10px; background: #0c0c14; font-size: 13px; cursor: pointer; }
.hero-c canvas { width: 72px; height: 72px; }
.hero-c.on { border-color: var(--sel); background: #1c1a10; color: var(--sel); }
.make-name { display: grid; gap: 6px; margin: 14px 0; font-size: 15px; }
.make-name input { font: inherit; font-size: 18px; padding: 10px; border-radius: 8px; border: 2px solid #ddd; background: #000; color: #fff; -webkit-user-select: text; user-select: text; }
.make-go { display: flex; gap: 10px; justify-content: center; }

/* ---- フィールド ---- */
#map { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: calc(100% - var(--ctrl-h)); }
#f-status { position: absolute; left: 8px; top: 8px; min-width: 128px; pointer-events: none; }
#f-status b { color: var(--gold); font-weight: 400; }
.f-region { position: absolute; left: 50%; top: 96px; transform: translateX(-50%); padding: 8px 18px; border: 3px solid #fff; border-radius: 10px; background: rgba(0,0,0,0.82); font-size: 18px; white-space: nowrap; pointer-events: none; animation: region-in 2.6s ease both; }
@keyframes region-in { 0% { opacity: 0; } 12% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
#f-ctrl { position: absolute; left: 0; right: 0; bottom: 0; height: var(--ctrl-h); display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 10px; background: #000; border-top: 3px solid #fff; }
#pad { position: relative; width: 156px; height: 156px; flex: none; }
#pad button { position: absolute; width: 56px; height: 56px; border: 2px solid #fff; border-radius: 12px; background: #15151f; font-size: 20px; touch-action: none; cursor: pointer; }
#pad button.down { background: #3a3a50; }
#pad .pad-u { left: 50px; top: 0; }
#pad .pad-d { left: 50px; bottom: 0; }
#pad .pad-l { left: 0; top: 50px; }
#pad .pad-r { right: 0; top: 50px; }
.f-btns { display: grid; gap: 12px; width: min(150px, 40%); }
.f-btns .btn { min-height: 54px; }

/* ---- 町 ---- */
#town-cv { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 35%; }
.town-name { position: absolute; left: 0; right: 0; top: 10px; text-align: center; font-size: 20px; text-shadow: 0 2px 0 #000, 0 0 8px #000; }
#town-status { position: absolute; right: 8px; top: 44px; }
.town-menu { position: absolute; left: 10px; right: 10px; top: calc(35% + 6px); bottom: 10px; overflow-y: auto; touch-action: pan-y; }

/* ---- バトル ---- */
#battle { display: flex; flex-direction: column; background: #000; }
/* 出会ったとき：まんなかから 窓が ひらく */
#battle.opening { animation: b-open 0.36s ease-out both; }
@keyframes b-open { from { clip-path: inset(46% 40% 46% 40%); } to { clip-path: inset(0 0 0 0); } }
#map.enc { animation: enc-blink 0.5s steps(1) both; }
@keyframes enc-blink { 0% { filter: none; } 17% { filter: invert(1); } 34% { filter: none; } 51% { filter: invert(1); } 68% { filter: none; } 85% { filter: brightness(0); } 100% { filter: brightness(0); } }
.b-top { position: relative; flex: none; height: 30%; min-height: 170px; transition: height 0.3s ease; }
#battle.intro .b-top { height: calc(100% - 100px); }
#battle.intro .b-mid, #battle.intro .b-cmd { display: none; }
#b-cv { position: absolute; inset: 0; width: 100%; height: 100%; }
.b-stat { position: absolute; left: 6px; right: 6px; top: 4px; display: flex; flex-wrap: wrap; gap: 0 14px; padding: 3px 10px; font-size: 14px; line-height: 1.5; }
.b-stat .low { color: var(--hp-low); }
.b-stat .sp { margin-left: auto; color: var(--accent); font-size: 12px; align-self: center; }
.b-stat .boss { width: 100%; color: var(--boss); font-size: 13px; }
.b-stat .pips i { display: inline-block; width: 10px; height: 10px; margin-left: 3px; border: 1px solid var(--boss); border-radius: 50%; vertical-align: -1px; }
.b-stat .pips i.on { background: var(--boss); }
.b-msg { flex: none; position: relative; margin: 4px 6px 0; padding: 5px 12px; height: calc(3 * 1.45em + 14px); font-size: 14px; line-height: 1.45; overflow: hidden; }
#battle.intro .b-msg { cursor: pointer; }
.b-msg-next { position: absolute; right: 10px; bottom: 2px; font-size: 12px; animation: blink 0.9s steps(2) infinite; }
.b-hint { margin-top: 8px; padding: 8px 11px; border-color: var(--accent); }
.b-hint .h { color: var(--accent); font-size: 13px; margin-bottom: 4px; }
.b-hint dl { margin: 0; }
.b-hint dt { color: var(--gold); font-size: 13px; margin-top: 6px; }
.b-hint dd, .b-hint p { margin: 2px 0 0; font-family: var(--font-text); font-size: calc(var(--text-size) - 1px); line-height: 1.6; }
.b-hint .x { color: var(--ink-dim); font-size: 12px; }
.b-mid { flex: 1; overflow-y: auto; padding: 8px 8px 12px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.b-q { padding: 8px 11px 10px; }
.q-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 12px; color: var(--ink-dim); margin-bottom: 4px; }
.q-head .d1 { color: #ffb08a; }
.q-head .d2 { color: #ffe08a; }
.q-head .d3 { color: #8ad8ff; }
.q-text { font-family: var(--font-text); font-size: var(--text-size); line-height: 1.65; -webkit-user-select: text; user-select: text; }
.q-text code, .exp code { font-family: ui-monospace, Menlo, monospace; font-size: 0.88em; background: var(--code-bg); padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.q-text b, .exp b { color: var(--gold); font-weight: 700; }
.b-pick { margin: 10px 2px 4px; font-size: 13px; color: var(--sel); }
.b-opts { display: grid; gap: 6px; }
.opt {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: start;
  width: 100%;
  padding: 8px 10px 9px 8px;
  border: 2px solid #777;
  border-radius: 10px;
  background: #0b0b12;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.opt .tag { display: grid; place-items: center; width: 30px; height: 30px; border: 2px solid #fff; border-radius: 50%; font-size: 16px; background: #222; }
.opt .who { display: block; font-size: 11px; color: var(--ink-dim); margin-bottom: 1px; }
.opt .txt { font-family: var(--font-text); font-size: var(--text-size); line-height: 1.55; }
.opt.on { border-color: var(--sel); background: #1c1a0c; }
.opt.on .tag { background: var(--sel); color: #000; border-color: var(--sel); }
.opt.ok { border-color: var(--ok); background: #0c1c0c; }
.opt.ok .tag { background: var(--ok); color: #000; border-color: var(--ok); }
.opt.ng { border-color: var(--ng); background: #200c0c; }
.opt.ng .tag { background: var(--ng); color: #000; border-color: var(--ng); }
.opt:disabled { cursor: default; }
.b-res { margin-top: 10px; padding: 10px 12px; }
.res-h { font-size: 18px; margin-bottom: 6px; }
.res-h.ok { color: var(--ok); }
.res-h.ng { color: var(--ng); }
.exp { font-family: var(--font-text); font-size: var(--text-size); line-height: 1.7; -webkit-user-select: text; user-select: text; }
.exp p { margin: 0 0 8px; }
.b-cmd { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 0 6px; margin: 4px 6px 6px; padding: 4px 6px; }
.b-cmd button { position: relative; min-height: 44px; padding: 4px 8px 4px 26px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); text-align: left; font-family: var(--font-ui); font-size: 18px; cursor: pointer; touch-action: manipulation; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-cmd button::before { content: ''; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--sel); }
.b-cmd button:active, .b-cmd button.on { background: #1f1f2c; }
.b-cmd button:active::before, .b-cmd button.on::before, .b-cmd button:hover::before { content: '▶'; }
.b-cmd button:disabled { opacity: 0.4; }
.b-cmd button .s { font-size: 13px; color: var(--sel); }
.b-cmd .wide { grid-column: 1 / -1; text-align: center; padding-left: 8px; color: var(--sel); }
.b-cmd .wide::before { content: '' !important; }
.opt.gone { opacity: 0.3; border-style: dashed; }
.opt.gone .txt { text-decoration: line-through; }
.b-opts.target .opt:not(.gone):not(:disabled) { animation: target 0.7s ease-in-out infinite alternate; }
@keyframes target { from { border-color: #777; } to { border-color: var(--sel); } }

/* ---- パネル（メニュー・ふりかえりの書など） ---- */
#panel { display: flex; flex-direction: column; background: #000; }
.p-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 3px solid #fff; }
.p-head h2 { margin: 0; font-weight: 400; font-size: 19px; color: var(--gold); }
.p-back { min-height: 40px; }
.p-body { flex: 1; overflow-y: auto; padding: 10px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.p-body .win { padding: 10px 12px; margin-bottom: 10px; }
.p-body h3 { margin: 4px 0 8px; font-weight: 400; font-size: 16px; color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 15px; }
.kv dt { color: var(--ink-dim); }
.kv dd { margin: 0; text-align: right; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs button { flex: 1; min-height: 40px; padding: 4px 6px; border: 2px solid #666; border-radius: 8px; background: #0c0c14; font-size: 14px; cursor: pointer; }
.tabs button.on { border-color: var(--sel); color: var(--sel); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips button { min-height: 34px; padding: 2px 10px; border: 1px solid #666; border-radius: 999px; background: #0c0c14; font-size: 13px; cursor: pointer; }
.chips button.on { border-color: var(--accent); color: var(--accent); }
.qlist { display: grid; gap: 6px; }
.qrow { display: grid; gap: 2px; width: 100%; padding: 8px 10px; border: 2px solid #555; border-radius: 10px; background: #0b0b12; text-align: left; cursor: pointer; }
.qrow .top { display: flex; gap: 8px; font-size: 13px; align-items: center; }
.qrow .id { color: var(--accent); }
.qrow .miss { color: var(--ng); }
.qrow .good { color: var(--ok); }
.qrow .done { margin-left: auto; color: var(--ok); }
.qrow .yet { margin-left: auto; color: var(--sel); }
.qrow .head { font-family: var(--font-text); font-size: 14px; line-height: 1.5; color: #e8e8f0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.empty { padding: 20px 6px; text-align: center; color: var(--ink-dim); font-size: 15px; line-height: 1.7; }
.detail-opts { display: grid; gap: 6px; margin: 10px 0; }
.detail-opts .opt { cursor: default; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.row-btns .btn { flex: 1; }
.stat-t { width: 100%; border-collapse: collapse; font-size: 13px; }
.stat-t th, .stat-t td { padding: 6px 4px; border-bottom: 1px solid #333; text-align: right; }
.stat-t th:first-child, .stat-t td:first-child { text-align: left; }
.stat-t th { color: var(--ink-dim); font-weight: 400; }
.gl dt { color: var(--gold); margin-top: 10px; font-size: 15px; }
.gl dd { margin: 3px 0 0; font-family: var(--font-text); font-size: 14px; line-height: 1.6; }
.note { font-family: var(--font-text); font-size: 13px; line-height: 1.6; color: var(--ink-dim); }
.code-area { width: 100%; min-height: 90px; font-family: ui-monospace, monospace; font-size: 12px; background: #111; color: #fff; border: 1px solid #888; border-radius: 6px; padding: 6px; -webkit-user-select: text; user-select: text; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 15px; }
.set-row .btn { min-width: 96px; min-height: 40px; }

/* ---- メッセージ ---- */
.talk { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: flex-end; padding: 10px; background: rgba(0,0,0,0.15); }
.talk-box { position: relative; padding: 12px 14px 22px; font-size: 17px; line-height: 1.7; min-height: 96px; max-height: 60%; overflow-y: auto; touch-action: pan-y; white-space: pre-wrap; cursor: pointer; }
.talk-next { position: absolute; right: 12px; bottom: 4px; font-size: 13px; animation: blink 0.9s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.talk-ask { align-self: flex-end; margin-bottom: 8px; min-width: 160px; max-width: 90%; order: -1; }
.talk-ask .menu button { font-size: 17px; }

/* ---- 画面効果 ---- */
.fade { position: absolute; inset: 0; z-index: 30; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.22s linear; }
.fade.on { opacity: 1; pointer-events: auto; }
.flash { position: absolute; inset: 0; z-index: 25; pointer-events: none; opacity: 0; }
.flash.red { animation: flash-red 0.45s ease-out; }
.flash.white { animation: flash-white 0.5s ease-out; }
@keyframes flash-red { 0% { opacity: 0.55; background: #ff2020; } 100% { opacity: 0; background: #ff2020; } }
@keyframes flash-white { 0%, 40% { opacity: 0.9; background: #fff; } 100% { opacity: 0; background: #fff; } }
#stage.shake { animation: shake 0.35s linear; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translate(-6px, 2px); } 40% { transform: translate(5px, -3px); } 60% { transform: translate(-4px, 3px); } 80% { transform: translate(3px, -1px); } }
.turn { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: #000; font-size: 20px; }
@media (prefers-reduced-motion: reduce) { #stage.shake { animation: none; } .flash.red, .flash.white { animation-duration: 0.2s; } }
.q-text p, .exp p { margin: 0 0 8px; }
.q-text p:last-child, .exp p:last-child { margin-bottom: 0; }
.exp details summary { cursor: pointer; color: var(--accent); font-family: var(--font-ui); font-size: 14px; }
.res-rec { margin-top: 8px; font-size: 13px; color: var(--ink-dim); }
.res-rec .good { color: var(--ok); }
.town-menu .menu { gap: 0; padding: 4px 6px; }
.town-menu .menu button { min-height: 38px; padding-top: 4px; padding-bottom: 4px; }
.town-menu .menu .sub { font-size: 11px; }
.dict details { border-bottom: 1px solid #333; padding: 6px 0; }
.dict summary { cursor: pointer; font-size: 15px; color: var(--gold); }
.dict .exp { margin-top: 6px; font-size: calc(var(--text-size) - 1px); }
.talk-ask { max-height: 70%; overflow-y: auto; touch-action: pan-y; }
.menu .r { white-space: nowrap; }
.b-cmd .wait { grid-column: 1 / -1; min-height: 88px; display: grid; place-items: center; color: var(--ink-dim); font-size: 14px; }
