:root {
  --ink-strong: #2f1d15;
  --ink: #4b3228;
  --ink-muted: #6f4f42;
  --edge: rgba(121, 67, 45, 0.62);
  --focus: #2f9ad8;
  --card-shadow: 0 20px 38px rgba(30, 11, 7, 0.35);
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink-strong);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #1f120d;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
}

p {
  margin: 0;
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

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

.bg-layer,
.bg-overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.bg-layer {
  background-position: center;
  background-size: cover;
  filter: saturate(0.95) brightness(0.92);
  transform: scale(1.02);
}

.bg-overlay {
  background:
    linear-gradient(180deg, rgba(21, 9, 5, 0.32) 0%, rgba(21, 9, 5, 0.03) 36%, rgba(21, 9, 5, 0.56) 100%),
    radial-gradient(circle at 50% -8%, rgba(255, 241, 210, 0.24), transparent 56%);
}

.panel {
  position: relative;
  z-index: 2;
  border: 2px solid var(--edge);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(4px);
}

.status-card {
  position: absolute;
  z-index: 3;
  left: 22px;
  top: 16px;
  width: min(390px, calc(100vw - 136px));
  padding: 14px 16px;
  color: #fff2e4;
  background: linear-gradient(170deg, rgba(191, 88, 90, 0.92), rgba(127, 55, 70, 0.92));
}

.status-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.title {
  letter-spacing: 0.08em;
  font-size: 1.25rem;
}

.story-progress {
  margin-top: 5px;
  font-size: 0.78rem;
  color: rgba(255, 225, 199, 0.94);
}

.quota-summary {
  margin-top: 4px;
  font-size: 0.76rem;
  color: rgba(255, 236, 216, 0.96);
}

.stats-help-wrap {
  position: relative;
  flex-shrink: 0;
}

.stats-help-toggle {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 231, 206, 0.78);
  color: #fff3e5;
  background: rgba(113, 46, 56, 0.68);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 180ms ease, filter 180ms ease;
}

.stats-help-toggle:hover,
.stats-help-toggle:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.stats-help-popover {
  position: absolute;
  left: calc(100% + 10px);
  top: -4px;
  z-index: 20;
  width: min(460px, calc(100vw - 56px));
  max-height: min(68vh, 520px);
  overflow: auto;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid rgba(250, 214, 178, 0.58);
  background: rgba(77, 28, 35, 0.94);
  box-shadow: 0 10px 20px rgba(30, 11, 7, 0.35);
}

.stats-help-popover .panel-title {
  color: #ffe3c5;
}

.stats-help-popover .stat-hint-list {
  margin: 0;
  padding-left: 16px;
}

.stats-help-popover .stat-hint-list li {
  color: rgba(255, 236, 216, 0.94);
  font-size: 0.77rem;
  line-height: 1.42;
}

.stats-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px 10px;
}

.stat-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(255, 220, 193, 0.28);
}

.stat-name {
  font-size: 0.87rem;
  color: rgba(255, 240, 226, 0.95);
}

.stat-value {
  font-size: 0.93rem;
  font-weight: 700;
}

.stage-menu {
  position: absolute;
  z-index: 3;
  right: 24px;
  top: 30px;
  width: min(220px, 34vw);
  display: grid;
  gap: 10px;
}

.stage-menu-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.menu-btn-stats {
  display: none;
}

.menu-btn-mobile-phase {
  display: none;
}

.menu-btn {
  border: 1.5px solid rgba(250, 205, 170, 0.6);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
  color: #fff3e9;
  background: linear-gradient(180deg, rgba(189, 102, 111, 0.95), rgba(146, 67, 84, 0.96));
  box-shadow: 0 8px 16px rgba(40, 12, 18, 0.35);
  cursor: pointer;
  transition: transform 180ms ease, filter 180ms ease;
}

.menu-btn:hover,
.menu-btn:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.menu-btn-secondary {
  background: linear-gradient(180deg, rgba(197, 130, 79, 0.95), rgba(155, 93, 57, 0.96));
}

.menu-btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  filter: saturate(0.72);
  box-shadow: none;
  transform: none;
}

.menu-btn:disabled:hover,
.menu-btn:disabled:focus-visible {
  transform: none;
  filter: saturate(0.72);
}

.phase-guide {
  position: absolute;
  z-index: 3;
  right: 24px;
  top: 216px;
  width: min(220px, 34vw);
  padding: 10px 11px;
  border: 1px solid rgba(247, 212, 178, 0.56);
  border-radius: 10px;
  background: linear-gradient(170deg, rgba(107, 43, 55, 0.9), rgba(85, 34, 47, 0.88));
  box-shadow: 0 8px 16px rgba(37, 13, 17, 0.34);
}

.phase-guide-kicker {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 231, 209, 0.9);
}

.phase-guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.phase-guide-toggle {
  border: 1px solid rgba(255, 220, 192, 0.46);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.66rem;
  color: #ffe7cf;
  background: rgba(133, 57, 70, 0.52);
  cursor: pointer;
  transition: filter 170ms ease, transform 170ms ease;
}

.phase-guide-toggle:hover,
.phase-guide-toggle:focus-visible {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.phase-guide-body {
  margin-top: 4px;
}

.phase-guide-body[hidden] {
  display: none;
}

.phase-guide-title {
  margin: 3px 0 0;
  font-size: 0.87rem;
  line-height: 1.35;
  color: #fff0df;
}

.phase-guide-deadline,
.phase-guide-progress {
  margin: 4px 0 0;
  font-size: 0.73rem;
  color: rgba(255, 224, 196, 0.9);
}

.phase-guide-list {
  margin: 7px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 5px;
}

.phase-guide-list li {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 6px;
  align-items: start;
  font-size: 0.72rem;
  line-height: 1.42;
}

.phase-guide-task-btn {
  border: 1px solid rgba(255, 219, 191, 0.32);
  border-radius: 8px;
  padding: 5px 6px;
  text-align: left;
  color: inherit;
  background: rgba(255, 244, 228, 0.08);
  cursor: pointer;
  transition: filter 170ms ease, border-color 170ms ease, transform 170ms ease;
}

.phase-guide-task-btn:hover,
.phase-guide-task-btn:focus-visible {
  border-color: rgba(255, 228, 205, 0.56);
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.phase-guide-task-btn.active {
  border-color: rgba(255, 235, 212, 0.72);
  background: rgba(255, 244, 225, 0.2);
  box-shadow: 0 0 0 1px rgba(255, 214, 177, 0.34);
}

.phase-guide-list li.phase-guide-done {
  color: rgba(202, 252, 210, 0.92);
}

.phase-guide-list li.phase-guide-todo {
  color: rgba(255, 228, 206, 0.92);
}

.phase-guide-dot {
  margin-top: 1px;
  font-size: 0.72rem;
  font-weight: 700;
}

.stage-character {
  position: absolute;
  z-index: 1;
  left: clamp(56px, 15vw, 260px);
  bottom: 0;
  pointer-events: none;
}

.stage-avatar {
  width: min(40vw, 620px);
  height: min(78vh, 860px);
  object-fit: contain;
  object-position: center bottom;
  display: block;
  filter: drop-shadow(0 16px 24px rgba(24, 7, 6, 0.55));
}

.stage-avatar-name {
  display: none;
}

.stage-dialogue {
  position: absolute;
  z-index: 3;
  left: 30px;
  right: 30px;
  bottom: 18px;
  padding: 14px 18px;
  background: linear-gradient(170deg, rgba(251, 233, 202, 0.74), rgba(234, 198, 150, 0.66));
  backdrop-filter: blur(6px);
}

.stage-dialogue.npc-dialogue-active {
  left: auto;
  right: 24px;
  width: min(560px, 44vw);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  overflow: visible;
  max-height: none;
}

.stage-dialogue.npc-dialogue-active > .dialogue-header,
.stage-dialogue.npc-dialogue-active > .stage-dialogue-text,
.stage-dialogue.npc-dialogue-active > .stage-dialogue-meta,
.stage-dialogue.npc-dialogue-active > .live-effects,
.stage-dialogue.npc-dialogue-active > #stage-story-choices {
  display: none;
}

.dialogue-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

#stage-dialogue-name {
  font-size: 1.03rem;
  color: #6e2a24;
}

.date-text {
  font-size: 0.82rem;
  color: rgba(101, 62, 48, 0.86);
}

.stage-dialogue-text {
  margin-top: 6px;
  line-height: 1.65;
  font-size: 0.98rem;
  color: #3f271f;
  text-shadow: 0 1px 0 rgba(255, 248, 238, 0.38);
  white-space: pre-line;
  max-height: min(40vh, 360px);
  overflow-y: auto;
  padding-right: 6px;
}

.stage-dialogue-meta {
  margin-top: 7px;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.live-effects {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.live-effects:empty {
  display: none;
}

.live-effects {
  display: none !important;
}

.live-effect-item {
  border-left: 3px solid rgba(159, 96, 63, 0.75);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.84rem;
  color: #533629;
  background: rgba(255, 248, 236, 0.8);
}

.live-effect-item.positive {
  border-left-color: #4d8b5f;
}

.live-effect-item.warning {
  border-left-color: #9b3d4a;
}

.plan-results,
.stat-hints {
  margin-top: 8px;
  border-radius: 9px;
  border: 1px solid rgba(145, 91, 63, 0.35);
  background: rgba(255, 251, 243, 0.78);
  padding: 7px 9px;
}

.plan-results:empty,
.stat-hints:empty {
  display: none;
}

.panel-title {
  font-size: 0.8rem;
  color: #5d3a2d;
  margin-bottom: 5px;
  font-weight: 700;
}

.plan-result-list,
.stat-hint-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.plan-result-list li,
.stat-hint-list li {
  font-size: 0.8rem;
  color: #533629;
  line-height: 1.45;
}

.plan-result-list li.positive {
  color: #3f6f4b;
}

.plan-result-list li.warning {
  color: #8f3541;
}

.result-card {
  width: min(560px, 94vw);
}

.result-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.result-list li {
  font-size: 0.86rem;
  line-height: 1.5;
  color: #4f3227;
}

.result-list li.positive {
  color: #3f6f4b;
}

.result-list li.warning {
  color: #8f3541;
}

.stage-story-choices {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.stage-story-choices .story-choice-btn,
.stage-story-choices .primary-btn {
  width: 100%;
}

.story-text-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.story-text-action {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  color: rgba(111, 69, 52, 0.9);
  cursor: pointer;
  user-select: none;
}

.story-text-action:hover,
.story-text-action:focus-visible {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stage-dialogue.can-story-advance {
  cursor: pointer;
}

.npc-card-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgba(120, 73, 53, 0.28);
  border-radius: 12px;
  background: rgba(214, 203, 191, 0.88);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: clamp(360px, 50vh, 520px);
  overflow: hidden;
}

.npc-card-fixed {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
  padding-right: 132px;
}

.npc-card-actions {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 1;
}

.npc-card-close {
  position: static;
  padding: 3px 8px;
  font-size: 0.74rem;
}

.npc-card-fullscreen {
  position: static;
  padding: 3px 8px;
  font-size: 0.74rem;
}

.npc-card-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
}

.npc-card-line h3 {
  font-size: 0.92rem;
  color: #632f22;
}

.npc-inline-bio {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(93, 61, 48, 0.86);
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.npc-card-panel .favor {
  margin: 0;
  margin-left: auto;
  font-size: 0.8rem;
}

.npc-card-panel .quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.npc-card-panel .quick-options button {
  width: auto;
  min-width: 0;
  padding: 5px 8px;
  font-size: 0.76rem;
}

.npc-card-panel .chat-box {
  margin-top: 0;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid rgba(127, 78, 53, 0.28);
  padding: 10px;
  background: rgba(255, 255, 255, 0.92);
}

.npc-card-panel .chat-line {
  padding: 4px 6px;
  font-size: 0.78rem;
  line-height: 1.35;
}

.npc-card-panel .chat-line.chat-loading {
  opacity: 0.78;
}

.npc-card-panel .chat-line.chat-streaming {
  opacity: 0.95;
}

.chat-loading-spinner {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 5px;
  border-radius: 50%;
  border: 2px solid rgba(128, 74, 54, 0.32);
  border-top-color: rgba(128, 74, 54, 0.9);
  vertical-align: middle;
  animation: chatSpin 720ms linear infinite;
}

.chat-streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 0.88em;
  margin-left: 4px;
  border-radius: 2px;
  background: rgba(122, 73, 53, 0.9);
  vertical-align: text-bottom;
  animation: chatCursorBlink 880ms steps(1, end) infinite;
}

.npc-card-panel .chat-form {
  margin-top: 0;
  flex: 0 0 auto;
}

.npc-card-panel.chat-fullscreen {
  position: relative;
  inset: auto;
  z-index: 3;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgba(120, 73, 53, 0.32);
  border-radius: 12px;
  background: rgba(214, 203, 191, 0.94);
  box-shadow: 0 14px 24px rgba(31, 13, 10, 0.28);
  height: clamp(460px, 72vh, 760px);
}

.npc-card-panel.chat-fullscreen .npc-card-fixed {
  flex: 0 0 auto;
}

.npc-card-panel.chat-fullscreen .chat-box {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
}

.npc-card-panel.chat-fullscreen .chat-form {
  flex: 0 0 auto;
  margin-top: 0;
}

body.chat-fullscreen-active {
  overflow: auto;
}

.ending-banner {
  position: fixed;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 12;
  max-width: min(700px, 94vw);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 211, 151, 0.66);
  color: #fff2dc;
  background: linear-gradient(160deg, rgba(111, 38, 39, 0.96), rgba(156, 76, 57, 0.95));
  box-shadow: var(--card-shadow);
}

.overlay-modal,
.story-modal {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(23, 9, 6, 0.62);
}

#result-modal {
  z-index: 12;
}

#system-modal {
  z-index: 14;
}

body.admin-dashboard-mode .status-card,
body.admin-dashboard-mode .primary-menu,
body.admin-dashboard-mode .phase-guide,
body.admin-dashboard-mode .stage-portrait,
body.admin-dashboard-mode .stage-dialogue,
body.admin-dashboard-mode .ending-banner,
body.admin-dashboard-mode .save-panel,
body.admin-dashboard-mode .recharge-panel,
body.admin-dashboard-mode #action-modal,
body.admin-dashboard-mode #scene-picker-modal,
body.admin-dashboard-mode #npc-modal,
body.admin-dashboard-mode #story-modal,
body.admin-dashboard-mode #quota-modal,
body.admin-dashboard-mode #result-modal {
  display: none !important;
}

body.admin-dashboard-mode #system-modal {
  z-index: 80;
  padding: 0;
  background: rgba(24, 10, 8, 0.9);
}

body.admin-dashboard-mode #system-modal .overlay-card.system-card {
  width: min(1240px, 100vw);
  max-height: 100vh;
  min-height: 100vh;
  border-radius: 0;
  padding: 18px 16px 24px;
}

body.admin-dashboard-mode #system-modal [data-close-modal="system"] {
  display: none !important;
}

body.admin-dashboard-mode .system-card {
  color: #12263a;
  border: 1px solid #d7dfeb;
  background: linear-gradient(180deg, #f8fbff 0%, #f0f4fa 100%);
}

body.admin-dashboard-mode .system-card .subtle {
  color: #4d647f;
}

body.admin-dashboard-mode #system-modal .overlay-header {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #d9e2ee;
}

body.admin-dashboard-mode #system-panel-title {
  margin: 0;
  font-size: 1.36rem;
  color: #102840;
}

body.admin-dashboard-mode .auth-panel,
body.admin-dashboard-mode .admin-panel {
  margin-top: 14px;
  border-top: none;
  padding-top: 0;
}

body.admin-dashboard-mode .auth-head {
  margin-bottom: 12px;
}

body.admin-dashboard-mode .auth-forms {
  gap: 12px;
}

body.admin-dashboard-mode .auth-form-block {
  border: 1px solid #dbe3ef;
  border-radius: 12px;
  padding: 12px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(24, 54, 94, 0.06);
}

body.admin-dashboard-mode .auth-form-title {
  font-size: 0.84rem;
  color: #2d4662;
}

body.admin-dashboard-mode .auth-form-block input,
body.admin-dashboard-mode .admin-adjust-form input,
body.admin-dashboard-mode .admin-password-form input,
body.admin-dashboard-mode .save-slot {
  border: 1px solid #cdd8e8;
  border-radius: 8px;
  padding: 8px 10px;
  color: #172f47;
  background: #fdfefe;
  font-size: 0.82rem;
}

body.admin-dashboard-mode .auth-form-block input::placeholder,
body.admin-dashboard-mode .admin-adjust-form input::placeholder,
body.admin-dashboard-mode .admin-password-form input::placeholder {
  color: #7a8fa8;
}

body.admin-dashboard-mode .auth-user-meta {
  color: #284461;
  font-size: 0.83rem;
}

body.admin-dashboard-mode .auth-user-actions {
  margin-top: 10px;
  gap: 8px;
}

body.admin-dashboard-mode .save-btn {
  border: 1px solid #b8cae4;
  border-radius: 9px;
  padding: 7px 10px;
  color: #14304a;
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  font-size: 0.82rem;
  font-weight: 600;
}

body.admin-dashboard-mode .save-btn:hover,
body.admin-dashboard-mode .save-btn:focus-visible {
  filter: none;
  transform: translateY(-1px);
  border-color: #8aa8d1;
  box-shadow: 0 6px 14px rgba(32, 76, 130, 0.18);
}

body.admin-dashboard-mode .admin-title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

body.admin-dashboard-mode .admin-title-row .panel-title {
  font-size: 1.06rem;
  color: #153352;
}

body.admin-dashboard-mode .admin-stats-row {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.admin-dashboard-mode .admin-stat-card {
  border: 1px solid #d7e2f0;
  border-radius: 12px;
  background: #ffffff;
  padding: 12px;
  box-shadow: 0 9px 18px rgba(23, 56, 94, 0.08);
}

body.admin-dashboard-mode .admin-stat-label {
  margin: 0;
  font-size: 0.78rem;
  color: #607892;
}

body.admin-dashboard-mode .admin-stat-value {
  margin-top: 8px;
  font-size: 1.3rem;
  line-height: 1.1;
  font-weight: 700;
  color: #122d4a;
}

body.admin-dashboard-mode .admin-stat-note {
  margin-top: 8px;
  font-size: 0.74rem;
  color: #6f859f;
}

body.admin-dashboard-mode .admin-users-list {
  margin-top: 12px;
  max-height: 46vh;
}

body.admin-dashboard-mode .admin-sections-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

body.admin-dashboard-mode .admin-card {
  border: 1px solid #d8e1ef;
  border-radius: 12px;
  padding: 12px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(24, 56, 92, 0.07);
}

body.admin-dashboard-mode .admin-card .panel-title {
  color: #173859;
}

body.admin-dashboard-mode .admin-adjust-block,
body.admin-dashboard-mode .admin-password-block,
body.admin-dashboard-mode .admin-logs-block,
body.admin-dashboard-mode .admin-daily-block {
  margin-top: 0;
}

body.admin-dashboard-mode .admin-adjust-form,
body.admin-dashboard-mode .admin-password-form {
  margin-top: 8px;
}

body.admin-dashboard-mode .admin-quota-logs,
body.admin-dashboard-mode .admin-daily-summary {
  margin-top: 8px;
  max-height: 34vh;
}

body.admin-dashboard-mode .admin-table-shell {
  border: 1px solid #d7e1ef;
  border-radius: 10px;
  overflow: auto;
  background: #ffffff;
}

body.admin-dashboard-mode .admin-table,
body.admin-dashboard-mode .admin-mini-table {
  min-width: 840px;
  font-size: 0.78rem;
  color: #19334f;
}

body.admin-dashboard-mode .admin-table th,
body.admin-dashboard-mode .admin-table td,
body.admin-dashboard-mode .admin-mini-table th,
body.admin-dashboard-mode .admin-mini-table td {
  border: 1px solid #e1e9f5;
  padding: 8px 9px;
}

body.admin-dashboard-mode .admin-table th,
body.admin-dashboard-mode .admin-mini-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf4fd;
  color: #214363;
  font-weight: 700;
}

body.admin-dashboard-mode .admin-role-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

body.admin-dashboard-mode .admin-role-badge.is-admin {
  color: #0f4f57;
  background: #d7f5f0;
  border: 1px solid #8acfc4;
}

body.admin-dashboard-mode .admin-role-badge.is-user {
  color: #465f7a;
  background: #eef4fb;
  border: 1px solid #c9d9ec;
}

body.admin-dashboard-mode .admin-empty {
  margin: 0;
  border: 1px dashed #c8d6e8;
  border-radius: 10px;
  background: #f7fbff;
  padding: 16px 14px;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 9, 7, 0.72);
  backdrop-filter: blur(3px);
}

.auth-gate-card {
  width: min(520px, 94vw);
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(245, 216, 186, 0.62);
  background: linear-gradient(160deg, rgba(252, 236, 211, 0.98), rgba(233, 202, 162, 0.97));
  box-shadow: 0 14px 30px rgba(32, 12, 10, 0.42);
}

.auth-gate-title {
  margin: 0;
  font-size: 1.06rem;
  color: #5f2e22;
}

.auth-gate-subtitle {
  margin: 6px 0 0;
  font-size: 0.84rem;
  color: rgba(99, 62, 49, 0.88);
}

.auth-gate-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.auth-gate-grid input {
  border: 1px solid rgba(123, 73, 49, 0.34);
  border-radius: 8px;
  padding: 8px 9px;
  background: rgba(255, 251, 246, 0.9);
}

.auth-gate-actions {
  margin-top: 9px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.auth-gate-message {
  margin: 8px 0 0;
  min-height: 1.4em;
  font-size: 0.82rem;
  color: #5f3a2e;
}

.auth-gate-message.is-error {
  color: #8e2f3f;
}

body.auth-gate-open {
  overflow: hidden;
}

.auth-gate-register-modal {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(24, 11, 9, 0.4);
}

.auth-gate-register-card {
  width: min(420px, 92%);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(245, 216, 186, 0.72);
  background: linear-gradient(160deg, rgba(255, 242, 221, 0.99), rgba(239, 211, 174, 0.98));
}

.auth-gate-register-title {
  margin: 0;
  font-size: 0.98rem;
  color: #5f2e22;
}

.auth-gate-register-subtitle {
  margin: 5px 0 0;
  font-size: 0.8rem;
  color: rgba(99, 62, 49, 0.88);
}

.auth-gate-register-grid {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.auth-gate-register-grid input {
  border: 1px solid rgba(123, 73, 49, 0.34);
  border-radius: 8px;
  padding: 8px 9px;
  background: rgba(255, 251, 246, 0.92);
}

.auth-gate-register-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.story-modal {
  z-index: 10;
  align-items: end;
  padding-bottom: 24px;
}

.overlay-card,
.story-card {
  width: min(980px, 96vw);
  max-height: min(90vh, 960px);
  overflow: auto;
  padding: 16px;
  color: var(--ink-strong);
  border-color: rgba(115, 66, 46, 0.62);
  background: linear-gradient(158deg, rgba(255, 245, 228, 0.97), rgba(241, 212, 170, 0.96));
}

.action-panel-card {
  width: min(1100px, 97vw);
  max-height: min(90vh, 960px);
}

.quota-card {
  width: min(420px, 94vw);
}

.quota-modal-line {
  margin-top: 8px;
  color: #5b3a2f;
  font-size: 0.9rem;
  line-height: 1.5;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-header h2,
.section-header h3 {
  font-size: 1rem;
}

.subtle {
  margin-top: 4px;
  font-size: 0.83rem;
  color: var(--ink-muted);
}

.planning-panel {
  border: 1px solid rgba(151, 95, 64, 0.32);
  border-radius: 11px;
  padding: 12px;
  background: rgba(255, 252, 246, 0.72);
}

.action-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.action-card {
  border: 1px solid rgba(151, 92, 62, 0.42);
  border-radius: 10px;
  padding: 8px;
  background: rgba(255, 249, 242, 0.84);
  display: grid;
  gap: 6px;
}

.action-card.recommended {
  border-color: rgba(177, 116, 44, 0.66);
  box-shadow: 0 0 0 1px rgba(214, 161, 96, 0.44), 0 6px 12px rgba(126, 80, 39, 0.12);
  background: linear-gradient(180deg, rgba(255, 248, 235, 0.95), rgba(255, 240, 215, 0.9));
}

.action-recommend-banner {
  margin: 6px 0 2px;
  padding: 6px 8px;
  border: 1px solid rgba(187, 126, 61, 0.48);
  border-radius: 8px;
  color: #6d4228;
  background: rgba(253, 232, 202, 0.85);
  font-size: 0.76rem;
}

.action-recommend-tag {
  margin: 0;
  color: #8a4f2a;
  font-weight: 700;
  font-size: 0.72rem;
}

.action-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.action-title strong {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 0.95rem;
}

.action-card p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.action-preview {
  color: #664132;
  font-size: 0.78rem;
}

.energy-tag {
  color: #913e2a;
  font-size: 0.76rem;
}

.action-card button {
  border: 1px solid rgba(123, 71, 46, 0.48);
  border-radius: 8px;
  padding: 5px;
  background: linear-gradient(180deg, rgba(252, 226, 185, 0.94), rgba(217, 162, 111, 0.94));
  cursor: pointer;
  transition: transform 180ms ease, filter 180ms ease;
}

.action-card button:hover,
.action-card button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.plan-box {
  margin-top: 12px;
  border-top: 1px solid rgba(119, 74, 53, 0.24);
  padding-top: 10px;
}

.plan-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  min-height: 74px;
}

.plan-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(116, 70, 51, 0.3);
  background: rgba(255, 250, 245, 0.76);
}

.plan-item button {
  border: none;
  background: transparent;
  color: #9d4b58;
  cursor: pointer;
}

.plan-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.log-panel {
  margin-top: 12px;
  border: 1px solid rgba(151, 95, 64, 0.32);
  border-radius: 11px;
  padding: 12px;
  background: rgba(255, 252, 246, 0.72);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.event-log {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  max-height: 220px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.event-log li {
  border-left: 3px solid rgba(162, 92, 64, 0.7);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.84rem;
  background: rgba(255, 251, 245, 0.72);
}

.event-log li.positive {
  border-left-color: #4d8b5f;
}

.event-log li.warning {
  border-left-color: #9b3d4a;
}

.primary-btn,
.ghost-btn,
.close-btn {
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  transition: transform 190ms ease, filter 190ms ease;
}

.primary-btn {
  border: 1px solid rgba(102, 50, 27, 0.5);
  color: #fff6ec;
  background: linear-gradient(180deg, #bc6f4e, #8f4d33);
}

.ghost-btn {
  border: 1px solid rgba(133, 84, 60, 0.34);
  background: rgba(255, 246, 235, 0.86);
}

.close-btn {
  border: 1px solid rgba(133, 84, 60, 0.45);
  background: rgba(255, 248, 240, 0.82);
}

.primary-btn:hover,
.primary-btn:focus-visible,
.ghost-btn:hover,
.ghost-btn:focus-visible,
.close-btn:hover,
.close-btn:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.scene-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.scene-btn {
  border: 2px solid rgba(236, 177, 129, 0.6);
  border-radius: 9px;
  padding: 10px 8px;
  text-align: center;
  color: #fff5ec;
  background: linear-gradient(180deg, rgba(193, 103, 114, 0.84), rgba(152, 73, 83, 0.86));
  cursor: pointer;
  transition: transform 220ms ease, box-shadow 220ms ease, filter 220ms ease;
}

.scene-btn:hover,
.scene-btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(57, 18, 20, 0.35);
  filter: brightness(1.06);
}

.scene-btn.active {
  background: linear-gradient(180deg, rgba(225, 154, 112, 0.95), rgba(176, 102, 72, 0.95));
}

.npc-dialog-card {
  width: min(860px, 97vw);
}

.npc-section-header {
  margin-top: 8px;
}

.npc-select {
  min-width: 132px;
  border: 1px solid rgba(122, 80, 57, 0.4);
  border-radius: 8px;
  padding: 4px 6px;
  background: rgba(255, 248, 240, 0.86);
}

.npc-head {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
}

.npc-avatar {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(124, 73, 49, 0.42);
  background: rgba(254, 250, 244, 0.75);
}

.favor {
  margin-top: 3px;
  color: #87561f;
  font-size: 0.84rem;
}

.npc-bio {
  margin: 10px 0;
  font-size: 0.83rem;
  color: var(--ink);
}

.quick-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.quick-options button {
  border: 1px solid rgba(143, 83, 59, 0.36);
  border-radius: 8px;
  padding: 6px;
  font-size: 0.8rem;
  background: rgba(255, 251, 246, 0.82);
  cursor: pointer;
  transition: filter 180ms ease, transform 180ms ease;
}

.quick-options button:hover,
.quick-options button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.chat-box {
  margin-top: 10px;
  min-height: 140px;
  max-height: 240px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid rgba(127, 78, 53, 0.3);
  padding: 8px;
  background: rgba(255, 252, 248, 0.74);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-line {
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.83rem;
}

.chat-line.user {
  align-self: flex-end;
  background: rgba(214, 154, 117, 0.34);
}

.chat-line.npc {
  align-self: flex-start;
  background: rgba(168, 100, 122, 0.22);
}

.chat-form {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-form input {
  border: 1px solid rgba(121, 73, 49, 0.34);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 252, 248, 0.88);
}

.system-card {
  width: min(560px, 95vw);
  color: #fff3e5;
  border-color: rgba(255, 211, 168, 0.45);
  background: linear-gradient(165deg, rgba(124, 52, 65, 0.94), rgba(103, 43, 59, 0.94));
}

.group-card {
  width: min(380px, 94vw);
  color: #fff3e5;
  border-color: rgba(255, 211, 168, 0.45);
  background: linear-gradient(165deg, rgba(124, 52, 65, 0.94), rgba(103, 43, 59, 0.94));
  text-align: center;
}

.group-qr {
  display: block;
  width: min(260px, 100%);
  margin: 12px auto 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 226, 198, 0.42);
  background: rgba(255, 248, 240, 0.95);
}

.group-note {
  margin: 0;
  font-size: 0.84rem;
  color: rgba(255, 231, 210, 0.95);
}

.stats-mobile-card,
.phase-guide-modal-card {
  width: min(420px, 94vw);
  color: #fff3e5;
  border-color: rgba(255, 211, 168, 0.45);
  background: linear-gradient(165deg, rgba(124, 52, 65, 0.94), rgba(103, 43, 59, 0.94));
}

.stats-mobile-card .subtle {
  color: rgba(255, 226, 206, 0.9);
}

.stats-modal-grid {
  margin-top: 10px;
  max-height: min(52vh, 420px);
  overflow: auto;
}

.phase-guide-modal-card .phase-guide-title {
  margin-top: 2px;
}

.phase-guide-modal-card .phase-guide-deadline,
.phase-guide-modal-card .phase-guide-progress,
.phase-guide-modal-card .phase-guide-list li {
  color: rgba(255, 228, 206, 0.92);
}

.phase-guide-modal-card .phase-guide-list {
  margin-top: 8px;
  max-height: min(54vh, 440px);
  overflow: auto;
  padding-right: 2px;
}

.system-card .subtle {
  color: rgba(255, 226, 206, 0.9);
}

.system-block {
  margin-top: 6px;
}

.ai-config-block {
  border-bottom: 1px solid rgba(255, 226, 204, 0.34);
  padding-bottom: 10px;
}

.ai-config-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 7px 8px;
  align-items: center;
}

.ai-config-grid label {
  font-size: 0.76rem;
  color: rgba(255, 239, 219, 0.92);
}

.ai-config-grid select,
.ai-config-grid input {
  width: 100%;
  border: 1px solid rgba(255, 226, 198, 0.44);
  border-radius: 7px;
  padding: 6px 8px;
  color: #fff4e6;
  background: rgba(140, 61, 74, 0.46);
  font-size: 0.78rem;
}

.ai-config-grid input::placeholder {
  color: rgba(255, 226, 204, 0.72);
}

.auth-panel {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 226, 204, 0.34);
  padding-top: 10px;
}

.auth-head .subtle {
  margin-top: 0;
  font-size: 0.75rem;
}

.auth-forms {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.auth-form-block {
  border: 1px solid rgba(255, 226, 198, 0.28);
  border-radius: 8px;
  padding: 8px;
  background: rgba(139, 61, 74, 0.22);
  display: grid;
  gap: 6px;
}

.auth-form-title {
  font-size: 0.76rem;
  color: rgba(255, 241, 226, 0.94);
}

.auth-form-block input {
  border: 1px solid rgba(255, 226, 198, 0.44);
  border-radius: 7px;
  padding: 6px 8px;
  color: #fff4e6;
  background: rgba(140, 61, 74, 0.46);
  font-size: 0.78rem;
}

.auth-form-block input::placeholder {
  color: rgba(255, 226, 204, 0.7);
}

.auth-user-panel {
  margin-top: 8px;
}

.auth-user-meta {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(255, 239, 219, 0.94);
}

.auth-user-actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
}

.admin-panel {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 226, 204, 0.34);
  padding-top: 9px;
}

.admin-users-list {
  margin-top: 6px;
  max-height: 220px;
  overflow: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  color: rgba(255, 240, 220, 0.96);
}

.admin-table th,
.admin-table td {
  border: 1px solid rgba(255, 220, 179, 0.3);
  padding: 4px 6px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: #ffe8c4;
  background: rgba(120, 54, 68, 0.4);
  font-weight: 700;
}

.admin-adjust-block,
.admin-password-block,
.admin-logs-block,
.admin-daily-block {
  margin-top: 8px;
}

.admin-adjust-form {
  margin-top: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
}

.admin-password-form {
  margin-top: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
}

.admin-adjust-form input {
  border: 1px solid rgba(255, 226, 198, 0.44);
  border-radius: 7px;
  padding: 5px 7px;
  color: #fff4e6;
  background: rgba(140, 61, 74, 0.46);
  font-size: 0.76rem;
}

.admin-adjust-form input::placeholder {
  color: rgba(255, 226, 204, 0.74);
}

.admin-password-form input {
  border: 1px solid rgba(255, 226, 198, 0.44);
  border-radius: 7px;
  padding: 5px 7px;
  color: #fff4e6;
  background: rgba(140, 61, 74, 0.46);
  font-size: 0.76rem;
}

.admin-password-form input::placeholder {
  color: rgba(255, 226, 204, 0.74);
}

.admin-quota-logs,
.admin-daily-summary {
  margin-top: 6px;
  max-height: 220px;
  overflow: auto;
}

.admin-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
  color: rgba(255, 240, 220, 0.96);
}

.admin-mini-table th,
.admin-mini-table td {
  border: 1px solid rgba(255, 220, 179, 0.3);
  padding: 4px 5px;
  text-align: left;
  vertical-align: top;
}

.admin-mini-table th {
  color: #ffe8c4;
  background: rgba(120, 54, 68, 0.4);
  font-weight: 700;
}

.recharge-panel {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 226, 204, 0.34);
  padding-top: 9px;
}

.recharge-package-list {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.recharge-package-card {
  border: 1px solid rgba(255, 226, 198, 0.28);
  border-radius: 8px;
  padding: 8px;
  background: rgba(139, 61, 74, 0.22);
  display: grid;
  gap: 8px;
}

.recharge-package-head {
  display: grid;
  gap: 2px;
}

.recharge-package-points {
  font-size: 0.82rem;
  color: rgba(255, 241, 226, 0.96);
}

.recharge-package-price {
  font-size: 0.85rem;
  color: #ffe7c5;
  font-weight: 700;
}

.ai-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.ai-toggle input {
  accent-color: #3b7fc2;
}

.save-panel {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 226, 204, 0.34);
  padding-top: 9px;
}

.save-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8rem;
  color: rgba(255, 241, 226, 0.94);
}

.save-slot {
  min-width: 92px;
  border: 1px solid rgba(255, 226, 198, 0.44);
  border-radius: 7px;
  padding: 3px 6px;
  color: #fff4e6;
  background: rgba(140, 61, 74, 0.46);
}

.save-actions {
  margin-top: 7px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.save-btn {
  border: 1px solid rgba(255, 220, 179, 0.42);
  border-radius: 7px;
  padding: 4px 5px;
  color: #fff5ea;
  background: rgba(130, 56, 69, 0.56);
  font-size: 0.78rem;
  cursor: pointer;
  transition: transform 170ms ease, filter 170ms ease;
}

.save-btn:hover,
.save-btn:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.save-btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
  filter: saturate(0.74);
}

.save-btn:disabled:hover,
.save-btn:disabled:focus-visible {
  transform: none;
  filter: saturate(0.74);
}

.save-btn.danger {
  background: rgba(106, 38, 48, 0.68);
}

.save-meta {
  margin-top: 7px;
  line-height: 1.45;
  font-size: 0.74rem;
  color: rgba(255, 233, 211, 0.92);
}

.save-meta strong {
  color: #ffe9be;
}

.story-card {
  width: min(1080px, 95vw);
  max-height: min(75vh, 840px);
  background: linear-gradient(170deg, rgba(253, 233, 198, 0.98), rgba(240, 201, 151, 0.97));
}

.story-card h2 {
  font-size: 1.18rem;
}

.story-body {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.story-body p {
  margin: 0;
  line-height: 1.6;
  color: var(--ink);
  border: 1px solid rgba(124, 75, 54, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 250, 243, 0.76);
}

.story-body p.cinematic-line {
  animation: cinematicFadeIn 360ms ease both;
}

.story-choices {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.story-choice-btn {
  border: 1.5px solid rgba(124, 68, 43, 0.56);
  border-radius: 9px;
  padding: 9px 10px;
  text-align: left;
  background: linear-gradient(180deg, rgba(255, 237, 203, 0.95), rgba(219, 169, 116, 0.95));
  cursor: pointer;
  transition: transform 200ms ease, filter 200ms ease;
}

.story-choice-btn:hover,
.story-choice-btn:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.hidden {
  display: none;
}

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

@media (max-width: 1180px) {
  .status-card {
    width: min(360px, calc(100vw - 128px));
  }

  .stage-menu {
    width: min(180px, 30vw);
  }

  .phase-guide {
    width: min(180px, 30vw);
    top: 204px;
  }

  .stage-character {
    left: clamp(20px, 8vw, 150px);
  }

  .stage-avatar {
    width: min(46vw, 520px);
  }
}

@media (max-width: 900px) {
  html {
    font-size: 13px;
  }

  .title,
  .story-card h2,
  .auth-gate-title,
  body.admin-dashboard-mode #system-panel-title,
  body.admin-dashboard-mode .admin-title-row .panel-title,
  body.admin-dashboard-mode .admin-stat-value {
    font-size: 1rem;
  }

  .status-card {
    display: none;
  }

  .status-card.mobile-collapsed {
    display: none;
  }

  .stats-help-popover {
    left: auto;
    right: 0;
    top: calc(100% + 8px);
    width: min(420px, 92vw);
    max-height: min(48vh, 360px);
  }

  .stage-menu {
    left: 10px;
    right: 10px;
    top: 10px;
    width: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
    padding-bottom: 0;
  }

  .stage-menu-row {
    display: contents;
  }

  .menu-btn-stats:not(.hidden) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  #open-phase-guide-modal {
    display: none !important;
  }

  .phase-guide {
    display: none;
  }

  .menu-btn {
    min-width: 0;
    width: 100%;
    padding: 8px 10px;
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: normal;
  }

  .stage-character {
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
  }

  body.npc-chat-active .stage-character {
    bottom: 200px;
  }

  body.story-choice-active-mobile:not(.npc-chat-active) .stage-character {
    bottom: var(--story-mobile-portrait-bottom, 150px);
  }

  body.story-mobile-shenyuan-portrait-shift:not(.npc-chat-active) .stage-character {
    bottom: calc(var(--story-mobile-portrait-bottom, 150px) - 24px);
  }

  .stage-avatar {
    width: min(70vw, 420px);
    height: min(58vh, 620px);
  }

  .stage-dialogue:not(.npc-dialogue-active) {
    left: 10px;
    right: 10px;
    bottom: 10px;
    padding: 10px 10px 8px;
    height: 158px;
    min-height: 158px;
    max-height: 158px;
    overflow: hidden;
  }

  .stage-dialogue.npc-dialogue-active {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: 10px;
    max-height: none;
    overflow: visible;
  }

  .stage-dialogue:not(.npc-dialogue-active) .stage-dialogue-text {
    margin-top: 4px;
    max-height: calc(1.58em * 3 + 2px);
    overflow: hidden;
    padding-right: 4px;
  }

  .stage-dialogue:not(.npc-dialogue-active) .stage-dialogue-meta {
    margin-top: 4px;
  }

  body.story-choice-active-mobile .stage-dialogue:not(.npc-dialogue-active) {
    height: auto;
    min-height: 0;
    max-height: min(66vh, 560px);
    overflow-y: auto;
  }

  body.story-choice-active-mobile .stage-dialogue:not(.npc-dialogue-active) .stage-dialogue-text {
    max-height: none;
    overflow: visible;
  }

  body.story-choice-active-mobile .stage-dialogue:not(.npc-dialogue-active) .stage-story-choices {
    margin-top: 6px;
    gap: 5px;
  }

  body.story-choice-active-mobile .stage-dialogue:not(.npc-dialogue-active) .story-choice-btn {
    padding: 6px 8px;
    line-height: 1.3;
  }

  body.story-choice-active-mobile .stage-dialogue:not(.npc-dialogue-active) .story-text-actions {
    gap: 8px;
  }

  body.story-choice-active-mobile .stage-dialogue:not(.npc-dialogue-active) .story-text-action {
    font-size: 0.72rem;
  }

  .overlay-card,
  .story-card {
    padding: 14px;
  }

  .action-list,
  .quick-options,
  .scene-list {
    grid-template-columns: 1fr;
  }

  .chat-form {
    grid-template-columns: 1fr auto;
  }

  .save-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auth-forms {
    grid-template-columns: 1fr;
  }

  .ai-config-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .ai-config-grid label {
    margin-top: 4px;
  }

  .auth-user-actions {
    flex-wrap: wrap;
  }

  .admin-adjust-form {
    grid-template-columns: 1fr;
  }

  .admin-password-form {
    grid-template-columns: 1fr;
  }

  .recharge-package-list {
    grid-template-columns: 1fr;
  }

  .auth-gate-grid {
    grid-template-columns: 1fr;
  }

  .auth-gate-actions,
  .auth-gate-register-actions {
    grid-template-columns: 1fr;
  }

  body.admin-dashboard-mode #system-modal {
    padding: 0;
  }

  body.admin-dashboard-mode #system-modal .overlay-card.system-card {
    width: 100vw;
    padding: max(12px, env(safe-area-inset-top)) 10px calc(16px + env(safe-area-inset-bottom));
  }

  body.admin-dashboard-mode .admin-title-row {
    align-items: start;
    flex-direction: column;
  }

  body.admin-dashboard-mode .admin-stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.admin-dashboard-mode .admin-sections-grid {
    grid-template-columns: 1fr;
  }

  body.admin-dashboard-mode .admin-users-list {
    max-height: 40vh;
  }

  body.admin-dashboard-mode .admin-quota-logs,
  body.admin-dashboard-mode .admin-daily-summary {
    max-height: 30vh;
  }

  .npc-card-panel {
    margin-top: 8px;
    padding: 8px;
    height: clamp(340px, 52vh, 500px);
  }

  .npc-card-fixed {
    gap: 6px;
    padding-right: 120px;
  }

  .npc-card-close {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .npc-card-fullscreen {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .npc-card-line {
    gap: 6px;
    align-items: start;
  }

  .npc-card-line h3 {
    font-size: 0.86rem;
  }

  .npc-inline-bio {
    font-size: 0.74rem;
    line-height: 1.3;
  }

  .npc-card-panel .favor {
    font-size: 0.74rem;
  }

  .npc-card-panel .quick-options {
    gap: 5px;
  }

  .npc-card-panel .quick-options button {
    padding: 5px 7px;
    font-size: 0.72rem;
  }

  .npc-card-panel .chat-box {
    padding: 8px;
  }

  .npc-card-panel .chat-line {
    font-size: 0.74rem;
  }

  .npc-card-panel.chat-fullscreen {
    padding: 8px;
    height: clamp(420px, 74vh, 680px);
  }

  .npc-card-panel.chat-fullscreen .chat-box {
    max-height: none;
  }

  #stats-mobile-modal,
  #phase-guide-mobile-modal {
    z-index: 16;
  }

  #stats-mobile-modal .overlay-card,
  #phase-guide-mobile-modal .overlay-card {
    width: min(420px, 94vw);
    max-height: min(84vh, 760px);
  }
}

@media (max-width: 560px) {
  .title {
    font-size: 1rem;
  }

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

  body.admin-dashboard-mode .admin-stats-row {
    grid-template-columns: 1fr;
  }

  .stage-avatar {
    width: min(78vw, 330px);
    height: min(52vh, 500px);
  }

  #stage-dialogue-name {
    font-size: 0.94rem;
  }

  .date-text,
  .stage-dialogue-meta {
    font-size: 0.75rem;
  }

  .stage-dialogue-text {
    font-size: 0.92rem;
  }

  .npc-card-line {
    gap: 4px;
  }

  .npc-card-fixed {
    padding-right: 112px;
    gap: 3px;
  }

  .npc-card-line h3 {
    font-size: 0.84rem;
  }

  .npc-inline-bio {
    font-size: 0.72rem;
  }

  .npc-card-panel .favor {
    font-size: 0.72rem;
  }

  .npc-card-close {
    padding: 3px 7px;
    font-size: 0.7rem;
  }

  .npc-card-fullscreen {
    padding: 3px 7px;
    font-size: 0.7rem;
  }

  .npc-card-panel .chat-box {
    padding: 7px;
  }

  .npc-card-panel {
    height: clamp(280px, 46vh, 360px);
  }

  .npc-card-panel:not(.chat-fullscreen) .chat-box {
    min-height: 96px;
  }

  .npc-card-panel.chat-fullscreen {
    height: clamp(390px, 78vh, 620px);
  }

  .phase-guide-modal-card .phase-guide-title {
    font-size: 0.8rem;
  }

  .phase-guide-modal-card .phase-guide-deadline,
  .phase-guide-modal-card .phase-guide-progress,
  .phase-guide-modal-card .phase-guide-list li {
    font-size: 0.68rem;
  }

  .phase-guide-modal-card .phase-guide-task-btn {
    padding: 3px 5px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .status-card {
    max-height: min(44vh, 280px);
  }

  .phase-guide {
    max-height: none;
  }

  .stage-avatar {
    width: min(40vw, 360px);
    height: min(64vh, 360px);
  }

  .stage-dialogue {
    max-height: min(58vh, 300px);
    padding: 10px;
  }

  .phase-guide-modal-card .phase-guide-list {
    max-height: min(54vh, 260px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@keyframes chatSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes chatCursorBlink {
  0%,
  49% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0;
  }
}

@keyframes cinematicFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

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