:root {
  color-scheme: light;
  --ink: #202729;
  --muted: #687173;
  --paper: #f4f0e9;
  --paper-strong: #fffdf9;
  --forest: #286b58;
  --forest-dark: #183f37;
  --wine: #7f3f50;
  --violet: #745a83;
  --brass: #b69251;
  --brass-dark: #80642f;
  --danger: #9b3f3f;
  --line: rgba(32, 39, 41, 0.2);
  --dialogue-height: 190px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #22292a;
  color: var(--ink);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: var(--paper);
}

/* Setup */

.setup-screen {
  position: relative;
  z-index: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding-top: calc(30px + var(--safe-top));
  color: var(--paper-strong);
}

.setup-backdrop,
.ending-backdrop {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image: url("assets/backgrounds/home-day.webp");
  background-size: cover;
  background-position: 46% center;
}

.setup-screen::before,
.ending-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgba(22, 31, 31, 0.28);
  pointer-events: none;
}

.setup-title {
  width: min(100%, 560px);
  padding: 0 22px 28px;
  text-shadow: 0 2px 18px rgba(16, 20, 20, 0.45);
}

.chapter-kicker {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #e8dfcc;
}

.setup-title h1 {
  max-width: 10em;
  margin: 0;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 38px;
  font-weight: 600;
  line-height: 1.12;
}

.title-name {
  margin: 10px 0 0;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 19px;
  color: #f1e5cb;
}

.setup-band {
  width: 100%;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  background: rgba(247, 244, 237, 0.94);
  border-top: 1px solid rgba(255, 255, 255, 0.55);
  color: var(--ink);
  backdrop-filter: blur(16px);
}

.name-field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.name-field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-size: 15px;
}

.name-field input:focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 2px rgba(40, 107, 88, 0.12);
}

.setup-group {
  min-width: 0;
  margin: 0 0 13px;
  padding: 0;
  border: 0;
}

.setup-group legend {
  margin-bottom: 7px;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.relation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.setup-option,
.segment-button,
.difficulty-button,
.insight-toggle {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
}

.setup-option {
  position: relative;
  min-height: 39px;
  padding: 8px 30px 8px 10px;
  text-align: left;
  font-size: 13px;
}

.setup-option span {
  position: absolute;
  top: 50%;
  right: 9px;
  transform: translateY(-50%);
  font-size: 10px;
  color: #8c9191;
}

.setup-option:disabled {
  opacity: 0.55;
}

.setup-option.is-selected,
.segment-button.is-selected,
.difficulty-button.is-selected {
  border-color: var(--forest);
  background: #e7f0eb;
  color: var(--forest-dark);
  box-shadow: inset 3px 0 0 var(--forest);
}

.segment-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.segment-button {
  min-height: 38px;
  border-radius: 0;
  font-size: 13px;
}

.segment-button:first-child {
  border-radius: 6px 0 0 6px;
}

.segment-button:last-child {
  margin-left: -1px;
  border-radius: 0 6px 6px 0;
}

.segment-button:disabled {
  opacity: 0.55;
}

.setup-screen.is-mind-selected .setup-band {
  border-color: rgba(198, 178, 132, 0.72);
  box-shadow: 0 18px 45px rgba(30, 40, 37, 0.24);
}

.difficulty-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.difficulty-button {
  display: grid;
  min-height: 54px;
  align-content: center;
  gap: 2px;
  padding: 6px 4px;
}

.difficulty-button strong {
  font-size: 13px;
}

.difficulty-button span {
  overflow-wrap: anywhere;
  font-size: 10px;
  color: var(--muted);
}

.insight-toggle {
  width: 100%;
  min-height: 36px;
  margin-top: 7px;
  color: var(--violet);
}

.insight-toggle[aria-pressed="true"] {
  border-color: var(--violet);
  background: #eee8f1;
}

.primary-command,
.secondary-command {
  min-height: 46px;
  border-radius: 6px;
  font-weight: 800;
}

.primary-command {
  width: 100%;
  border: 1px solid var(--forest-dark);
  background: var(--forest-dark);
  color: #fff;
}

.secondary-command {
  border: 1px solid rgba(255, 255, 255, 0.46);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.setup-load-command {
  width: 100%;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.56);
  color: var(--forest-dark);
}

.setup-gallery-command,
.setup-mind-gallery-command,
.ending-gallery-command,
.ending-mind-gallery-command {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
}

.setup-gallery-command,
.setup-mind-gallery-command {
  width: 100%;
  border-color: #b9ad99;
  background: #ebe5da;
  color: var(--forest-dark);
}

.setup-mind-gallery-command {
  border-color: #b9acbf;
  background: #ebe6ed;
}

.setup-commands:not(.has-mind-gallery) .setup-gallery-command {
  grid-column: 1 / -1;
}

.setup-gallery-command strong,
.setup-mind-gallery-command strong,
.ending-gallery-command strong,
.ending-mind-gallery-command strong {
  color: var(--brass-dark);
  font-size: 12px;
}

.setup-commands {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

/* Game stage */

.game-screen {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #d8d4cd;
  color: #fff;
}

.scene-backdrop,
.scene-light,
.rain-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scene-backdrop {
  z-index: 0;
  background-image: url("assets/backgrounds/home-day.webp");
  background-size: cover;
  background-position: 46% center;
  transform: scale(1.01);
  transition: filter 900ms ease, transform 1200ms ease;
}

.background-home .scene-backdrop {
  background-image: url("assets/backgrounds/home-day.webp");
  background-position: 46% center;
}

.background-home-day .scene-backdrop {
  background-image: url("assets/backgrounds/home-day.webp");
  background-position: 46% center;
}

.background-cafe .scene-backdrop {
  background-image: url("assets/backgrounds/cafe-evening.webp");
  background-position: 52% center;
}

.background-rain-street .scene-backdrop {
  background-image: url("assets/backgrounds/rain-street-night.webp");
  background-position: 54% center;
}

.background-home-night .scene-backdrop {
  background-image: url("assets/backgrounds/home-night.webp");
  background-position: 46% center;
}

.background-station .scene-backdrop {
  background-image: url("assets/backgrounds/station-blue-hour.webp");
  background-position: 52% center;
}

.background-kitchen .scene-backdrop {
  background-image: url("assets/backgrounds/kitchen-morning.webp");
  background-position: 48% center;
}

.background-hallway-night .scene-backdrop {
  background-image: url("assets/backgrounds/home-hallway-night.webp");
  background-position: 50% center;
}

.background-hallway .scene-backdrop {
  background-image: url("assets/backgrounds/home-hallway-night.webp");
  background-position: 50% center;
}

.background-rain .scene-backdrop {
  background-image: url("assets/backgrounds/rain-street-night.webp");
  background-position: 54% center;
}

.background-rooftop .scene-backdrop {
  background-image: url("assets/backgrounds/rooftop-evening.webp");
  background-position: 50% center;
}

.background-mind-home-night .scene-backdrop {
  background-image: url("assets/backgrounds/home-night.webp");
  background-position: 54% center;
}

.background-mind-home .scene-backdrop {
  background-image: url("assets/backgrounds/home-day.webp");
  background-position: 54% center;
}

.background-mind-cafe .scene-backdrop {
  background-image: url("assets/backgrounds/cafe-evening.webp");
  background-position: 44% center;
}

.background-mind-rooftop .scene-backdrop {
  background-image: url("assets/backgrounds/rooftop-evening.webp");
  background-position: 58% center;
}

.background-mind-station .scene-backdrop {
  background-image: url("assets/backgrounds/station-blue-hour.webp");
  background-position: 45% center;
}

.background-mind-hallway .scene-backdrop {
  background-image: url("assets/backgrounds/home-hallway-night.webp");
  background-position: 42% center;
}

.background-mind-kitchen .scene-backdrop {
  background-image: url("assets/backgrounds/kitchen-morning.webp");
  background-position: 44% center;
}

.scene-light {
  z-index: 1;
  background: rgba(255, 246, 226, 0.05);
  transition: background-color 900ms ease;
}

.mood-evening .scene-light {
  background: rgba(77, 51, 66, 0.2);
}

.mood-night .scene-backdrop,
.mood-rain .scene-backdrop {
  filter: brightness(0.66) saturate(0.78) contrast(1.05);
}

.mood-night .scene-light {
  background: rgba(20, 38, 48, 0.34);
}

.mood-rain .scene-light {
  background: rgba(30, 47, 56, 0.28);
}

.background-rain-street.mood-rain .scene-backdrop {
  filter: brightness(0.86) saturate(0.86) contrast(1.04);
}

.background-rain-street.mood-rain .scene-light {
  background: rgba(22, 38, 47, 0.16);
}

.background-home-night.mood-night .scene-backdrop {
  filter: brightness(0.9) saturate(0.9) contrast(1.03);
}

.background-home-night.mood-night .scene-light {
  background: rgba(18, 30, 36, 0.12);
}

.background-station.mood-evening .scene-light {
  background: rgba(36, 43, 58, 0.12);
}

.background-kitchen.mood-day .scene-light {
  background: rgba(255, 250, 239, 0.04);
}

.background-hallway-night.mood-night .scene-backdrop {
  filter: brightness(0.94) saturate(0.9) contrast(1.03);
}

.background-hallway-night.mood-night .scene-light {
  background: rgba(30, 24, 22, 0.08);
}

.background-rooftop.mood-evening .scene-backdrop {
  filter: brightness(0.93) saturate(0.94) contrast(1.02);
}

.background-rooftop.mood-evening .scene-light {
  background: rgba(40, 48, 58, 0.08);
}

.mode-mind .scene-backdrop {
  filter: brightness(0.82) saturate(0.78) contrast(1.08);
  animation: mind-breathe 13s ease-in-out infinite alternate;
}

.mode-mind.mood-day .scene-backdrop {
  filter: brightness(0.95) saturate(0.72) contrast(1.05);
}

.mode-mind .scene-light {
  background: rgba(151, 184, 168, 0.13);
  box-shadow: inset 0 0 0 1px rgba(226, 210, 171, 0.13), inset 0 0 80px rgba(49, 40, 58, 0.18);
}

@keyframes mind-breathe {
  from { transform: scale(1.025) translateX(-0.25%); }
  to { transform: scale(1.055) translateX(0.25%); }
}

.rain-layer {
  z-index: 2;
  display: none;
  opacity: 0.24;
  background-image: repeating-linear-gradient(104deg, transparent 0 21px, rgba(220, 238, 244, 0.55) 22px 23px, transparent 24px 49px);
  background-size: 140px 220px;
  animation: rain-shift 1.4s linear infinite;
}

.mood-rain .rain-layer {
  display: block;
}

@keyframes rain-shift {
  from { background-position: 0 -220px; }
  to { background-position: -28px 220px; }
}

.game-topbar {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
  display: flex;
  width: 100%;
  min-height: calc(58px + var(--safe-top));
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  padding: calc(9px + var(--safe-top)) 10px 7px;
  background: rgba(17, 25, 26, 0.7);
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(11px);
}

.scene-heading {
  min-width: 0;
  flex: 1;
}

.scene-heading p,
.scene-heading h2 {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-heading p {
  margin-bottom: 2px;
  font-size: 10px;
  color: #d6c8ab;
}

.scene-heading h2 {
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 14px;
  font-weight: 600;
}

.game-tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
}

.game-tools button {
  min-width: 31px;
  height: 29px;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 9px;
}

.game-tools button:last-child {
  font-size: 15px;
}

.game-tools button[aria-pressed="true"] {
  border-color: #d5b870;
  background: rgba(181, 144, 79, 0.3);
  color: #fff2c8;
}

.priority-tools {
  position: absolute;
  top: calc(67px + var(--safe-top));
  right: 10px;
  z-index: 19;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.priority-tools button {
  min-width: 94px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(229, 207, 157, 0.82);
  border-radius: 4px;
  background: rgba(28, 70, 59, 0.92);
  box-shadow: 0 5px 16px rgba(5, 18, 15, 0.28);
  color: #fff7e5;
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(8px);
}

.priority-auto-button {
  white-space: nowrap;
}

.priority-auto-button[aria-pressed="true"] {
  border-color: #fff0c5;
  background: #d7bd83;
  box-shadow: 0 0 0 2px rgba(255, 240, 197, 0.2), 0 5px 16px rgba(5, 18, 15, 0.32);
  color: #173d35;
}

.priority-tools button:active {
  transform: translateY(1px);
  background: rgba(43, 91, 77, 0.96);
}

.progress-dots {
  position: absolute;
  top: calc(72px + var(--safe-top));
  left: 12px;
  z-index: 19;
  display: flex;
  gap: 6px;
}

.progress-dots span {
  width: 7px;
  height: 7px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: rgba(20, 28, 28, 0.35);
}

.progress-dots span.is-complete {
  background: #d7c08a;
}

.progress-dots span.is-current {
  background: #f7f2e6;
  box-shadow: 0 0 0 3px rgba(247, 242, 230, 0.18);
}

.character-stage {
  position: absolute;
  inset: 62px 0 var(--dialogue-height);
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.character {
  position: absolute;
  display: block;
  width: auto;
  object-fit: contain;
  object-position: bottom;
  filter: drop-shadow(0 18px 24px rgba(10, 15, 14, 0.24));
  transform-origin: bottom center;
  transition: opacity 450ms ease, transform 650ms ease, filter 650ms ease;
  user-select: none;
}

.tiehe-character {
  right: -3%;
  bottom: -2px;
  height: min(55svh, 520px);
}

.hide-tiehe .tiehe-character {
  opacity: 0;
}

.player-character {
  left: -9%;
  bottom: 4px;
  height: min(29svh, 280px);
  opacity: 0;
  transform: translateX(-16px);
}

.show-player .player-character {
  opacity: 0.88;
  transform: translateX(0);
}

.presentation-phone .character-stage {
  opacity: 0;
}

.emotion-neutral {
  transform: translateY(0);
}

.emotion-smile {
  filter: drop-shadow(0 18px 24px rgba(10, 15, 14, 0.22)) brightness(1.04) saturate(1.04);
  transform: translateY(-4px) rotate(0.7deg);
}

.emotion-dry {
  transform: translateY(-2px) rotate(-0.7deg);
}

.emotion-guarded {
  right: -8%;
  filter: drop-shadow(0 16px 24px rgba(10, 15, 14, 0.28)) saturate(0.78) brightness(0.88);
  transform: scale(0.94) translateY(6px);
}

.emotion-hurt {
  filter: drop-shadow(0 18px 24px rgba(10, 15, 14, 0.3)) saturate(0.68) brightness(0.83);
  transform: translateY(8px);
}

.emotion-close {
  right: 0;
  filter: drop-shadow(0 20px 25px rgba(10, 15, 14, 0.22)) brightness(1.06);
  transform: scale(1.035) translateY(-3px);
}

.phone-stage {
  position: absolute;
  top: calc(167px + var(--safe-top));
  bottom: calc(var(--dialogue-height) + 62px);
  left: 50%;
  z-index: 8;
  width: calc(100% - 32px);
  max-width: 420px;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(242, 239, 232, 0.91);
  box-shadow: 0 22px 55px rgba(12, 18, 18, 0.3);
  color: var(--ink);
  backdrop-filter: blur(14px);
}

.phone-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  min-height: 40px;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}

.phone-header strong {
  font-size: 13px;
}

.phone-signal {
  justify-self: end;
}

.phone-thread {
  display: flex;
  height: calc(100% - 40px);
  flex-direction: column;
  gap: 9px;
  overflow-y: auto;
  padding: 14px 12px 22px;
}

.message-bubble {
  width: fit-content;
  max-width: 84%;
  padding: 9px 11px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(23, 31, 31, 0.08);
  font-size: 13px;
  line-height: 1.55;
}

.message-bubble.is-player {
  align-self: flex-end;
  background: #dcebe3;
}

.choice-panel {
  position: absolute;
  right: 12px;
  bottom: calc(var(--dialogue-height) + var(--safe-bottom) + 17px);
  left: 12px;
  z-index: 30;
  display: grid;
  max-height: min(45svh, 390px, calc(100svh - var(--dialogue-height) - 76px));
  gap: 7px;
  overflow-y: auto;
  padding: 2px;
}

.presentation-phone .choice-panel {
  right: auto;
  left: 50%;
  width: calc(100% - 40px);
  max-width: 400px;
  transform: translateX(-50%);
}

.choice-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px 13px 10px 10px;
  border: 1px solid rgba(24, 55, 47, 0.3);
  border-radius: 6px;
  background: rgba(253, 251, 246, 0.97);
  box-shadow: 0 7px 20px rgba(13, 30, 26, 0.17);
  color: var(--ink);
  text-align: left;
  font-size: 13px;
  backdrop-filter: blur(10px);
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.choice-key {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  background: var(--forest-dark);
  box-shadow: 0 2px 7px rgba(15, 45, 36, 0.22);
  color: #fff8e8;
  font-size: 12px;
  font-weight: 800;
}

.choice-copy {
  min-width: 0;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.choice-button:focus-visible {
  outline: 3px solid rgba(215, 189, 131, 0.78);
  outline-offset: 2px;
}

.choice-button:active {
  transform: translateY(1px);
  background: #edf3ef;
}

.mode-mind .choice-button {
  border-color: rgba(116, 90, 131, 0.42);
  background: rgba(255, 253, 248, 0.96);
}

.mode-mind .choice-key {
  background: var(--violet);
}

@media (hover: hover) {
  .choice-button:hover {
    transform: translateY(-1px);
    border-color: rgba(40, 107, 88, 0.68);
    background: #fffdf8;
    box-shadow: 0 9px 24px rgba(13, 30, 26, 0.22);
  }
}

.effect-feedback {
  position: absolute;
  right: 14px;
  bottom: calc(var(--dialogue-height) + var(--safe-bottom) + 14px);
  left: 14px;
  z-index: 29;
  min-height: 28px;
  padding: 6px 9px;
  transform: translateY(7px);
  opacity: 0;
  border-left: 3px solid #d7bd83;
  background: rgba(18, 29, 29, 0.78);
  color: #fff5df;
  font-size: 11px;
  transition: opacity 220ms ease, transform 220ms ease;
  pointer-events: none;
}

.effect-feedback.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.dialogue-box {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  min-height: calc(var(--dialogue-height) + var(--safe-bottom));
  padding: 17px 20px calc(18px + var(--safe-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(18, 29, 29, 0.9);
  color: #f9f6ef;
  backdrop-filter: blur(16px);
  cursor: pointer;
}

.dialogue-meta {
  display: flex;
  min-height: 22px;
  align-items: baseline;
  gap: 9px;
}

.dialogue-meta strong {
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 16px;
  color: #e4cf9d;
}

.dialogue-meta span {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.56);
}

.dialogue-box p {
  min-height: 76px;
  margin: 9px 0 0;
  font-size: 15px;
  line-height: 1.78;
  overflow-wrap: anywhere;
}

.continue-indicator {
  position: absolute;
  right: 18px;
  bottom: calc(12px + var(--safe-bottom));
  color: #e2cb92;
  font-size: 20px;
  opacity: 0;
  animation: continue-pulse 1.2s ease-in-out infinite;
}

.dialogue-box.can-continue .continue-indicator {
  opacity: 1;
}

.mode-mind .dialogue-box {
  border-top-color: rgba(222, 200, 149, 0.58);
  background: rgba(24, 31, 31, 0.92);
}

.mode-mind .dialogue-meta strong,
.mode-mind .continue-indicator {
  color: #e3cda0;
}

@keyframes continue-pulse {
  0%, 100% { transform: translateY(-1px); }
  50% { transform: translateY(4px); }
}

/* Ending */

.ending-screen {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: calc(54px + var(--safe-top)) 20px calc(26px + var(--safe-bottom));
  color: #fff;
}

.ending-screen::before {
  background: rgba(20, 31, 30, 0.72);
}

.ending-backdrop,
.ending-screen::before {
  position: fixed;
}

.ending-content {
  width: min(100%, 680px);
  margin: 0 auto;
}

.ending-kind {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  color: #dbc58f;
}

.ending-content h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 34px;
  font-weight: 600;
}

.ending-quote {
  margin: 18px 0 26px;
  padding-left: 14px;
  border-left: 3px solid var(--brass);
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 16px;
  line-height: 1.8;
}

.ending-summary,
.review-content {
  margin-top: 16px;
  padding: 16px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.24);
}

.ending-summary h3,
.review-content h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #ead9ae;
}

.ending-summary p,
.review-content p,
.review-content li {
  font-size: 13px;
  line-height: 1.72;
}

.review-content ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.review-stat {
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.19);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
}

.review-stat span,
.review-stat strong {
  display: block;
}

.review-stat span {
  margin-bottom: 3px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.62);
}

.review-stat strong {
  font-size: 13px;
}

.ending-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 20px;
}

.ending-perspective-command,
.ending-gallery-command,
.ending-mind-gallery-command {
  min-width: 0;
}

.ending-actions:not(.has-perspective):not(.is-mind-result) .ending-gallery-command {
  grid-column: 1 / -1;
}

/* Modals */

.modal-layer {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: calc(24px + var(--safe-top));
  background: rgba(10, 16, 16, 0.66);
}

.modal-panel {
  width: 100%;
  max-height: calc(88svh - var(--safe-top));
  overflow: hidden;
  border-top: 1px solid rgba(255, 255, 255, 0.42);
  background: #f5f1e9;
  color: var(--ink);
  box-shadow: 0 -20px 55px rgba(7, 12, 12, 0.35);
}

.modal-header {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 0 17px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 18px;
}

.icon-command {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 25px;
}

.modal-content {
  max-height: calc(88svh - 52px - var(--safe-top));
  overflow-y: auto;
  padding: 16px 17px calc(20px + var(--safe-bottom));
}

.slot-list {
  display: grid;
  gap: 8px;
}

.collection-overview {
  padding: 2px 0 16px;
  border-bottom: 1px solid var(--line);
}

.mind-collection-overview {
  padding: 2px 0 15px;
  border-bottom: 1px solid var(--line);
}

.mind-latest-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid rgba(32, 39, 41, 0.12);
}

.mind-latest-line span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.mind-latest-line strong {
  overflow-wrap: anywhere;
  color: var(--violet);
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}

.mind-gallery-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 14px;
}

.mind-gallery-tabs button {
  min-width: 0;
  min-height: 42px;
  border: 1px solid #b9b1bd;
  border-radius: 0;
  background: #ebe7ec;
  color: #665d69;
  font-size: 12px;
}

.mind-gallery-tabs button:first-child {
  border-radius: 6px 0 0 6px;
}

.mind-gallery-tabs button + button {
  margin-left: -1px;
}

.mind-gallery-tabs button:last-child {
  border-radius: 0 6px 6px 0;
}

.mind-gallery-tabs button.is-selected {
  position: relative;
  border-color: var(--violet);
  background: #ded5e2;
  color: #43374a;
}

.mind-gallery-tabs strong {
  margin-left: 4px;
  color: var(--brass-dark);
  font-size: 10px;
}

.mind-stage-heading {
  margin: 17px 0 10px;
}

.mind-stage-heading span {
  color: var(--forest-dark);
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 15px;
  font-weight: 600;
}

.mind-stage-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.5;
}

.mind-catalog-grid {
  display: grid;
  gap: 9px;
}

.mind-catalog-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 5px 10px;
  padding: 12px;
  border: 1px solid #c8c0c9;
  border-radius: 6px;
  background: #fffdf9;
}

.mind-catalog-card.is-locked {
  background: #e9e5e8;
  color: #817b82;
}

.mind-catalog-card.is-latest {
  border-color: var(--brass);
  box-shadow: inset 3px 0 0 var(--brass);
}

.mind-catalog-index {
  grid-row: 1 / span 2;
  color: var(--violet);
  font-family: Georgia, serif;
  font-size: 13px;
  font-weight: 700;
}

.mind-catalog-copy {
  min-width: 0;
}

.mind-catalog-copy > span {
  color: var(--forest);
  font-size: 9px;
  font-weight: 800;
}

.mind-catalog-copy h3 {
  margin: 3px 0 5px;
  overflow-wrap: anywhere;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 15px;
  font-weight: 600;
}

.mind-catalog-copy p,
.mind-catalog-insight p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.62;
}

.mind-catalog-card > small {
  grid-column: 2;
  color: #8f7d59;
  font-size: 9px;
}

.mind-catalog-insight {
  grid-column: 1 / -1;
  margin-top: 5px;
  padding-top: 9px;
  border-top: 1px solid rgba(32, 39, 41, 0.13);
}

.mind-catalog-insight strong {
  display: block;
  margin-bottom: 5px;
  color: var(--violet);
  font-size: 10px;
}

.mind-catalog-insight p + p {
  margin-top: 6px;
  color: #4d5b58;
}

.mind-gallery-tabs button:focus-visible {
  z-index: 1;
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.collection-summary {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.collection-summary div span,
.collection-summary div strong {
  display: block;
}

.collection-summary div span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.collection-summary div strong {
  color: var(--forest-dark);
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 24px;
  font-weight: 600;
}

.collection-summary p,
.collection-caption {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.collection-progress {
  height: 6px;
  margin-top: 11px;
  overflow: hidden;
  border-radius: 3px;
  background: #d9d2c7;
}

.collection-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--forest);
}

.collection-caption {
  margin-top: 7px;
}

.collection-perspective-button {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 52px;
  margin-top: 13px;
  padding: 8px 11px;
  border: 1px solid #b8c9be;
  border-radius: 6px;
  background: #e7eee9;
  color: var(--forest-dark);
  text-align: left;
}

.collection-perspective-button span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

.collection-perspective-button strong {
  overflow-wrap: anywhere;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 13px;
  font-weight: 600;
}

.ending-catalog-grid {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.ending-catalog-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 4px 10px;
  min-height: 112px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf9;
}

.ending-catalog-card.is-locked {
  background: #eae5dc;
  color: #817b72;
}

.ending-catalog-index {
  grid-row: 1 / span 2;
  color: var(--brass-dark);
  font-family: Georgia, serif;
  font-size: 16px;
}

.ending-catalog-copy {
  min-width: 0;
}

.ending-catalog-copy > span {
  color: var(--forest);
  font-size: 10px;
  font-weight: 800;
}

.ending-catalog-copy h3 {
  margin: 3px 0 5px;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 15px;
  font-weight: 600;
}

.ending-catalog-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.ending-catalog-card > small {
  grid-column: 2;
  align-self: end;
  color: #8f7d59;
  font-size: 9px;
}

.catalog-perspective-button {
  grid-column: 2;
  justify-self: start;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #abc0b4;
  border-radius: 5px;
  background: #edf3ef;
  color: var(--forest-dark);
  font-size: 10px;
  font-weight: 800;
}

.collection-perspective-button:focus-visible,
.catalog-perspective-button:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.perspective-reader {
  min-height: 100%;
  margin: -16px -17px calc(-20px - var(--safe-bottom));
  background: var(--paper-strong);
}

.perspective-hero {
  position: relative;
  height: min(38svh, 280px);
  min-height: 220px;
  overflow: hidden;
  background: #c9c6bf;
}

.perspective-scene,
.perspective-hero::after {
  position: absolute;
  inset: 0;
}

.perspective-scene {
  background-size: cover;
  background-position: center;
}

.perspective-hero::after {
  content: "";
  z-index: 1;
  background: rgba(22, 31, 30, 0.18);
  pointer-events: none;
}

.perspective-bg-home .perspective-scene {
  background-image: url("assets/backgrounds/home-day.webp");
  background-position: 46% center;
}

.perspective-bg-kitchen .perspective-scene {
  background-image: url("assets/backgrounds/kitchen-morning.webp");
  background-position: 48% center;
}

.perspective-bg-cafe .perspective-scene {
  background-image: url("assets/backgrounds/cafe-evening.webp");
  background-position: 52% center;
}

.perspective-bg-station .perspective-scene {
  background-image: url("assets/backgrounds/station-blue-hour.webp");
  background-position: 52% center;
}

.perspective-bg-hallway .perspective-scene {
  background-image: url("assets/backgrounds/home-hallway-night.webp");
  background-position: 50% center;
}

.perspective-bg-home-night .perspective-scene {
  background-image: url("assets/backgrounds/home-night.webp");
  background-position: 46% center;
}

.perspective-hero img {
  position: absolute;
  z-index: 2;
  right: 2%;
  bottom: -2px;
  width: auto;
  height: 96%;
  max-width: 63%;
  object-fit: contain;
  object-position: right bottom;
  filter: drop-shadow(0 10px 14px rgba(10, 18, 17, 0.28));
}

.perspective-heading {
  position: absolute;
  z-index: 3;
  bottom: 17px;
  left: 18px;
  width: 54%;
  color: #fff;
  text-shadow: 0 2px 12px rgba(8, 13, 13, 0.72);
}

.perspective-heading span {
  display: block;
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 800;
}

.perspective-heading h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 24px;
  font-weight: 600;
}

.perspective-copy {
  padding: 22px 21px calc(26px + var(--safe-bottom));
  background: var(--paper-strong);
  color: #303637;
}

.perspective-copy p {
  margin: 0 0 1.05em;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 14px;
  line-height: 1.9;
  text-align: justify;
  text-indent: 2em;
}

.perspective-copy .perspective-signature {
  margin: 18px 0 0;
  color: var(--forest);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  text-indent: 0;
}

.save-slot {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  min-height: 58px;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf9;
  color: var(--ink);
  text-align: left;
}

.save-slot > strong {
  color: var(--forest-dark);
  font-size: 12px;
}

.save-slot div {
  min-width: 0;
}

.save-slot div strong,
.save-slot div span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-slot div strong {
  font-size: 13px;
}

.save-slot div span,
.save-slot time {
  font-size: 10px;
  color: var(--muted);
}

.log-list {
  display: grid;
  gap: 13px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-list li {
  padding-left: 12px;
  border-left: 3px solid #c7b484;
}

.log-list strong,
.log-list span {
  display: block;
}

.log-list strong {
  margin-bottom: 3px;
  font-size: 12px;
  color: var(--forest-dark);
}

.log-list span {
  font-size: 13px;
  line-height: 1.65;
}

.setting-list {
  display: grid;
  gap: 18px;
}

.setting-row {
  display: grid;
  gap: 7px;
}

.setting-row label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
}

.setting-row input[type="range"] {
  width: 100%;
  accent-color: var(--forest);
}

.status-section + .status-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.status-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--forest-dark);
}

.status-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.status-item {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fffdf9;
}

.status-item span,
.status-item strong {
  display: block;
}

.status-item span {
  margin-bottom: 3px;
  font-size: 10px;
  color: var(--muted);
}

.status-item strong {
  font-size: 13px;
}

@media (max-width: 365px) {
  :root {
    --dialogue-height: 184px;
  }

  .setup-title h1 {
    font-size: 34px;
  }

  .game-tools button {
    min-width: 27px;
    padding: 0 3px;
    font-size: 8px;
  }

  .priority-tools {
    gap: 8px;
  }

  .priority-tools button {
    min-width: 88px;
    padding: 0 9px;
    font-size: 11px;
  }

  .dialogue-box {
    padding-right: 16px;
    padding-left: 16px;
  }

  .dialogue-box p {
    font-size: 14px;
  }
}

@media (min-width: 700px) {
  .setup-title,
  .setup-band {
    width: min(100%, 660px);
    margin-right: auto;
    margin-left: auto;
  }

  .setup-band {
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 8px;
  }

  .tiehe-character {
    right: 14%;
    height: min(64svh, 640px);
  }

  .player-character {
    left: 14%;
    height: min(35svh, 340px);
  }

  .dialogue-box {
    right: 4%;
    bottom: 20px;
    left: 4%;
    min-height: 184px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
  }

  .choice-panel,
  .effect-feedback {
    right: 10%;
    left: 10%;
  }

  .modal-layer {
    align-items: center;
    padding: 24px;
  }

  .modal-panel {
    width: min(100%, 620px);
    max-height: 80svh;
    border: 1px solid rgba(255, 255, 255, 0.42);
    border-radius: 8px;
  }

  .ending-catalog-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
