:root {
  --ink: #1c1010;
  --muted: #785f55;
  --paper: #f7ead4;
  --paper-deep: #e7cfa9;
  --red: #8e2018;
  --red-deep: #4b1110;
  --gold: #d4a64f;
  --jade: #367461;
  --shadow: 0 24px 70px rgba(34, 12, 8, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--paper);
  background:
    radial-gradient(circle at 18% 10%, rgba(212, 166, 79, 0.18), transparent 28%),
    linear-gradient(135deg, #210909 0%, #3e1010 42%, #160a0a 100%);
  font-family: "Noto Serif SC", "Songti SC", "Microsoft YaHei", serif;
}

button {
  font: inherit;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(21, 7, 6, 0.8), rgba(21, 7, 6, 0.36)),
    url("assets/palace-background.png") center / cover;
}

.start-screen.hidden {
  display: none;
}

.start-card {
  width: min(560px, 100%);
  padding: 34px;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 246, 226, 0.96), rgba(231, 207, 169, 0.96));
  border: 1px solid rgba(245, 214, 135, 0.76);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.start-card h1 {
  color: var(--red-deep);
  text-shadow: none;
}

.start-card p {
  color: #5c3d31;
  line-height: 1.7;
}

.start-card label {
  display: block;
  margin: 20px 0 8px;
  color: var(--red);
  font-weight: 800;
}

.start-card input {
  width: 100%;
  border: 1px solid rgba(104, 31, 21, 0.24);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--ink);
  background: rgba(255, 251, 239, 0.8);
  font: inherit;
}

.start-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.start-actions button {
  border: 1px solid rgba(104, 31, 21, 0.24);
  border-radius: 8px;
  padding: 13px 14px;
  color: #fff4d4;
  background: var(--red);
  cursor: pointer;
}

.start-actions button:disabled {
  cursor: not-allowed;
  color: #6d574d;
  background: #d7c4a3;
}

.game-shell {
  width: min(1420px, calc(100vw - 32px));
  margin: 16px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
}

.stage {
  position: relative;
  min-height: calc(100vh - 32px);
  overflow: hidden;
  border: 1px solid rgba(226, 181, 91, 0.4);
  border-radius: 10px;
  box-shadow: var(--shadow);
  background: #25100d;
}

.scene-art,
.scene-vignette {
  position: absolute;
  inset: 0;
}

.scene-art {
  background-image: url("assets/palace-background.png");
  background-size: cover;
  background-position: center;
  filter: saturate(1.06) contrast(1.02);
}

.scene-vignette {
  background:
    linear-gradient(90deg, rgba(24, 9, 7, 0.78), transparent 30%, rgba(24, 9, 7, 0.58)),
    linear-gradient(0deg, rgba(19, 6, 6, 0.82), transparent 56%);
}

.topbar,
.character-card,
.court-list,
.dialogue-panel {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 28px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.label {
  margin: 0 0 6px;
  color: #f2d48b;
  font-size: 12px;
  letter-spacing: 0.2em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: 1.05;
  text-shadow: 0 3px 24px rgba(0, 0, 0, 0.42);
}

.ghost-button,
.archive-panel button {
  border: 1px solid rgba(244, 213, 143, 0.5);
  color: #fff2cf;
  background: rgba(55, 18, 14, 0.58);
  border-radius: 7px;
  padding: 10px 16px;
  cursor: pointer;
}

.character-card {
  width: 290px;
  margin-left: 28px;
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  background: rgba(26, 9, 8, 0.72);
  border: 1px solid rgba(226, 181, 91, 0.44);
  border-radius: 8px;
  backdrop-filter: blur(12px);
}

.portrait {
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  flex: none;
  color: #2b120a;
  background: linear-gradient(145deg, #ffe6a5, #b9852f);
  border-radius: 50%;
  font-size: 28px;
  font-weight: 800;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.character-card h2 {
  margin-bottom: 5px;
  font-size: 24px;
}

.character-card p:last-child {
  margin-bottom: 0;
  color: #e7d7bd;
}

.address-name {
  margin: 6px 0 0;
  color: #f2d48b !important;
  font-size: 13px;
}

.court-list {
  width: 255px;
  margin: 18px 28px 0 auto;
  padding: 16px;
  background: rgba(247, 234, 212, 0.88);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.court-list h2,
.map-panel h2,
.archive-panel h2 {
  margin-bottom: 12px;
  font-size: 18px;
}

.person {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid rgba(100, 56, 36, 0.18);
}

.person:first-of-type {
  border-top: 0;
}

.mini {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #7c1d17;
  color: #f9e2a9;
  font-weight: 700;
}

.person strong {
  display: block;
  font-size: 14px;
}

.person span {
  color: var(--muted);
  font-size: 12px;
}

.relation {
  color: var(--red);
  font-size: 12px;
}

.dialogue-panel {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 28px;
  padding: 22px;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 246, 226, 0.95), rgba(231, 207, 169, 0.96));
  border: 1px solid rgba(255, 236, 181, 0.75);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.speaker-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--red);
  font-weight: 800;
}

#storyText {
  min-height: 76px;
  margin: 10px 0 18px;
  color: #2a1610;
  font-size: 18px;
  line-height: 1.75;
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.choice {
  min-height: 64px;
  border: 1px solid rgba(104, 31, 21, 0.22);
  border-radius: 8px;
  padding: 13px 14px;
  color: #2b130e;
  background: rgba(255, 251, 239, 0.74);
  cursor: pointer;
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.choice:hover,
.choice:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(142, 32, 24, 0.65);
  background: #fff7df;
  outline: none;
}

.choice small {
  display: block;
  margin-top: 6px;
  color: #7a5d51;
}

.control-deck {
  min-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.meters,
.map-panel,
.archive-panel {
  padding: 18px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(226, 181, 91, 0.5);
  border-radius: 10px;
  box-shadow: 0 14px 42px rgba(24, 8, 6, 0.24);
}

.meters {
  display: grid;
  gap: 15px;
}

.meter {
  display: grid;
  grid-template-columns: 52px 32px 1fr;
  gap: 10px;
  align-items: center;
}

.meter span {
  color: #5b3528;
  font-size: 14px;
}

.meter strong {
  text-align: right;
}

.meter div {
  height: 9px;
  overflow: hidden;
  background: #d9c09a;
  border-radius: 999px;
}

.meter i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold));
  transition: width 220ms ease;
}

.score-meter i {
  background: linear-gradient(90deg, var(--jade), var(--gold));
}

.chapter-panel {
  padding: 18px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(226, 181, 91, 0.5);
  border-radius: 10px;
  box-shadow: 0 14px 42px rgba(24, 8, 6, 0.24);
}

.chapter-panel h2 {
  margin-bottom: 12px;
  font-size: 18px;
}

.chapter-track {
  display: grid;
  gap: 8px;
}

.chapter-step {
  position: relative;
  padding: 10px 12px;
  border: 1px solid rgba(76, 44, 32, 0.14);
  border-radius: 8px;
  background: rgba(255, 251, 239, 0.48);
}

.chapter-step.active {
  color: #fff8df;
  background: linear-gradient(135deg, var(--red), var(--red-deep));
}

.chapter-step.done {
  background: rgba(54, 116, 97, 0.14);
}

.chapter-step strong,
.chapter-step span,
.chapter-step em {
  display: block;
}

.chapter-step strong {
  font-size: 13px;
}

.chapter-step span,
.chapter-step em {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.chapter-step.active span,
.chapter-step.active em {
  color: #f0d6b8;
}

.map-grid {
  display: grid;
  gap: 9px;
}

.place {
  padding: 12px;
  border: 1px solid rgba(76, 44, 32, 0.16);
  border-radius: 8px;
  background: rgba(255, 251, 239, 0.55);
}

.place.active {
  color: #fff8df;
  background: linear-gradient(135deg, var(--red), var(--red-deep));
  border-color: rgba(245, 208, 117, 0.62);
}

.place strong {
  display: block;
  margin-bottom: 4px;
}

.place span,
.archive-panel p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.place.active span {
  color: #f0d6b8;
}

.archive-panel {
  margin-top: auto;
}

.archive-panel button {
  width: 100%;
  margin-top: 8px;
  color: #fff4d4;
  background: var(--red);
}

.ending .dialogue-panel {
  background: linear-gradient(180deg, rgba(42, 12, 12, 0.96), rgba(106, 23, 17, 0.96));
  color: #fff3d4;
}

.ending #storyText,
.checkpoint #storyText,
.ending .speaker-row {
  color: #fff3d4;
}

.checkpoint .dialogue-panel {
  background: linear-gradient(180deg, rgba(52, 22, 12, 0.94), rgba(117, 43, 18, 0.96));
  color: #fff3d4;
}

@media (max-width: 1040px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .stage,
  .control-deck {
    min-height: 760px;
  }

  .control-deck {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .game-shell {
    width: 100%;
    margin: 0;
  }

  .stage {
    min-height: 820px;
    border-radius: 0;
  }

  .topbar {
    padding: 18px;
    gap: 12px;
  }

  .top-actions {
    flex-direction: column;
  }

  h1 {
    max-width: 260px;
    font-size: 34px;
  }

  .ghost-button {
    padding: 8px 12px;
  }

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

  .character-card,
  .court-list {
    width: auto;
    margin: 12px 18px 0;
  }

  .court-list {
    display: none;
  }

  .dialogue-panel {
    left: 14px;
    right: 14px;
    bottom: 14px;
    padding: 16px;
  }

  .choices {
    grid-template-columns: 1fr;
  }

  #storyText {
    font-size: 16px;
  }
}
