:root {
  --ink: #25332a;
  --jade: #244239;
  --jade-dark: #1c3029;
  --muted: #655e4b;
  --paper: #f2ead8;
  --sheet: #faf4e6;
  --edge: #cdbb97;
  --gold: #d5be8c;
  --seal: #9a3d2b;
  --seal-dark: #79301f;
  --display: "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
}

body {
  color: var(--ink);
  background:
    radial-gradient(ellipse at 58% 0%, #f6efde 8%, transparent 67%),
    #e6d9bf;
  font: 15px/1.8 "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  overflow-wrap: anywhere;
}

.container {
  max-width: none;
  background: none;
  box-shadow: none;
}

button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 3px;
}

.cover {
  width: min(1360px, calc(100% - 72px));
  min-height: min(730px, calc(100dvh - 88px));
  margin: 44px auto;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(360px, 1fr);
  border: 1px solid #b3a078;
  background: var(--sheet);
  box-shadow: 0 16px 56px #35261429;
}

.cover-art { position: relative; min-width: 0; background: #b59d77; }
.cover-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 65% 50%;
}
.cover-art::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid #f7ecd6ab;
  pointer-events: none;
}
.cover-sheet {
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  padding: clamp(32px, 4.3vw, 75px);
  background: radial-gradient(ellipse at 100% 0%, #dfd1ad63, transparent 70%);
}
.cover-sheet::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid #aa966951;
  pointer-events: none;
}
.cover-heading { position: relative; align-self: flex-start; padding-right: 56px; }
.cover h1 {
  font: 700 clamp(70px, 9.2vw, 142px)/0.95 var(--display);
  color: var(--jade-dark);
  letter-spacing: 0.055em;
  margin: 0 0 27px;
}
.cover h1 small {
  display: block;
  margin-top: 18px;
  font-size: clamp(22px, 2.4vw, 35px);
  font-weight: 600;
  letter-spacing: 0.28em;
  line-height: 1.35;
}
.cover-seal {
  position: absolute;
  right: 1px;
  top: 0.7rem;
  background: var(--seal);
  color: #fff2d8;
  border: 1px solid var(--seal);
  box-shadow: inset 0 0 0 2px #ecd4a7;
  padding: 5px 7px;
  font: 700 14px/1.15 var(--display);
}
.cover-intro { max-width: 27em; color: var(--muted); line-height: 2; margin: 0 0 32px; }
.cover form { max-width: 380px; padding-top: 18px; border-top: 1px solid var(--edge); }
.cover label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.cover-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
.cover .name-input {
  width: 100%;
  min-width: 0;
  margin: 0;
  text-align: left;
  color: var(--ink);
  border-color: #b9a986;
  border-radius: 2px;
  background: #fffaf0;
  padding: 11px 12px;
}
.start-btn {
  display: inline-block;
  min-height: 46px;
  color: #fff6e6;
  background: var(--seal);
  border: 1px solid var(--seal-dark);
  border-radius: 2px;
  padding: 9px 28px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.17em;
}
.cover .start-btn { padding: 9px 18px; white-space: nowrap; }
.start-btn:hover { background: var(--seal-dark); }
.start-credit {
  display: flex;
  flex-wrap: wrap;
  column-gap: 12px;
  row-gap: 1px;
  color: var(--muted);
  font-size: 11px;
  margin-top: 32px;
}

.game-shell { max-width: 1340px; margin-inline: auto; min-height: 100dvh; }
.topbar {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(260px, 1.3fr) minmax(240px, 1.2fr);
  align-items: center;
  gap: 20px;
  padding: max(13px, env(safe-area-inset-top)) 22px 13px;
  color: #fff4dc;
  background: linear-gradient(110deg, var(--jade-dark), var(--jade));
  border-bottom: 2px solid #ad9362;
}
.topbar-identity { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar-title { text-align: start; font: 700 22px/1.2 var(--display); margin: 0; }
#quitBtn {
  min-height: 36px;
  flex: 0 0 auto;
  color: #fff4dc;
  cursor: pointer;
  background: #ffffff0c;
  border: 1px solid #f2dcab66;
  border-radius: 2px;
  padding: 2px 9px;
  font-size: 12px;
}
#quitBtn:hover { background: #ffffff1c; }
.topbar-stats { justify-content: center; gap: 4px 14px; font-size: 13px; }
.stat-item span { color: #f2d19a; }
.topbar .rank-badge { background: #9a4936; padding: 3px 6px; font-size: 11px; font-weight: 600; line-height: 1.3; }
.topbar .bars { margin: 0; gap: 12px; }
.bar-label { gap: 6px; }
.bar-bg { background: #d1cc9d38; }
.bar-fatigue .bar-fill { background: #dbaf66; }
.bar-mood .bar-fill { background: #a9c891; }
.bar-health .bar-fill { background: #d99784; }

.main {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(0, 1.5fr) minmax(126px, 0.38fr);
  grid-template-areas: "status story actions";
  align-items: start;
  gap: 18px;
  padding: 22px 22px 40px;
}
.status-sheet { grid-area: status; min-width: 0; }
.chronicle { grid-area: story; min-width: 0; }
.chronicle-art, .story-illustration {
  background: #ae9772 url("./assets/palace.jpg") center 53% / cover no-repeat;
  border: 1px solid #a9956d;
  box-shadow: inset 0 0 0 5px #f3e5c37a;
}
.chronicle-art { height: clamp(132px, 18vw, 235px); margin-bottom: 14px; }
.panel, .log-area {
  background: var(--sheet);
  border: 1px solid var(--edge);
  border-radius: 2px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.panel-house { background: #edf0e0; border-color: #bec5a8; }
.panel-title {
  color: var(--jade-dark);
  font: 700 16px/1.4 var(--display);
  border-color: var(--edge);
}
button.panel-title {
  width: 100%;
  min-height: 34px;
  padding: 0 0 6px;
  text-align: start;
  cursor: pointer;
  background: transparent;
  border: solid var(--edge);
  border-width: 0 0 1px;
}
.attr-grid { gap: 7px 13px; font-size: 13px; }
.attr-row { gap: 6px; align-items: baseline; }
.attr-name, .attr-desc, .panel-title-sub { color: var(--muted); }
.attr-val { color: var(--seal-dark); text-align: right; }
.log-area { max-height: none; overflow: visible; }
.log-area .panel-body { overflow-y: auto; max-height: 55vh; overscroll-behavior: contain; }
.log-entry { padding: 9px 0; font-size: 14px; }
.log-date { color: var(--muted); font-size: 11px; }

.action-bar {
  grid-area: actions;
  position: sticky;
  top: 88px;
  left: auto;
  bottom: auto;
  transform: none;
  padding: 10px;
  width: 100%;
  max-width: none;
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
  border: 1px solid #b8a480;
  background: #f6eddb;
}
.action-btn {
  min-width: 0;
  min-height: 44px;
  background: #eae2ce;
  color: var(--jade-dark);
  border: 1px solid #c9b794;
  border-radius: 2px;
  padding: 7px 4px;
  font-size: 14px;
  font-weight: 650;
}
.action-btn:hover { background: #ddd2b9; }
.action-btn:active { background: #d0bf9a; }
.action-btn:disabled { color: #706958; background: #f2ebde; border-color: #d6c9b1; }
#workBtn:not(:disabled) { color: #fff6e6; background: var(--seal); border-color: var(--seal-dark); }
#workBtn:not(:disabled):hover { background: var(--seal-dark); }
#saveBtn { color: var(--jade-dark); background: #dce5d4; border-color: #aeba9d; }

.origin-screen, .ending-screen {
  width: min(730px, calc(100% - 32px));
  margin: 24px auto;
  padding: clamp(17px, 4vw, 42px);
  background: var(--sheet);
  border: 1px solid var(--edge);
  box-shadow: 0 12px 35px #35261423;
}
.story-illustration { height: clamp(115px, 24vw, 225px); margin-bottom: 24px; }
.origin-screen .game-title, .ending-title { color: var(--jade-dark); font: 700 31px/1.3 var(--display); letter-spacing: 0.08em; }
.origin-screen .game-subtitle { color: var(--muted); margin-bottom: 16px; }
.origin-story, .ending-text {
  color: var(--ink);
  font-size: 16px;
  line-height: 2;
  text-align: start;
  white-space: pre-line;
  margin: 0 0 20px;
}
.ending-cond { padding: 13px 0; color: var(--muted); border-top: 1px solid var(--edge); }

.modal-overlay { background: #18251fc4; padding-inline: 12px; }
.modal {
  width: min(100%, 570px);
  max-width: none;
  padding: clamp(16px, 5vw, 28px);
  background: var(--sheet);
  border: 1px solid #aa9265;
  border-top: 5px solid var(--jade);
  border-radius: 3px;
  box-shadow: 0 12px 45px #1016116b;
}
.modal-title { color: var(--jade-dark); font: 700 23px/1.35 var(--display); padding-bottom: 10px; }
.modal-text { color: var(--ink); font-size: 15px; line-height: 1.95; }
/* 通知弹窗：重大事件与数值变动先于剧情播放，用左侧色条区分性质。 */
.modal-title.notice-good { color: var(--jade-dark); }
.modal-title.notice-bad { color: var(--seal-dark); }
.modal-title.notice-favor { color: var(--jade-dark); }
.notice-text {
  border-left: 3px solid var(--jade);
  padding-left: 12px;
  background: #fffaf0;
  padding-block: 8px;
}
.notice-bad .notice-text,
.notice-text.notice-bad { border-left-color: var(--seal-dark); }
.modal-title.notice-bad + .notice-text { border-left-color: var(--seal-dark); }
.notice-rest { color: #7a7566; font-size: 12px; margin-top: 8px; }
.modal-btn, .slot-btn, .child-btn {
  min-height: 44px;
  border-radius: 2px;
  color: var(--jade-dark);
  background: #eee6d2;
  border: 1px solid var(--edge);
}
.modal-btn:hover, .slot-btn:hover, .child-btn:hover { background: #ddd2b9; color: var(--jade-dark); }
.slot-btn.primary { color: #fff6e6; background: var(--jade); border-color: var(--jade-dark); }
.slot-row { background: #fffaf0; }
.toast { width: max-content; max-width: calc(100% - 32px); background: var(--jade-dark); }

.container { display: flow-root; }
.form-error { color: var(--seal-dark); font-size: 13px; margin-top: 7px; }
.form-error:empty { display: none; }
.cover-load {
  align-self: flex-start;
  margin-top: 20px;
  color: var(--jade-dark);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--edge);
  cursor: pointer;
  min-height: 44px;
}
.player-heading { min-width: 0; }
.topbar-title {
  max-height: 3.7em;
  overflow: auto;
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
}
.quiet-btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 4px 9px;
  border: 1px solid #f2dcab66;
  background: #ffffff15;
  color: #fff4dc;
  cursor: pointer;
}
details > .panel-title { cursor: pointer; padding: 4px 0 9px; }
details:not([open]) > .panel-title { margin-bottom: 0; border-bottom: 0; }
.sheet-note { color: var(--muted); font-size: 13px; }
.status-sheet .action-btn { margin-top: 8px; padding-inline: 10px; }
.family-list { list-style: none; }
.family-list li { border-bottom: 1px solid var(--edge); padding: 6px 0; }
.family-list span { display: block; font-size: 12px; color: var(--muted); }

/* 宫中人物攻略面板 */
.npc-list { list-style: none; margin: 0; }
.npc-row { padding: 8px 0; border-bottom: 1px dashed var(--edge); }
.npc-row:last-child { border-bottom: 0; }
.npc-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.npc-portrait { width: 40px; height: 58px; object-fit: cover; object-position: top center; border-radius: 4px; align-self: center; background: #e8dcc0; }
.npc-head strong { color: var(--jade-dark); font-size: 14px; }
.npc-disp { color: var(--muted); font-size: 12px; }
.npc-disp.npc-friendly { color: #1f6b45; }
.npc-disp.npc-hostile { color: #9c2f22; }
.npc-bond, .npc-gone { font-size: 11px; padding: 1px 5px; border-radius: 2px; }
.npc-bond { color: #fff6e6; background: var(--seal); }
.npc-gone { color: var(--muted); background: #e4ddcd; }
.npc-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.npc-stat { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.npc-stat b { color: var(--seal-dark); min-width: 12px; }
.npc-meter { display: inline-block; width: 34px; height: 4px; border-radius: 2px; background: #ded4bd; overflow: hidden; }
.npc-meter i { display: block; height: 100%; border-radius: inherit; }
.npc-favor .npc-meter i { background: #b4513c; }
.npc-love .npc-meter i { background: #c98b9a; }
.npc-trust .npc-meter i { background: #5b8a6f; }
.poison-btn { color: #fff2e2 !important; background: #6d2a20 !important; border-color: #4c1d16 !important; }
.poison-btn:hover { background: #552019 !important; }
.panel-people { background: #f4eee0; border-color: #c9b48f; }

/* 风云·四条剧情线面板 */
.panel-route { background: #f0ecdf; border-color: #b9b092; }
.route-list { list-style: none; margin: 0; }
.route-row { display: flex; flex-direction: column; gap: 1px; padding: 6px 0; border-bottom: 1px dashed var(--edge); }
.route-row:last-child { border-bottom: 0; }
.route-row strong { color: var(--muted); font-size: 13px; }
.route-row.route-on strong { color: var(--seal); }
.route-row span { font-size: 12px; color: var(--ink); line-height: 1.55; }
[data-value="scheme"]:not(:disabled) { color: #fff6e6; background: #3f5a4e; border-color: #2a4035; }
[data-value="scheme"]:not(:disabled):hover { background: #31483d; }
.ending-role { color: var(--muted); margin-bottom: 20px; }
.ending-text p + p { margin-top: 10px; }
.ending-cond ul { padding-inline-start: 22px; }
.ending-cond h2 { font-size: 16px; color: var(--jade-dark); }
.ending-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.ending-buttons .action-btn { padding-inline: 12px; }
dialog.modal {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(calc(100% - 24px), 570px);
  max-inline-size: none;
  max-block-size: min(86dvh, calc(100dvh - 24px));
  color: var(--ink);
}
dialog::backdrop { background: #18251fc4; }
dialog .scene-label { display: block; font-size: 13px; }
dialog .modal-btn { overflow-wrap: anywhere; }
.slot-head, .slot-sub { overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .cover { width: calc(100% - 40px); grid-template-columns: minmax(0, 1fr) minmax(340px, 0.9fr); }
  .cover-sheet { padding: 35px; }
  .topbar { gap: 10px; padding-inline: 14px; grid-template-columns: minmax(160px, 0.8fr) 1fr 1fr; }
  .main { gap: 12px; padding-inline: 14px; grid-template-columns: minmax(220px, 0.9fr) minmax(0, 1.25fr) minmax(100px, 0.38fr); }
  .status-sheet .attr-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 710px) {
  .cover { width: min(100% - 28px, 480px); min-height: auto; margin: max(14px, env(safe-area-inset-top)) auto 20px; grid-template-columns: minmax(0, 1fr); }
  .cover-art { aspect-ratio: 1.68; }
  .cover-art img { object-position: 65% 58%; }
  .cover-art::after, .cover-sheet::before { inset: 7px; }
  .cover-sheet { padding: 24px 24px 25px; }
  .cover h1 { font-size: clamp(58px, 15.7vw, 91px); margin-bottom: 13px; }
  .cover h1 small { margin-top: 9px; font-size: 22px; }
  .cover-intro { font-size: 14px; line-height: 1.75; margin-bottom: 17px; }
  .cover form { padding-top: 12px; }
  .start-credit { margin-top: 17px; }
  .topbar { grid-template-columns: minmax(0, 1fr); gap: 5px; padding: max(8px, env(safe-area-inset-top)) 12px 9px; }
  .topbar-title { font-size: 19px; }
  .topbar-stats { justify-content: space-between; gap: 1px 6px; font-size: 12px; }
  .topbar .bars { gap: 8px; }
  .main { display: block; padding: 12px 10px calc(125px + env(safe-area-inset-bottom)); }
  .chronicle-art { height: 94px; margin-bottom: 8px; }
  .log-area .panel-body { max-height: 32vh; }
  .panel, .log-area { padding-inline: 11px; }
  .status-sheet .attr-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-bar {
    position: fixed;
    inset: auto 0 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    box-shadow: 0 -4px 20px #392c191f;
  }
}

@media (max-width: 350px) {
  .cover-sheet { padding-inline: 16px; }
  .status-sheet .attr-grid { grid-template-columns: minmax(0, 1fr); }
}
