/* 閉店まぎわ。古い喫茶店：電球の黄色い光、焦げ茶の木、窓の外の雨。手帳はクリーム色の紙 */
* {
  box-sizing: border-box;
}

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

body {
  background: #16110c;
  color: #e8dcc4;
  font-family: "Yu Gothic", "YuGothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

[hidden] {
  display: none !important;
}

h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  color: #c8b48e;
}

button {
  padding: 0.45em 1.2em;
  border: 1px solid #6a5238;
  background: #2a2016;
  color: #f0e2c4;
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: #f0c880;
  background: #3a2c1c;
}

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

canvas {
  display: block;
  image-rendering: pixelated;
}

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

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

.title {
  margin: 0;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 400;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
}

.status {
  margin: 0;
  color: #9a8664;
  letter-spacing: 0.3em;
}

/* タイトル：晩を選ぶ（一晩目・二晩目…）。まだ選べない晩は鍵の絵 */
.nights {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
}

.night {
  display: inline-flex;
  gap: 0.5em;
  align-items: center;
  justify-content: center;
  min-width: 8rem;
  min-height: 2.75rem;
  letter-spacing: 0.15em;
}

.night-lock {
  width: 1.6rem;
  height: auto;
  aspect-ratio: 4 / 3;
}

.night-locked:disabled {
  opacity: 0.6;
}

.note {
  margin: 0;
  color: #a8946e;
  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: #c8b490;
  font-size: 0.85rem;
  text-align: left;
}

.controls dd {
  margin: 0;
}

#sound button[aria-pressed="true"] {
  border-color: #f0d8a0;
}

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

.sound-test {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  max-width: 44rem;
  font-size: 0.8rem;
}

#words-lines p,
#morning-lines p,
#ending-after p {
  margin: 0 0 0.6em;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  line-height: 2.2;
}

/* --- 上のすみ：壁の時計 --- */
.topbar {
  position: fixed;
  top: 0.5rem;
  left: 0.6rem;
  z-index: 15;
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.clock {
  width: 4rem;
  height: auto;
  aspect-ratio: 4 / 3;
}

.clock-time {
  margin: 0;
  font-family: "MS Gothic", "Osaka-Mono", monospace;
  color: #f0dcb0;
}

.shop-name {
  margin: 0.2rem 0 0;
  color: #a8946e;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}

/* --- 前半：カウンター --- */
.counter {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 4.5rem 1rem 1rem;
  background: radial-gradient(ellipse at 50% 40%, #3a2a18 0%, #1e160e 60%, #120d08 100%);
}

.scene {
  width: min(56rem, 94vw, calc((100vh - 15rem) * 1.6));
  height: auto;
  cursor: pointer;
  box-shadow: 0 0 0 3px #3a2a1a, 0 0 60px rgb(255 200 110 / 12%);
}

.talk {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: min(56rem, 94vw);
  min-height: 8rem;
}

.speaker {
  min-height: 1.2em;
  margin: 0;
  color: #c8a878;
  font-size: 0.85rem;
  letter-spacing: 0.2em;
}

.bubble {
  margin: 0;
  padding: 0.7rem 1rem;
  border-radius: 0.8rem;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  line-height: 1.9;
}

.bubble-say {
  background: #efe6d2;
  color: #2a2016;
}

.bubble-event {
  background: transparent;
  color: #d8c8a8;
  box-shadow: inset 0 0 0 1px #4a3a28;
}

.talk-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

#talk-next[data-task]:not([data-task=""]) {
  border-color: #f0c880;
  background: #4a3620;
}

/* --- 覚え書き --- */
.memo {
  position: fixed;
  top: 4.5rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(30rem, 92vw);
  padding: 0.8rem 1rem;
  background: #ece2c8;
  color: #2a2016;
  box-shadow: 0 0 0 3px #5a4228, 0 8px 40px rgb(0 0 0 / 60%);
}

.memo h2 {
  color: #5a4228;
}

.memo-lines {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0 0 0 0.2em;
  overflow-y: auto;
  list-style: none;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: 0.86rem;
  line-height: 1.8;
}

.memo-lines li {
  padding: 0.2em 0;
  border-bottom: 1px solid rgb(120 90 60 / 25%);
}

.memo-event {
  color: #6a5a48;
}

.memo button {
  align-self: flex-end;
}

/* --- 後半：閉店後 --- */
.closed {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(13rem, 1fr) minmax(22rem, 2fr) minmax(19rem, 1.3fr);
  gap: 0.6rem;
  padding: 4.6rem 0.6rem 0.6rem;
  background: radial-gradient(ellipse at 50% 55%, #2e2216 0%, #1c150e 60%, #110d08 100%);
}

.items-box,
.desk-box,
.book-box {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}

.desk-box {
  position: relative;
}

.items {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 0.4rem;
  background: #2a1e14;
}

.desk-shelf-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.3rem;
}

.desk-shelf-back {
  display: none;
}

.desk-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem;
  border-color: #4a3826;
  background: #2a2016;
  font-size: 0.72rem;
}

.desk-item .desk-picture {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
}

.desk-item.desk-out {
  opacity: 0.35;
}

.desk {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  align-content: start;
  gap: 0.4rem;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem;
  background: #4a3424;
  box-shadow: inset 0 0 0 4px #34241a, inset 0 0 60px rgb(255 200 110 / 16%);
}

.desk-empty {
  grid-column: 1 / -1;
  margin: 1rem 0;
  color: #1e1610;
  font-size: 0.85rem;
  text-align: center;
}

.desk-item.desk-zoomed {
  border-color: #f0d8a0;
}

.zoom {
  position: absolute;
  inset: 1.6rem 0 0;
  z-index: 5;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: rgb(10 8 6 / 72%);
}

.desk-zoom-body {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  overflow-y: auto;
  padding: 0.8rem 1rem;
  background: #241a12;
  box-shadow: inset 0 0 0 3px #4a3622;
}

.desk-zoom-name {
  margin: 0;
  color: #c8b48e;
  font-size: 0.9rem;
  font-weight: 400;
}

.desk-picture-large {
  width: min(24rem, 100%);
  height: auto;
}

.desk-zoom-text p {
  margin: 0;
  line-height: 1.8;
}

.desk-actions,
.desk-compare-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.desk-compare {
  border-style: dashed;
}

.desk-compare-view {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px dashed #6a5238;
}

.memo-button {
  align-self: flex-start;
}

/* 右：推理帳（右に開く手帳） */
.book {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem 0.7rem;
  background: #ece2c8;
  color: #2a2016;
  box-shadow: inset 6px 0 0 #b8a27a, inset 0 0 30px rgb(160 120 60 / 25%);
}

.book-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgb(120 90 60 / 30%);
}

.book-person {
  grid-column: 1 / -1;
  margin: 0;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  color: #4a3622;
}

.book-stamp {
  position: absolute;
  top: 0.1rem;
  right: 0.3rem;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 2px solid #b23a2a;
  border-radius: 50%;
  color: #b23a2a;
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  transform: rotate(-12deg);
}

.book-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.25em 0.5em;
  border-color: #c0ac84;
  background: #f4ecd8;
  color: #2a2016;
  font-size: 0.8rem;
  text-align: left;
}

.book-cell:hover:not(:disabled),
.book-cell:focus-visible {
  background: #fff6e0;
}

.book-cell:disabled {
  opacity: 1;
}

.book-selected {
  border-color: #b2602a;
  box-shadow: inset 0 0 0 1px #b2602a;
}

.book-label {
  color: #8a7454;
  font-size: 0.7rem;
}

.book-blank {
  color: #a89470;
}

.book-confirmed .book-value {
  color: #1e2a48;
}

.cell-title {
  margin: 0;
  color: #c8b48e;
  font-size: 0.82rem;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.choice {
  padding: 0.3em 0.8em;
  border-color: #b89a60;
  background: #efe4c8;
  color: #3a2a18;
  font-size: 0.82rem;
  text-align: left;
}

.choice:hover:not(:disabled),
.choice:focus-visible {
  background: #fff4d8;
}

.choice-current {
  border-color: #b2602a;
}

.book-note {
  min-height: 1.2em;
  margin: 0;
  color: #e0cca4;
  font-size: 0.82rem;
}

.book-actions {
  display: flex;
  gap: 0.5rem;
}

#check,
#book-close {
  border-color: #e0a878;
}

/* --- 翌朝・エンディング --- */
/* 絵の高さは、文の枠（ボタンの上）に、見出しの行が入るぶんを残して収まるまで */
.board,
.last {
  width: min(36rem, 92vw, calc((76vh - 8rem) * 1.33));
  height: auto;
}

.misses {
  position: fixed;
  right: 0.8rem;
  bottom: 0.6rem;
  margin: 0;
  color: #7a6a50;
  font-size: 0.72rem;
}

#ending {
  background: #000;
}

/* --- 右上のすみ：一時停止（PC でも出る。Esc と同じ） --- */
.pause-button {
  position: fixed;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 15;
  min-height: 2.75rem;
  padding: 0.3em 0.9em;
  font-size: 0.85rem;
}

/* --- 狭い画面（スマホの縦持ちなど。app.js が body に .narrow を付ける） --- */
.tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 35;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: #110d09;
  box-shadow: 0 -1px 0 #4a3826;
}

.tab {
  min-height: 3.2rem;
  border: 0;
  border-top: 3px solid transparent;
  background: transparent;
  color: #c8b490;
  font-size: 1rem;
}

.tab-current {
  border-top-color: #f0c880;
  background: #2a2016;
  color: #f8ead0;
}

.narrow {
  /* タブ・時計の分をあける */
  --top: calc(3.8rem + env(safe-area-inset-top));
  --bottom: calc(3.4rem + env(safe-area-inset-bottom));
}

.narrow button {
  min-height: 2.75rem;
}

.narrow .note,
.narrow .controls,
.narrow .speaker,
.narrow .memo-lines,
.narrow .cell-title,
.narrow .book-note,
.narrow .desk-zoom-text p,
.narrow .desk-empty {
  font-size: 0.95rem;
}

.narrow .controls {
  grid-template-columns: 1fr;
  gap: 0.1em;
}

.narrow .controls dd {
  margin-bottom: 0.5em;
  color: #a8946e;
}

.narrow .topbar {
  top: calc(0.4rem + env(safe-area-inset-top));
}

.narrow .clock {
  width: 3.2rem;
}

.narrow .shop-name {
  font-size: 0.8rem;
}

.narrow .pause-button {
  top: calc(0.5rem + env(safe-area-inset-top));
}

/* 覚え書きのボタンはタブにまとめる */
.narrow .memo-button {
  display: none;
}

/* 前半：上＝店の絵（横幅いっぱい）、下＝吹き出しと「つづける」 */
.narrow .counter {
  justify-content: flex-start;
  gap: 0.6rem;
  padding: var(--top) 0.5rem var(--bottom);
  overflow-y: auto;
}

.narrow .scene {
  flex: none;
  width: 100%;
}

.narrow .talk {
  width: 100%;
  min-height: 0;
}

.narrow .bubble {
  font-size: 1rem;
}

.narrow #talk-next {
  flex: 1;
  min-height: 3rem;
}

/* 後半：上＝机、下＝残った物。推理帳はタブで */
.narrow .closed {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: var(--top) 0.5rem var(--bottom);
  overflow-y: auto;
}

.narrow .items-box,
.narrow .desk-box,
.narrow .book-box {
  flex: none;
}

.narrow .desk-box {
  position: static;
  order: 1;
}

.narrow .items-box {
  order: 2;
}

.narrow .book-box {
  order: 3;
}

.narrow .desk {
  flex: none;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  min-height: 9rem;
  overflow: visible;
}

.narrow .items {
  flex: none;
  overflow: visible;
}

.narrow .desk-shelf-row {
  grid-template-columns: repeat(3, 1fr);
}

.narrow .desk-item {
  font-size: 0.9rem;
}

/* 大きく見る：上＝絵（横幅いっぱい）、下＝説明と調べ方のボタン */
.narrow .zoom {
  position: fixed;
  inset: var(--top) 0 var(--bottom);
  z-index: 20;
}

.narrow .desk-zoom-body {
  flex-wrap: nowrap;
  padding: 0.6rem 0.6rem 1rem;
}

.narrow .desk-picture-large {
  flex: none;
  width: 100%;
}

.narrow .desk-zoom-text {
  align-self: stretch;
}

.narrow .desk-action,
.narrow .desk-close {
  min-height: 2.75rem;
}

.narrow .book {
  overflow: visible;
}

.narrow .book-cell {
  min-height: 3.2rem;
  font-size: 0.95rem;
}

.narrow .book-label {
  font-size: 0.8rem;
}

/* 推理帳の候補：指で押しやすく（1つ 44px 以上） */
.narrow .choices {
  gap: 0.4rem;
}

.narrow .choice {
  min-height: 2.75rem;
  padding: 0.5em 0.9em;
  font-size: 0.95rem;
}

.narrow .book-actions button {
  flex: 1;
  min-height: 3rem;
}

/* 覚え書き：場面の上に重ねる（タブは見えたまま） */
.narrow .memo {
  top: var(--top);
  right: 0.4rem;
  bottom: var(--bottom);
  left: 0.4rem;
  width: auto;
}

.narrow .memo-lines {
  line-height: 1.9;
}

/* 翌朝・エンディング：横幅いっぱい */
.narrow .board,
.narrow .last {
  width: 100%;
}

.narrow #words-lines p,
.narrow #morning-lines p,
.narrow #ending-after p {
  font-size: 1rem;
}

.narrow .screen > button,
.narrow .text-screen-actions > button {
  min-width: 10rem;
}

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