/* =========================================================
   style.css ─ レイアウトと基本のモノクロームCRTテーマ
   色はすべて変数。侵蝕度による変化は effects.css で上書きする
   ========================================================= */

/* ドットフォント DotGothic16（SIL Open Font License。assets/fonts/OFL.txt） */
@font-face {
  font-family: "DotGothic16";
  src: url("../assets/fonts/DotGothic16-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  /* 蛍光体カラー（侵蝕度0＝緑） */
  --fg: #39ff7a;
  --fg-dim: #1f9a4a;
  --fg-faint: #0f4a25;
  --bg: #020904;
  --bg-panel: #031208;
  --bg-hi: #0a2a14;
  --glow: rgba(57, 255, 122, 0.45);

  /* エフェクト量（effects.css で段階的に変化） */
  --noise-opacity: 0.05;
  --scan-opacity: 0.22;
  --flicker-opacity: 0.02;
  --blur: 0px;
  --aberration: 0px;

  --font: "DotGothic16", "MS Gothic", "Osaka-Mono", monospace;
  --radius-crt: 22px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: #0b0b0a; /* モニター筐体 */
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  overflow: hidden;
  transition: color 1.5s;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- ブラウン管本体 ---------- */
.crt {
  position: relative;
  height: 100vh;
  height: 100dvh; /* スマホでアドレスバーの分だけ下が切れないように */
  padding: 18px;
  background:
    radial-gradient(ellipse at center, #141412 0%, #050505 100%);
}

.desktop {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-crt);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 40%, var(--bg-hi) 0%, var(--bg) 70%);
  box-shadow:
    0 0 0 2px #1b1b18,
    0 0 40px rgba(0, 0, 0, 0.9),
    inset 0 0 80px rgba(0, 0, 0, 0.85);
  text-shadow:
    0 0 2px var(--glow),
    0 0 8px var(--glow),
    var(--aberration) 0 0 rgba(255, 0, 60, 0.6),
    calc(var(--aberration) * -1) 0 0 rgba(0, 160, 255, 0.6);
  filter: blur(var(--blur));
}

/* ---------- メニューバー ---------- */
.menubar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 4px 16px;
  border-bottom: 1px solid var(--fg-dim);
  background: var(--bg-panel);
}

.menubar__logo {
  letter-spacing: 0.1em;
}

.menubar__menu {
  display: flex;
  gap: 4px;
}

.menu-item {
  padding: 0 10px;
}

.menu-item:hover {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
}

.menubar__status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 20px;
}

.erosion-meter {
  display: flex;
  align-items: center;
  gap: 8px;
}

.erosion-meter__bar {
  width: 120px;
  height: 10px;
  border: 1px solid var(--fg-dim);
  padding: 1px;
}

.erosion-meter__fill {
  display: block;
  height: 100%;
  width: 0%;
  /* 目盛り風の刻み */
  background: repeating-linear-gradient(90deg, var(--fg) 0 6px, transparent 6px 8px);
  transition: width 2s steps(10);
}

/* ---------- ウィンドウ ---------- */
.window {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 14px 16px;
  border: 2px solid var(--fg-dim);
  background: var(--bg-panel);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.6);
}

.window__titlebar {
  display: flex;
  justify-content: space-between;
  padding: 2px 10px;
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  letter-spacing: 0.05em;
}

.window__controls {
  display: flex;
  gap: 10px;
}

/* 舞台を画面いっぱいに取り、セリフ枠（2行目）と選択肢をその上に重ねる */
.window__body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
}

/* ---------- 舞台 ---------- */
.stage {
  grid-row: 1 / 3;
  grid-column: 1;
  position: relative;
  overflow: hidden;
  isolation: isolate; /* 色付け層の乗算を舞台の中だけに閉じ込める */
  background: #000;
  cursor: pointer;
}

.stage__bg {
  position: absolute;
  inset: 0;
  background: center 45% / cover no-repeat;
  filter: contrast(1.15) brightness(0.9) saturate(0.7);
  transform: scale(1.05);
  animation: bg-drift 40s ease-in-out infinite alternate;
  transition: filter 6s;
}

/* 夜の色調：乗算で全体を紺に沈め、手前の楕円（懐中電灯）だけ暖色で残す */
.stage__night {
  position: absolute;
  inset: 0;
  mix-blend-mode: multiply;
  background:
    radial-gradient(ellipse 32% 58% at 50% 88%, #fffaf0 0%, #b8b4a8 35%, #6a7090 65%, transparent 100%),
    linear-gradient(to bottom, #0b1226 0%, #1a2548 55%, #26335c 100%);
  animation: flashlight 6s ease-in-out infinite;
  transition: opacity 6s;
}

/* 懐中電灯の光そのもの：スクリーン合成で照らされた所を明るく持ち上げる */
.stage__light {
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
  background: radial-gradient(ellipse 24% 46% at 50% 90%,
    rgba(255, 236, 190, 0.55) 0%,
    rgba(255, 225, 170, 0.22) 45%,
    transparent 100%);
  animation: flashlight 6s ease-in-out infinite;
  transition: opacity 3s;
}

/* 夜明けの朝焼け：下から暖色、上は淡い水色の空。scene.dawn で .stage に is-dawn が付く */
.stage__dawn {
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(to top,
    rgba(255, 150, 90, 0.55) 0%,
    rgba(255, 200, 150, 0.3) 35%,
    rgba(170, 200, 255, 0.18) 70%,
    rgba(140, 170, 230, 0.1) 100%);
  transition: opacity 6s;
}

.stage.is-dawn .stage__dawn {
  opacity: 1;
}

/* 夜の紺を薄め、懐中電灯を消し、写真本来の明るさに戻す */
.stage.is-dawn .stage__night {
  animation: none;
  opacity: 0.15;
}

.stage.is-dawn .stage__light {
  animation: none;
  opacity: 0;
}

.stage.is-dawn .stage__bg {
  filter: contrast(1.05) brightness(1.08) saturate(0.95);
}

.stage.is-dawn .stage__snow {
  opacity: 0.15;
}

/* 懐中電灯の手ぶれ */
@keyframes flashlight {
  0%, 100% { background-position: 0 0, 0 0; }
  30% { background-position: -10px 3px, 0 0; }
  65% { background-position: 8px -2px, 0 0; }
  /* 電池が弱っているような一瞬のちらつき */
  66% { opacity: 0.75; }
  67% { opacity: 1; }
}

@keyframes bg-drift {
  to { transform: scale(1.12) translateY(-1%); }
}

.stage__snow {
  position: absolute;
  inset: 0;
  opacity: 0.55;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.85) 0.8px, transparent 1.4px) 0 0 / 14px 18px,
    radial-gradient(circle, rgba(255, 255, 255, 0.5) 0.7px, transparent 1.2px) 7px 9px / 21px 25px;
  animation: stage-snow 7s linear infinite;
  transition: opacity 6s;
}

@keyframes stage-snow {
  to { background-position: -14px 180px, 0 250px; }
}

/* 線路の奥に立つ白い人影（侵蝕が進むと近づく） */
.stage__ghost {
  position: absolute;
  left: 47.6%;
  top: 56%;
  width: 1.8%;
  height: 11%;
  background: rgba(225, 235, 255, 0.95);
  clip-path: polygon(30% 0, 70% 0, 62% 18%, 72% 40%, 100% 100%, 0 100%, 28% 40%, 38% 18%);
  filter: blur(1px) drop-shadow(0 0 6px rgba(200, 220, 255, 0.9));
  opacity: 0;
  transition: opacity 3s, left 3s, top 3s, width 3s, height 3s;
}

.stage__ghost.is-visible {
  opacity: 0.85;
  animation: ghost-waver 4s ease-in-out infinite;
}

@keyframes ghost-waver {
  48% { opacity: 0.5; }
  50% { opacity: 0.95; transform: translateX(1px); }
}

body[data-erosion="3"] .stage__ghost {
  left: 46.5%;
  top: 48%;
  width: 3.2%;
  height: 22%;
}

body[data-erosion="4"] .stage__ghost {
  left: 45%;
  top: 38%;
  width: 5.5%;
  height: 38%;
}

/* 登場人物の立ち絵。1人なら右、2人なら左右（data-slot） */
.stage__cast {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stage__figure {
  position: absolute;
  bottom: 0;
  margin: 0;
  opacity: 0;
  transition: opacity 1.4s, filter 0.4s;
}

/* 主人公は右、相手は左（ふたりなら左と中央） */
.stage__figure[data-slot="right"] {
  right: 2%;
}

.stage__figure[data-slot="left"] {
  left: 2%;
}

.stage__figure[data-slot="center"] {
  left: 27%;
}

.stage__figure.is-visible {
  opacity: 1;
}

/* 話していない人物は暗く沈め、話している人物を少し手前に出す */
.stage__figure.is-dim {
  filter: brightness(0.38) saturate(0.6);
}

.stage__figure.is-active {
  z-index: 1;
}

/* style: bust … ドット絵の胸像（主人公）。拡大してもドットのまま、下端はセリフ枠に隠れる */
.stage__figure--bust {
  height: 96%;
  aspect-ratio: 145 / 185;
  transition: opacity 1.4s, filter 0.3s, transform 0.3s;
}

.stage__figure--bust img {
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 10px rgba(140, 160, 255, 0.3));
}

.stage__figure--bust.is-active {
  transform: translateY(-1.5%);
}

/* ----- 主人公の表情に添える記号と動き（data-face は main.js の setFace が付ける） ----- */
.stage__figure--bust::after {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: 0;
}

/* 驚き：頭の上に「！」、ぴょんと跳ねる */
.stage__figure--bust[data-face="surprised"]::after {
  content: "！";
  top: 4%;
  left: 10%;
  opacity: 1;
  font-size: clamp(28px, 7vh, 56px);
  color: #ff5d4a;
  text-shadow: 0 0 8px rgba(255, 93, 74, 0.7);
  animation: emote-pop 0.35s steps(3) both;
}

.stage__figure--bust.is-reacting[data-face="surprised"] img {
  animation: face-jump 0.32s steps(4) 1;
}

/* 怯え：頭の上に青い縦線、小刻みに震える */
.stage__figure--bust[data-face="scared"]::after {
  top: 2%;
  left: 18%;
  width: 64%;
  height: 34%;
  opacity: 1;
  background: repeating-linear-gradient(90deg, rgba(110, 140, 255, 0.55) 0 3px, transparent 3px 13px);
  -webkit-mask-image: linear-gradient(to bottom, #000 20%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 20%, transparent 100%);
  animation: emote-fade 0.6s ease-out both;
}

.stage__figure--bust[data-face="scared"] img {
  animation: face-tremble 0.14s steps(2) infinite;
}

/* 困り：こめかみに汗 */
.stage__figure--bust[data-face="troubled"]::after {
  top: 24%;
  left: 17%;
  width: 5%;
  aspect-ratio: 1;
  opacity: 0.9;
  background: #9fd4ff;
  border-radius: 0 50% 50% 50%;
  transform: rotate(45deg);
  box-shadow: 0 0 6px rgba(159, 212, 255, 0.8);
  animation: emote-sweat 2.2s ease-in infinite;
}

/* 喜び：音符がふわりと浮かび、少し弾む */
.stage__figure--bust[data-face="joy"]::after {
  content: "♪";
  top: 8%;
  left: 6%;
  opacity: 1;
  font-size: clamp(22px, 5vh, 40px);
  color: #ffd27a;
  text-shadow: 0 0 8px rgba(255, 210, 122, 0.7);
  animation: emote-float 1.8s ease-in-out infinite;
}

.stage__figure--bust.is-reacting[data-face="joy"] img {
  animation: face-hop 0.5s steps(5) 1;
}

@keyframes emote-pop {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes emote-fade {
  from { opacity: 0; }
}

@keyframes emote-sweat {
  0% { translate: 0 0; opacity: 0; }
  20% { opacity: 0.9; }
  100% { translate: 0 40%; opacity: 0; }
}

@keyframes emote-float {
  50% { translate: 0 -12%; }
}

@keyframes face-jump {
  50% { transform: translateY(-4%); }
}

@keyframes face-hop {
  25%, 75% { transform: translateY(-2%); }
  50% { transform: translateY(0); }
}

@keyframes face-tremble {
  50% { transform: translateX(0.6%); }
}

.stage__figure img {
  display: block;
  width: 100%;
  height: 100%;
}

/* style: photo … 古写真をぼかし枠で浮かび上がらせる（老人） */
.stage__figure--photo {
  bottom: -4%;
  height: 108%;
  aspect-ratio: 3 / 4;
  /* 楕円の外側を完全に透明にして、写真の四角い縁を見せない */
  -webkit-mask-image: radial-gradient(ellipse 48% 56% at 50% 42%, #000 45%, transparent 100%);
  mask-image: radial-gradient(ellipse 48% 56% at 50% 42%, #000 45%, transparent 100%);
}

.stage__figure--photo img {
  object-fit: cover;
  object-position: center 30%;
  filter: contrast(1.2) brightness(0.8) saturate(0.65);
}

/* 肖像も夜の青に寄せる（マスクの内側だけに効く） */
.stage__figure--photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #5a6a9a;
  mix-blend-mode: multiply;
  opacity: 0.55;
}

/* style: figure … 背景が透明な立ち絵（PNG）を足元からそのまま立たせる */
.stage__figure--figure {
  height: 104%;
  aspect-ratio: 3 / 5;
}

.stage__figure--figure img {
  object-fit: contain;
  object-position: center bottom;
  filter: brightness(0.82) saturate(0.85) drop-shadow(0 0 14px rgba(140, 160, 255, 0.35));
}

/* style: portrait … 相手役の胸像（しの・かれん）。3人並んでも重なりすぎないよう、主人公より少し小さい */
.stage__figure--portrait {
  bottom: 11%; /* 口元がセリフの文字にかからない高さ。下端はぼかしてあるので浮いて見えない */
  height: 64%;
  aspect-ratio: 152 / 198;
  transition: opacity 1.4s, filter 0.3s, transform 0.3s;
}

.stage__figure--portrait img {
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  filter: brightness(0.9) saturate(0.9) drop-shadow(0 0 10px rgba(140, 160, 255, 0.3));
}

.stage__figure--portrait.is-active {
  transform: translateY(-1.5%);
}

/* 話している間は、立ち絵がかすかに明滅する */
.stage__figure.is-speaking img {
  animation: speak-flicker 0.2s steps(2) infinite;
}

@keyframes speak-flicker {
  50% { opacity: 0.85; }
}

/* 写真は通常フルカラー。侵蝕が進むと画面の色（アンバー→赤）に染まっていく */
.stage__tint {
  position: absolute;
  inset: 0;
  background: var(--fg);
  mix-blend-mode: color;
  opacity: 0;
  pointer-events: none;
  transition: opacity 2s;
}

body[data-erosion="2"] .stage__tint { opacity: 0.25; }
body[data-erosion="3"] .stage__tint { opacity: 0.45; }
body[data-erosion="4"] .stage__tint { opacity: 0.7; }

.stage__scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.85) 100%);
}

.stage__info {
  position: absolute;
  left: 20px;
  top: 16px;
  z-index: 2;
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: baseline;
  gap: 2px 14px;
  margin: 0;
  max-width: calc(100% - 40px);
  padding: 10px 18px;
  border: 1px solid var(--fg-dim);
  background: rgba(0, 0, 0, 0.62);
}

.stage__info dt {
  font-size: 12px;
  color: var(--fg-dim);
  border: 1px solid var(--fg-faint);
  padding: 0 6px;
}

.stage__info dd {
  margin: 0;
}

.stage__who {
  font-size: 22px;
  letter-spacing: 0.12em;
}

/* 相手が切り替わったときのちらつき */
.stage__who.is-changing {
  animation: who-in 0.6s steps(6) 1;
}

.stage__rec {
  position: absolute;
  right: 84px;
  top: 12px;
  z-index: 2;
  font-size: 12px;
}

.stage__logbtn {
  position: absolute;
  right: 14px;
  top: 8px;
  z-index: 2;
  padding: 0 10px;
  font-size: 13px;
  border: 1px solid var(--fg-dim);
  background: rgba(0, 0, 0, 0.6);
}

.stage__logbtn:hover,
.stage__logbtn:focus-visible,
.stage__logbtn[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

/* 写真の出典：セリフ枠に隠れないよう右上に置く */
.stage__credit {
  position: absolute;
  right: 14px;
  top: 36px;
  z-index: 2;
  max-width: 40%;
  font-size: 10px;
  text-align: right;
  color: var(--fg-dim);
}

@keyframes who-in {
  0% { opacity: 0; }
  30% { opacity: 1; }
  45% { opacity: 0.15; }
  100% { opacity: 1; }
}

/* ---------- セリフ枠（舞台の下に重なる。会話窓風） ---------- */
.log {
  --accent: #ff5d4a; /* 名前と下線の色 */
  grid-row: 2;
  grid-column: 1;
  z-index: 3;
  min-height: 150px;
  max-height: 46vh;
  overflow-y: auto;
  padding: 30px 8% 20px;
  cursor: pointer;
  background: linear-gradient(to bottom,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.72) 26%,
    rgba(0, 0, 0, 0.9) 100%);
}

/* ふだんは最新の1行だけを見せる（過去の行は LOG で開く） */
.log:not(.is-history) .log-entry:not(:last-child) {
  display: none;
}

.log-entry {
  max-width: 46em;
  margin: 0 auto 16px;
}

.log:not(.is-history) .log-entry {
  margin-bottom: 0;
}

/* 話者名：赤い下線が右へ消えていく */
.log-entry__who {
  display: block;
  width: min(16em, 100%);
  margin-bottom: 6px;
  padding: 0 0 2px 2px;
  font-size: 14px;
  letter-spacing: 0.12em;
  color: var(--accent);
  border-bottom: 2px solid;
  border-image: linear-gradient(to right, var(--accent) 0%, var(--accent) 40%, transparent 100%) 1;
}

.log-entry__text {
  margin: 0;
  font-size: 17px;
  white-space: pre-line;
}

/* 主人公の発言：履歴では小さな顔アイコンを添える（舞台に立ち絵があるので、セリフ枠では出さない） */
.log-entry.is-player {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.log-entry__face {
  display: none;
  flex: none;
  width: 44px;
  height: auto;
  image-rendering: pixelated;
}

.log.is-history .log-entry__face {
  display: block;
}

.log-entry__body {
  flex: 1;
  min-width: 0;
}

.log-entry.is-system {
  max-width: none;
  text-align: center;
  color: var(--fg-dim);
  letter-spacing: 0.2em;
}

/* LOG：会話の全履歴を舞台いっぱいに開く */
.log.is-history {
  grid-row: 1 / 3;
  max-height: none;
  padding: 20px 8% 24px;
  background: rgba(0, 0, 0, 0.92);
}

.log.is-history::before {
  content: "── LOG ──　（クリック / Esc / L で閉じる）";
  display: block;
  margin-bottom: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--fg-dim);
}

.log.is-history .log-entry:not(:last-child) {
  opacity: 0.72;
}

.log.is-history .log-entry__text {
  font-size: 15px;
}

.log.is-history .log-entry.is-narration .log-entry__text {
  padding-left: 1em;
  border-left: 1px solid var(--fg-faint);
}

/* 文字送り中のカーソルと、クリック待ちの ▼ */
.log-entry.is-typing .log-entry__text::after {
  content: "█";
  animation: blink 0.6s steps(1) infinite;
}

.log-entry.is-waiting .log-entry__text::after {
  content: " ▼";
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.log-entry.is-end {
  max-width: 32em;
  padding: 14px 20px;
  border: 1px solid var(--fg);
  text-align: center;
  box-shadow: 0 0 18px var(--glow);
}

.log.is-history .log-entry.is-end {
  margin: 28px auto;
}

.log-entry__title {
  margin: 0 0 6px;
  font-size: 20px;
  letter-spacing: 0.15em;
}

/* ---------- 選択肢（セリフ枠の上に重ねる） ---------- */
.choices {
  grid-row: 1;
  grid-column: 1;
  z-index: 4;
  align-self: end;
  justify-self: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(640px, 92%);
  max-height: calc(100% - 60px);
  overflow-y: auto;
  margin-bottom: 12px;
  padding: 14px 18px;
  border: 1px solid var(--fg-dim);
  background: rgba(2, 9, 4, 0.9);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.8);
}

/* 暗証番号などの入力は広めに */
.choices:has(.codepad) {
  width: min(920px, 96%);
}

/* 選ぶものがないとき（クリック待ちだけのとき）と、LOG を開いている間は隠す */
.choices:empty,
.choices:has(> .choices__hint:only-child),
.window__body:has(.log.is-history) .choices {
  display: none;
}

.choices__hint {
  margin: auto 0;
  text-align: center;
  font-size: 13px;
  color: var(--fg-dim);
  cursor: pointer;
}

.choice {
  display: flex;
  gap: 14px;
  width: 100%;
  padding: 6px 14px;
  border: 1px solid var(--fg-dim);
  text-align: left;
  animation: choice-in 0.3s steps(3) both;
}

.choice:hover:not(:disabled),
.choice:focus-visible {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

.choice:disabled {
  border-style: dashed;
  color: var(--fg-faint);
  cursor: default;
}

.choice__key {
  flex: none;
  color: var(--fg-dim);
}

.choice:hover:not(:disabled) .choice__key,
.choice:focus-visible .choice__key {
  color: var(--bg);
}

/* 透明にはせず「光って現れる」演出にする（アニメが止まっても選択肢が見える） */
@keyframes choice-in {
  from { transform: translateX(-8px); filter: brightness(2.5); }
  to { transform: none; filter: none; }
}

/* ---------- 暗証番号のダイヤル錠 ---------- */
.codepad {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 28px;
}

.codepad__label {
  flex-basis: 100%;
  margin: 0;
  font-size: 13px;
  color: var(--fg-dim);
}

.codepad__dials {
  display: flex;
  gap: 10px;
}

.dial {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid var(--fg-dim);
  background: #000;
}

.dial.is-current {
  border-color: var(--fg);
  box-shadow: 0 0 10px var(--glow);
}

.dial__btn {
  width: 100%;
  padding: 0 14px;
  font-size: 11px;
  color: var(--fg-dim);
}

.dial__btn:hover:not(:disabled) {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
}

.dial__digit {
  padding: 0 12px;
  font-size: 30px;
  line-height: 1.2;
}

.dial.is-current .dial__digit {
  animation: blink 1s steps(1) infinite;
}

.codepad__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 200px;
}

.codepad__actions .choice {
  padding: 4px 14px;
}

/* 五十音ボタン（自販機のボタン） */
.kanapad {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kanapad__slots {
  display: flex;
  gap: 6px;
}

.kanapad__slot {
  display: grid;
  place-items: center;
  width: 36px;
  height: 40px;
  border: 1px solid var(--fg-dim);
  background: #000;
  font-size: 22px;
}

.kanapad__slot.is-current {
  border-color: var(--fg);
  box-shadow: 0 0 10px var(--glow);
}

/* 1列が1行（あ行・か行…）になるよう縦に流す */
.kanapad__grid {
  display: grid;
  grid-template-rows: repeat(5, 26px);
  grid-auto-flow: column;
  grid-auto-columns: 26px;
  gap: 3px;
}

.kanapad__key {
  border: 1px solid var(--fg-faint);
  background: rgba(0, 0, 0, 0.6);
  font-size: 14px;
  line-height: 1;
}

.kanapad__key:hover:not(:disabled),
.kanapad__key:focus-visible {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

/* ラジオの受信機 */
.tuner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 340px;
}

.tuner__freq {
  font-size: 28px;
  letter-spacing: 0.1em;
  text-align: center;
  border: 1px solid var(--fg-dim);
  background: #000;
}

/* 目盛り：0.5 MHz ごとの細線、1 MHz ごとの太線 */
.tuner__scale {
  position: relative;
  height: 14px;
  border-bottom: 1px solid var(--fg-dim);
  background:
    repeating-linear-gradient(90deg, var(--fg-dim) 0 2px, transparent 2px 10%),
    repeating-linear-gradient(90deg, var(--fg-faint) 0 1px, transparent 1px 5%);
  background-size: 100% 100%, 100% 50%;
  background-position: 0 0, 0 100%;
  background-repeat: no-repeat;
}

.tuner__needle {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: #ff5a5a;
  box-shadow: 0 0 6px #ff5a5a;
  transform: translateX(-1px);
}

.tuner__slider {
  width: 100%;
  accent-color: var(--fg);
}

.tuner__btns {
  display: flex;
  gap: 6px;
}

.tuner__btn {
  flex: 1;
  padding: 2px 0;
  border: 1px solid var(--fg-dim);
}

.tuner__btn:hover,
.tuner__btn:focus-visible {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

.tuner__meter {
  font-size: 13px;
  color: var(--fg-dim);
}

.tuner__heard {
  margin: 0;
  min-height: 2.8em;
  font-size: 13px;
}

/* スマホで記録を見るリンク */
.codepad__phone {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 340px;
}

.codepad__qr {
  flex: none;
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  border: 2px solid var(--fg-dim);
  cursor: zoom-in;
}

.qrzoom {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.92);
  color: var(--fg);
  text-shadow: 0 0 6px var(--glow);
  cursor: zoom-out;
}

.qrzoom[hidden] {
  display: none;
}

.qrzoom img {
  width: min(70vmin, 360px);
  height: min(70vmin, 360px);
  padding: 12px;
  background: #fff;
  image-rendering: pixelated;
}

.qrzoom p {
  margin: 0;
  word-break: break-all;
}

.qrzoom__close {
  font-size: 12px;
  color: var(--fg-dim);
}

.codepad__phone-note {
  margin: 0;
  font-size: 12px;
  color: var(--fg-dim);
}

.codepad__phone-link {
  font-size: 13px;
  color: var(--fg);
  word-break: break-all;
}

.blink {
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- 地図モード ---------- */
.window__body.is-map {
  grid-template-rows: minmax(0, 1fr);
}

.window__body.is-map > .stage,
.window__body.is-map > .log,
.window__body.is-map > .choices {
  display: none;
}

.mapview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  min-height: 0;
}

.mapview[hidden] {
  display: none;
}

.mapview__frame {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: #000;
}

/* 大きさは mapview.js が枠に合わせて縦横比を保ったまま設定する */
.map {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--fg-dim);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.8);
}

/* 淡色地図を反転して夜の地図に（陸は黒、海は紺、文字は白く浮く） */
.map__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: invert(1) hue-rotate(180deg) brightness(0.8) contrast(1.1) saturate(0.8);
}

.map__snow {
  position: absolute;
  inset: 0;
  opacity: 0.3;
  pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.85) 0.8px, transparent 1.4px) 0 0 / 14px 18px,
    radial-gradient(circle, rgba(255, 255, 255, 0.5) 0.7px, transparent 1.2px) 7px 9px / 21px 25px;
  animation: stage-snow 7s linear infinite;
}

.map__routes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.map__route {
  fill: none;
  stroke: rgba(255, 214, 120, 0.4);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
  vector-effect: non-scaling-stroke;
}

/* 移動中の経路 */
.map__trail {
  fill: none;
  stroke: #ffd36a;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 4px #ffb000);
}

.map__pins {
  position: absolute;
  inset: 0;
}

/* 地点ピン：丸の中心が座標に来るよう、丸の半径ぶんだけずらす */
.pin {
  position: absolute;
  transform: translate(-8px, -50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  white-space: nowrap;
}

.pin__dot {
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--fg);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 8px var(--glow);
}

.pin__label {
  padding: 0 6px;
  font-size: 13px;
  border: 1px solid var(--fg-faint);
  background: rgba(0, 0, 0, 0.7);
}

.pin:hover .pin__label,
.pin:focus-visible .pin__label {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

.pin.is-visited .pin__dot {
  background: var(--fg-faint);
}

.pin.is-here .pin__dot {
  background: var(--fg);
}

.is-traveling .pin,
.is-traveling .mapside__item {
  pointer-events: none;
}

/* 地図上の登場人物 */
.actor {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.actor[hidden] {
  display: none;
}

.actor__dot {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.actor__label {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  font-size: 11px;
  white-space: nowrap;
}

.actor--player .actor__dot {
  background: #ffd36a;
  box-shadow: 0 0 0 3px rgba(255, 211, 106, 0.3), 0 0 14px #ffb000;
  animation: player-pulse 1.4s ease-in-out infinite;
}

.actor--player .actor__label {
  color: #ffd36a;
  text-shadow: 0 0 6px #ffb000;
}

@keyframes player-pulse {
  50% { box-shadow: 0 0 0 7px rgba(255, 211, 106, 0.1), 0 0 18px #ffb000; }
}

.actor--roujin .actor__dot {
  background: #c8d4ff;
  box-shadow: 0 0 10px #8aa0ff;
}

.actor--roujin .actor__label {
  color: #c8d4ff;
}

.actor--ghost .actor__dot {
  width: 10px;
  height: 16px;
  border-radius: 50% 50% 20% 20%;
  background: rgba(235, 240, 255, 0.9);
  box-shadow: 0 0 12px #fff;
  filter: blur(1px);
  animation: ghost-waver 3s ease-in-out infinite;
}

.actor--ghost .actor__label {
  color: #e8eeff;
  opacity: 0.8;
}

/* CASE.03：老人と女の「ふたりの影」 */
.actor--couple .actor__dot {
  width: 16px;
  height: 12px;
  border-radius: 40%;
  background: rgba(235, 240, 255, 0.85);
  box-shadow: 0 0 12px #fff;
  filter: blur(1px);
  animation: ghost-waver 4s ease-in-out infinite;
}

.actor--couple .actor__label {
  color: #e8eeff;
  opacity: 0.8;
}

/* 移動中の一言（吹き出し） */
.actor__bubble {
  position: absolute;
  bottom: calc(100% + 20px);
  left: 50%;
  z-index: 5;
  width: max-content;
  max-width: 230px;
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  text-shadow: none;
  transform: translateX(-50%);
  animation: bubble-in 0.25s steps(3) both;
}

@keyframes bubble-in {
  from { transform: translate(-50%, 6px); filter: brightness(2); }
  to { transform: translateX(-50%); filter: none; }
}

/* 宵宮しの（青白）・朱鷺田かれん（赤）・出会う前の「少女たち？」 */
.actor--mei .actor__dot,
.actor--izumi .actor__dot,
.actor--girls .actor__dot {
  width: 10px;
  height: 10px;
}

.actor--mei .actor__dot {
  background: #9fd4ff;
  box-shadow: 0 0 10px #5fb0ff;
}

.actor--mei .actor__label {
  color: #9fd4ff;
}

.actor--izumi .actor__dot {
  background: #ff8a9a;
  box-shadow: 0 0 10px #ff4d6a;
}

.actor--izumi .actor__label {
  color: #ff8a9a;
}

.actor--girls .actor__dot {
  background: #f0e6ff;
  box-shadow: 0 0 10px #c9b5ff;
  animation: ghost-waver 3s ease-in-out infinite;
}

.actor--girls .actor__label {
  color: #f0e6ff;
}

.map__credit {
  position: absolute;
  right: 6px;
  bottom: 4px;
  z-index: 3;
  padding: 0 4px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.5);
}

/* 地図の右側：現在地と地点一覧 */
.mapside {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  border-left: 2px solid var(--fg-dim);
  background: var(--bg);
}

.mapside__head {
  padding: 4px 14px;
  font-size: 12px;
  color: var(--fg-dim);
  border-bottom: 1px dashed var(--fg-dim);
}

.mapside__here {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 10px 14px 14px;
}

.mapside__here strong {
  font-size: 20px;
  font-weight: normal;
  letter-spacing: 0.1em;
}

.mapside__here span {
  font-size: 13px;
  color: var(--fg-dim);
}

.mapside__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 10px;
  list-style: none;
}

.mapside__item {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 5px 10px;
  border: 1px solid var(--fg-dim);
  text-align: left;
}

.mapside__item:hover,
.mapside__item:focus-visible {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

.mapside__item.is-here {
  border-color: var(--fg);
  background: var(--fg-faint);
}

.mapside__key {
  color: var(--fg-dim);
}

.mapside__mark {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-dim);
}

.mapside__goal {
  margin: 0;
  padding: 8px 14px 12px;
  font-size: 14px;
}

.mapside__goal::before {
  content: "▶ ";
  animation: blink 1s steps(1) infinite;
}

.mapside__notes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 10px 14px 14px 30px;
  font-size: 12px;
  white-space: pre-line;
}

.mapside__notes .is-empty {
  list-style: none;
  color: var(--fg-dim);
}

.mapside__hint {
  margin: auto 0 0;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--fg-dim);
  border-top: 1px dashed var(--fg-dim);
}

/* ---------- ステータスバー ---------- */
.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 16px;
  border-top: 1px solid var(--fg-dim);
  background: var(--bg-panel);
  font-size: 12px;
  color: var(--fg-dim);
}

/* ---------- 起動画面 ---------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 40px;
  background: var(--bg);
  color: var(--fg);
  text-shadow: 0 0 6px var(--glow);
}

.boot[hidden] {
  display: none;
}

.boot__log {
  margin: 0;
  font-family: var(--font);
  white-space: pre-wrap;
}

.boot__choices {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.boot__btn {
  padding: 6px 18px;
  border: 1px solid var(--fg);
}

.boot__btn:hover,
.boot__btn:focus-visible {
  background: var(--fg);
  color: var(--bg);
  text-shadow: none;
  outline: none;
}

/* PC の起動画面に出す「スマホで遊ぶ」QR */
.boot__phone {
  margin-top: 28px;
  max-width: 520px;
}

/* スマホの起動画面に出す、オフライン用の保存の進み具合 */
.boot__offline {
  margin: 24px 0 0;
  font-size: 13px;
  color: var(--fg-dim);
}

/* ---------- スマホ・タブレット（指で操作する端末） ---------- */
/* 案内の文言をマウス用とタッチ用で出し分ける */
.only-touch {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .only-touch { display: inline; }
  .only-mouse { display: none; }

  body {
    -webkit-tap-highlight-color: transparent; /* タップした所が青く光らないように */
    touch-action: manipulation; /* 連続タップで拡大されないように */
  }

  /* 長押しで文字が選択されないように */
  .stage,
  .log,
  .choices,
  .boot {
    -webkit-user-select: none;
    user-select: none;
  }

  .log.is-history::before {
    content: "── LOG ──　（タップで閉じる）";
  }

  /* スマホで遊んでいるときは、記録を見るQRは要らない（リンクだけ残す） */
  .codepad__qr { display: none; }

  /* 指で押しやすい大きさに */
  .menu-item { padding: 4px 10px; }
  .stage__logbtn { padding: 4px 12px; }
  .choice { padding: 10px 14px; }
  .boot__btn { padding: 10px 20px; }
}

/* ---------- 狭い画面 ---------- */
@media (max-width: 760px) {
  .crt { padding: 6px; }
  .menubar { flex-wrap: wrap; gap: 4px 10px; padding: 4px 10px; }
  /* メニュー（最初から・音声）はスマホでも使うので残し、ロゴを省く */
  .menubar__logo { display: none; }
  .menubar__status { gap: 10px; }
  .erosion-meter__bar { width: 60px; }
  .window { margin: 8px; }
  .stage__info { left: 8px; top: 8px; padding: 6px 10px; font-size: 12px; }
  .stage__who { font-size: 16px; }
  .stage__credit { display: none; }
  .stage__figure[data-slot="right"] { right: -12%; }
  .stage__figure[data-slot="left"] { left: -10%; }
  .stage__figure[data-slot="center"] { left: 14%; }
  .mapview { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .mapview__frame { padding: 6px; }
  .mapside { max-height: 42vh; border-left: none; border-top: 2px solid var(--fg-dim); }
  .log { min-height: 120px; padding: 24px 16px 14px; }
  .log-entry__text { font-size: 15px; }
  .choices { padding: 12px 14px; }
  .statusbar span:first-child { display: none; }
}

/* ---------- スマホ縦向き：舞台を上、セリフ枠を下に分けて並べる ---------- */
@media (max-width: 760px) and (orientation: portrait) {
  .window__titlebar { display: none; }
  .window__body { grid-template-rows: auto minmax(0, 1fr); }

  .stage {
    grid-row: 1;
    aspect-ratio: 3 / 4;
    max-height: 62dvh; /* 背の低いスマホでもセリフ枠の場所を残す */
  }

  /* セリフ枠は舞台に重ねず、下の段に置く */
  .log {
    grid-row: 2;
    min-height: 0;
    max-height: none;
    padding: 14px 16px;
    background: rgba(0, 0, 0, 0.9);
    border-top: 1px solid var(--fg-faint);
  }

  /* 選択肢もセリフ枠の段に出す（舞台の人物を隠さない）。上にセリフ1〜2行ぶんを残して下に寄せる */
  .choices {
    grid-row: 2;
    align-self: end;
    width: 96%;
    max-height: calc(100% - 100px);
    gap: 10px;
    margin: 0 0 22px; /* 画面下端（ホームバー付近）から少し離して押しやすく */
  }

  /* 選択肢が出ている間は舞台を縮めて、下の段（セリフ＋選択肢）を広く取る */
  .window__body:has(> .choices > .choice) > .stage { max-height: 40dvh; }

  /* 指で押しやすい大きさに */
  .choices > .choice {
    align-items: center;
    min-height: 52px;
    padding: 12px 16px;
    font-size: 16px;
  }

  /* 暗号・ダイヤル・受信機の入力は大きいので、舞台の段に重ねて広く使う（セリフは下の段に残る） */
  .choices:has(.codepad) {
    grid-row: 1;
    max-height: calc(100% - 8px);
    margin-bottom: 4px;
    padding: 10px 10px;
  }

  .stage__info { gap: 0 8px; padding: 4px 8px; font-size: 11px; }
  .stage__info dt { font-size: 10px; padding: 0 4px; }
  .stage__who { font-size: 14px; letter-spacing: 0.06em; }

  /* 人物は舞台の幅に合わせて小さく。3人並んでも顔が隠れないよう少しずつ重ねる */
  .stage__figure[data-slot="right"] { right: 0; }
  .stage__figure[data-slot="left"] { left: 0; }
  .stage__figure[data-slot="center"] { left: 25%; }
  .stage__figure--bust { height: 62%; }
  .stage__figure--portrait { bottom: 0; height: 46%; }
  .stage__figure--photo { height: 72%; }
  .stage__figure--figure { height: 72%; }

  .statusbar { padding: 2px 10px; font-size: 11px; }
}

/* ---------- スマホ横向き：高さが足りないので、飾りの枠を省いて舞台を広く取る ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .crt { padding: 0; }
  .desktop { border-radius: 0; }
  .menubar { gap: 12px; padding: 0 12px; font-size: 12px; line-height: 1.6; }
  .menubar__logo { display: none; }
  .menubar__status { gap: 12px; }
  .erosion-meter__bar { width: 70px; }
  .window { margin: 0; border-width: 1px 0 0; box-shadow: none; }
  .window__titlebar { display: none; }
  .statusbar { display: none; }

  .stage__info { left: 8px; top: 6px; gap: 0 8px; padding: 3px 8px; font-size: 11px; }
  .stage__info dt { font-size: 10px; padding: 0 4px; }
  .stage__who { font-size: 14px; letter-spacing: 0.06em; }
  .stage__credit { display: none; }

  .log { min-height: 0; max-height: 52vh; padding: 22px 6% 8px; }
  .log-entry__who { font-size: 12px; margin-bottom: 2px; }
  .log-entry__text { font-size: 14px; line-height: 1.55; }
  .choices { padding: 8px 12px; gap: 6px; max-height: calc(100% - 28px); margin-bottom: 18px; }
  .choice { padding: 6px 12px; }
  .choices > .choice { min-height: 44px; padding: 8px 14px; align-items: center; }

  .stage__figure--portrait { bottom: 14%; }

  .mapview { grid-template-columns: minmax(0, 1fr) 240px; }
  .mapview__frame { padding: 6px; }
  .mapside { font-size: 13px; }
}
