:root {
  color-scheme: dark;
  --bg: #111817;
  --surface: #17211f;
  --surface-2: #1d2926;
  --surface-3: #24322e;
  --line: rgba(224, 235, 228, 0.14);
  --line-strong: rgba(224, 235, 228, 0.26);
  --text: #edf2ee;
  --muted: #a7b5ae;
  --faint: #718179;
  --accent: #d56a50;
  --accent-strong: #e47b5f;
  --accent-ink: #19110e;
  --positive: #69a98d;
  --negative: #d46b62;
  --warning: #d0a450;
  --info: #6f9fbd;
  --map-border: rgba(232, 241, 235, 0.2);
  --shadow: 0 18px 55px rgba(3, 11, 9, 0.34);
  --font-sans: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #e8eeea;
  --surface: #f5f8f5;
  --surface-2: #edf2ee;
  --surface-3: #e2eae5;
  --line: rgba(26, 44, 37, 0.14);
  --line-strong: rgba(26, 44, 37, 0.26);
  --text: #18221f;
  --muted: #596861;
  --faint: #7b8b83;
  --accent: #bd503b;
  --accent-strong: #a94130;
  --accent-ink: #f9f4ef;
  --positive: #34765f;
  --negative: #ad423c;
  --warning: #9b6e20;
  --info: #3c718d;
  --map-border: rgba(17, 39, 31, 0.22);
  --shadow: 0 18px 48px rgba(33, 56, 47, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body,
button,
input {
  font-family: var(--font-sans);
}

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
}

button,
input,
a {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 120ms ease;
}

button:hover {
  border-color: var(--accent);
  background: var(--surface-3);
}

button:active {
  transform: translateY(1px) scale(0.98);
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

[hidden] {
  display: none !important;
}

.compat-screen,
.loading-screen {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background:
    linear-gradient(rgba(17, 24, 23, 0.3), rgba(17, 24, 23, 0.88)),
    url("/assets/civilization/town-map.png") center / cover no-repeat;
}

.compat-screen {
  text-shadow: 0 2px 18px rgba(4, 10, 9, 0.8);
}

.compat-screen h1,
.loading-screen h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4.2rem);
  letter-spacing: 0;
}

.compat-screen p,
.loading-screen p {
  max-width: 34rem;
  margin: 0;
  color: #d5ded8;
  line-height: 1.7;
}

.loading-mark,
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(235, 242, 237, 0.34);
  border-radius: 50%;
  background: rgba(18, 29, 25, 0.7);
}

.loading-mark::before,
.brand-mark::before {
  content: "";
  width: 21px;
  height: 21px;
  border: 5px solid #d7b45b;
  border-top-color: transparent;
  border-radius: 50%;
  transform: rotate(-32deg);
}

.loading-mark span,
.brand-mark span {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(8px, 7px);
}

.loading-lines {
  display: grid;
  width: min(280px, 70vw);
  gap: 6px;
  margin-top: 10px;
}

.loading-lines i {
  display: block;
  height: 4px;
  transform-origin: left;
  border-radius: 4px;
  background: rgba(232, 240, 235, 0.18);
  animation: load-line 1.25s cubic-bezier(0.16, 1, 0.3, 1) infinite alternate;
}

.loading-lines i:nth-child(2) {
  animation-delay: 120ms;
}

.loading-lines i:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes load-line {
  from { transform: scaleX(0.2); background: rgba(232, 240, 235, 0.14); }
  to { transform: scaleX(1); background: var(--accent); }
}

.civilization-app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 74px minmax(0, 1fr);
  background: var(--bg);
}

.topbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(190px, 0.7fr) minmax(520px, 1.8fr) auto;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 8px 30px rgba(2, 9, 7, 0.16);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 10px 16px;
}

.brand-mark {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  background: var(--surface-3);
}

.brand-mark::before {
  width: 18px;
  height: 18px;
  border-width: 4px;
}

.brand-block h1 {
  overflow: hidden;
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
  letter-spacing: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand-block p {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.live-indicator {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--positive) 16%, transparent);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(88px, 1fr));
  min-width: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.metric-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-content: center;
  gap: 3px 8px;
  min-width: 0;
  padding: 8px 12px;
  border-left: 1px solid var(--line);
  text-align: left;
  background: transparent;
}

.metric-item:first-child {
  border-left: 0;
}

.metric-item:hover {
  border-color: var(--line);
  background: var(--surface-2);
}

.metric-item span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.metric-item strong {
  grid-row: 2;
  font-family: var(--font-mono);
  font-size: clamp(0.92rem, 1.4vw, 1.22rem);
  font-variant-numeric: tabular-nums;
}

.metric-delta {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  font-family: var(--font-mono);
  font-size: 0.69rem;
}

.metric-delta.good { color: var(--positive); }
.metric-delta.bad { color: var(--negative); }
.metric-delta.neutral { color: var(--faint); }

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  padding: 10px 12px;
}

.top-actions button {
  min-height: 34px;
  white-space: nowrap;
}

.icon-command {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-3);
}

.icon-command span {
  width: 16px;
  font-family: var(--font-mono);
  color: var(--accent-strong);
}

.icon-command b {
  font-size: 0.78rem;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-family: var(--font-mono);
  font-weight: 800;
}

.text-command {
  font-size: 0.78rem;
}

.speed-control,
.story-filters,
.graph-toolbar {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.speed-control button,
.story-filters button,
.graph-toolbar button {
  min-height: 28px;
  border: 0;
  padding: 0 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
}

.speed-control button:hover,
.story-filters button:hover,
.graph-toolbar button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.speed-control button.active,
.story-filters button.active,
.graph-toolbar button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
}

.map-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  border-right: 1px solid var(--line);
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #101816;
}

#townCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#townCanvas.dragging {
  cursor: grabbing;
}

.map-heading {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid rgba(234, 241, 236, 0.22);
  border-radius: 8px;
  color: #edf2ee;
  background: rgba(14, 23, 20, 0.78);
  box-shadow: 0 10px 30px rgba(2, 8, 6, 0.24);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.map-heading p,
.map-heading strong {
  margin: 0;
}

.map-heading p {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 800;
}

.map-heading strong {
  color: #b9c8bf;
  font-size: 0.72rem;
}

.active-effects {
  position: absolute;
  top: 62px;
  left: 16px;
  display: grid;
  gap: 6px;
  max-width: min(380px, calc(100% - 90px));
  pointer-events: none;
}

.active-effect {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: #edf2ee;
  background: rgba(14, 23, 20, 0.82);
  backdrop-filter: blur(10px);
  font-size: 0.72rem;
}

.active-effect b {
  color: #efb377;
}

.active-effect span:last-child {
  color: #b9c8bf;
  font-family: var(--font-mono);
}

.map-tools {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 6px;
}

.map-tools button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-color: rgba(234, 241, 236, 0.22);
  color: #edf2ee;
  background: rgba(14, 23, 20, 0.82);
  backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-weight: 800;
}

.map-hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  max-width: calc(100% - 160px);
  transform: translateX(-50%);
  padding: 8px 11px;
  border-radius: 8px;
  color: #d8e1db;
  background: rgba(14, 23, 20, 0.72);
  font-size: 0.72rem;
  pointer-events: none;
  transition: opacity 240ms ease, transform 240ms ease;
}

.map-hint.dismissed {
  opacity: 0;
  transform: translate(-50%, 8px);
}

.event-spotlight {
  position: absolute;
  right: 66px;
  top: 16px;
  max-width: min(360px, calc(100% - 96px));
  padding: 10px 12px;
  border: 1px solid rgba(234, 241, 236, 0.22);
  border-radius: 8px;
  color: #edf2ee;
  background: rgba(14, 23, 20, 0.86);
  box-shadow: 0 12px 38px rgba(2, 8, 6, 0.28);
  backdrop-filter: blur(12px);
}

.event-spotlight strong,
.event-spotlight span {
  display: block;
}

.event-spotlight strong {
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.event-spotlight span {
  color: #bdcbc3;
  font-size: 0.72rem;
  line-height: 1.55;
}

.god-composer {
  display: grid;
  grid-template-columns: minmax(170px, 0.55fr) minmax(320px, 1.5fr) auto;
  align-items: center;
  gap: 16px;
  padding: 13px 16px max(13px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.god-copy h2,
.story-header h2,
.dialog-shell h2 {
  margin: 0;
  letter-spacing: 0;
}

.god-copy h2 {
  font-size: 0.96rem;
}

.god-copy p,
.story-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

#godEventForm {
  min-width: 0;
}

#godEventForm label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.god-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.god-input-row input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--text);
  background: var(--bg);
}

.god-input-row input::placeholder {
  color: var(--faint);
}

.primary-command {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 800;
  white-space: nowrap;
}

.primary-command:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.form-message {
  margin: 6px 0 0;
  color: var(--negative);
  font-size: 0.72rem;
}

.event-suggestions {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 6px;
}

.event-suggestions button {
  min-height: 29px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 0.68rem;
}

.story-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface);
}

.story-header {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.story-header > div:first-child {
  min-width: 0;
}

.story-header h2 {
  font-size: 1.04rem;
}

.story-filters {
  justify-self: start;
}

.story-timeline {
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}

.story-event {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  min-height: auto;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
  background: transparent;
}

.story-event:hover,
.story-event.selected {
  border-color: var(--line);
  background: var(--surface-2);
}

.event-day {
  display: grid;
  align-content: start;
  justify-items: start;
  padding-top: 1px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.64rem;
}

.event-day strong {
  color: var(--text);
  font-size: 0.9rem;
}

.event-copy {
  min-width: 0;
}

.event-copy strong,
.event-copy span,
.event-copy small {
  display: block;
}

.event-copy strong {
  margin-bottom: 5px;
  font-size: 0.84rem;
  line-height: 1.4;
}

.event-copy span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.event-copy small {
  margin-top: 8px;
  color: var(--faint);
  font-size: 0.63rem;
}

.story-event[data-importance="5"]::before,
.story-event[data-importance="4"]::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
}

.empty-state {
  align-self: center;
  padding: 28px;
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 7px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.citizen-drawer {
  position: fixed;
  z-index: 12;
  top: 74px;
  right: 0;
  bottom: 0;
  width: min(430px, 100vw);
  overflow: auto;
  border-left: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface) 97%, transparent);
  box-shadow: -20px 0 60px rgba(3, 11, 9, 0.36);
  transform: translateX(104%);
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(18px);
}

.citizen-drawer.open {
  transform: translateX(0);
}

.citizen-drawer > header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.follow-button {
  min-height: 34px;
  font-size: 0.75rem;
}

.follow-button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.citizen-content {
  padding: 16px 18px 32px;
}

.citizen-hero {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 17px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.portrait-canvas {
  display: block;
  width: 112px;
  height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.citizen-identity p,
.citizen-identity h2,
.citizen-identity span {
  margin: 0;
}

.citizen-identity p {
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
}

.citizen-identity h2 {
  margin-top: 4px;
  font-size: 1.7rem;
  letter-spacing: 0;
}

.citizen-identity span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.55;
}

.citizen-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.citizen-section:last-child {
  border-bottom: 0;
}

.citizen-section h3 {
  margin: 0 0 10px;
  font-size: 0.8rem;
}

.citizen-section > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.65;
}

.citizen-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.citizen-number {
  min-width: 0;
  padding: 10px;
  background: var(--surface-2);
}

.citizen-number span,
.citizen-number strong {
  display: block;
}

.citizen-number span {
  color: var(--muted);
  font-size: 0.64rem;
}

.citizen-number strong {
  overflow: hidden;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  text-overflow: ellipsis;
}

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

.personality-item {
  padding: 8px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 72%, transparent);
  background: var(--surface-2);
}

.personality-item span,
.personality-item b {
  display: block;
}

.personality-item span {
  color: var(--muted);
  font-size: 0.64rem;
}

.personality-item b {
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.relationship-list,
.memory-list {
  display: grid;
  gap: 7px;
}

.relationship-link {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 9px;
  text-align: left;
  background: var(--surface-2);
}

.relation-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--relation-color, var(--muted));
}

.relationship-link span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.relationship-link small {
  color: var(--muted);
  font-size: 0.64rem;
}

.memory-entry {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.memory-entry:last-child {
  border-bottom: 0;
}

.memory-entry time {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.memory-entry p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.55;
}

dialog {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 20px;
  color: var(--text);
  background: rgba(5, 12, 10, 0.68);
  backdrop-filter: blur(10px);
}

dialog::backdrop {
  background: rgba(5, 12, 10, 0.44);
}

.dialog-shell {
  width: min(620px, 100%);
  max-height: calc(100dvh - 40px);
  margin: auto;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-shell > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-shell > header p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.7rem;
}

.dialog-shell > header h2 {
  font-size: 1.18rem;
}

.dialog-shell > footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.preview-event-content {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.preview-event-content > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.impact-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.impact-item {
  padding: 10px 8px;
  text-align: center;
  background: var(--surface-2);
}

.impact-item span,
.impact-item strong {
  display: block;
}

.impact-item span {
  color: var(--muted);
  font-size: 0.62rem;
}

.impact-item strong {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.impact-item strong.positive { color: var(--positive); }
.impact-item strong.negative { color: var(--negative); }

.graph-shell {
  width: min(1120px, 100%);
  height: min(780px, calc(100dvh - 40px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.graph-toolbar {
  justify-self: start;
  margin: 12px 18px;
}

.graph-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

#relationshipGraph {
  display: block;
  width: 100%;
  height: 100%;
}

#relationshipGraph .graph-edge {
  stroke-opacity: 0.42;
  vector-effect: non-scaling-stroke;
}

#relationshipGraph .graph-node {
  cursor: pointer;
}

#relationshipGraph .graph-node circle {
  stroke: rgba(237, 242, 238, 0.72);
  stroke-width: 2;
}

#relationshipGraph .graph-node text {
  fill: var(--text);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 800;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}

#graphHint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  font-size: 0.68rem;
  pointer-events: none;
}

.save-dialog .dialog-shell {
  width: min(520px, 100%);
}

.save-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 18px;
}

.save-actions a {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}

.save-actions a:hover {
  border-color: var(--accent);
}

.save-note {
  margin: 0;
  padding: 0 18px 18px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.55;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-3);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1420px) {
  .topbar {
    grid-template-columns: 180px minmax(460px, 1fr) auto;
  }

  .top-actions {
    gap: 5px;
  }

  .top-actions button {
    padding-inline: 8px;
  }

  .icon-button {
    width: 34px;
  }

  .god-composer {
    grid-template-columns: minmax(140px, 0.45fr) minmax(300px, 1.4fr);
  }

  .event-suggestions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, auto);
    justify-content: end;
  }
}

@media (max-width: 1160px) {
  body {
    overflow: auto;
  }

  .civilization-app {
    grid-template-rows: auto auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    grid-template-columns: minmax(180px, 0.6fr) minmax(420px, 1.4fr);
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    overflow-x: auto;
    border-top: 1px solid var(--line);
  }

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

  .map-column {
    border-right: 0;
  }

  .map-stage {
    min-height: min(68dvh, 760px);
  }

  .story-panel {
    min-height: 420px;
    border-top: 1px solid var(--line);
  }

  .story-timeline {
    max-height: 56dvh;
  }

  .citizen-drawer {
    top: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .brand-block {
    padding: 9px 12px;
  }

  .metric-strip {
    grid-template-columns: repeat(5, minmax(98px, 1fr));
    overflow-x: auto;
    scrollbar-width: none;
    border: 0;
    border-top: 1px solid var(--line);
  }

  .metric-strip::-webkit-scrollbar,
  .top-actions::-webkit-scrollbar,
  .event-suggestions::-webkit-scrollbar,
  .graph-toolbar::-webkit-scrollbar {
    display: none;
  }

  .metric-item {
    min-height: 58px;
  }

  .top-actions {
    grid-column: auto;
    padding: 7px 10px;
  }

  .text-command,
  .icon-command b {
    font-size: 0.72rem;
  }

  .map-stage {
    min-height: 58dvh;
  }

  .map-heading {
    top: 10px;
    left: 10px;
  }

  .active-effects {
    top: 56px;
    left: 10px;
  }

  .map-tools {
    right: 10px;
    bottom: 10px;
  }

  .map-hint {
    bottom: 10px;
    max-width: calc(100% - 120px);
    text-align: center;
  }

  .event-spotlight {
    top: auto;
    right: 58px;
    bottom: 10px;
    left: 10px;
  }

  .god-composer {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 13px 12px max(13px, env(safe-area-inset-bottom));
  }

  .god-copy p {
    display: none;
  }

  .god-input-row {
    grid-template-columns: 1fr;
  }

  .god-input-row input,
  .god-input-row button {
    width: 100%;
  }

  .event-suggestions {
    grid-column: auto;
    grid-template-columns: repeat(4, minmax(88px, 1fr));
    justify-content: stretch;
    overflow-x: auto;
  }

  .event-suggestions button {
    white-space: nowrap;
  }

  .story-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface);
  }

  .citizen-drawer {
    top: auto;
    width: 100%;
    height: min(82dvh, 760px);
    border-top: 1px solid var(--line-strong);
    border-left: 0;
    transform: translateY(104%);
  }

  .citizen-drawer.open {
    transform: translateY(0);
  }

  .citizen-hero {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .portrait-canvas {
    width: 92px;
    height: 108px;
  }

  dialog {
    padding: 8px;
  }

  .dialog-shell,
  .graph-shell {
    max-height: calc(100dvh - 16px);
  }

  .graph-shell {
    height: calc(100dvh - 16px);
  }

  .graph-toolbar {
    max-width: calc(100% - 28px);
    overflow-x: auto;
  }

  .impact-grid {
    grid-template-columns: repeat(3, 1fr);
  }

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

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