:root {
    color-scheme: dark;
    font: 13px/1.45 "Inter", system-ui, sans-serif;
    color: #e5edf0;
    background: #0c1318;
    --panel: #101a21;
    --surface: #17242c;
    --line: #273841;
    --muted: #a1b2bb;
    --accent: #8edac7;
    --gold: #efd193;
}

* { box-sizing: border-box; }
h1, h2, h3, p { margin: 0; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; overflow: hidden; }
button, input, textarea, select {
    color: inherit;
    background: var(--surface);
    border: 1px solid #344751;
    border-radius: 6px;
    font: inherit;
    padding: 7px 9px;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { cursor: pointer; }
button:hover, button.active, button[aria-pressed="true"] { color: var(--accent); border-color: #5d9b90; }
button:disabled { opacity: .5; cursor: wait; }
input, textarea, select { width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 58px; }
p { color: var(--muted); }
[hidden] { display: none !important; }

.topbar {
    min-height: 61px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 15px;
    background: #111b22;
    border-bottom: 1px solid #34454e;
}
.brand { display: flex; gap: 10px; align-items: center; white-space: nowrap; letter-spacing: .16em; font-size: 16px; }
.brand-icon { color: var(--accent); font-size: 25px; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: .06em; font-weight: 500; }
#clock { color: var(--gold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.controls, #speeds, .view-tools, .tabs { display: flex; gap: 4px; align-items: center; }
.controls { gap: 8px; }
.controls select { width: auto; }
#pause { width: 33px; height: 34px; display: grid; place-items: center; font-size: 0; }
#pause::before { content: ''; width: 4px; height: 10px; border-inline: 2px solid currentColor; }
#pause.paused::before { width: 0; height: 0; border: 5px solid transparent; border-right: 0; border-left: 8px solid currentColor; }
#connection { color: var(--muted); white-space: nowrap; font-size: 11px; }
#connection.online { color: var(--accent); }

main {
    display: grid;
    grid-template-columns: minmax(192px, 16.5vw) minmax(0, 1fr) minmax(235px, 20vw);
    flex: 1;
    min-height: 0;
}
aside {
    padding: 17px 14px;
    overflow: auto;
    background: var(--panel);
    scrollbar-width: thin;
    scrollbar-color: #3a525d transparent;
}
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
h2 { font-size: 18px; font-weight: 630; margin-bottom: 14px; }
h3 { font-size: 12px; margin: 17px 0 8px; color: #c1d0d6; font-weight: 630; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.stats > div {
    min-width: 0;
    padding: 7px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
}
.stats small { display: block; font-size: 10px; color: var(--muted); }
.stats small span { color: var(--accent); }
.stats b { font-size: clamp(13px, 1.5vw, 21px); font-variant-numeric: tabular-nums; font-weight: 580; }
.list-heading { display: flex; justify-content: space-between; }
#count { color: var(--accent); }
.district, .agent, .entry {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 7px 5px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    text-align: left;
}
button.district:hover, button.agent:hover, button.entry:hover, .agent.selected { background: #1e3039; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.agent .identity { min-width: 0; flex: 1; }
.agent strong, .entry strong { display: block; font-size: 12px; }
.agent small, .entry small { font-size: 10px; color: var(--muted); }
.agent .activity { font-size: 10px; color: #b2d4cc; text-align: right; }
#agents { margin-top: 6px; }

.world { position: relative; overflow: hidden; background: #405867; isolation: isolate; }
#scene, .world > div:first-child canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#scene { cursor: grab; }
#scene:active { cursor: grabbing; }
.view-label, .scene-settings, .navigator, .view-tools {
    position: absolute;
    background: #111c24e8;
    border: 1px solid #a6bac240;
    border-radius: 8px;
    box-shadow: 0 6px 22px #0a10162e;
}
.view-label { top: 15px; left: 15px; padding: 10px 13px; pointer-events: none; }
h1 { font-size: clamp(19px, 2vw, 28px); font-weight: 600; line-height: 1.05; letter-spacing: -.035em; }
#weather { margin-top: 5px; color: #b4cacd; font-size: 11px; }
.scene-settings { right: 15px; top: 15px; display: flex; gap: 7px; align-items: center; padding: 5px 7px; }
.scene-settings label { font-size: 11px; color: var(--muted); }
.scene-settings select { width: auto; padding: 3px 4px; }
.navigator { right: 15px; bottom: 15px; padding: 4px; }
#minimap { display: block; width: min(158px, 22vw); height: auto; border-radius: 5px; cursor: crosshair; }
.view-tools { bottom: 15px; left: 15px; padding: 4px; flex-wrap: wrap; }
.view-tools .zoom { min-width: 25px; font-weight: 700; }
.view-tools button { font-size: 11px; padding: 5px 7px; white-space: nowrap; }
#worlderror:not(:empty) {
    position: absolute; top: 84px; left: 15px; right: 15px;
    background: #412c37; color: #fff5f3; padding: 9px; border-radius: 5px;
}
#rain {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .29;
    background: repeating-linear-gradient(112deg, transparent 0 16px, #b4cbd445 17px, transparent 18px 33px);
    background-size: 72px 120px;
    mask-image: linear-gradient(transparent, #000 24%, #000 72%, transparent);
    animation: rain .46s linear infinite;
}
@keyframes rain { to { background-position: -36px 120px; } }

.tabs { margin-bottom: 15px; border-bottom: 1px solid var(--line); }
.tabs button {
    flex: 1;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 7px 2px 9px;
    font-size: 11px;
    background: transparent;
}
.tabs button.active { border-bottom-color: var(--accent); }
.tab form { display: grid; gap: 6px; margin: 16px 0; }
.tab form button { color: #d0f1e7; background: #213c3c; }
.tab label { color: #c3d6dc; font-size: 12px; font-weight: 580; }
.avatar {
    width: 42px; height: 42px; flex-shrink: 0; border-radius: 7px;
    display: grid; place-items: center; font-size: 17px;
    border: 1px solid #4c7777; background: #224143; color: var(--accent);
}
.profilehead { display: flex; gap: 9px; align-items: center; margin-bottom: 11px; }
.profilehead h2 { margin: 0; line-height: 1.2; }
.eyebrow { color: var(--accent); font-size: 10px; letter-spacing: .07em; }
.profilehead p { font-size: 11px; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; gap: 8px; border-bottom: 1px solid var(--line); }
.kv span { color: var(--muted); }
.kv strong { font-weight: 560; text-align: right; }
.meter { height: 3px; background: #30444e; border-radius: 3px; margin: 4px 0 8px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
#reply, .taskitem { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface); padding: 8px; border-radius: 5px; margin: 7px 0; }
#reply:empty { display: none; }
.memory { padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }

footer {
    display: flex; align-items: center; gap: 12px; min-height: 35px; padding: 0 14px;
    background: #101b23; border-top: 1px solid var(--line); position: relative; z-index: 1;
}
#journal summary { cursor: pointer; color: var(--accent); white-space: nowrap; font-size: 11px; }
#events {
    position: absolute; bottom: 100%; left: 12px; width: min(470px, calc(100vw - 24px));
    max-height: min(280px, 45vh); overflow: auto;
    border: 1px solid var(--line); border-radius: 8px 8px 0 0; padding: 8px 12px; background: var(--panel);
}
#feed, #status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 11px; }
#feed { flex: 1; }
#status { max-width: 40%; color: var(--accent); }

@media (max-width: 1050px) {
    main { grid-template-columns: minmax(0, 1fr) 250px; grid-template-rows: minmax(360px, 1fr) 220px; }
    .world { grid-area: 1 / 1; }
    .left { grid-area: 2 / 1; border-top: 1px solid var(--line); }
    .right { grid-area: 1 / 2 / 3; }
    .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .stats b { font-size: 17px; }
}
@media (max-width: 690px), (max-height: 680px) {
    html, body { min-height: 100%; height: auto; }
    body { overflow: auto; }
    .topbar { padding: 8px 10px; gap: 7px; display: grid; grid-template-columns: auto 1fr auto; }
    #clock { justify-self: center; font-size: 11px; }
    #connection { grid-area: 1 / 3; }
    .topbar .controls { grid-column: 1 / -1; flex-wrap: wrap; }
    main { display: flex; flex-direction: column; }
    .world { height: 66svh; min-height: 335px; order: -1; }
    .left, .right { max-height: 540px; border-top: 1px solid var(--line); }
    .view-label { top: 8px; left: 8px; padding: 8px; }
    .scene-settings { top: 8px; right: 8px; }
    .navigator { right: 8px; bottom: 47px; }
    #minimap { width: 106px; }
    .view-tools { bottom: 8px; left: 8px; }
}
@media (prefers-reduced-motion: reduce) { #rain { animation: none; } }
