:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b0d0c;
  color: #ece9df;
  --bg: #0b0d0c;
  --panel: #111412;
  --panel-2: #151816;
  --panel-3: #1a1e1b;
  --line: #292e2a;
  --line-soft: #202420;
  --muted: #8f958f;
  --text: #ece9df;
  --soft-text: #c6c7c1;
  --accent: #d9d1bb;
  --good: #8ebc9a;
  --bad: #c48d86;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 310px minmax(0, 1fr); }
.character-sidebar { position: sticky; top: 0; height: 100vh; overflow: hidden; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #0f1210; }
.brand-row { display: flex; align-items: center; justify-content: space-between; padding: 26px 22px 18px; }
.eyebrow { color: #7f877f; font-size: 10px; letter-spacing: .17em; font-weight: 800; text-transform: uppercase; }
.brand-title { margin-top: 5px; font-family: Georgia, serif; font-size: 23px; }
.game-link { color: #a9aea8; text-decoration: none; font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 7px 11px; }
.game-link:hover { border-color: #4a514b; color: var(--text); }
.admin-nav { display: flex; gap: 6px; padding: 0 16px 14px; flex-wrap: wrap; }
.admin-nav a { color: #8f958f; text-decoration: none; border: 1px solid #292e2a; border-radius: 7px; padding: 7px 9px; font-size: 11px; }
.admin-nav a.active, .admin-nav a:hover { color: #e2d9c5; border-color: #5b5039; background: #181914; }
.admin-nav.horizontal { padding: 0; justify-content: flex-end; }
.check-row { display: flex !important; align-items: center; gap: 6px; color: #b5b9b3; font-size: 11px; min-height: 37px; }
.wide-controls { max-width: 720px; }
.link-button { display: inline-flex; text-decoration: none; align-items: center; justify-content: center; }
.location-admin-hero { display: grid; grid-template-columns: minmax(280px, 46%) 1fr; gap: 24px; padding: 26px 0; }
.location-art-frame { min-height: 270px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #0b0e0c; display: grid; place-items: center; }
.location-art-frame img { width: 100%; height: 100%; min-height: 270px; object-fit: cover; }
.location-art-frame > div { color: #6f766f; }
.location-admin-copy h2 { font: 400 clamp(34px, 4vw, 52px)/1 Georgia, serif; margin: 10px 0; }
.location-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.dialog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.dialog-grid select, .dialog-grid input { width: 100%; background: #171a18; color: var(--text); border: 1px solid #343934; border-radius: 8px; padding: 9px 10px; }
.dialog-check { margin-top: 12px; }
.map-page { min-height: 100vh; background: #090b0a; color: var(--text); }
.map-admin-header { height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 24px; border-bottom: 1px solid var(--line); background: #0e1110; }
.map-admin-header h1 { margin: 4px 0 0; font: 400 30px Georgia, serif; }
.map-layout { display: grid; grid-template-columns: minmax(0,1fr) 320px; grid-template-rows: auto 1fr; min-height: calc(100vh - 78px); }
.map-toolbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: #101311; color: #919790; font-size: 11px; }
.map-toolbar label { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.map-toolbar label + label { margin-left: 0; }
.map-toolbar select { background: #171a18; color: var(--text); border: 1px solid #343934; border-radius: 6px; padding: 6px 8px; }
.world-map-canvas { position: relative; overflow: auto; min-height: 620px; background-image: radial-gradient(circle at center, rgba(87,74,48,.08), transparent 55%), linear-gradient(#111512 1px, transparent 1px), linear-gradient(90deg,#111512 1px,transparent 1px); background-size: auto, 40px 40px, 40px 40px; }
.map-lines, .map-nodes { position: absolute; left: 0; top: 0; width: var(--map-width); height: var(--map-height); }
.map-lines { pointer-events: none; }
.map-lines line { stroke: #645334; stroke-width: 2; stroke-dasharray: 7 6; opacity: .75; }
.map-node { position: absolute; width: 142px; min-height: 84px; transform: translate(-50%,-50%); border: 1px solid #4d4534; border-radius: 10px; color: #ddd6c7; background: linear-gradient(rgba(17,20,18,.78),rgba(17,20,18,.92)), var(--node-art, none) center/cover; padding: 10px; text-align: left; box-shadow: 0 8px 26px rgba(0,0,0,.25); }
.map-node:hover { border-color: #92764b; transform: translate(-50%,-50%) scale(1.03); }
.map-node.player-here { outline: 2px solid #b39762; }
.map-node-icon { color: #d0aa6d; font-size: 20px; display: block; margin-bottom: 5px; }
.map-node strong { display: block; font: 14px Georgia, serif; }
.map-node small { display: block; color: #8e948e; font-size: 9px; margin-top: 4px; }
.map-inspector { border-left: 1px solid var(--line); background: #0e1110; overflow: auto; }
.map-inspector-art { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-bottom: 1px solid var(--line); }
.map-inspector-copy { padding: 18px; }
.map-inspector h2 { margin: 6px 0; font: 400 28px Georgia, serif; }
.map-inspector p { color: #9ca19b; line-height: 1.55; font-size: 12px; }
.map-inspector dl { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; margin: 18px 0; font-size: 11px; }
.map-inspector dt { color: #727971; }.map-inspector dd { margin: 0; color: #d3d0c8; }
.activity-page { min-height: 100vh; background: #0b0d0c; }
.activity-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px 28px; border-bottom: 1px solid var(--line); background: #0e1110; }
.activity-header h1 { margin: 5px 0 4px; font: 400 34px Georgia, serif; }
.activity-header p { margin: 0; color: var(--muted); font-size: 12px; }
.activity-main { padding: 22px 28px 60px; max-width: 1600px; margin: 0 auto; }
.activity-stats { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px; margin-bottom: 14px; }
.activity-stat { border: 1px solid var(--line); background: #111412; border-radius: 10px; padding: 13px 14px; }
.activity-stat span, .activity-stat small { display: block; color: var(--muted); font-size: 9px; }
.activity-stat strong { display: block; margin: 5px 0 3px; color: #e0d9c8; font: 18px Georgia, serif; }
.activity-filters { display: grid; grid-template-columns: 170px 190px 190px minmax(220px,1fr) auto; gap: 9px; align-items: end; margin-bottom: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #101311; }
.activity-filters label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; }
.activity-filters select, .activity-filters input { width: 100%; border: 1px solid #343934; border-radius: 7px; background: #171a18; color: var(--text); padding: 8px 9px; outline: none; }
.activity-grid { display: grid; grid-template-columns: minmax(0,1fr) 280px; gap: 14px; align-items: start; }
.activity-feed-wrap, .activity-health { border: 1px solid var(--line); border-radius: 11px; background: #101311; overflow: hidden; }
.activity-feed-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.activity-feed-head span { color: var(--muted); font-size: 10px; }
.activity-feed { height: calc(100vh - 270px); min-height: 480px; overflow-y: auto; padding: 10px; display: grid; align-content: start; gap: 8px; }
.activity-entry { border: 1px solid #272c27; border-left-width: 3px; border-radius: 8px; background: #141714; padding: 11px 12px; }
.activity-entry.type-npc_dialogue { border-left-color: #b69b68; }
.activity-entry.type-npc_activity { border-left-color: #817a6b; }
.activity-entry.type-social_action { border-left-color: #708b79; }
.activity-entry.type-npc_move { border-left-color: #6f8091; }
.activity-entry.type-world_event { border-left-color: #9a6f65; }
.activity-entry-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; color: #747b74; font-size: 9px; }
.activity-type { color: #c4b89e; text-transform: uppercase; letter-spacing: .06em; }
.activity-hidden { color: #c38f86; }
.activity-entry-title { margin-top: 6px; color: #e1dbcc; font: 15px Georgia, serif; }
.activity-message { margin-top: 6px; color: #aeb3ad; white-space: pre-wrap; line-height: 1.5; font-size: 11px; }
.dialogue-log { display: grid; gap: 6px; margin-top: 8px; }
.dialogue-line { display: grid; grid-template-columns: 110px minmax(0,1fr); gap: 10px; padding: 7px 8px; border: 1px solid #252a26; background: #101310; border-radius: 6px; }
.dialogue-line strong { color: #d0b47f; font: 12px Georgia, serif; }
.dialogue-line p { margin: 0; color: #d1d0c9; font-size: 11px; line-height: 1.45; }
.activity-reason { margin-top: 7px; color: #6f776f; font-size: 9px; }
.activity-debug { margin-top: 8px; border-top: 1px solid #252a26; padding-top: 7px; }
.activity-debug summary { cursor: pointer; color: #988c72; font-size: 9px; }
.activity-debug pre { margin: 7px 0 0; max-height: 280px; overflow: auto; border: 1px solid #252a26; border-radius: 6px; background: #0d100e; color: #9fa69f; padding: 8px; font: 9px/1.45 Consolas, monospace; white-space: pre-wrap; }
.faction-admin-main { padding: 18px; display: grid; gap: 16px; }
.faction-admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 14px; }
.faction-admin-card { border: 1px solid #2d322d; border-radius: 9px; background: #111411; padding: 14px; }
.faction-admin-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; border-bottom: 1px solid #272c27; padding-bottom: 10px; }
.faction-admin-head h2 { margin: 3px 0 0; color: #d9c39d; font: 20px Georgia, serif; }
.faction-metric-grid { display: grid; grid-template-columns: repeat(5, minmax(90px, 1fr)); gap: 7px; margin: 12px 0; }
.faction-metric-grid .activity-stat { min-width: 0; }
.faction-columns { display: grid; grid-template-columns: minmax(0,.8fr) minmax(0,1.2fr); gap: 14px; }
.faction-columns h3 { margin: 10px 0 7px; color: #a9997c; font: 12px Georgia, serif; }
.faction-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.faction-tags span { border: 1px solid #343832; border-radius: 999px; padding: 4px 7px; color: #969e96; font-size: 8px; }
.faction-relation-row { display: flex; justify-content: space-between; border-bottom: 1px solid #222722; padding: 6px 2px; color: #888f88; font-size: 9px; }
.faction-relation-row strong { color: #c3af8d; }
.faction-history-row { border: 1px solid #292e29; border-radius: 5px; padding: 7px; margin-bottom: 6px; }
.faction-history-row > div { display: flex; justify-content: space-between; gap: 8px; }
.faction-history-row strong { color: #c5b18f; font: 10px Georgia, serif; }
.faction-history-row small { color: #707770; font-size: 8px; }
.faction-history-row p { margin: 4px 0 0; color: #858c85; font-size: 8px; line-height: 1.4; }
@media (max-width: 900px) {
  .faction-admin-grid { grid-template-columns: 1fr; }
  .faction-metric-grid { grid-template-columns: repeat(2, 1fr); }
  .faction-columns { grid-template-columns: 1fr; }
}
.activity-health { position: sticky; top: 14px; padding: 14px; }
.activity-health h2 { margin: 0 0 12px; font: 20px Georgia, serif; }
.health-block { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.health-block:last-child { border-bottom: 0; }
.health-block span, .health-block small { display: block; color: var(--muted); font-size: 9px; line-height: 1.45; }
.health-block strong { display: block; margin: 5px 0; color: #d8d3c6; font-size: 12px; }
.search-wrap { padding: 0 16px 12px; }
.search-wrap input { width: 100%; background: #151816; border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 11px 12px; outline: none; }
.search-wrap input:focus { border-color: #555e57; }
.sidebar-meta { padding: 0 20px 10px; color: var(--muted); font-size: 11px; }
.character-list { overflow: auto; padding: 0 10px 18px; display: grid; gap: 4px; }
.character-item { border: 1px solid transparent; border-radius: 9px; padding: 12px; background: transparent; text-align: left; color: var(--text); width: 100%; }
.character-item:hover { background: #151816; }
.character-item.active { background: #181c19; border-color: #343a35; }
.character-item-name { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 14px; font-weight: 700; }
.character-item-meta { color: var(--muted); font-size: 11px; margin-top: 5px; line-height: 1.5; }
.source-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; background: #747b75; }
.source-dot.ai { background: #b4a47c; }

.admin-main { min-width: 0; padding: 34px clamp(28px, 4vw, 62px) 80px; }
.admin-header { display: flex; justify-content: space-between; gap: 30px; align-items: flex-end; border-bottom: 1px solid var(--line); padding-bottom: 24px; }
.admin-header h1 { font-family: Georgia, serif; font-weight: 400; font-size: clamp(34px, 4vw, 50px); margin: 7px 0 6px; }
.admin-header p { color: var(--muted); margin: 0; max-width: 700px; line-height: 1.55; }
.header-actions { flex: none; }
.button { border-radius: 9px; border: 1px solid transparent; padding: 10px 15px; font-weight: 750; }
.button.primary { background: #e3ddcd; color: #101210; }
.button.secondary { background: #171a18; color: #dedbd2; border-color: #343934; }
.button:disabled { opacity: .45; cursor: default; }

.automation-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 30px; margin: 22px 0 28px; padding: 20px; border: 1px solid var(--line); background: #111412; border-radius: 12px; }
.automation-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.automation-copy p { color: var(--muted); line-height: 1.55; max-width: 760px; margin: 7px 0; }
.runtime-line { color: #747c75; font-size: 11px; margin-top: 8px; }
.status-pill, .badge { border: 1px solid #343a35; background: #171a18; color: #aeb3ad; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.status-pill.online { color: #9fc7a8; border-color: #34513c; background: #132018; }
.status-pill.offline { color: #c79e99; border-color: #543934; background: #201615; }
.automation-controls { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.automation-controls label:not(.toggle-row), .dialog-card label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.automation-controls select, .automation-controls input[type="number"], .dialog-card textarea { background: #171a18; color: var(--text); border: 1px solid #343934; border-radius: 8px; padding: 9px 10px; outline: none; }
.automation-controls input[type="number"] { width: 95px; }
.toggle-row { display: flex; align-items: center; gap: 8px; color: #c9cbc5; font-size: 12px; min-height: 37px; }
.toggle-row input { display: none; }
.switch { width: 36px; height: 20px; border-radius: 999px; background: #303530; position: relative; transition: .2s; }
.switch::after { content: ''; width: 14px; height: 14px; border-radius: 50%; background: #aeb2ad; position: absolute; left: 3px; top: 3px; transition: .2s; }
.toggle-row input:checked + .switch { background: #77705d; }
.toggle-row input:checked + .switch::after { transform: translateX(16px); background: #f2ecdc; }

.character-view { display: grid; gap: 22px; }
.hidden { display: none !important; }
.empty-state { border: 1px dashed #303530; color: var(--muted); border-radius: 12px; padding: 50px; text-align: center; }
.character-hero { display: flex; justify-content: space-between; gap: 30px; padding: 26px 0 22px; }
.character-hero h2 { font: 400 clamp(36px, 4vw, 52px)/1 Georgia, serif; margin: 9px 0 10px; }
.hero-personality { color: #afb4ae; max-width: 760px; line-height: 1.65; margin: 0; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.hero-stats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; align-content: flex-start; }
.hero-stat { min-width: 95px; background: #121513; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; }
.hero-stat span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.hero-stat strong { display: block; margin-top: 4px; font-size: 17px; }

.section-stack { display: grid; gap: 16px; }
.detail-section { border: 1px solid var(--line); background: #101311; border-radius: 12px; overflow: hidden; }
.section-title { padding: 15px 18px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-title h3 { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.section-title span { color: var(--muted); font-size: 10px; }
.section-body { padding: 17px 18px; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 12px 18px; }
.metric { min-width: 0; }
.metric-head { display: flex; justify-content: space-between; gap: 10px; color: #c9cbc5; font-size: 11px; margin-bottom: 6px; }
.metric-head .value { color: #858c86; font-variant-numeric: tabular-nums; }
.bar { height: 5px; border-radius: 999px; background: #242824; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #8f8977; border-radius: inherit; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 9px 18px; }
.kv { border-bottom: 1px solid #202420; padding: 7px 0 9px; min-width: 0; }
.kv .key { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.kv .val { margin-top: 4px; color: #d5d3cb; font-size: 13px; overflow-wrap: anywhere; }
.list { display: grid; gap: 8px; }
.list-item { background: #151816; border: 1px solid #252a26; border-radius: 9px; padding: 11px 12px; }
.list-item-title { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 700; }
.list-item-body { color: #9ba19b; font-size: 11px; line-height: 1.55; margin-top: 5px; white-space: pre-wrap; }
.list-item-meta { color: #6f766f; font-size: 10px; margin-top: 6px; }
.relationship-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.relationship-table th { color: #717971; text-align: right; font-weight: 600; padding: 7px 8px; border-bottom: 1px solid #252a26; }
.relationship-table th:first-child, .relationship-table td:first-child { text-align: left; }
.relationship-table td { text-align: right; padding: 9px 8px; border-bottom: 1px solid #1f231f; color: #c4c7c1; }
.relationship-table tr:last-child td { border-bottom: 0; }
.code-block { max-height: 420px; overflow: auto; background: #0b0e0c; border: 1px solid #202420; border-radius: 9px; padding: 13px; color: #9fa59f; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }

.generate-dialog { border: 0; padding: 0; background: transparent; color: var(--text); width: min(620px, calc(100vw - 30px)); }
.generate-dialog::backdrop { background: rgba(0, 0, 0, .68); backdrop-filter: blur(3px); }
.dialog-card { background: #111412; border: 1px solid #343934; border-radius: 14px; padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.45); }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.dialog-head h3 { font: 400 29px Georgia, serif; margin: 5px 0 0; }
.dialog-card > p { color: var(--muted); font-size: 12px; line-height: 1.55; }
.dialog-card textarea { width: 100%; resize: vertical; min-height: 115px; }
.icon-button { background: transparent; border: 0; color: #969c96; font-size: 27px; line-height: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.generation-status { min-height: 18px; margin-top: 10px; color: var(--muted); font-size: 11px; }

@media (max-width: 980px) {
  .admin-shell { grid-template-columns: 245px minmax(0, 1fr); }
  .automation-panel { grid-template-columns: 1fr; }
  .automation-controls { justify-content: flex-start; }
}

@media (max-width: 760px) {
  .admin-shell { display: block; }
  .character-sidebar { position: static; height: auto; max-height: 430px; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-main { padding: 24px 18px 60px; }
  .admin-header, .character-hero { display: block; }
  .header-actions { margin-top: 18px; }
  .hero-stats { justify-content: flex-start; margin-top: 18px; }
  .relationship-table { min-width: 720px; }
  .section-body:has(.relationship-table) { overflow-x: auto; }
  .location-admin-hero { grid-template-columns: 1fr; }
  .dialog-grid { grid-template-columns: 1fr; }
  .map-admin-header { height: auto; padding: 14px; display: block; }
  .admin-nav.horizontal { justify-content: flex-start; margin-top: 10px; }
  .map-layout { grid-template-columns: 1fr; min-height: auto; }
  .map-toolbar { flex-wrap: wrap; }
  .map-toolbar label { margin-left: 0; }
  .map-inspector { border-left: 0; border-top: 1px solid var(--line); }
  .activity-header { display: block; padding: 18px; }
  .activity-header .admin-nav { margin-top: 12px; }
  .activity-main { padding: 15px; }
  .activity-stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .activity-filters { grid-template-columns: 1fr 1fr; }
  .activity-search { grid-column: 1 / -1; }
  .activity-grid { grid-template-columns: 1fr; }
  .activity-feed { height: 55vh; min-height: 360px; }
  .activity-health { position: static; }
  .dialogue-line { grid-template-columns: 1fr; gap: 4px; }
}
