:root {
  color-scheme: dark;
  --ink: #272923;
  --paper: #f3eee2;
  --paper-deep: #dfd5c2;
  --brick: #8e332e;
  --brick-dark: #62231f;
  --green: #2e594a;
  --mustard: #c29742;
  --blue: #3c6178;
  --line: rgba(240, 235, 223, 0.24);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #20231f;
  color: var(--paper);
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0;
}

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

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(194, 151, 66, 0.65);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.novel-layout {
  width: 100%;
  height: 100dvh;
}

.novel-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #171916;
  isolation: isolate;
}

.visual-field,
.stage-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.visual-field {
  overflow: hidden;
  background: #171916;
  cursor: pointer;
}

.stage-image {
  object-fit: cover;
  object-position: center center;
  transform: scale(1.002);
  transition: opacity 180ms ease, transform 560ms ease;
}

.novel-stage.is-changing .stage-image {
  opacity: 0.2;
  transform: scale(1.02);
}

.stage-image.is-prop {
  padding: 72px 18px 228px;
  background: #191a17;
  object-fit: contain;
  transform: none;
}

.stage-image.is-key-art {
  object-position: center 32%;
}

.mood-portrait {
  position: absolute;
  z-index: 2;
  right: 15px;
  bottom: 190px;
  width: 116px;
  height: 116px;
  border: 3px solid rgba(243, 238, 226, 0.94);
  border-radius: 3px;
  background: var(--paper-deep);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  object-fit: cover;
  transform: rotate(1.5deg);
  animation: portrait-in 250ms ease both;
}

.scene-caption {
  position: absolute;
  z-index: 2;
  top: calc(72px + env(safe-area-inset-top));
  left: 14px;
  max-width: calc(100% - 28px);
  padding: 5px 8px;
  border-left: 3px solid var(--mustard);
  background: rgba(18, 20, 17, 0.78);
  color: #f1eadb;
  font-size: 11px;
  font-weight: 700;
}

.evidence-mark {
  position: absolute;
  z-index: 2;
  top: calc(110px + env(safe-area-inset-top));
  left: 50%;
  padding: 6px 10px;
  border: 1px solid rgba(243, 238, 226, 0.72);
  background: var(--brick);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  transform: translateX(-50%);
}

.stage-header {
  position: absolute;
  z-index: 5;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  min-height: 64px;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 20, 17, 0.82);
}

.brand-block {
  min-width: 0;
  flex: 1;
}

.brand-block span {
  display: block;
  margin-bottom: 1px;
  color: #e9c776;
  font-size: 10px;
  font-weight: 800;
}

.brand-block strong {
  display: block;
  overflow: hidden;
  color: #fff;
  font-family: "SimSun", "Songti SC", serif;
  font-size: 15px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  flex: none;
  gap: 3px;
}

.header-button,
.close-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

a.header-button {
  text-decoration: none;
}

.header-button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.audio-button {
  position: relative;
  font-family: Georgia, serif;
  font-size: 21px;
}

.audio-button span {
  transition: opacity 160ms ease;
}

.audio-button.is-muted span {
  opacity: 0.38;
}

.audio-button.is-muted::after {
  position: absolute;
  width: 20px;
  border-top: 2px solid currentColor;
  content: "";
  transform: rotate(-48deg);
}

.clue-button {
  position: relative;
}

.clue-button b {
  position: absolute;
  top: 2px;
  right: 1px;
  display: grid;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  place-items: center;
  border-radius: 9px;
  background: var(--brick);
  color: #fff;
  font-size: 10px;
}

.progress-track {
  position: absolute;
  right: 0;
  bottom: -2px;
  left: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.14);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--mustard);
  transition: width 300ms ease;
}

.dialogue-panel {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: 178px;
  padding: 19px 60px calc(18px + env(safe-area-inset-bottom)) 18px;
  border-top: 4px solid var(--brick);
  background: rgba(246, 241, 229, 0.96);
  color: var(--ink);
  cursor: pointer;
}

.dialogue-panel.is-ending {
  min-height: 210px;
  border-top-color: var(--mustard);
  text-align: center;
}

.speaker-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 7px;
}

.speaker-line strong {
  color: var(--brick-dark);
  font-family: "SimSun", "Songti SC", serif;
  font-size: 17px;
}

.speaker-line span {
  color: #7b776d;
  font-size: 11px;
}

.frame-title {
  margin: 0 0 7px;
  font-family: "SimSun", "Songti SC", serif;
  font-size: 23px;
  line-height: 1.25;
}

.dialogue-text {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: #353831;
  font-family: "SimSun", "Songti SC", serif;
  font-size: 17px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.advance-button {
  position: absolute;
  right: 14px;
  bottom: calc(17px + env(safe-area-inset-bottom));
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--brick-dark);
  border-radius: 50%;
  background: var(--brick);
  color: #fff;
  cursor: pointer;
}

.advance-button span {
  margin-top: -3px;
  font-size: 32px;
  line-height: 1;
}

.advance-button:hover {
  background: var(--brick-dark);
}

.advance-button:disabled {
  cursor: wait;
  opacity: 0.5;
}

.voice-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  width: 100%;
  max-width: 330px;
  min-height: 46px;
  margin-top: 8px;
  padding: 7px 10px;
  align-items: center;
  gap: 8px;
  border: 1px solid #9fb5a6;
  border-radius: 3px;
  background: #dce7dd;
  color: var(--green);
  cursor: pointer;
  font-size: 12px;
}

.voice-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
}

.voice-wave {
  display: flex;
  align-items: center;
  gap: 3px;
}

.voice-wave i {
  display: block;
  width: 3px;
  height: 9px;
  background: currentColor;
}

.voice-wave i:nth-child(2),
.voice-wave i:nth-child(4) {
  height: 17px;
}

.voice-wave i:nth-child(3) {
  height: 24px;
}

.voice-button.is-playing .voice-wave i {
  animation: wave 520ms ease-in-out infinite alternate;
}

.choice-panel {
  position: absolute;
  z-index: 7;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: 56%;
  overflow-y: auto;
  padding: 18px 14px calc(15px + env(safe-area-inset-bottom));
  border-top: 4px solid var(--mustard);
  background: rgba(29, 32, 28, 0.96);
  color: #fff;
}

.choice-panel p {
  margin: 0 4px 12px;
  font-family: "SimSun", "Songti SC", serif;
  font-size: 18px;
  font-weight: 700;
}

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

.choice-list button {
  position: relative;
  min-height: 50px;
  padding: 10px 40px 10px 13px;
  border: 1px solid rgba(243, 238, 226, 0.52);
  border-radius: 3px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  text-align: left;
}

.choice-list button::after {
  position: absolute;
  top: 50%;
  right: 14px;
  content: "›";
  color: #e9c776;
  font-size: 24px;
  transform: translateY(-54%);
}

.choice-list button:hover {
  border-color: #e9c776;
  background: rgba(255, 255, 255, 0.08);
}

.choice-list button:disabled {
  cursor: wait;
  opacity: 0.5;
}

.transition-mask {
  position: absolute;
  z-index: 6;
  inset: 0;
  background: #121411;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.transition-mask.is-visible {
  opacity: 0.36;
}

.story-journal {
  display: none;
}

dialog {
  max-width: calc(100% - 24px);
  padding: 0;
  border: 1px solid #bfb5a2;
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

dialog::backdrop {
  background: rgba(15, 17, 14, 0.72);
}

.name-dialog {
  width: min(410px, calc(100% - 26px));
}

.name-dialog form {
  padding: 24px 20px 20px;
}

.dialog-kicker {
  margin: 0 0 5px;
  color: var(--brick);
  font-size: 11px;
  font-weight: 800;
}

.name-dialog h2 {
  margin: 0 0 22px;
  font-family: "SimSun", "Songti SC", serif;
  font-size: 23px;
  line-height: 1.35;
}

.name-dialog label {
  display: block;
  margin-bottom: 6px;
  color: #5d5d55;
  font-size: 13px;
  font-weight: 700;
}

.name-dialog input {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid #a89f90;
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 18px;
}

.dialog-actions button {
  min-height: 46px;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--brick-dark);
  background: var(--brick);
  color: #fff;
}

.secondary-button {
  border: 1px solid #a89f90;
  background: transparent;
  color: var(--ink);
}

.sheet-dialog,
.clue-dialog {
  width: min(450px, calc(100% - 18px));
}

.sheet-header {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  padding: 7px 9px 7px 17px;
  border-bottom: 1px solid #d3cab9;
}

.sheet-header .close-button {
  color: var(--ink);
  font-size: 23px;
}

.sheet-actions {
  display: grid;
  padding: 9px 12px 14px;
}

.audio-settings {
  display: grid;
  padding: 2px 0 8px;
  border-bottom: 1px solid #d3cab9;
}

.audio-setting {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.audio-setting input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--brick);
}

.audio-setting input:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.sheet-actions button {
  min-height: 48px;
  padding: 0 6px;
  border: 0;
  border-bottom: 1px solid #d3cab9;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  text-align: left;
}

.sheet-actions button:last-child {
  border-bottom: 0;
  color: var(--brick);
}

.clue-grid {
  display: grid;
  gap: 1px;
  max-height: 68dvh;
  overflow-y: auto;
  padding: 10px 12px 14px;
}

.clue-entry {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid #d3cab9;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.clue-entry img {
  width: 72px;
  height: 72px;
  object-fit: cover;
}

.clue-entry small {
  display: block;
  color: var(--brick);
  font-size: 10px;
  font-weight: 800;
}

.clue-entry strong {
  display: block;
  margin: 1px 0 2px;
  font-family: "SimSun", "Songti SC", serif;
  font-size: 16px;
}

.clue-entry p {
  margin: 0;
  color: #747067;
  font-size: 12px;
  line-height: 1.45;
}

.empty-state {
  padding: 34px 10px;
  color: #7d786e;
  text-align: center;
}

.image-dialog {
  width: min(900px, calc(100% - 18px));
  max-height: calc(100dvh - 20px);
  overflow: hidden;
  border: 0;
  background: #151714;
  color: #fff;
}

.image-dialog img {
  display: block;
  width: 100%;
  max-height: calc(100dvh - 92px);
  object-fit: contain;
}

.image-dialog p {
  margin: 0;
  padding: 10px 50px 12px 13px;
  color: #e5dfd3;
  font-size: 13px;
}

.image-close {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 8px;
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  background: rgba(17, 19, 16, 0.76);
  color: #fff;
  cursor: pointer;
  font-size: 22px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 14px;
  top: calc(72px + env(safe-area-inset-top));
  bottom: auto;
  left: 14px;
  max-width: 390px;
  margin: auto;
  padding: 10px 13px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  background: #242721;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translateY(7px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

@keyframes portrait-in {
  from {
    opacity: 0;
    transform: translateY(8px) rotate(1.5deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(1.5deg);
  }
}

@keyframes wave {
  to {
    height: 23px;
    opacity: 0.42;
  }
}

@media (max-height: 690px) {
  .dialogue-panel {
    min-height: 154px;
    padding-top: 14px;
  }

  .mood-portrait {
    bottom: 165px;
    width: 96px;
    height: 96px;
  }

  .dialogue-text {
    font-size: 16px;
    -webkit-line-clamp: 3;
  }
}

@media (min-width: 900px) {
  body {
    padding: 18px;
  }

  .novel-layout {
    display: grid;
    grid-template-columns: minmax(430px, 500px) minmax(270px, 320px);
    width: min(820px, 100%);
    height: min(900px, calc(100dvh - 36px));
    margin: auto;
    overflow: hidden;
    border: 1px solid rgba(243, 238, 226, 0.28);
    border-radius: 6px;
    box-shadow: 0 22px 58px rgba(0, 0, 0, 0.38);
  }

  .novel-stage {
    border-right: 1px solid #bfb5a2;
  }

  .story-journal {
    display: flex;
    min-width: 0;
    flex-direction: column;
    overflow-y: auto;
    background: #eee8db;
    color: var(--ink);
  }

  .journal-heading {
    padding: 25px 20px 21px;
    background: var(--green);
    color: #fff;
  }

  .journal-heading span,
  .journal-label {
    display: block;
    color: #e7c878;
    font-size: 10px;
    font-weight: 800;
  }

  .journal-heading h2 {
    margin: 5px 0 6px;
    font-family: "SimSun", "Songti SC", serif;
    font-size: 24px;
  }

  .journal-heading p {
    margin: 0;
    color: #d1ddd6;
    font-size: 12px;
  }

  .story-journal section {
    padding: 17px 18px;
    border-bottom: 1px solid #d2c8b6;
  }

  .story-journal section .journal-label {
    color: var(--brick);
  }

  .journal-player {
    display: block;
    margin-top: 3px;
    font-family: "SimSun", "Songti SC", serif;
    font-size: 20px;
    overflow-wrap: anywhere;
  }

  .journal-section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
  }

  .story-journal h3 {
    margin: 0;
    font-size: 14px;
  }

  #clueCount {
    color: #79756c;
    font-size: 11px;
  }

  .journal-clues {
    display: grid;
    gap: 8px;
    margin-top: 10px;
  }

  .journal-clues .clue-entry {
    grid-template-columns: 48px minmax(0, 1fr);
    padding: 5px 0 9px;
  }

  .journal-clues .clue-entry img {
    width: 48px;
    height: 48px;
  }

  .journal-clues .clue-entry p {
    display: none;
  }

  .decision-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    color: #78746b;
    font-size: 12px;
  }

  .decision-item {
    padding-left: 9px;
    border-left: 2px solid var(--mustard);
    color: #4e504a;
  }

  .toast {
    left: calc(50% - 250px);
  }
}

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