:root {
  color-scheme: light;
  --desk: #213536;
  --desk-deep: #172729;
  --desk-line: #385052;
  --paper: #d6dbcf;
  --paper-light: #e7eadf;
  --paper-deep: #c5ccbd;
  --ink: #202a2a;
  --ink-soft: #3e4b4a;
  --muted: #706b61;
  --muted-dark: #aebbb7;
  --rule: #a6ae9e;
  --rule-dark: #496163;
  --brass: #b58b4d;
  --brass-pale: #d5bd86;
  --wax: #365f6b;
  --wax-dark: #234650;
  --teal: #708174;
  --danger: #99453d;
  --paper-shadow: 10px 12px 0 rgba(8, 18, 19, .16), 0 18px 48px rgba(5, 14, 15, .2);
  --display: "FangSong", "STFangsong", "SimSun", serif;
  --body: "Microsoft YaHei", "PingFang SC", sans-serif;
  --utility: "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background-color: var(--desk);
  background-image:
    linear-gradient(rgba(232, 224, 205, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 224, 205, .035) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--paper-light);
  font-family: var(--body);
  font-size: 15px;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, label.file-button { user-select: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid var(--brass-pale);
  outline-offset: 3px;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  padding: 25px 18px 20px;
  display: flex;
  flex-direction: column;
  background: var(--desk-deep);
  border-right: 1px solid #4a5f5e;
  box-shadow: inset -7px 0 20px rgba(0, 0, 0, .13);
}
.brand { display: flex; gap: 13px; align-items: center; padding: 3px 8px 27px; }
.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--brass-pale);
  border-radius: 50%;
  color: var(--brass-pale);
  font: 22px var(--display);
  box-shadow: inset 0 0 0 4px var(--desk-deep), inset 0 0 0 5px rgba(213, 189, 134, .35);
}
.brand strong { display: block; font-family: var(--display); font-size: 19px; letter-spacing: .08em; }
.brand span { display: block; margin-top: 4px; color: var(--muted-dark); font-size: 11px; }
.nav-list { display: grid; gap: 5px; }
.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--muted-dark);
  text-align: left;
  cursor: pointer;
  transition: color .15s ease, background .15s ease, transform .15s ease;
}
.nav-item span { display: inline-grid; width: 28px; color: var(--brass-pale); font-family: var(--utility); }
.nav-item:hover { background: rgba(231, 224, 205, .07); color: var(--paper-light); }
.nav-item.active {
  transform: translateX(4px);
  background: var(--paper);
  border-color: var(--rule);
  border-left-color: var(--wax);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 6px 7px 0 rgba(0, 0, 0, .13);
}
.nav-item.active span { color: var(--wax); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px 9px 0; color: var(--muted-dark); font-size: 11px; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: #76ad8e; box-shadow: 0 0 0 3px rgba(118, 173, 142, .12); }
.save-dot.saving { background: var(--brass-pale); }

.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  height: 74px;
  padding: 0 34px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(23, 39, 41, .96);
  border-bottom: 1px solid var(--rule-dark);
  box-shadow: 0 6px 18px rgba(4, 13, 14, .13);
}
.project-title {
  width: min(420px, 45vw);
  padding: 8px 2px 7px;
  border: 0;
  border-bottom: 1px solid rgba(213, 189, 134, .45);
  background: transparent;
  color: var(--paper-light);
  font: 700 20px var(--display);
  letter-spacing: .06em;
}
.project-title:hover, .project-title:focus { border-bottom-color: var(--brass-pale); }
.top-actions, .heading-actions, .hero-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.top-actions { margin-left: auto; }
.mobile-menu { display: none; border: 0; background: transparent; color: var(--paper-light); font-size: 23px; }
.main-content { max-width: 1540px; margin: 0 auto; padding: 36px 38px 64px; }
.view { display: none; animation: pageIn .2s ease-out; }
.view.active { display: block; }
@keyframes pageIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.button, .tool-button, .icon-button {
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--paper-light);
  color: var(--ink);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.button { min-height: 40px; padding: 9px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.button:hover, .tool-button:hover, .icon-button:hover { border-color: var(--brass); box-shadow: 3px 3px 0 rgba(35, 42, 40, .16); transform: translate(-1px, -1px); }
.button.primary { background: var(--wax); border-color: var(--wax-dark); color: #fff7e7; font-weight: 700; }
.button.primary:hover { background: #426f7b; }
.button.secondary { background: var(--brass-pale); border-color: var(--brass); color: var(--ink); }
.button.ghost { background: transparent; border-color: var(--rule); color: var(--ink-soft); }
.topbar .button.ghost, .section-heading .button.ghost { border-color: var(--rule-dark); color: var(--paper-light); }
.topbar .button.ghost:hover, .section-heading .button.ghost:hover { border-color: var(--brass-pale); background: rgba(231, 224, 205, .07); }
.button.danger { background: var(--danger); border-color: #71302c; color: #fff7e7; }
.button.small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.file-button { cursor: pointer; }
.file-button input { display: none; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0; }
.tool-button { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.tool-button.active { background: var(--wax); border-color: var(--wax-dark); color: #fff7e7; }

.eyebrow { margin: 0 0 8px; color: var(--wax); font: 700 10px var(--utility); letter-spacing: .14em; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: var(--display); font-weight: 700; letter-spacing: .035em; }
h1 { margin-bottom: 11px; font-size: clamp(31px, 3.2vw, 46px); line-height: 1.14; }
h2 { margin-bottom: 8px; font-size: 23px; }
h3 { font-size: 16px; }
p { color: var(--muted); line-height: 1.75; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 28px; }
.section-heading > div:first-child { max-width: 760px; }
.section-heading h1 { color: var(--paper-light); }
.section-heading .eyebrow { color: var(--brass-pale); }
.section-heading p:last-child { margin-bottom: 0; color: var(--muted-dark); }

.panel {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background-color: var(--paper);
  background-image: linear-gradient(rgba(60, 73, 71, .025) 1px, transparent 1px);
  background-size: 100% 28px;
  color: var(--ink);
  box-shadow: var(--paper-shadow);
}
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; color: var(--ink); }
.hero-card {
  position: relative;
  min-height: 318px;
  padding: 48px 52px;
  display: grid;
  grid-template-columns: 1.18fr .82fr;
  align-items: center;
  overflow: hidden;
  border: 1px solid #a3ac9b;
  border-radius: 2px;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(54, 71, 69, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(54, 71, 69, .06) 1px, transparent 1px);
  background-size: 34px 34px;
  color: var(--ink);
  box-shadow: 13px 15px 0 rgba(7, 17, 18, .2), 0 24px 55px rgba(3, 12, 13, .18);
  clip-path: polygon(0 0, calc(100% - 25px) 0, 100% 25px, 100% 100%, 0 100%);
}
.hero-card::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 25px;
  height: 25px;
  background: linear-gradient(45deg, #a8b0a1 49%, var(--desk) 51%);
}
.hero-card > div:first-child { position: relative; z-index: 2; }
.hero-card h1 { max-width: 650px; margin-bottom: 14px; color: var(--ink); font-size: clamp(42px, 5.3vw, 68px); }
.hero-card p { max-width: 650px; color: #59615e; font-size: 16px; }
.hero-orbit {
  position: relative;
  min-height: 236px;
  border: 1px solid rgba(55, 75, 73, .4);
  background:
    linear-gradient(rgba(73, 101, 98, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(73, 101, 98, .08) 1px, transparent 1px);
  background-size: 24px 24px;
}
.hero-orbit > span { position: absolute; top: 10px; left: 12px; color: var(--muted); font: 10px var(--utility); letter-spacing: .1em; }
.planet {
  position: absolute;
  left: 51%;
  top: 51%;
  width: 126px;
  height: 126px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: start center;
  padding-top: 10px;
  border: 1px solid var(--ink-soft);
  border-radius: 50%;
  background: transparent;
  color: var(--wax);
  font: 18px var(--display);
  box-shadow: inset 0 0 0 22px rgba(85, 127, 125, .06), inset 0 0 0 23px rgba(62, 75, 74, .25);
}
.planet::before, .planet::after { content: ""; position: absolute; background: rgba(62, 75, 74, .55); }
.planet::before { left: 50%; top: -32px; bottom: -32px; width: 1px; }
.planet::after { top: 50%; left: -32px; right: -32px; height: 1px; }
.hero-orbit::before, .hero-orbit::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(85, 127, 125, .66);
  transform: rotate(-13deg);
}
.hero-orbit::before { inset: 24% 9% 18% 6%; border-radius: 48% 35% 52% 41%; }
.hero-orbit::after { inset: 35% 3% 30% 17%; border-color: rgba(151, 72, 61, .5); border-radius: 42% 55% 39% 50%; transform: rotate(8deg); }
.hero-orbit i { position: absolute; z-index: 2; width: 8px; height: 8px; border: 2px solid var(--paper); border-radius: 50%; background: var(--wax); box-shadow: 0 0 0 1px var(--wax); }
.hero-orbit i:nth-of-type(1) { left: 14%; top: 43%; }
.hero-orbit i:nth-of-type(2) { right: 13%; top: 25%; background: var(--teal); box-shadow: 0 0 0 1px var(--teal); }
.hero-orbit i:nth-of-type(3) { right: 20%; bottom: 17%; background: var(--brass); box-shadow: 0 0 0 1px var(--brass); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 25px 0 20px;
  border: 1px solid var(--rule);
  background: var(--paper);
  box-shadow: 7px 8px 0 rgba(7, 17, 18, .13);
}
.stat-card { min-width: 0; padding: 18px 23px; border-right: 1px solid var(--rule); background: transparent; color: var(--ink); }
.stat-card:last-child { border-right: 0; }
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card span { font-size: 12px; }
.stat-card strong { display: block; margin: 2px 0 4px; color: var(--wax); font: 34px var(--utility); }
.dashboard-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 20px; }
.dashboard-grid .panel { padding: 28px; }
.getting-started ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; }
.getting-started li { display: flex; gap: 14px; align-items: flex-start; }
.getting-started li > span {
  flex: 0 0 31px;
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border: 1px solid var(--wax);
  border-radius: 50%;
  color: var(--wax);
  background: transparent;
  font: 700 13px var(--utility);
}
.getting-started li strong { display: block; margin-bottom: 3px; color: var(--ink); }
.getting-started li p { margin: 0; font-size: 13px; }

.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; }
.map-panel { overflow: hidden; }
.map-toolbar { min-height: 56px; display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--rule); background: var(--paper-deep); flex-wrap: wrap; }
.toolbar-spacer { flex: 1; }
.map-stage-wrap { position: relative; min-height: 650px; overflow: hidden; background: #1a2b2c; }
.map-canvas { width: 100%; height: min(70vh, 750px); min-height: 650px; display: block; cursor: grab; touch-action: none; }
.map-canvas.add-mode { cursor: crosshair; }
.map-canvas.dragging { cursor: grabbing; }
.map-hint { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 8px 13px; border: 1px solid var(--brass); border-radius: 2px; background: rgba(23, 39, 41, .92); color: var(--paper); font-size: 12px; pointer-events: none; opacity: 0; transition: opacity .2s; }
.map-hint.visible { opacity: 1; }
.map-inspector { min-height: 650px; max-height: calc(100vh - 135px); padding: 22px; overflow: auto; }
.stack-list, .entity-list { display: grid; gap: 9px; }
.list-card {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--teal);
  border-radius: 2px;
  background: var(--paper-light);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.list-card:hover { border-color: var(--brass); }
.list-card strong { display: block; }
.list-card small { color: var(--muted); }
.marker-swatch { display: inline-block; width: 10px; height: 10px; margin-right: 7px; border-radius: 50%; }

.entity-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 20px; min-height: 690px; }
.entity-sidebar, .entity-editor { padding: 22px; }
.entity-sidebar { max-height: calc(100vh - 150px); overflow: auto; }
.search-input, input[type="text"], input[type="number"], input[type="color"], textarea, select, .project-title { outline: none; }
.search-input, .form-field input, .form-field textarea, .form-field select, .emblem-controls input:not([type="color"]), .emblem-controls select, .prompt-form input, .prompt-form textarea, .prompt-form select, #markerEditor input, #markerEditor textarea, #markerEditor select, #relationForm input, #relationForm textarea, #relationForm select, #timelineForm input, #timelineForm textarea, #timelineForm select {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-light);
  color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; }
.search-input { margin-bottom: 12px; }
.chip-row { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 5px 9px; border: 1px solid var(--rule); border-radius: 2px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.chip.active { border-color: var(--wax); background: var(--wax); color: #fff7e7; }
.entity-item { display: grid; gap: 4px; padding: 13px; border: 1px solid var(--rule); border-radius: 2px; background: var(--paper-light); color: var(--ink); text-align: left; cursor: pointer; }
.entity-item.active { border-color: var(--wax); box-shadow: inset 3px 0 var(--wax); }
.entity-item span { color: var(--wax); font: 10px var(--utility); letter-spacing: .08em; }
.entity-item small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-heading { display: flex; justify-content: space-between; gap: 15px; align-items: flex-start; margin-bottom: 20px; }
.editor-title-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-field { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.form-field.full { grid-column: 1 / -1; }
.form-field textarea.large { min-height: 135px; }
.editor-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }

.relation-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; }
.relation-graph-panel { min-height: 650px; overflow: hidden; }
#relationGraph { width: 100%; min-height: 650px; display: block; }
.relation-list-panel { max-height: calc(100vh - 150px); padding: 22px; overflow: auto; }
.graph-node text { fill: var(--ink); font-family: var(--body); font-size: 12px; pointer-events: none; }
.graph-node circle { stroke: var(--paper-light); stroke-width: 3; }
.graph-link { stroke: var(--teal); stroke-width: 2; opacity: .72; }
.graph-link-label { fill: var(--muted); font: 10px var(--body); }

.timeline-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; }
#timelineForm { min-height: 300px; padding: 22px; }
.timeline-panel { min-height: 560px; padding: 28px; }
.timeline-list { position: relative; padding-left: 42px; display: grid; gap: 9px; }
.timeline-list::before { content: ""; position: absolute; top: 0; bottom: 0; left: 14px; width: 1px; background: var(--wax); }
.timeline-item { position: relative; padding: 16px 18px; border: 1px solid var(--rule); border-radius: 2px; background: var(--paper-light); color: var(--ink); }
.timeline-item::before { content: ""; position: absolute; left: -34px; top: 22px; width: 11px; height: 11px; border: 3px solid var(--paper); border-radius: 50%; background: var(--wax); box-shadow: 0 0 0 1px var(--wax); }
.timeline-item time { color: var(--wax); font: 700 11px var(--utility); }
.timeline-item h3 { margin: 5px 0; }
.timeline-item p { margin: 0; font-size: 13px; }

.emblem-layout { display: grid; grid-template-columns: minmax(420px, .9fr) minmax(320px, .7fr); gap: 20px; }
.emblem-preview-panel {
  min-height: 650px;
  display: grid;
  place-items: center;
  padding: 40px;
  background-color: var(--desk-deep);
  background-image:
    linear-gradient(rgba(231, 224, 205, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(231, 224, 205, .04) 1px, transparent 1px);
  background-size: 28px 28px;
  border-color: var(--rule-dark);
}
#emblemPreview { width: min(100%, 540px); filter: drop-shadow(9px 14px 0 rgba(0, 0, 0, .24)); }
.emblem-controls { padding: 28px; display: grid; gap: 18px; align-content: start; }
.emblem-controls label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.emblem-controls input[type="color"] { width: 100%; height: 44px; padding: 4px; border: 1px solid var(--rule); border-radius: 2px; background: var(--paper-light); }
.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.help-text { color: var(--muted); font-size: 12px; line-height: 1.6; }

.prompt-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.prompt-form, .prompt-result { padding: 26px; }
.prompt-form { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.prompt-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.prompt-form label.full { grid-column: 1 / -1; }
.prompt-result pre { min-height: 490px; margin: 0; padding: 19px; border: 1px solid #3d5556; border-radius: 2px; background: var(--desk-deep); color: var(--paper); white-space: pre-wrap; line-height: 1.8; font-family: var(--body); }

.data-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.data-card { min-height: 260px; padding: 25px; display: flex; flex-direction: column; align-items: flex-start; }
.data-card p { flex: 1; font-size: 13px; }
.data-icon { width: 42px; height: 42px; margin-bottom: 20px; display: grid; place-items: center; border: 1px solid var(--wax); border-radius: 50%; background: transparent; color: var(--wax); font: 700 18px var(--utility); }
.danger-card { border-color: rgba(151, 72, 61, .65); }
.danger-card .data-icon { border-color: var(--danger); background: var(--danger); color: #fff7e7; }
.privacy-note { margin-top: 20px; padding: 20px 24px; }
.privacy-note p { margin: 6px 0 0; }

.empty-state { min-height: 260px; padding: 30px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 17px; }
.empty-state p { margin: 6px 0 0; }
.empty-state.compact { min-height: 180px; }
.hidden { display: none !important; }
.form-stack { display: grid; gap: 13px; }
.form-actions { display: flex; gap: 9px; margin-top: 14px; }
.subtle-divider { height: 1px; margin: 18px 0; background: var(--rule); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 20px; display: grid; place-items: center; background: rgba(7, 16, 17, .76); }
.modal { width: min(520px, 100%); max-height: 90vh; padding: 25px; overflow: auto; border: 1px solid var(--rule); border-radius: 4px; background: var(--paper); color: var(--ink); box-shadow: 16px 18px 0 rgba(0, 0, 0, .25), 0 30px 80px rgba(0, 0, 0, .32); }
.modal-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-heading h2 { margin: 0; }
.toast-region { position: fixed; right: 24px; bottom: 24px; z-index: 120; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 360px; padding: 12px 15px; border: 1px solid var(--brass); border-radius: 3px; background: var(--paper-light); color: var(--ink); box-shadow: 7px 8px 0 rgba(0, 0, 0, .2); animation: toastIn .2s ease; }
.toast.error { border-color: #71302c; background: var(--danger); color: #fff7e7; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

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

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card:nth-child(2) { border-right: 0; }
  .stat-card:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
  .data-grid { grid-template-columns: repeat(2, 1fr); }
  .map-layout, .relation-layout { grid-template-columns: 1fr; }
  .map-inspector, .relation-list-panel { max-height: none; min-height: 260px; }
  .relation-graph-panel, #relationGraph { min-height: 520px; }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; width: 246px; transform: translateX(-103%); transition: transform .2s ease; box-shadow: 12px 0 35px rgba(0, 0, 0, .28); }
  .sidebar.open { transform: none; }
  .mobile-menu { display: block; }
  .topbar { padding: 0 18px; }
  .top-actions .ghost { display: none; }
  .main-content { padding: 25px 18px 48px; }
  .hero-card { grid-template-columns: 1fr; padding: 38px 30px; }
  .hero-orbit { display: none; }
  .dashboard-grid, .entity-layout, .timeline-layout, .emblem-layout, .prompt-layout { grid-template-columns: 1fr; }
  .entity-sidebar { max-height: 350px; }
  .emblem-preview-panel { min-height: 440px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  .stats-grid, .data-grid, .form-grid, .prompt-form, .color-grid { grid-template-columns: 1fr; }
  .stat-card { border-right: 0; border-bottom: 1px solid var(--rule); }
  .stat-card:nth-child(3) { border-bottom: 1px solid var(--rule); }
  .stat-card:last-child { border-bottom: 0; }
  .prompt-form label.full, .form-field.full { grid-column: auto; }
  .top-actions .primary { display: none; }
  .project-title { width: 100%; }
  .hero-card { min-height: 330px; padding: 35px 24px; }
  .hero-card h1 { font-size: 43px; }
  .map-stage-wrap, .map-canvas { min-height: 460px; }
}

/* 手机沿用原有纸面配色，调整操作空间。 */
.mobile-only { display: none; }
.menu-overlay { position: fixed; inset: 0; z-index: 19; border: 0; background: #071011b8; }
.menu-close { align-self: flex-end; }
.menu-open, .dialog-open { overflow: hidden; }
.device-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 24px; font-size: 12px; color: var(--muted-dark); }
#mobileSaveStatus { display: none; }
.panel, .form-field, .editor-title-row, label { min-width: 0; }
.list-card, .entity-item, .timeline-item, .privacy-note, .prompt-result { overflow-wrap: anywhere; }
.modal { max-height: calc(100dvh - 40px); }
@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  #mobileSaveStatus { display: inline; }
  .sidebar { height: 100dvh; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(20px, env(safe-area-inset-bottom)); overflow-y: auto; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); padding-top: env(safe-area-inset-top); height: auto; min-height: 68px; gap: 10px; }
  .project-title { min-width: 0; flex: 1; width: 0; }
  .main-content { padding: 18px max(12px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .device-status { padding: 8px 12px; }
  button, .button, .button.small, .tool-button, .chip, .nav-item, .file-button { min-height: 44px; }
  .icon-button, .mobile-menu { min-width: 44px; height: 44px; flex-shrink: 0; }
  input, select, textarea { font-size: 16px !important; max-width: 100%; }
  .heading-actions, .hero-actions, .form-actions, .editor-actions { flex-wrap: wrap; }
  .map-stage-wrap { min-height: 0; }
  .map-canvas { min-height: 260px; height: clamp(260px, 55dvh, 560px); }
  .map-inspector, .relation-list-panel { min-height: 0; max-height: none; padding: 16px; }
  .map-hint { max-width: calc(100% - 24px); width: max-content; text-align: center; }
  .entity-layout { min-height: 0; }
  .entity-sidebar { max-height: none; }
  .entity-layout:not(.editing) .entity-editor, .entity-layout.editing .entity-sidebar { display: none; }
  .entity-editor, .entity-sidebar { padding: 16px; }
  #entityBack { margin-bottom: 16px; }
  .editor-heading { flex-wrap: wrap; }
  .editor-title-row { width: 100%; grid-template-columns: minmax(90px, 1fr) minmax(0, 2fr); }
  .relation-graph-panel, #relationGraph { min-height: 0; }
  .relation-graph-panel { overflow-x: auto; }
  #relationGraph { width: max(100%, 600px); height: 420px; }
  .emblem-preview-panel { min-height: 0; padding: 20px; }
  #emblemPreview { max-height: 50dvh; }
  .modal-backdrop { padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
  .modal { padding: 18px; max-height: calc(100dvh - 40px); overscroll-behavior: contain; }
  .toast-region { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .toast { width: 100%; min-width: 0; max-width: 100%; }
}
