/* 『ぽかぽんと しろいえほん』
 * 配色は既存シリーズ(ピンク+クリーム)を基調にしつつ、本作は「白」が主題なので
 * 全体をさらに淡くしてある。三層(現実/えほん/おもいで)は body[data-layer] で切り替える。
 */

:root {
  --pink: #e8879c;
  --pink-soft: #f3b8c4;
  --pink-bg: #fdf0f3;
  --cream: #fffaf3;
  --ink: #5a4a42;
  --ink-soft: #9a8a80;
  /* 層ごとの背景トーン */
  --layer-real: #dcdce2;      /* 現実: 灰がかった薄暗さ */
  --layer-ehon: #fdf6e8;      /* えほん: あたたかいクリーム */
  --layer-omoide: #efe6d8;    /* おもいで: セピア */
}

* { box-sizing: border-box; }

/* display:flex等を当てた要素でも hidden属性を必ず効かせる。
 * これが無いと全画面・全オーバーレイが重なって表示される(P1で実際に起きた) */
[hidden] { display: none !important; }

html { touch-action: manipulation; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  color: var(--ink);
  background: var(--cream);
  /* 連打・ドラッグで本文が選択状態になるのを防ぐ(読み物UIなので選択は不要) */
  user-select: none;
  -webkit-user-select: none;
}

/* あいことばの入力・表示だけは選択/コピーできるようにする */
#aikotoba-input,
#aikotoba-words {
  user-select: text;
  -webkit-user-select: text;
}

.screen {
  position: relative;
  min-height: 100vh;
  padding: 16px 16px 90px; /* フッターぶんの余白 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ---- タイトル ---- */

.title-box { text-align: center; }

.game-title {
  font-size: clamp(32px, 8vw, 56px);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.08em;
  line-height: 1.4;
  margin: 0 0 8px;
}

.title-sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 32px;
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.title-note {
  margin-top: 28px;
  font-size: 11px;
  color: var(--ink-soft);
}

.primary-button,
.secondary-button {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 10px 36px;
  border-radius: 999px;
  border: 2px solid var(--pink-soft);
  cursor: pointer;
}

.primary-button {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

.primary-button:hover { filter: brightness(1.05); }

.secondary-button {
  background: #fff;
  color: var(--pink);
}

.secondary-button:hover { background: var(--pink-bg); }

/* ---- 開始時の案内 ---- */

.notice-box {
  text-align: center;
  font-size: 17px;
  line-height: 2.2;
  color: var(--ink);
  animation: notice-in 1.2s ease-out;
}

@keyframes notice-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---- ノベル画面 ---- */

#screen-novel { padding: 0 0 90px; justify-content: flex-end; }

#novel-bg {
  position: absolute;
  inset: 0;
  transition: background-color 1.2s ease;
  background: var(--layer-real);
}

body[data-layer="real"] #novel-bg { background: var(--layer-real); }
body[data-layer="ehon"] #novel-bg { background: var(--layer-ehon); }
body[data-layer="omoide"] #novel-bg { background: var(--layer-omoide); }

/* セリフ窓は共通オーバーレイ。ノベル画面でも探索フィールドの上でも同じ位置に出る */
#novel-window {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 46px;
  z-index: 8;
  width: min(720px, calc(100% - 24px));
  min-height: 150px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--pink-soft);
  border-radius: 16px;
  padding: 18px 22px 26px;
  cursor: pointer;
}

#name-plate {
  display: inline-block;
  margin: 0 0 6px;
  padding: 2px 14px;
  background: var(--ink-soft);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
}

/* 話者ごとの色分け(二匹はスプライトと同じ色系で揃える) */
#name-plate[data-who="ぽか"] { background: #a8763f; }
#name-plate[data-who="ぽん"] { background: #c89a52; }
#name-plate[data-who="みみ"] { background: #a8a4c0; }

#novel-text {
  margin: 0;
  font-size: 16px;
  line-height: 1.9;
  white-space: pre-wrap;
  min-height: 60px;
}

/* 本文は分かち書き(空白)の位置でだけ折り返す。keep-allが無いと、スマホの幅で
 * 単語の途中で改行されて読みにくい。極端に長い語だけ overflow-wrap で逃がす */
#novel-text,
.choice-button,
.op-item-button,
.notice-box,
.howto-body,
.panel-label,
.panel-note,
#backlog-list,
#aikotoba-words,
.title-sub {
  word-break: keep-all;
  overflow-wrap: anywhere;
  line-break: strict;
}

#advance-mark {
  position: absolute;
  right: 18px;
  bottom: 10px;
  color: var(--pink);
  font-size: 12px;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

.novel-controls {
  position: fixed;
  top: 12px;
  right: max(24px, calc(env(safe-area-inset-right) + 10px));
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.novel-controls button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--pink-soft);
  background: #fff;
  font-size: 17px;
  cursor: pointer;
}

#btn-auto.on { background: var(--pink); color: #fff; border-color: var(--pink); }

/* 設定パネル */
#config-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(90, 74, 66, 0.4);
  padding: 16px;
}

.config-card { text-align: left; }

.config-group {
  border: 1px solid var(--pink-soft);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 14px;
}

.config-group legend { font-weight: 700; font-size: 13px; padding: 0 6px; }

.config-group label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

.cfg-slider { width: 100%; }
.cfg-slider input { flex: 1; }

/* ---- 演出 ---- */

/* フェード用オーバーレイ(fx.js)。transition時間はJSが指定する */
#fx-white,
#fx-black {
  position: fixed;
  inset: 0;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition-property: opacity;
  transition-timing-function: ease;
}

#fx-white { background: #fffdf8; }
#fx-black { background: #241f38; }

/* 画面がぼやけて戻る。fixedの子要素がずれないよう、bodyではなく各画面にかける */
.screen, #novel-window, #cg-card {
  transition: filter 0.6s ease;
}
body.fx-blur .screen,
body.fx-blur #novel-window,
body.fx-blur #cg-card {
  filter: blur(3px);
}

/* シーンの絵の説明(＜＞仮表示) */
#bg-caption {
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: 4;
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

/* 演出指示の仮表示 */
#novel-window.placeholder { border-style: dashed; }
#novel-window.placeholder #novel-text { color: var(--ink-soft); font-size: 13px; }

/* CG(一枚絵)の仮表示。共通オーバーレイ(どの画面の上にも出る) */
#cg-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 9;
  width: min(480px, calc(100% - 48px));
  padding: 32px 24px;
  text-align: center;
  background: #fff;
  border: 2px dashed var(--pink-soft);
  border-radius: 16px;
  cursor: pointer;
}

#cg-card .cg-num { margin: 0; font-size: 12px; color: var(--ink-soft); }
#cg-card .cg-title { margin: 6px 0; font-size: 20px; font-weight: 700; }
#cg-card .cg-desc { margin: 0; font-size: 13px; color: var(--ink-soft); }

/* ＊(時間経過) */
#pause-mark {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--ink-soft);
  cursor: pointer;
}

/* 選択肢: ▽メニューと同じ「中央のカード型」に統一する(セリフ窓は下に見えたまま) */
#choice-overlay {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  width: min(420px, calc(100% - 48px));
}

.choice-button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  padding: 12px 18px;
  border-radius: 14px;
  border: 2px solid var(--pink-soft);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 2px 8px rgba(90, 74, 66, 0.15);
}

.choice-button:hover { border-color: var(--pink); background: var(--pink-bg); }

/* ▽操作(みる/しらべる)のメニュー。選択肢と同じ中央カード型に揃える */
#op-overlay {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  width: min(420px, calc(100% - 48px));
}

#op-title {
  margin: 0;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

#op-items { display: flex; flex-direction: column; gap: 12px; }

.op-item-button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  padding: 12px 18px;
  border-radius: 14px;
  border: 2px solid var(--pink-soft);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 2px 8px rgba(90, 74, 66, 0.15);
}

.op-item-button.seen { color: var(--ink-soft); border-color: #ddd; }
.op-item-button:hover { background: var(--pink-bg); }

#op-overlay .secondary-button { align-self: center; }

.panel-note { margin: 0; font-size: 13px; color: var(--ink-soft); }

/* あそびかた */
.howto-card { text-align: left; max-height: calc(100vh - 32px); overflow-y: auto; }
.howto-body { font-size: 14px; line-height: 1.7; }
.howto-head { margin: 8px 0 2px; font-weight: 700; color: var(--pink); }
.howto-list { margin: 0; padding-left: 18px; }
.howto-list li { margin: 2px 0; }

/* パネル(つづきから・あいことば表示・タイトルへ戻る) */
#quit-overlay,
#howto-overlay,
#ending-overlay,
#final-overlay,
#continue-panel,
#aikotoba-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(90, 74, 66, 0.4);
  padding: 16px;
}

.panel-card {
  width: min(420px, 100%);
  background: #fff;
  border: 2px solid var(--pink-soft);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.panel-label { margin: 0; font-weight: 700; }

.panel-error { margin: 0; color: var(--pink); font-size: 13px; }

.panel-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

#aikotoba-input {
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 2px solid var(--pink-soft);
  border-radius: 12px;
  resize: none;
}

#aikotoba-words {
  margin: 0;
  font-size: 17px;
  line-height: 1.9;
  font-weight: 700;
  color: var(--ink);
}

/* バックログ */
#backlog-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(90, 74, 66, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 90px;
}

#backlog-list {
  width: min(640px, 100%);
  flex: 1;
  overflow-y: auto;
  color: #fff;
  font-size: 14px;
  line-height: 1.9;
}

#backlog-list .bl-name { color: var(--pink-soft); font-weight: 700; margin-right: 8px; }
#backlog-list p { margin: 4px 0; }

#backlog-close { margin-top: 12px; }

/* ---- 絵本探索(ドット風・仮) ---- */

#screen-explore { background: #2a2530; }

.explore-frame {
  position: relative;
  width: min(768px, 100%);
  text-align: center;
}

#canvas-wrap { position: relative; }

#explore-canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  border-radius: 8px;
  background: #000;
  cursor: pointer;
}

/* 住人の名前タグ。canvas内に文字を描くと潰れるのでDOMで重ねる */
#entity-tags {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.entity-tag {
  position: absolute;
  transform: translate(-50%, 0); /* キャラクターの下に出す */
  background: rgba(30, 24, 44, 0.7);
  color: #f5f0e8;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

/* 二匹の顔がそのまま切り替えボタン。操作中の子が明るく光る */
#switch-row {
  position: absolute;
  top: 10px;
  left: 10px; /* 右上は共通ボタン列(📖🔖⚙️🏠)と被るので左に置く */
  display: flex;
  gap: 8px;
}

.switch-face {
  width: 48px;
  height: 48px;
  padding: 4px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(30, 24, 44, 0.55);
  cursor: pointer;
  opacity: 0.6;
}

.switch-face.active {
  border-color: var(--pink-soft);
  background: rgba(255, 255, 255, 0.25);
  opacity: 1;
  box-shadow: 0 0 8px rgba(243, 184, 196, 0.6);
}

.switch-face canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* 会話・しらべるのアクションボタン(実体のスポットに立つと出る) */
#btn-action {
  position: absolute;
  left: 12px;
  bottom: 44px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid var(--pink);
  background: #fff;
  color: var(--pink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  animation: notice-in 0.3s ease-out;
}

#explore-hint {
  color: #e8e0d8;
  font-size: 13px;
  min-height: 1.5em;
  margin: 10px 0 0;
}

/* ---- フッター ---- */

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  background: rgba(255, 250, 243, 0.92);
  border-top: 1px solid var(--pink-soft);
  text-align: center;
  padding: 6px 8px;
}

.footer-meta {
  margin: 0;
  font-size: 11px;
  color: var(--ink-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  justify-content: center;
}

.footer-meta a { color: var(--ink-soft); }

/* ---- 規約モーダル(legal-modal.js) ---- */

#legal-modal { position: fixed; inset: 0; z-index: 100; }
#legal-modal.hidden { display: none; }

.legal-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.legal-modal-panel {
  position: absolute;
  inset: 5% 4%;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
}

.legal-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--pink);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

#legal-modal-frame { width: 100%; height: 100%; border: none; }
