* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #0d0c0a;
  color: #cfcabd;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
}

[hidden] {
  display: none !important;
}

h2 {
  margin: 0;
  font-weight: 400;
  letter-spacing: 0.1em;
}

button {
  padding: 0.6em 1.6em;
  border: 1px solid #6a6456;
  background: #1a1814;
  color: #e4dfd2;
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: #d8c89a;
  background: #2a261e;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  /* 低い解像度で描いたものを、ぼかさずに拡大する */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* 階段・はしごで移ったとき */
#view.passing {
  animation: passing 0.7s;
}

@keyframes passing {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 画面いっぱいの画面（タイトル・導入・一時停止・エンディング） */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 1.5rem;
  padding: 1rem;
  background: #0d0c0a;
  text-align: center;
  overflow-y: auto;
}

#paused {
  z-index: 20;
  background: rgb(0 0 0 / 88%);
}

.title {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 400;
  letter-spacing: 0.2em;
  /* 最後の文字の右の字間ぶん、左へ寄って見えるのを戻す */
  text-indent: 0.2em;
}

.status {
  margin: 0;
  color: #918c80;
  font-size: 0.95rem;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
}

.note,
.hint {
  margin: 0;
  color: #918c80;
  font-size: 0.85rem;
  line-height: 1.8;
}

.error {
  color: #e08a7a;
}

#caution-text {
  white-space: pre-line;
}

/* 操作の説明（注意書き・一時停止） */
.controls {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.35em 1.6em;
  margin: 0;
  color: #b4ae9f;
  font-size: 0.85rem;
  text-align: left;
}

.controls dd {
  margin: 0;
}

.settings {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

.settings button[aria-pressed="true"],
#sound button[aria-pressed="true"] {
  border-color: #f0d080;
  color: #f0d080;
}

#volume label {
  display: inline-flex;
  gap: 0.5em;
  align-items: center;
  margin-left: 1em;
}

#volume input {
  width: 8rem;
  accent-color: #f0d080;
}

/* 一時停止の「ヒント：あり／なし」（packages/guide） */
#hints button[aria-pressed="true"] {
  border-color: #f0d080;
  color: #f0d080;
}

.hint-note {
  margin-left: 1em;
}

/* 手帳の上の、いまやること */
.goal {
  margin: 0 0 0.6rem;
  color: #f0d080;
  font-size: 0.9rem;
}

/* デバッグのときだけの「効果音をためす」 */
.sound-test {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  max-width: 44rem;
  font-size: 0.8rem;
}

.sound-test .note {
  width: 100%;
}

/* 歩いているときの表示 */
#hud {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
}

#hud p {
  position: absolute;
  margin: 0;
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  margin: -2px;
  border-radius: 50%;
  background: rgb(255 255 255 / 55%);
}

#prompt {
  top: 54%;
  width: 100%;
  font-size: 0.85rem;
  text-align: center;
}

#caption {
  bottom: 14%;
  left: 15%;
  width: 70%;
  font-size: 1.1rem;
  line-height: 1.8;
  text-align: center;
  white-space: pre-line;
}

#pages-count {
  top: 1rem;
  left: 1.2rem;
}

#keys {
  bottom: 1rem;
  left: 1.2rem;
  color: #a8a294;
  font-size: 0.85rem;
}

#notice {
  top: 1rem;
  right: 1.2rem;
  padding: 0.4em 0.8em;
  border: 1px solid #6a6456;
  background: rgb(10 10 10 / 75%);
  font-size: 0.85rem;
}

#notice.buzz {
  animation: buzz 0.4s;
}

@keyframes buzz {
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  #notice.buzz {
    animation: none;
  }
}

/* 館の手前に出すもの */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / 60%);
}

.phone-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(26rem, 90vw);
  height: 92vh;
  padding: 1.2rem 0.8rem 0.8rem;
  border: 1px solid #444;
  border-radius: 1.6rem;
  background: #111;
  text-align: center;
}

/* 掲示板（スマホ・導入・エンディングで共通） */
.board {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  background: #efefef;
  color: #1a1a1a;
  font-family: "Yu Gothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
  text-align: left;
}

.board-title {
  padding: 0.5em 0.8em;
  background: #d8d0c0;
  color: #a02020;
  font-weight: 700;
}

.board-posts {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.4em 0.8em;
}

.board-post {
  padding: 0.5em 0;
  border-bottom: 1px solid #d4d4d4;
}

.board-head {
  color: #666;
  font-size: 0.72rem;
  overflow-wrap: anywhere;
}

.board-number {
  margin-right: 0.6em;
  color: #333;
}

.board-name {
  margin-right: 0.6em;
  color: #1a7a3a;
  font-weight: 700;
}

.board-body {
  margin: 0.3em 0 0;
  font-size: 0.92rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.board-post-self {
  background: #e4ebf4;
}

/* 書き込みの【画像】。押すと大きく出る */
.board-image {
  display: inline-block;
  margin: 0.2em 0.4em 0.2em 0;
  padding: 0;
  border: 1px solid #999;
  background: #222;
  line-height: 0;
  vertical-align: top;
  cursor: zoom-in;
}

.board-image canvas {
  display: block;
  width: 4.2rem;
  height: auto;
}

.board-zoom {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / 82%);
  cursor: zoom-out;
}

.board-zoom[hidden] {
  display: none;
}

.board-zoom canvas {
  max-width: 90vw;
  max-height: 86vh;
  width: auto;
  height: 86vh;
  object-fit: contain;
}

#intro-board,
#ending-board {
  flex: 0 1 auto;
  width: min(44rem, 94vw);
  height: 74vh;
}

#ending-board {
  height: 50vh;
}

.intro-actions,
.notebook-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

/* 拾ったページ */
.reading-body {
  display: flex;
  gap: 2.5rem;
  align-items: center;
  max-width: 90vw;
}

#reading-page canvas {
  height: min(70vh, 32rem);
}

#reading-note {
  max-width: 24rem;
  line-height: 2;
  white-space: pre-line;
}

/* 手帳 */
.notebook-body {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  align-items: center;
  width: min(70rem, 96vw);
  max-height: 96vh;
  padding: 1.4rem;
  overflow-y: auto;
  background: #2a231a;
}

/* 持ち物。手帳の画面のすみに出す */
.notebook-items {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  min-width: 9rem;
  padding: 0.6em 1em;
  border: 1px solid #6a5c46;
  background: #2a231a;
  font-size: 0.85rem;
  line-height: 1.7;
}

.notebook-items p {
  margin: 0;
}

.notebook-items p:first-child {
  color: #b4a88a;
}

/* 手記。手帳のページの下に、横にならべる */
.notebook-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.notebook-notes p {
  margin: 0;
  color: #b4a88a;
}

.notebook-notes button {
  padding: 0.4em 0.9em;
}

/* 前庭の門の「帰る？」 */
.leave-body {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  align-items: center;
  max-width: 90vw;
  padding: 2rem 3rem;
  border: 1px solid #6a6456;
  background: #14120f;
  text-align: center;
}

.leave-text {
  margin: 0;
  line-height: 1.8;
}

.leave-choices {
  display: flex;
  gap: 1rem;
}

/* 端の絵がつながって見えるように、すきまなく並べる */
#slots {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  width: 100%;
}

.slot {
  position: relative;
  padding: 0 0 1.8rem;
  border: 0;
  border-bottom: 4px solid transparent;
  background: none;
}

.slot canvas,
.slot-empty {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
}

.slot-empty {
  border: 1px dashed #6a5c46;
}

.slot-label {
  position: absolute;
  bottom: 0.2rem;
  left: 0;
  width: 100%;
  font-size: 0.85rem;
}

.slot-selected {
  border-bottom-color: #f0d080;
}

.slot-selected canvas,
.slot-selected .slot-empty {
  box-shadow: inset 0 0 0 4px #f0d080;
  filter: brightness(1.15);
}

.slot-wrong {
  border-bottom-color: #c05040;
}

.slot-sewn {
  border-bottom-color: #7a9a5a;
}

#notebook-detail,
#notebook-message {
  margin: 0;
  min-height: 3.6em;
  line-height: 1.8;
  text-align: center;
  white-space: pre-line;
}

#notebook-detail {
  min-height: 5.4em;
}

#notebook-message {
  min-height: 1.8em;
  color: #f0d8a0;
}

#ending-lines p {
  line-height: 2.2;
  white-space: pre-line;
}

#ending-board.ending-phone {
  width: min(26rem, 90vw);
  height: 70vh;
  /* 文の枠（ボタンの上）に収める */
  max-height: 100%;
  padding: 1.2rem 0.8rem;
  border: 1px solid #444;
  border-radius: 1.6rem;
  background: #111;
}

.ending-phone .board-posts {
  background: #efefef;
}

/* エンド一覧 */
.ending-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
}

.ending-card {
  width: 15rem;
  margin: 0;
}

.ending-card canvas,
.ending-blank {
  display: block;
  width: 100%;
  aspect-ratio: 8 / 5;
  margin-bottom: 0.6rem;
  border: 1px solid #4a4438;
}

.ending-card-unseen {
  color: #918c80;
}

.ending-afterword {
  white-space: pre-line;
}

#debug {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 30;
  margin: 0;
  padding: 0.5em;
  background: rgb(0 0 0 / 70%);
  font-size: 0.75rem;
}
