:root {
  color-scheme: dark;
  --ink: #f6f0e7;
  --muted: #b8c3c4;
  --dim: #6f8583;
  --paper: rgba(17, 23, 25, 0.76);
  --paper-strong: rgba(9, 13, 15, 0.9);
  --line: rgba(246, 240, 231, 0.2);
  --accent: #e6b15f;
  --accent-strong: #ffd58e;
  --danger: #f26d6d;
  --teal: #62d0c3;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  --radius: 8px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  place-items: stretch;
}

.stage {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  background: #0b0f10;
  isolation: isolate;
}

.background {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.035);
  transition: opacity 700ms ease, transform 1600ms ease;
  z-index: -4;
}

.background.is-active {
  opacity: 1;
  transform: scale(1);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(4, 8, 9, 0.66) 0%, rgba(4, 8, 9, 0.24) 42%, rgba(4, 8, 9, 0.58) 100%),
    linear-gradient(180deg, rgba(6, 9, 10, 0.08), rgba(6, 9, 10, 0.72) 86%);
  z-index: -3;
  pointer-events: none;
}

.weather-layer {
  position: absolute;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 500ms ease;
}

.weather-layer.rain {
  opacity: 0.4;
  background-image:
    repeating-linear-gradient(104deg, rgba(208, 236, 231, 0.26) 0 1px, transparent 1px 10px);
  background-size: 190px 190px;
  animation: rainFall 820ms linear infinite;
}

.weather-layer.dust {
  opacity: 0.25;
  background-image:
    radial-gradient(circle at 12% 24%, rgba(255, 221, 165, 0.48) 0 1px, transparent 2px),
    radial-gradient(circle at 78% 64%, rgba(98, 208, 195, 0.35) 0 1px, transparent 2px);
  background-size: 160px 110px, 230px 170px;
  animation: dustDrift 10s ease-in-out infinite alternate;
}

.light-sweep {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(114deg, transparent 0 46%, rgba(255, 205, 128, 0.12) 50%, transparent 58% 100%);
  transform: translateX(-42%);
  animation: sweep 8s ease-in-out infinite;
  mix-blend-mode: screen;
}

.title-screen,
.game-screen {
  position: absolute;
  inset: 0;
}

.title-screen {
  display: grid;
  align-items: end;
  padding: clamp(28px, 6vw, 88px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 420ms ease, visibility 420ms ease;
}

.title-screen.is-active {
  opacity: 1;
  visibility: visible;
}

.title-copy {
  width: min(720px, 100%);
  transform: translateY(16px);
  animation: riseIn 720ms ease forwards;
}

.kicker {
  margin: 0 0 12px;
  color: var(--accent-strong);
  font-size: clamp(14px, 1.6vw, 18px);
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-family: "Microsoft YaHei UI", "Noto Serif SC", serif;
  font-size: clamp(54px, 11vw, 132px);
  line-height: 0.94;
  letter-spacing: 0;
  text-wrap: balance;
}

.tagline {
  width: min(560px, 100%);
  margin: 20px 0 28px;
  color: #efe7dc;
  font-size: clamp(17px, 2.4vw, 24px);
  line-height: 1.6;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.primary-action,
.ghost-action,
.danger-action,
.choice-button,
.slot-button {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 11px 18px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.primary-action {
  background: var(--accent);
  color: #1a130c;
  font-weight: 800;
}

.ghost-action,
.danger-action,
.slot-button {
  background: rgba(12, 17, 19, 0.52);
  border: 1px solid var(--line);
  color: var(--ink);
  backdrop-filter: blur(16px);
}

.danger-action {
  width: 100%;
  margin-top: 12px;
  color: #ffd6d6;
  border-color: rgba(242, 109, 109, 0.45);
}

.primary-action:hover,
.ghost-action:hover,
.danger-action:hover,
.choice-button:hover,
.slot-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.game-screen {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: clamp(14px, 2.2vw, 28px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 420ms ease, visibility 420ms ease;
}

.game-screen.is-active {
  opacity: 1;
  visibility: visible;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
}

.chapter-label {
  display: block;
  color: var(--accent-strong);
  font-size: 13px;
  margin-bottom: 3px;
}

#scenePlace {
  display: block;
  max-width: min(44vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(16px, 1.8vw, 20px);
}

.quick-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip {
  width: min(760px, 100%);
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.status-strip span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius);
  padding: 5px 10px;
  color: #efe7dc;
  background: rgba(8, 13, 14, 0.54);
  border: 1px solid rgba(246, 240, 231, 0.14);
  backdrop-filter: blur(14px);
  font-size: 13px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: inline-grid;
  place-items: center;
  background: rgba(9, 14, 15, 0.58);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  font-size: 14px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button.is-active {
  background: rgba(255, 180, 92, 0.22);
  border-color: rgba(255, 180, 92, 0.7);
}

.character-zone {
  position: relative;
  display: grid;
  align-items: end;
  justify-items: center;
  min-height: 0;
  pointer-events: none;
}

.character {
  width: min(42vw, 430px);
  max-height: calc(100svh - 250px);
  object-fit: contain;
  opacity: 0;
  transform: translateY(20px) scale(0.985);
  filter: drop-shadow(0 28px 42px rgba(0, 0, 0, 0.46));
  transition: opacity 360ms ease, transform 420ms ease, filter 420ms ease;
}

.character.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.character.left {
  justify-self: start;
  margin-left: clamp(18px, 12vw, 220px);
}

.character.right {
  justify-self: end;
  margin-right: clamp(18px, 12vw, 220px);
}

.dialogue-box {
  align-self: end;
  width: min(1040px, 100%);
  min-height: 164px;
  margin: 0 auto;
  padding: clamp(18px, 2.4vw, 26px);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(17, 23, 25, 0.86), rgba(8, 12, 14, 0.88));
  border: 1px solid rgba(246, 240, 231, 0.22);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  cursor: pointer;
}

.speaker-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.speaker-name {
  color: var(--accent-strong);
  font-weight: 800;
  font-size: 18px;
}

.progress-hint {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.dialogue-text {
  min-height: 70px;
  margin: 0;
  color: #fbf7ef;
  font-size: clamp(18px, 2.1vw, 24px);
  line-height: 1.72;
}

.choice-panel {
  position: absolute;
  left: 50%;
  bottom: clamp(214px, 26vh, 300px);
  width: min(680px, calc(100% - 32px));
  transform: translateX(-50%);
  display: grid;
  gap: 10px;
  z-index: 4;
  pointer-events: none;
}

.consequence-toast {
  position: absolute;
  left: 50%;
  top: 96px;
  max-width: min(560px, calc(100% - 32px));
  transform: translate(-50%, -10px);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: #21170d;
  background: rgba(255, 213, 142, 0.92);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
  z-index: 12;
  font-size: 14px;
}

.consequence-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.choice-panel.is-active {
  pointer-events: auto;
}

.choice-button {
  width: 100%;
  min-height: 54px;
  text-align: left;
  background: rgba(14, 20, 21, 0.86);
  border: 1px solid rgba(255, 180, 92, 0.35);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(12px);
  animation: choiceIn 260ms ease forwards;
}

.choice-button small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.choice-button.is-disabled,
.choice-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  border-color: rgba(246, 240, 231, 0.16);
  transform: none;
}

.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(460px, 100%);
  height: 100%;
  padding: 22px;
  background: rgba(7, 10, 11, 0.92);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(20px);
  transform: translateX(104%);
  transition: transform 260ms ease;
  z-index: 20;
  overflow: auto;
}

.side-panel.is-open {
  transform: translateX(0);
}

.side-panel.compact {
  width: min(380px, 100%);
}

.side-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.side-panel h2 {
  margin: 0;
  font-size: 22px;
}

.history-list,
.slot-list,
.ending-list {
  display: grid;
  gap: 12px;
}

.history-item,
.ending-item,
.empty-note {
  padding: 12px 0;
  border-bottom: 1px solid rgba(246, 240, 231, 0.12);
}

.history-item strong,
.ending-item strong {
  display: block;
  color: var(--accent-strong);
  margin-bottom: 6px;
}

.history-item p,
.ending-item p,
.empty-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.slot-button {
  display: block;
  width: 100%;
  text-align: left;
}

.slot-button strong {
  display: block;
  margin-bottom: 5px;
}

.slot-button span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.setting-row,
.setting-check {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  color: var(--muted);
}

.setting-row input {
  width: 100%;
  accent-color: var(--accent);
}

.setting-check {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.setting-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(22px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes choiceIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sweep {
  0%,
  58% {
    transform: translateX(-48%);
    opacity: 0;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translateX(54%);
    opacity: 0;
  }
}

@keyframes rainFall {
  to {
    background-position: 0 190px;
  }
}

@keyframes dustDrift {
  to {
    background-position: 38px 20px, -32px 28px;
  }
}

@media (max-width: 720px) {
  html,
  body {
    overflow: auto;
  }

  .stage {
    min-height: 100svh;
  }

  .game-screen {
    padding: 12px;
    grid-template-rows: auto auto minmax(240px, 1fr) auto;
  }

  .topbar {
    align-items: flex-start;
  }

  .quick-controls {
    gap: 6px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 12px;
  }

  .character {
    width: min(68vw, 300px);
    max-height: 46svh;
  }

  .character.left,
  .character.right {
    justify-self: center;
    margin: 0;
  }

  .dialogue-box {
    min-height: 188px;
    padding: 16px;
  }

  .dialogue-text {
    font-size: 18px;
  }

  .choice-panel {
    bottom: 218px;
  }

  .status-strip {
    gap: 6px;
  }

  .status-strip span {
    font-size: 12px;
    padding: 4px 8px;
  }

  .title-screen {
    padding: 24px;
  }

  .title-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

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