/* v0.69: cache bump for Akane hidden reaction head-followup patch. */
:root {
  --ui-bg: rgba(20, 14, 10, 0.82);
  --ui-border: rgba(255, 230, 180, 0.9);
  --ui-text: #fff7e8;
  --accent: #ffd77a;

  /* iPhone Safari / Chrome の上下UIを避けるための追加余白 */
  --ui-top-reserve: 28px;
  --ui-bottom-reserve: 56px;

  --textbox-height: 26dvh;
  --textbox-height-expanded: 34dvh;
  --choice-max-height: calc(100dvh - env(safe-area-inset-top) - var(--ui-top-reserve) - env(safe-area-inset-bottom) - var(--ui-bottom-reserve) - var(--textbox-height) - 24px);

  --dialog-font-size: clamp(18px, 2.4vw, 30px);
  --name-font-size: clamp(16px, 2.1vw, 24px);
  --choice-font-size: clamp(16px, 2vw, 22px);

  /* 立ち絵は 0,0 重ねの同一キャンバス前提。必要ならここを調整。 */
  --character-aspect: 2 / 3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #111;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ui-text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
  user-select: none;
  cursor: pointer;
  overflow: hidden;
}

#bg-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}

.bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  opacity: 0;
  transition: opacity .35s ease;
  filter: saturate(1.04) contrast(1.02);
  pointer-events: none;
}

.bg-img.active {
  opacity: 1;
}

/* 漫画ページ表示時: 縦長ページを全部見せるため、背景は cover ではなく contain。 */
#game.manga-page-mode .bg-img {
  object-fit: contain;
  object-position: center center;
  background: #0d0b09;
  filter: none;
}

#game.manga-page-mode #bg-shade {
  background: rgba(0,0,0,.12);
}

/* 漫画ページ単独表示: 会話ウィンドウを被せず、ページ鑑賞を優先する。 */
#game.manga-page-mode #message-box,
#game.manga-page-mode #choices {
  display: none !important;
}

#manga-hint {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 18px);
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  z-index: 40;
  padding: 9px 14px;
  border: 1px solid rgba(255, 230, 180, .62);
  border-radius: 999px;
  background: rgba(16, 12, 10, .58);
  color: rgba(255, 247, 232, .92);
  font-size: clamp(12px, 2.6vw, 16px);
  letter-spacing: .04em;
  box-shadow: 0 6px 18px rgba(0,0,0,.32);
  pointer-events: none;
}

@media (orientation: landscape) {
  #manga-hint {
    top: calc(env(safe-area-inset-top) + 18px);
    bottom: auto;
  }
}

#bg-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.05), rgba(0,0,0,.25));
  pointer-events: none;
}

#character-layer {
  position: absolute;
  z-index: 22;
  right: 5vw;
  bottom: calc(env(safe-area-inset-bottom) + var(--ui-bottom-reserve) + var(--textbox-height) - 3dvh);
  width: min(34vw, 500px);
  aspect-ratio: var(--character-aspect);
  pointer-events: auto;
  cursor: auto;
}

#character-layer.akane-touch-hot {
  cursor: pointer;
}

.character-img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}

#mouth,
#eye {
  display: none;
}

#message-box {
  position: absolute;
  z-index: 30;
  left: 4vw;
  right: 4vw;
  bottom: calc(env(safe-area-inset-bottom) + var(--ui-bottom-reserve));
  height: var(--textbox-height);
  padding: clamp(12px, 1.6vw, 18px) clamp(16px, 2.2vw, 24px) clamp(20px, 2.2vw, 26px);
  border: 2px solid var(--ui-border);
  border-radius: 18px;
  background: var(--ui-bg);
  box-shadow: 0 12px 36px rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  cursor: pointer;
  overflow: hidden;
}

#message-box.expanded-textbox {
  height: var(--textbox-height-expanded);
}

#message-box.scroll-fallback #text {
  overflow-y: auto;
  padding-right: .3em;
}

#speaker {
  min-height: 1.45em;
  margin-bottom: .35em;
  font-size: var(--name-font-size);
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#text {
  max-height: calc(100% - 2.0em);
  font-size: var(--dialog-font-size);
  line-height: 1.58;
  letter-spacing: .03em;
  white-space: pre-wrap;
  overflow: hidden;
}

#text.small-text {
  font-size: calc(var(--dialog-font-size) * 0.90);
  line-height: 1.52;
}

#text.tiny-text {
  font-size: calc(var(--dialog-font-size) * 0.80);
  line-height: 1.46;
}

#next-mark {
  position: absolute;
  right: clamp(14px, 2vw, 22px);
  bottom: clamp(8px, 1.4vw, 12px);
  color: var(--accent);
  animation: blink 1.1s infinite;
}

#choices {
  position: absolute;
  z-index: 36;
  left: 8vw;
  top: calc(env(safe-area-inset-top) + var(--ui-top-reserve));
  display: grid;
  gap: 14px;
  width: min(560px, 82vw);
  max-height: var(--choice-max-height);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

#choices::-webkit-scrollbar {
  width: 6px;
}

#choices::-webkit-scrollbar-thumb {
  background: rgba(255, 230, 180, .38);
  border-radius: 999px;
}

.choice-button {
  border: 2px solid rgba(255, 230, 180, .9);
  border-radius: 16px;
  padding: 14px 18px;
  min-height: 52px;
  background: rgba(28, 18, 12, .88);
  color: var(--ui-text);
  text-align: left;
  font-size: var(--choice-font-size);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transition: transform .12s ease, background .12s ease;
}

.choice-button:hover,
.choice-button:focus,
.choice-button.selected {
  background: rgba(94, 60, 30, .96);
  color: #fff;
  transform: translateX(8px);
}

.choice-button.selected::before {
  content: "▶ ";
  color: var(--accent);
}

#snaky-video-panel {
  position: absolute;
  overflow: hidden;
  left: 50%;
  top: 50%;
  z-index: 16;
  width: min(34vw, 420px);
  min-width: 260px;
  padding: 10px;
  border: 1px solid rgba(118, 236, 255, .72);
  border-radius: 16px;
  background: rgba(7, 12, 20, .76);
  box-shadow: 0 0 22px rgba(80, 220, 255, .20), 0 14px 38px rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  opacity: 0;
  transform: translate(-50%, calc(-50% + 8px));
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}

#game.snaky-room-mode #snaky-video-panel {
  opacity: 1;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.snaky-video-title {
  margin: 0 0 7px;
  color: #bffcff;
  font-size: clamp(11px, 1.3vw, 15px);
  font-weight: 700;
  letter-spacing: .12em;
  text-shadow: 0 0 8px rgba(118, 236, 255, .55);
}

#snaky-video-panel iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 10px;
  background: #000;
}

.snaky-video-click-guard {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.001);
  z-index: 2;
  cursor: default;
}

.snaky-video-click-guard::after {
  content: "クリック不可";
  position: absolute;
  right: 8px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: rgba(255, 247, 232, .82);
  font-size: 10px;
  letter-spacing: .05em;
  opacity: 0;
  transition: opacity .15s ease;
}

#snaky-video-panel:hover .snaky-video-click-guard::after {
  opacity: 1;
}

@media (max-width: 760px), (orientation: portrait) {
  #snaky-video-panel {
    width: min(58vw, 300px);
    min-width: 170px;
    padding: 7px;
    border-radius: 12px;
  }

  .snaky-video-title {
    font-size: 10px;
    margin-bottom: 5px;
  }
}

@media (max-width: 520px) and (orientation: portrait) {
  #snaky-video-panel {
    width: min(66vw, 260px);
    min-width: 160px;
  }
}

#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(55,32,18,.65), rgba(0,0,0,.82));
  opacity: 1;
  transition: opacity .28s ease;
  pointer-events: auto;
}

#loading-overlay.hidden-loading {
  opacity: 0;
  pointer-events: none;
}

.loading-box {
  min-width: min(76vw, 420px);
  padding: 28px 32px;
  border: 1px solid rgba(255,230,180,.65);
  border-radius: 22px;
  background: rgba(20,14,10,.72);
  box-shadow: 0 18px 50px rgba(0,0,0,.48);
  text-align: center;
  backdrop-filter: blur(6px);
}

.loading-logo {
  font-size: clamp(38px, 8vw, 58px);
  line-height: 1;
  margin-bottom: 14px;
  animation: loadingPulse 1.1s infinite ease-in-out;
}

.loading-text {
  color: #fff7e8;
  font-weight: 700;
  letter-spacing: .05em;
  font-size: clamp(17px, 3vw, 24px);
}

.hidden { display: none !important; }

@keyframes blink {
  0%, 45% { opacity: 1; }
  46%, 100% { opacity: .25; }
}

@keyframes loadingPulse {
  0%, 100% { transform: translateY(0); opacity: .75; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* 縦長画面: 選択肢と会話欄が画面を埋めすぎないようにする。 */
@media (orientation: portrait) {
  :root {
    --ui-top-reserve: 18px;
    --ui-bottom-reserve: 56px;
    --textbox-height: 22dvh;
    --textbox-height-expanded: 30dvh;
    --dialog-font-size: clamp(16px, 4.0vw, 24px);
    --name-font-size: clamp(15px, 3.6vw, 22px);
    --choice-font-size: clamp(14px, 3.5vw, 20px);
  }

  #character-layer {
    right: -7vw;
    bottom: calc(env(safe-area-inset-bottom) + var(--ui-bottom-reserve) + var(--textbox-height) - 3dvh);
    width: min(48vw, 360px);
  }

  #message-box {
    left: 4vw;
    right: 4vw;
    border-radius: 14px;
    padding: 10px 14px 18px;
  }

  #choices {
    left: 4vw;
    right: auto;
    width: min(68vw, 430px);
    max-height: min(42dvh, var(--choice-max-height));
    gap: 8px;
  }

  .choice-button {
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 12px;
    line-height: 1.25;
  }

  .choice-button:hover,
  .choice-button:focus,
  .choice-button.selected {
    transform: translateX(4px);
  }
}

@media (max-width: 420px) and (orientation: portrait) {
  :root {
    --textbox-height: 21dvh;
    --choice-font-size: clamp(13px, 3.4vw, 18px);
  }

  #choices {
    width: min(64vw, 320px);
    max-height: min(40dvh, var(--choice-max-height));
    gap: 7px;
  }

  .choice-button {
    min-height: 36px;
    padding: 8px 10px;
  }

  #character-layer {
    right: -12vw;
    width: 52vw;
  }
}

/* 横長画面: スマホ横で選択肢が会話欄へ食い込まないよう、選択肢エリアを小さくしてスクロール可能にする。 */
@media (orientation: landscape) {
  :root {
    --ui-top-reserve: 18px;
    --ui-bottom-reserve: 18px;
    --textbox-height: 24dvh;
    --textbox-height-expanded: 31dvh;
    --dialog-font-size: clamp(15px, 2.0vw, 24px);
    --name-font-size: clamp(13px, 1.6vw, 20px);
    --choice-font-size: clamp(13px, 1.65vw, 19px);
    --choice-max-height: calc(100dvh - env(safe-area-inset-top) - var(--ui-top-reserve) - env(safe-area-inset-bottom) - var(--ui-bottom-reserve) - var(--textbox-height) - 18px);
  }

  #character-layer {
    --char-h: min(54dvh, 520px);
    right: 4vw;
    bottom: calc(env(safe-area-inset-bottom) + var(--ui-bottom-reserve) + var(--textbox-height) - 4dvh);
    height: var(--char-h);
    width: calc(var(--char-h) * 0.6667);
  }

  #message-box {
    left: 4vw;
    right: 4vw;
    padding: 9px 14px 16px;
    border-radius: 14px;
  }

  #text {
    line-height: 1.42;
  }

  #choices {
    left: 5vw;
    width: min(440px, 46vw);
    max-height: var(--choice-max-height);
    gap: 6px;
  }

  .choice-button {
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 12px;
    line-height: 1.18;
    box-shadow: 0 5px 14px rgba(0,0,0,.32);
  }

  .choice-button:hover,
  .choice-button:focus,
  .choice-button.selected {
    transform: translateX(4px);
  }
}

/* 高さの低い横長スマホではさらに圧縮する。 */
@media (orientation: landscape) and (max-height: 430px) {
  :root {
    --ui-top-reserve: 10px;
    --ui-bottom-reserve: 12px;
    --textbox-height: 22dvh;
    --dialog-font-size: clamp(13px, 1.8vw, 20px);
    --name-font-size: clamp(12px, 1.45vw, 18px);
    --choice-font-size: clamp(12px, 1.55vw, 17px);
    --choice-max-height: calc(100dvh - env(safe-area-inset-top) - var(--ui-top-reserve) - env(safe-area-inset-bottom) - var(--ui-bottom-reserve) - var(--textbox-height) - 14px);
  }

  #choices {
    width: min(420px, 44vw);
    gap: 5px;
    padding-right: 4px;
  }

  .choice-button {
    min-height: 30px;
    padding: 6px 9px;
    border-radius: 11px;
  }

  #message-box {
    padding: 7px 12px 14px;
  }

  #character-layer {
    --char-h: min(50dvh, 430px);
    bottom: calc(env(safe-area-inset-bottom) + var(--ui-bottom-reserve) + var(--textbox-height) - 3dvh);
  }
}


#map-panel {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(4px);
}

.map-card {
  width: min(960px, 92vw);
  max-height: 86dvh;
  overflow: auto;
  padding: 22px 22px 18px;
  border: 2px solid rgba(255, 230, 180, .85);
  border-radius: 22px;
  background: rgba(20, 14, 10, 0.90);
  box-shadow: 0 18px 54px rgba(0,0,0,.55);
}

.map-title {
  font-size: clamp(24px, 3vw, 38px);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: .04em;
}

.map-subtitle {
  margin-top: 6px;
  margin-bottom: 16px;
  font-size: clamp(14px, 1.8vw, 20px);
  color: rgba(255,247,232,.92);
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    "entrance entrance snaky"
    "akane manga model3d"
    "gadget camera model3d"
    "note studio model3d";
  gap: 12px;
}

.map-room {
  min-height: 90px;
  border: 2px solid rgba(130, 228, 255, .55);
  border-radius: 16px;
  background: rgba(16, 22, 28, .78);
  color: #fff7e8;
  font-size: clamp(16px, 2vw, 24px);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  padding: 14px 12px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}

.map-room span {
  display: inline-block;
  margin-top: 4px;
  font-size: clamp(12px, 1.4vw, 16px);
  font-weight: 500;
  color: rgba(191, 252, 255, .92);
}

.map-room:hover,
.map-room:focus {
  transform: translateY(-2px);
  background: rgba(36, 46, 58, .92);
  border-color: rgba(255, 230, 180, .92);
}

.room-entrance { grid-area: entrance; }
.room-snaky { grid-area: snaky; }
.room-akane { grid-area: akane; }
.room-camera { grid-area: camera; }
.room-gadget { grid-area: gadget; }
.room-manga { grid-area: manga; }
.room-model3d { grid-area: model3d; min-height: 192px; }
.room-note { grid-area: note; }
.room-studio { grid-area: studio; }

.map-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.map-close-button {
  border: 2px solid rgba(255, 230, 180, .9);
  border-radius: 999px;
  padding: 10px 18px;
  background: rgba(94, 60, 30, .96);
  color: #fff7e8;
  font-size: clamp(14px, 1.6vw, 18px);
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 760px), (orientation: portrait) {
  .map-card {
    width: min(94vw, 720px);
    padding: 18px 16px 16px;
  }

  .map-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "entrance snaky"
      "akane manga"
      "gadget camera"
      "note studio"
      "model3d model3d";
  }

  .map-room {
    min-height: 84px;
    font-size: clamp(16px, 4.3vw, 22px);
  }

  .room-model3d { min-height: 110px; }
}


#special-image-viewer {
  position: absolute;
  inset: 0;
  z-index: 86;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 6, 8, 0.78);
  backdrop-filter: blur(6px);
}

.special-image-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(92vw, 880px);
}

.special-image-caption {
  padding: 10px 16px;
  border: 1px solid rgba(255, 230, 180, .75);
  border-radius: 999px;
  background: rgba(20, 14, 10, .78);
  color: #fff7e8;
  font-size: clamp(16px, 1.8vw, 22px);
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
}

.special-image-frame {
  width: min(82vw, 720px);
  height: min(76dvh, 960px);
  border: 2px solid rgba(255, 230, 180, .9);
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255, 248, 240, .12);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .45);
}

#special-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center center;
  transform-origin: 50% 42%;
  will-change: transform;
}

#special-image.animate-colorcon {
  animation: colorconFocusLoop 4s ease-in-out forwards;
}

.special-image-hint {
  color: rgba(255,247,232,.88);
  font-size: clamp(12px, 1.5vw, 16px);
  letter-spacing: .04em;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0,0,0,.35);
}

@keyframes colorconFocusLoop {
  0% { transform: scale(1); }
  50% { transform: scale(1.55); }
  100% { transform: scale(1); }
}

@media (max-width: 760px), (orientation: portrait) {
  .special-image-stage {
    width: min(96vw, 680px);
    gap: 10px;
  }

  .special-image-frame {
    width: min(92vw, 560px);
    height: min(68dvh, 760px);
    border-radius: 18px;
  }
}


/* 汎用展示ビューア: 漫画を最初の試験台にして、BCLカード/初日カバー/カメラ解説にも転用する。 */
#exhibit-viewer {
  position: absolute;
  inset: 0;
  z-index: 84;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 18px) calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 18px);
  background: rgba(6, 5, 4, .72);
  backdrop-filter: blur(5px);
}

.exhibit-viewer-card {
  width: min(94vw, 1120px);
  height: min(92dvh, 880px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: clamp(10px, 1.4vw, 16px);
  border: 2px solid rgba(255, 230, 180, .88);
  border-radius: 22px;
  background: rgba(20, 14, 10, .88);
  box-shadow: 0 22px 68px rgba(0,0,0,.58);
}

.exhibit-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.exhibit-viewer-title {
  color: var(--accent);
  font-size: clamp(18px, 2.2vw, 28px);
  font-weight: 800;
  letter-spacing: .04em;
}

.exhibit-viewer-counter {
  margin-top: 3px;
  color: rgba(255, 247, 232, .78);
  font-size: clamp(12px, 1.5vw, 16px);
}

.exhibit-viewer-close {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 230, 180, .86);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(94, 60, 30, .94);
  color: #fff7e8;
  font-size: clamp(13px, 1.5vw, 16px);
  font-weight: 700;
  cursor: pointer;
}

.exhibit-viewer-stage {
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 16px;
  background: radial-gradient(circle at center, rgba(255,248,232,.12), rgba(0,0,0,.28));
}

.exhibit-viewer-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 12px 34px rgba(0,0,0,.42);
}

.exhibit-viewer-image.slide-next {
  animation: exhibitSlideNext .26s ease both;
}

.exhibit-viewer-image.slide-prev {
  animation: exhibitSlidePrev .26s ease both;
}

.exhibit-viewer-caption {
  min-height: 1.8em;
  padding: 4px 6px;
  color: rgba(255,247,232,.92);
  font-size: clamp(13px, 1.6vw, 18px);
  text-align: center;
  line-height: 1.45;
  white-space: pre-line;
}

.exhibit-viewer-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.exhibit-nav-button {
  min-height: 46px;
  border: 2px solid rgba(255, 230, 180, .86);
  border-radius: 14px;
  background: rgba(28, 18, 12, .88);
  color: var(--ui-text);
  font-size: clamp(14px, 1.7vw, 19px);
  font-weight: 700;
  cursor: pointer;
}

.exhibit-nav-button:disabled {
  opacity: .38;
  cursor: default;
}

.exhibit-back-button {
  background: rgba(94, 60, 30, .90);
}

.exhibit-link-button {
  background: rgba(45, 82, 105, .92);
  border-color: rgba(180, 232, 255, .86);
}

@keyframes exhibitSlideNext {
  0% { transform: translateX(10%); opacity: .2; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes exhibitSlidePrev {
  0% { transform: translateX(-10%); opacity: .2; }
  100% { transform: translateX(0); opacity: 1; }
}

@media (orientation: portrait) {
  .exhibit-viewer-card {
    width: min(96vw, 760px);
    height: min(90dvh, 980px);
    gap: 8px;
  }

  .exhibit-viewer-controls {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .exhibit-nav-button {
    min-height: 42px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .exhibit-viewer-card {
    width: min(96vw, 980px);
    height: min(90dvh, 440px);
    padding: 8px;
    gap: 6px;
    border-radius: 16px;
  }

  .exhibit-viewer-title {
    font-size: clamp(15px, 2vw, 22px);
  }

  .exhibit-viewer-caption {
    font-size: clamp(11px, 1.6vw, 14px);
    min-height: 1.2em;
    padding: 0 4px;
  }

  .exhibit-nav-button {
    min-height: 34px;
    border-radius: 10px;
    font-size: clamp(12px, 1.7vw, 16px);
  }
}


#version-badge {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 10px);
  top: calc(env(safe-area-inset-top) + 8px);
  z-index: 2000;
  padding: 4px 8px;
  border: 1px solid rgba(255, 220, 150, 0.55);
  border-radius: 999px;
  background: rgba(20, 10, 4, 0.55);
  color: rgba(255, 230, 170, 0.88);
  font-size: 12px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.visit-counter-badge {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 10px);
  top: calc(env(safe-area-inset-top) + 8px);
  z-index: 2000;
  padding: 4px 8px;
  border: 1px solid rgba(255, 220, 150, 0.55);
  border-radius: 999px;
  background: rgba(20, 10, 4, 0.55);
  color: rgba(255, 230, 170, 0.88);
  font-size: 12px;
  letter-spacing: 0.04em;
  pointer-events: none;
}


/* v0.35: 漫画表紙選択シェルフ */
#collection-shelf {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 36px) 4vw calc(env(safe-area-inset-bottom) + 52px);
  box-sizing: border-box;
  background: rgba(10, 7, 5, 0.45);
  backdrop-filter: blur(6px);
}

#collection-shelf.hidden {
  display: none;
}

.collection-shelf-card {
  width: min(1120px, 94vw);
  max-height: min(820px, 86dvh);
  border: 1px solid rgba(255, 232, 184, 0.42);
  border-radius: 24px;
  background: rgba(24, 17, 12, 0.88);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
  color: #fff7dc;
  padding: clamp(16px, 2.4vw, 28px);
  box-sizing: border-box;
  overflow: auto;
}

.collection-shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.collection-shelf-title {
  font-size: clamp(22px, 2.6vw, 36px);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.collection-shelf-close,
.collection-shelf-back {
  appearance: none;
  border: 1px solid rgba(255, 231, 180, 0.45);
  border-radius: 999px;
  background: rgba(255, 228, 170, 0.14);
  color: #fff3cf;
  font-size: clamp(15px, 1.6vw, 20px);
  padding: 10px 18px;
  cursor: pointer;
}

.collection-shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: clamp(14px, 2vw, 24px);
}

.collection-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  text-align: left;
  appearance: none;
  border: 1px solid rgba(255, 231, 180, 0.32);
  border-radius: 18px;
  background: rgba(255, 246, 215, 0.08);
  color: #fff7dc;
  padding: 12px;
  cursor: pointer;
  box-shadow: 0 14px 36px rgba(0,0,0,0.26);
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.collection-card:hover,
.collection-card:focus-visible {
  transform: translateY(-2px);
  background: rgba(255, 246, 215, 0.16);
  border-color: rgba(255, 231, 180, 0.68);
  outline: none;
}

.collection-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(0,0,0,0.32);
}

.collection-card-title {
  font-size: clamp(16px, 1.6vw, 21px);
  font-weight: 700;
  line-height: 1.35;
}

.collection-card-note {
  font-size: clamp(13px, 1.2vw, 16px);
  opacity: 0.78;
}

.collection-shelf-actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

@media (orientation: portrait) {
  .collection-shelf-card {
    max-height: 78dvh;
  }

  .collection-shelf-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


/* v0.49: 展示ビューアのマウスドラッグ操作用 */
.exhibit-viewer img,
.exhibit-viewer-image,
#exhibit-viewer img {
  user-select: none;
  -webkit-user-drag: none;
}


/* v0.51: 会話を選択肢までスキップするボタン */
.skip-to-choices-button {
  position: absolute;
  right: clamp(42px, 5.6vw, 62px);
  bottom: clamp(6px, 1.2vw, 10px);
  z-index: 2;
  width: clamp(28px, 4vw, 38px);
  height: clamp(28px, 4vw, 38px);
  border: 1px solid rgba(255, 230, 180, .72);
  border-radius: 999px;
  background: rgba(28, 18, 12, .68);
  color: var(--accent);
  font-size: clamp(16px, 2.8vw, 23px);
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.34);
  opacity: .86;
}

.skip-to-choices-button:hover,
.skip-to-choices-button:focus {
  background: rgba(94, 60, 30, .92);
  color: #fff7e8;
  outline: none;
}

.skip-to-choices-button.hidden {
  display: none !important;
}



/* v0.52: 漫画ビューアだけ、4K/大画面で大きく表示する */
#exhibit-viewer[data-collection-type="manga"] {
  align-items: center;
  justify-content: center;
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-card {
  width: min(98vw, 2400px);
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 12px);
  max-height: 98dvh;
  padding: clamp(4px, .7vw, 10px);
  gap: clamp(4px, .7vw, 8px);
  border-radius: 14px;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-header {
  min-height: 0;
  align-items: center;
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-title {
  font-size: clamp(14px, 1.35vw, 22px);
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-counter {
  font-size: clamp(11px, 1vw, 14px);
  margin-top: 0;
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-close {
  padding: 5px 12px;
  font-size: clamp(12px, 1vw, 14px);
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-stage {
  border-radius: 10px;
  background: rgba(0,0,0,.42);
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-image {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0,0,0,.34);
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-caption {
  min-height: 1.1em;
  padding: 0 4px;
  font-size: clamp(11px, 1vw, 14px);
  line-height: 1.25;
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-controls {
  gap: 6px;
}

#exhibit-viewer[data-collection-type="manga"] .exhibit-nav-button {
  min-height: clamp(30px, 3.8dvh, 40px);
  border-radius: 10px;
  font-size: clamp(12px, 1.1vw, 16px);
}

@media (orientation: portrait) {
  #exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-card {
    width: 98vw;
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 10px);
    max-height: 98dvh;
    padding: 5px;
    gap: 5px;
  }

  #exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-controls {
    grid-template-columns: 1fr 1fr;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #exhibit-viewer[data-collection-type="manga"] .exhibit-viewer-card {
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 8px);
    max-height: 98dvh;
    padding: 4px;
    gap: 4px;
  }

  #exhibit-viewer[data-collection-type="manga"] .exhibit-nav-button {
    min-height: 30px;
  }
}


/* v0.53: ルーム公開スケジュール / 開発者モード */
.map-room.room-locked {
  opacity: .58;
  border-style: dashed;
  filter: saturate(.72);
}

.map-room.room-locked span {
  color: #f2c88f;
}

.map-room.room-dev-access {
  outline: 2px solid rgba(98, 225, 255, .72);
  box-shadow: 0 0 0 2px rgba(98, 225, 255, .22), 0 0 18px rgba(98, 225, 255, .18);
}

.map-room.room-dev-access span {
  color: #8fefff;
}

body.dev-mode #version-badge {
  color: #8fefff;
  border-color: rgba(98, 225, 255, .65);
  box-shadow: 0 0 16px rgba(98, 225, 255, .18);
}


/* v0.54: SNAKY World Ranking board */
#snaky-ranking-panel {
  position: absolute;
  inset: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

#snaky-ranking-panel.hidden {
  display: none !important;
}

.snaky-ranking-card {
  width: min(96vw, 1040px);
  max-height: 92dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.2vw, 14px);
  padding: clamp(14px, 2vw, 24px);
  border: 1px solid rgba(255, 230, 180, .42);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(18, 13, 10, .95), rgba(55, 31, 18, .92)),
    radial-gradient(circle at 20% 0%, rgba(255, 190, 90, .16), transparent 38%);
  box-shadow: 0 18px 58px rgba(0, 0, 0, .62);
  color: #fff3df;
  backdrop-filter: blur(8px);
}

.snaky-ranking-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.snaky-ranking-title {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 800;
  letter-spacing: .08em;
  font-size: clamp(22px, 3vw, 38px);
  color: #ffe2a6;
  text-shadow: 0 0 18px rgba(255, 190, 90, .24);
}

.snaky-ranking-status {
  margin-top: 4px;
  color: #dbc39f;
  font-size: clamp(13px, 1.5vw, 16px);
}

.snaky-ranking-close,
.snaky-ranking-button {
  border: 1px solid rgba(255, 232, 190, .38);
  border-radius: 999px;
  background: rgba(34, 22, 14, .82);
  color: #ffe8c0;
  min-height: 38px;
  padding: 8px 15px;
  cursor: pointer;
}

.snaky-ranking-close:hover,
.snaky-ranking-button:hover,
.snaky-ranking-close:focus,
.snaky-ranking-button:focus {
  background: rgba(114, 68, 30, .96);
  color: #fff8eb;
  outline: none;
}

.snaky-ranking-summary {
  min-height: 1.4em;
  color: #f4d6a6;
  font-size: clamp(12px, 1.25vw, 15px);
}

.snaky-ranking-body {
  overflow: auto;
  border-radius: 12px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .09);
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: clamp(13px, 1.45vw, 18px);
}

.ranking-table th,
.ranking-table td {
  padding: clamp(8px, 1.2vw, 13px);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  text-align: right;
  white-space: nowrap;
}

.ranking-table th {
  position: sticky;
  top: 0;
  background: rgba(34, 20, 12, .96);
  color: #ffdf98;
  font-size: .82em;
  letter-spacing: .08em;
  z-index: 1;
}

.ranking-table th:nth-child(2),
.ranking-table td:nth-child(2) {
  text-align: left;
}

.ranking-table tr:nth-child(1) td {
  color: #fff0b8;
  font-weight: 800;
}

.ranking-name {
  max-width: 12em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-score {
  color: #fff5dd;
  font-weight: 800;
}

.ranking-loading,
.ranking-error,
.ranking-empty {
  padding: clamp(22px, 4vw, 42px);
  text-align: center;
  color: #f3d7ae;
  line-height: 1.8;
}

.ranking-error {
  color: #ffb8a8;
}

.snaky-ranking-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.snaky-ranking-button {
  border-radius: 12px;
  width: 100%;
  font-size: clamp(12px, 1.3vw, 15px);
}

.snaky-ranking-button.ranking-back {
  background: rgba(74, 48, 32, .86);
}

@media (orientation: portrait), (max-width: 720px) {
  #snaky-ranking-panel {
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .snaky-ranking-card {
    width: 98vw;
    max-height: 96dvh;
    padding: 12px;
    border-radius: 14px;
  }

  .snaky-ranking-actions {
    grid-template-columns: 1fr 1fr;
  }

  .ranking-table th,
  .ranking-table td {
    padding: 8px 6px;
  }

  .ranking-table th:nth-child(5),
  .ranking-table td:nth-child(5) {
    display: none;
  }
}

