:root {
  color-scheme: dark;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #fff4e6;
  background: #171315;
  --paper: #fff4e6;
  --muted: #d1b9a4;
  --edge: rgb(255 222 176 / .25);
  --margin: clamp(12px, 2.6vw, 36px);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #fbd08a; outline-offset: 3px; }

#selection {
  min-height: 100svh;
  padding: clamp(42px, 10vh, 110px) clamp(20px, 8vw, 135px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    linear-gradient(90deg, rgb(23 15 15 / .92), rgb(24 15 16 / .3)),
    linear-gradient(0deg, #171315 8%, transparent 92%),
    url("./plates/memory-cover.webp") center 43% / cover;
}
.cover-title, .scene-options { width: min(100%, 1070px); }
.cover-title { margin-bottom: clamp(28px, 5vh, 54px); }
.cover-title h1 {
  margin: 0;
  font: 600 clamp(44px, 7vw, 100px)/1.1 "Songti SC", "SimSun", serif;
  letter-spacing: .09em;
  text-shadow: 0 2px 28px #2d1710;
}
.cover-title p { margin: 17px 0 0; color: #f0d9bf; font-size: 16px; line-height: 1.6; }
.scene-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(14px, 2.4vw, 32px); }
.scene-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: end;
  aspect-ratio: 16 / 9;
  background: #291d1d;
  color: var(--paper);
  padding: 7px;
  border: 1px solid var(--edge);
  text-decoration: none;
  box-shadow: 0 14px 48px rgb(0 0 0 / .30);
  transition: border-color .28s, transform .28s;
}
.scene-card::after {
  position: absolute;
  inset: 7px;
  content: "";
  background: linear-gradient(transparent 34%, rgb(23 14 16 / .93));
  pointer-events: none;
}
.scene-card img {
  position: absolute;
  inset: 7px;
  width: calc(100% - 14px);
  height: calc(100% - 14px);
  object-fit: cover;
}
.scene-card:hover { border-color: #e5ae78; transform: translateY(-4px); }
.card-label {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 5px 12px;
  width: 100%;
  padding: clamp(12px, 2vw, 24px);
  font: 600 clamp(25px, 3vw, 42px)/1.15 "Songti SC", "SimSun", serif;
}
.card-label small { font: 400 .875rem/1.4 "Microsoft YaHei", sans-serif; color: #f1d8b7; }

#viewer { display: none; position: fixed; inset: 0; background: #161319; }
.show-viewer #viewer { display: block; }
.show-viewer #selection { display: none; }
#preview-canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#preview-canvas:active { cursor: grabbing; }
.viewer-header, .viewer-footer { position: absolute; inset-inline: 0; padding: var(--margin); pointer-events: none; }
.viewer-header > *, .viewer-footer button { pointer-events: auto; }
.viewer-header {
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  background: linear-gradient(rgb(18 13 15 / .84), transparent);
}
.viewer-header h1 {
  margin: 0;
  text-align: center;
  font: 600 clamp(17px, 2.3vw, 28px)/1.25 "Songti SC", "SimSun", serif;
  text-shadow: 0 2px 12px #10090c;
  pointer-events: none;
}
.viewer-header > a { justify-self: start; }
#music-player {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 11px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: rgb(34 23 24 / .94);
}
#music-player div { display: grid; gap: 2px; }
#music-player strong { font-size: .875rem; font-weight: 600; }
#music-status { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.music-symbol { color: #efc183; font-size: 1.4rem; }
#music-player[data-playing="true"] .music-symbol { color: #ffdeb1; text-shadow: 0 0 12px #e5a760; }

.viewer-footer {
  bottom: 0;
  z-index: 3;
  padding-bottom: max(var(--margin), env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(transparent, rgb(20 14 17 / .91));
}
.viewer-footer p { margin: 9px 0 0; color: #eedbca; font-size: .81rem; text-shadow: 0 1px 5px #100d0b; }
.control-buttons, #scene-views { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px; }
.control-buttons { width: fit-content; max-width: 100%; margin-inline: auto; }
#scene-views { margin-bottom: 6px; }
#scene-views:empty { display: none; }
.preview-button {
  display: inline-block;
  min-height: 36px;
  padding: .48em .76em;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: rgb(35 24 25 / .94);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-size: .875rem;
  white-space: nowrap;
  transition: background .18s, border-color .18s;
}
.preview-button:hover { border-color: #dbb28b; background: #49322e; }
.preview-button:disabled { opacity: .48; cursor: default; }
.preview-button[aria-pressed="true"], .preview-button[aria-expanded="true"] { background: #efd3ad; color: #281a17; }
#preview-status {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100% - 32px);
  background: #30211f;
  padding: 15px 20px;
  border-radius: 7px;
  text-align: center;
}
.preview-error-detail { display: block; margin-top: 6px; max-width: 42ch; overflow-wrap: anywhere; color: var(--muted); }
#retry-preview { margin-top: 10px; }
#night-render {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  color: var(--paper);
  background: #11100e;
}
#night-render::backdrop { background: #11100e; }
#night-render img { display: block; width: 100%; height: 100%; object-fit: contain; }
#night-render form { position: absolute; top: var(--margin); left: var(--margin); }

#room-tools {
  position: absolute;
  z-index: 2;
  right: var(--margin);
  top: 50%;
  transform: translateY(-50%);
  width: min(306px, calc(100vw - 24px));
  max-height: min(calc(100dvh - 166px), 420px);
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: linear-gradient(140deg, rgb(49 33 30 / .98), rgb(27 21 28 / .97)), url("./plates/memory-grain.png");
  box-shadow: 0 12px 42px rgb(0 0 0 / .45);
}
.room-tools-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.room-tools-header h2 { font: 600 1.28rem/1.2 "Songti SC", "SimSun", serif; margin: 0; }
#room-object-list, #room-object-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
#room-object-list { margin-top: 10px; }
#room-object-image { display: block; width: 100%; height: clamp(65px, 13vh, 125px); object-fit: contain; margin-top: 10px; }
#room-object-status { margin: 9px 0; font-size: .875rem; color: #f2dbc4; line-height: 1.55; }
#winding-progress { width: 84px; height: 7px; accent-color: #e7b878; }
#winding-value { font-size: .81rem; color: #f1c58d; }
#wind-music, #room-object-controls > button:only-child:not(:disabled) { background: #efd3ad; color: #281a17; }
#room-hotspots { position: absolute; inset: 0; pointer-events: none; }
.room-hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  padding: 0;
  overflow: hidden;
  color: transparent;
  border: 1px solid #ffe4be;
  border-radius: 50%;
  background-color: #eebf7b;
  box-shadow: inset 0 0 0 6px #392920, 0 2px 12px #1c1310;
  cursor: pointer;
  pointer-events: auto;
}
.room-hotspot:hover, .room-hotspot:focus-visible { box-shadow: 0 0 13px #ffd391; }

@media (max-width: 650px) {
  .scene-options { grid-template-columns: 1fr; }
  .show-viewer #viewer { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  #preview-canvas { position: absolute; inset: 0; }
  .viewer-header, .viewer-footer { position: relative; grid-column: 1; }
  .viewer-header { grid-row: 1; }
  .viewer-footer { grid-row: 3; }
  .viewer-header { grid-template-columns: auto 1fr auto; }
  .viewer-header h1 { font-size: .95rem; }
  .music-symbol { display: none; }
  #music-player { gap: 5px; padding: 4px 4px 4px 7px; }
  #room-tools {
    position: relative;
    grid-area: 2 / 1;
    place-self: end;
    inset: auto;
    transform: none;
    width: min(298px, calc(100vw - 24px));
    max-height: min(42dvh, calc(100% - 10px));
    margin: 0 var(--margin) 10px;
    padding: 12px;
  }
  #room-object-image { height: 60px; }
  .viewer-footer p { font-size: .75rem; }
}
@media (max-height: 480px) {
  #room-object-image { display: none; }
}
@media (max-width: 360px) {
  .preview-button { padding-inline: .50em; }
  .viewer-header { gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .scene-card, .preview-button { transition: none; }
  .scene-card:hover { transform: none; }
}

#look-reticle { position: absolute; pointer-events: none; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 7px; height: 7px; border-radius: 50%; border: 1px solid #fff1cc; box-shadow: 0 0 4px #140e0a; z-index: 1; }

#story-transition {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  color: var(--paper);
  font: 600 clamp(20px, 3.5vw, 44px)/1.4 "Songti SC","SimSun",serif;
  background: rgb(17 13 17 / .73);
  animation: story-room-fade 2.4s ease both;
}
@keyframes story-room-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #story-transition { animation-duration: .45s; } }
