:root {
  color-scheme: dark;
  --ink: #f6f1e8;
  --muted: #c8bcad;
  --dim: #8d8377;
  --night: #10100f;
  --panel: rgba(16, 16, 15, 0.82);
  --panel-solid: #1a1816;
  --line: rgba(246, 241, 232, 0.18);
  --gold: #c79a4a;
  --teal: #2f8f8a;
  --wine: #9b2d30;
  --violet: #7970a8;
  --paper: #eadcc5;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  background: var(--night);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    system-ui,
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.scene-image {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.86) contrast(1.05);
  transform: scale(1.03);
  transition:
    opacity 420ms ease,
    filter 420ms ease,
    transform 900ms ease;
  z-index: 0;
}

.scene-shade {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.16) 44%, rgba(0, 0, 0, 0.68)),
    linear-gradient(0deg, rgba(0, 0, 0, 0.84), rgba(0, 0, 0, 0.08) 45%, rgba(0, 0, 0, 0.52));
  z-index: 1;
}

.film-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.18;
  background-image:
    radial-gradient(circle at 14% 21%, rgba(255, 255, 255, 0.18) 0 1px, transparent 1px),
    radial-gradient(circle at 78% 66%, rgba(255, 255, 255, 0.11) 0 1px, transparent 1px);
  background-size: 23px 23px, 31px 31px;
  mix-blend-mode: soft-light;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 16px clamp(16px, 3vw, 34px);
}

.brand-mark {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--paper);
  letter-spacing: 0;
}

.brand-mark span {
  font-size: 16px;
  font-weight: 700;
}

.brand-mark small {
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 12, 12, 0.38);
  color: var(--ink);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: rgba(199, 154, 74, 0.85);
  background: rgba(199, 154, 74, 0.15);
  outline: none;
  transform: translateY(-1px);
}

.icon-button.dark {
  background: rgba(0, 0, 0, 0.28);
}

.layout {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 20px;
  min-height: calc(100vh - 64px);
  padding: 14px clamp(16px, 3vw, 34px) 28px;
}

.home-mode .layout {
  grid-template-columns: minmax(0, 1fr);
}

.home-panel {
  display: grid;
  align-content: center;
  min-height: calc(100vh - 120px);
  max-width: 760px;
}

.title-block {
  max-width: 680px;
}

.kicker {
  margin: 0 0 16px;
  color: var(--gold);
  font-size: 14px;
}

h1 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(56px, 10vw, 122px);
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 0 14px 50px var(--shadow);
}

.subtitle {
  max-width: 520px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.75;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 34px;
}

.primary-action,
.plain-action,
.choice-button {
  border: 1px solid rgba(246, 241, 232, 0.18);
  border-radius: 8px;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.primary-action {
  min-height: 46px;
  padding: 0 22px;
  background: var(--paper);
  color: #171411;
  font-weight: 700;
}

.primary-action:hover,
.primary-action:focus-visible {
  background: #fff0d2;
  outline: none;
  transform: translateY(-1px);
}

.primary-action.compact {
  width: fit-content;
  min-height: 40px;
}

.plain-action {
  min-height: 46px;
  padding: 0 18px;
  background: rgba(10, 10, 10, 0.42);
  color: var(--ink);
}

.plain-action:hover,
.plain-action:focus-visible,
.choice-button:hover,
.choice-button:focus-visible {
  border-color: rgba(199, 154, 74, 0.88);
  background: rgba(199, 154, 74, 0.14);
  outline: none;
  transform: translateY(-1px);
}

.plain-action:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

.disclaimer {
  max-width: 640px;
  margin: 34px 0 0;
  color: rgba(246, 241, 232, 0.62);
  font-size: 12px;
  line-height: 1.8;
}

.game-panel {
  align-self: end;
  display: grid;
  gap: 12px;
  max-width: 860px;
}

.scene-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--paper);
}

.scene-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(16, 16, 15, 0.46);
  font-size: 12px;
}

.story-panel,
.terminal-panel,
.heartbeat-panel,
.side-panel,
.modal-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px var(--shadow);
  backdrop-filter: blur(18px);
}

.story-panel {
  min-height: 340px;
  padding: clamp(18px, 3vw, 28px);
}

.speaker {
  min-height: 22px;
  margin: 0 0 14px;
  color: var(--gold);
  font-weight: 700;
}

.story-text {
  display: grid;
  gap: 13px;
  color: var(--ink);
  font-size: clamp(16px, 1.8vw, 19px);
  line-height: 1.86;
}

.story-text p {
  margin: 0;
}

.choices {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.choice-button {
  width: 100%;
  min-height: 52px;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  text-align: left;
  line-height: 1.55;
}

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

.side-panel {
  align-self: end;
  display: grid;
  gap: 18px;
  padding: 18px;
}

.side-section h2 {
  margin: 0 0 10px;
  color: var(--paper);
  font-size: 14px;
}

.inventory-list,
.route-summary {
  display: grid;
  gap: 8px;
}

.inventory-pill,
.memory-line {
  border-left: 3px solid var(--teal);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.memory-line:nth-child(2n) {
  border-left-color: var(--wine);
}

.terminal-panel {
  padding: 20px;
  background: rgba(7, 8, 7, 0.9);
}

.terminal-log {
  display: grid;
  gap: 8px;
  min-height: 210px;
  max-height: 330px;
  overflow: auto;
  color: #d6f7d0;
  font-family:
    "Cascadia Mono",
    Consolas,
    monospace;
  font-size: 14px;
  line-height: 1.6;
}

.terminal-line.user {
  color: #f5e3a8;
}

.terminal-line.ai {
  color: #b6f1df;
}

.terminal-form {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  border-top: 1px solid rgba(214, 247, 208, 0.2);
  padding-top: 12px;
  color: #d6f7d0;
  font-family:
    "Cascadia Mono",
    Consolas,
    monospace;
}

.terminal-form input {
  width: 100%;
  border: 0;
  background: transparent;
  color: #d6f7d0;
  outline: none;
}

.heartbeat-panel {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.pulse-field {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
}

.heart-button {
  width: 132px;
  aspect-ratio: 1;
  border: 1px solid rgba(155, 45, 48, 0.7);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #e36f6d, #9b2d30 58%, #431212);
  color: #fff2ea;
  cursor: pointer;
  box-shadow: 0 0 42px rgba(155, 45, 48, 0.42);
  transition: transform 90ms ease;
}

.heart-button:active,
.heart-button.pulsing {
  transform: scale(0.94);
}

.heart-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7);
}

.heartbeat-readout {
  display: grid;
  gap: 6px;
}

.heartbeat-readout span {
  color: var(--paper);
  font-size: 54px;
  font-weight: 800;
  line-height: 1;
}

.heartbeat-readout small {
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.58);
}

.modal-panel {
  width: min(860px, 100%);
  max-height: min(760px, 88vh);
  overflow: hidden;
  background: rgba(26, 24, 22, 0.96);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.modal-head h2 {
  margin: 0;
  color: var(--paper);
  font-size: 18px;
}

.modal-body {
  max-height: calc(88vh - 76px);
  overflow: auto;
  padding: 18px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.modal-card {
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.045);
}

.modal-card img {
  width: 100%;
  height: 102px;
  object-fit: cover;
  display: block;
}

.modal-card button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  padding: 10px;
}

.modal-card p {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  line-height: 1.65;
}

.ending-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  margin: 0 8px 8px 0;
  padding: 0 10px;
  background: rgba(121, 112, 168, 0.2);
  color: var(--paper);
  font-size: 12px;
}

[hidden] {
  display: none !important;
}

.source-page {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 52px 0;
  color: var(--ink);
}

.source-page h1 {
  font-size: clamp(36px, 7vw, 72px);
}

.source-page p,
.source-page li {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.85;
}

@media (max-width: 880px) {
  .topbar {
    min-height: 58px;
    padding: 12px 14px;
  }

  .brand-mark small {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: calc(100vh - 58px);
    padding: 10px 14px 22px;
  }

  .home-panel {
    min-height: calc(100vh - 94px);
  }

  .game-panel,
  .side-panel {
    align-self: stretch;
  }

  .story-panel {
    min-height: 300px;
  }

  .side-panel {
    padding: 14px;
  }

  .pulse-field {
    grid-template-columns: 1fr;
  }

  .heart-button {
    width: min(132px, 42vw);
  }
}

@media (max-width: 520px) {
  .topbar-actions {
    gap: 6px;
  }

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

  h1 {
    font-size: 54px;
  }

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

  .primary-action,
  .plain-action {
    width: 100%;
  }

  .scene-meta span {
    max-width: 100%;
  }
}
