:root {
    --bg: #f4f3ef;
    --surface: #ffffff;
    --surface-2: #ebe9e2;
    --text: #1d1d1f;
    --muted: #6b6b70;
    --accent: #8a6a12;
    --link: #1f5fbf;
    --border: #d6d3ca;
    --unowned: #3a3a3e;
    --major: #b3261e;
    --why: #2f6fa8;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121214;
        --surface: #1b1b1f;
        --surface-2: #26262c;
        --text: #e8e8ea;
        --muted: #9a9aa2;
        --accent: #e6cd8a;
        --link: #6cb3ff;
        --border: #34343c;
        --unowned: #333338;
        --major: #ff8c78;
        --why: #8cbff0;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

button {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 10px;
    cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }

input, select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
}

h2, h3 { margin: 0; }
h3 { font-size: 13px; color: var(--accent); margin: 12px 0 4px; display: flex; align-items: center; gap: 6px; }

.hint { color: var(--muted); font-style: italic; font-size: 12px; }
.boot, .status { padding: 24px; color: var(--muted); white-space: pre-wrap; }

.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.brand { color: var(--accent); }
.seed { width: 80px; }
.stats { gap: 12px; color: var(--muted); }
.stats .date { color: var(--text); font-weight: 600; }
.hash { font-family: ui-monospace, Consolas, monospace; }
.tabs { display: flex; gap: 4px; margin-left: auto; }

main { padding: 12px 16px; }

/* ----- World grid ----- */
.world { display: flex; gap: 16px; align-items: flex-start; }
.grid { flex: 1; min-width: 0; }
.kingdom { margin-bottom: 18px; }
.kingdom h2 { font-size: 14px; color: var(--accent); display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 2px; flex: none; }
.provinces { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.province {
    border: 3px solid; border-radius: 4px; padding: 4px;
    display: flex; flex-direction: column; min-height: 170px; color: #fff;
}
.province.selected { outline: 3px solid var(--text); }
.province-head {
    background: none; border: none; padding: 2px 2px 4px; text-align: left; color: #fff;
    display: flex; flex-direction: column;
}
.province-head small { opacity: .8; }
.lordships { flex: 1; display: grid; gap: 2px; }
.lordship {
    border: 2px solid transparent; border-radius: 3px; padding: 2px; min-height: 36px; color: #f2f2f2;
    display: flex; flex-direction: column; justify-content: center; align-items: center; font-size: 11px; overflow: hidden;
}
.lordship .lname { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lordship.seat { border-color: rgb(242, 191, 51); }
.lordship.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }

/* ----- Detail panel ----- */
.panel {
    width: 360px; flex: none; position: sticky; top: 64px;
    max-height: calc(100vh - 80px); overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
}
.panel-head { display: flex; gap: 8px; align-items: flex-start; }
.panel-head h2 { font-size: 16px; }
.panel-head small { color: var(--muted); }
.panel-head .close { margin-left: auto; }
.panel p { margin: 4px 0; }
.ruler { display: flex; gap: 10px; margin: 6px 0 10px; }
.avatar {
    width: 48px; height: 48px; flex: none; border-radius: 50%; color: #fff; font-weight: 700; padding: 0;
}
.links { list-style: none; margin: 0; padding: 0; }
.link {
    background: none; border: none; padding: 1px 0; color: var(--link); text-align: left; display: block;
}
.link:hover { text-decoration: underline; }
.link.strong { font-weight: 700; color: var(--text); }

/* ----- Chronicle ----- */
.chronicle { max-width: 1000px; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.toolbar input[placeholder] { width: 260px; }
.entry { padding: 1px 0 1px 12px; }
.entry.major { color: var(--major); font-weight: 600; }
.entry.minor { color: var(--muted); font-size: 12px; }
.why { color: var(--why); font-style: italic; font-size: 12px; padding-left: 24px; font-weight: 400; }

.log { white-space: pre-wrap; font: 12px/1.4 ui-monospace, Consolas, monospace; color: var(--muted); }

/* ----- Person modal ----- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 10; }
.modal {
    position: fixed; z-index: 11; inset: 30px; max-width: 1300px; margin: 0 auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    display: flex; flex-direction: column;
}
.modal-head {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; color: var(--accent); }
.modal-body { flex: 1; overflow: auto; padding: 10px 14px; position: relative; }
.graph { width: 100%; height: calc(100% - 10px); min-height: 420px; display: block; }
.graph .node { cursor: pointer; }
.graph .node circle { stroke: var(--text); stroke-width: 1.5; }
.graph .node.center circle { stroke-width: 3; }
.graph .node.dead { opacity: .45; }
.graph .initials { fill: #fff; font-weight: 700; font-size: 14px; text-anchor: middle; pointer-events: none; }
.graph .node-label { fill: var(--text); font-size: 12px; text-anchor: middle; }
.graph .opinion rect { fill: rgba(0, 0, 0, .65); }
.graph .opinion text { fill: #f2f2cc; font-size: 11px; text-anchor: middle; }
.legend { position: absolute; left: 14px; bottom: 10px; list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 6px; }
.inspector ul { margin: 0; padding-left: 18px; }
.plan .score { color: var(--muted); }
.plan .failed { color: var(--major); }

#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    padding: 8px 16px; background: #b3261e; color: #fff;
}
#blazor-error-ui .reload { color: #fff; }

@media (max-width: 800px) {
    .world { flex-direction: column; }
    .panel { width: 100%; position: static; max-height: none; }
    .modal { inset: 8px; }
    .tabs { margin-left: 0; }
}
