:root {
  --bg: #0b1016;
  --bg2: #111820;
  --panel: #161f2a;
  --panel2: #1b2633;
  --line: #243140;
  --line2: #34465a;
  --ink: #edf3f8;
  --ink2: #b1c1d2;
  --ink3: #8b9eb3;
  --accent: #70e1c5;
  --r: 12px;
}

[hidden] { display: none !important; }
button, select, summary, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, select:focus-visible, summary:focus-visible,
[tabindex]:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
button, select { touch-action: manipulation; }
button { font: inherit; }
main { grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: minmax(0, 1fr); }
#world-pane { min-height: 0; }
#world { touch-action: none; }
#brain-pane { overflow: hidden; box-shadow: -8px 0 32px #0002; }
#topbar { padding: 18px 20px 14px; gap: 14px; background: var(--bg2); }
.lab-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { display: grid; place-items: center; width: 42px; height: 42px;
  flex: none; border: 1px solid #3d685f; background: #18342f; border-radius: 13px; color: var(--accent); }
.brand-icon svg { width: 29px; height: 29px; }
.lab-brand strong { display: block; font-size: 17px; letter-spacing: -.5px; font-weight: 650; }
.lab-brand small { display: block; color: var(--ink3); font-size: 11px; margin-top: 4px; }
.sidebar-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  padding: 4px; border: 1px solid var(--line); border-radius: 11px; background: #0b1118; }
.sidebar-tabs button { border: 0; border-radius: 7px; background: transparent;
  color: var(--ink3); padding: 9px 4px; min-height: 38px; cursor: pointer; font-size: 12px; font-weight: 600; }
.sidebar-tabs button:hover { color: var(--ink); background: #1b2633; }
.sidebar-tabs button[aria-selected="true"] { background: #25363e; color: var(--accent); box-shadow: 0 1px 5px #0004; }
.sidebar-content { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin;
  scrollbar-color: var(--line2) transparent; }
[data-tab-panel] { padding: 16px 20px 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.session-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.session-state { display: flex; gap: 7px; align-items: center; color: var(--accent); font-size: 11px; }
.session-state::before { content: ''; width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.session-state.paused { color: #f4cc83; }
.session-clock { font: 11px var(--mono); color: var(--ink3); }
.mouse-card { padding: 14px; border: 1px solid #36534e; border-radius: 14px;
  background: linear-gradient(135deg, #1c302e, #16212b 80%); }
.mouse-heading { display: flex; gap: 10px; align-items: center; }
.eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink3); }
.mouse-heading h2 { font-size: 20px; line-height: 1.2; letter-spacing: -.5px; margin: 4px 0; }
.mouse-heading .mouse-title { flex: 1; min-width: 0; }
.mouse-meta { color: var(--ink3); font-size: 11px; }
.next-mouse { width: 38px; height: 38px; border: 1px solid #41605d; border-radius: 10px;
  background: #203934; color: var(--accent); cursor: pointer; font-size: 20px; }
.next-mouse:hover { background: #2a4943; }
.mouse-location { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; font-size: 10px; }
.mouse-location span { padding: 4px 8px; background: #0d171c; color: var(--ink2); border-radius: 6px; }
.mouse-location #ui-behavior { color: var(--accent); }
.mouse-needs { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mouse-needs label { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink3); margin-bottom: 6px; }
.mouse-needs output { color: var(--ink2); font: 10px var(--mono); }
.mouse-needs meter { display: block; width: 100%; height: 5px; border: 0; border-radius: 9px;
  background: #0c141b; appearance: none; }
.mouse-needs meter::-webkit-meter-bar { background: #0c141b; border: 0; border-radius: 9px; }
.mouse-needs meter::-webkit-meter-optimum-value { background: #e8bd77; border-radius: 9px; }
.mouse-needs meter::-moz-meter-bar { background: #e8bd77; border-radius: 9px; }
.mouse-needs .thirst meter::-webkit-meter-optimum-value { background: #80b7eb; }
.mouse-needs .thirst meter::-moz-meter-bar { background: #80b7eb; }
.btn { font-size: 12px; border-radius: 8px; min-height: 38px; padding: 9px 12px;
  transition: background .15s, border-color .15s, color .15s; }
.btn.on { color: var(--accent); border-color: #42756a; background: #203e36; font-weight: 500; }
.btn.primary { color: #0c3027; background: var(--accent); border-color: var(--accent); font-weight: 650; }
.btn.primary:hover { background: #9aecd7; }
.btn.ghost { border-color: var(--line); }
.btn.danger { color: #e9a4ab; }
.auto-control { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-top: 12px; text-align: left; }
.auto-control::after { content: ''; width: 25px; height: 14px; border-radius: 20px;
  background: radial-gradient(circle at 7px 7px, #91a3b5 0 4px, transparent 4.5px), #34414f; }
.auto-control.on::after { background: radial-gradient(circle at 18px 7px, var(--accent) 0 4px, transparent 4.5px), #306454; }
.hint { color: var(--ink3); font-size: 11px; line-height: 1.6; margin: 10px 0 0; }
.hint kbd { font-size: 9px; }
.control-section { margin-top: 20px; }
.control-section h3 { margin: 0 0 12px; color: var(--ink); font-size: 12px; font-weight: 600; }
.playback { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.playback .btn { min-height: 42px; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 10px; color: var(--ink3); }
.field select { appearance: auto; color-scheme: dark; width: 100%; min-height: 42px; padding: 9px 10px;
  border: 1px solid var(--line2); border-radius: 8px; background: #192430; color: var(--ink); font: 12px var(--sans); cursor: pointer; }
.button-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.button-pair .btn { white-space: normal; }
.guide-card { display: flex; gap: 12px; margin-top: 24px; padding: 14px;
  background: #14252b; border: 1px solid #28454b; border-radius: 10px; }
.guide-icon { color: #8ecdbf; font-size: 18px; }
.guide-card h3 { font-size: 11px; margin: 0 0 6px; color: #b9dfd5; }
.guide-card p { margin: 0 0 8px; font-size: 11px; line-height: 1.6; color: var(--ink3); }
.text-button { padding: 0; color: var(--accent); font-size: 11px; background: none; border: 0; cursor: pointer; text-align: left; }
.text-button:hover { text-decoration: underline; }
#stats-card { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
#stats-card summary { font-size: 11px; padding: 5px 0; color: var(--ink2); }
.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); padding: 10px; background: #131e28; }
.stat label { font-size: 9px; color: var(--ink3); }
.stat b { margin-top: 5px; font-size: 16px; }
.panel-intro { margin-bottom: 20px; }
.panel-intro h2 { font-size: 18px; font-weight: 600; margin: 0 0 7px; letter-spacing: -.3px; }
.panel-intro p { font-size: 12px; color: var(--ink3); margin: 0; line-height: 1.6; }
#brain-panels { gap: 12px; }
.pcard { padding: 14px; background: #151f29; border: 1px solid var(--line); border-radius: 11px; }
.pcard > h4 { color: var(--ink2); font-size: 10px; letter-spacing: .07em; min-height: 22px; }
.pcard > h4 em { color: var(--ink3); font-size: 8px; }
#brain-card { flex: none; height: 240px; min-height: 240px; padding-bottom: 8px; }
#brain-wrap { min-height: 180px; }
#brain-card.shut { height: auto; min-height: 0; }
.arow { padding-top: 5px; padding-bottom: 5px; }
.arow .lb { font-size: 11px; }
#insp { font-size: 12px; line-height: 1.65; }
#insp .nm { font-size: 14px; }
.tool-list { display: grid; gap: 9px; }
.tool-button { display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: 10px; text-align: left; padding: 13px; white-space: normal; }
.tool-button span { font-weight: 600; }
.tool-button small { display: block; margin-top: 5px; font-size: 10px; line-height: 1.5; color: var(--ink3); font-weight: 400; }
.tool-button kbd { flex: none; }
.menuwrap { margin-top: 22px; }
.menuwrap > .btn { width: 100%; text-align: left; }
.menu { padding: 0; }
.panel-categories { display: flex; gap: 4px; margin: 12px 14px 6px; padding: 4px;
  flex: none; border: 1px solid var(--line); border-radius: 10px; background: #0c141c; }
.panel-categories button { flex: 1; min-height: 34px; border: 0; border-radius: 7px;
  background: transparent; color: var(--ink3); font-size: 11px; cursor: pointer; }
.panel-categories button:hover { color: var(--ink); }
.panel-categories button[aria-pressed="true"] { color: var(--accent); background: #213a35; font-weight: 600; }
#panel-menu > .body { padding: 2px 14px 12px; }
#panel-menu .mrow { display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 57px; padding: 10px; border: 1px solid transparent; border-radius: 8px;
  font-size: 12px; text-align: left; background: transparent; cursor: pointer; }
#panel-menu .mrow + .mrow { margin-top: 3px; }
#panel-menu .mrow:hover { background: #1c2b35; border-color: var(--line2); }
#panel-menu .mrow.on { background: #162a28; }
.panel-option-copy { flex: 1; min-width: 0; }
.panel-option-copy strong { display: block; color: var(--ink); font-weight: 500; }
.panel-option-copy small { display: block; color: var(--ink3); font-size: 10px; line-height: 1.5; margin-top: 4px; }
.panel-switch { flex: none; width: 29px; height: 17px; border-radius: 20px;
  background: radial-gradient(circle at 8px 8.5px, #a3b2c3 0 5px, transparent 5.5px), #354350; }
.mrow.on .panel-switch { background: radial-gradient(circle at 21px 8.5px, var(--accent) 0 5px, transparent 5.5px), #326353; }
#panel-menu-footer { flex: none; padding: 12px 14px; border-top: 1px solid var(--line); background: #111c25; }
#panel-menu .mfoot { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; padding: 0; border: 0; }
#panel-menu .mfoot button { min-height: 38px; font-size: 11px; border: 1px solid var(--line2);
  border-radius: 8px; color: var(--ink2); background: #1c2a36; cursor: pointer; }
#panel-menu .mfoot button:hover { color: var(--ink); background: #293b49; }
#panel-menu .mfoot button:last-child { border-color: #42756a; background: #203e36; color: var(--accent); }
.restart-section { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 22px; }
.restart-section .btn { width: 100%; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 20px; border-top: 1px solid var(--line); background: var(--bg2); flex: none; }
.sidebar-footer .btn { min-height: 34px; padding: 6px 12px; font-size: 11px; }
.sidebar-footer .text-button { color: var(--ink3); }
.float { border-radius: 15px; display: flex; flex-direction: column; }
.float.popup-window { overflow: hidden; background: #111b25f7; border: 1px solid #405364;
  box-shadow: 0 18px 50px #0008, 0 2px 8px #0006; }
.float > .body { min-height: 0; overflow: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: #405364 transparent; }
.float.popup-window > .body { padding: 12px 14px 14px; }
.float[data-collapsed] > :not(h5) { display: none !important; }
.float.is-floating {
  position: fixed !important; left: var(--floating-x) !important; top: var(--floating-y) !important;
  right: auto !important; bottom: auto !important; transform: none !important;
  max-width: var(--floating-max-width) !important;
  max-height: min(var(--popup-preferred-height, 640px), var(--floating-max-height)) !important;
  box-shadow: 0 16px 48px #0009;
}
.floating-title { touch-action: none; user-select: none; cursor: grab !important; flex: none; }
.floating-title .panel-fold { cursor: inherit; }
.floating-title.dragging { cursor: grabbing !important; }
.floating-grip { width: 6px; height: 14px; flex: none; opacity: .65;
  background: radial-gradient(circle, var(--ink3) 1px, transparent 1.5px) 0 0 / 4px 4px; }
.float.popup-window > h5 { gap: 6px; min-height: 76px; padding: 12px; margin: 0;
  font-size: 13px; letter-spacing: 0; text-transform: none; color: var(--ink);
  background: linear-gradient(120deg, #1d3037, #18232e); border-bottom: 1px solid #354752; }
.float.popup-window h5 :is(.panel-close, .panel-minimize) { display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0; margin: 0; flex: none; border: 1px solid #435462;
  border-radius: 8px; background: #1b2934; color: var(--ink2); font-size: 20px;
  font-weight: 400; line-height: 1; cursor: pointer; letter-spacing: 0; }
.float.popup-window h5 :is(.panel-close, .panel-minimize):hover { background: #314754; color: var(--ink); }
.float.popup-window h5 .panel-close:hover { border-color: #a56670; background: #4b2b36; color: #ffd0d7; }
.panel-fold { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
  padding: 2px 0; border: 0; background: transparent; color: inherit; font: inherit;
  letter-spacing: inherit; text-transform: inherit; text-align: left; cursor: pointer; }
.popup-icon { display: grid; place-items: center; flex: none; width: 30px; height: 32px;
  border-radius: 9px; background: #203d39; color: var(--accent); }
.popup-icon svg { width: 20px; height: 20px; }
.popup-heading-copy { flex: 1; min-width: 0; }
.popup-heading-copy strong { display: block; color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1.4; }
.popup-heading-copy small { display: block; margin-top: 3px; font-size: 10px; font-weight: 400;
  line-height: 1.5; color: #a3b7c5; }
.popup-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  flex: none; min-height: 34px; padding: 2px 14px; background: #121f28; border-bottom: 1px solid var(--line); }
.popup-toolbar > span { font-size: 10px; color: var(--ink3); }
.popup-reset { background: transparent; border: 0; padding: 6px 0 6px 8px; min-height: 30px;
  color: #a4d5c8; font-size: 10px; cursor: pointer; }
.popup-reset:hover { color: var(--accent); text-decoration: underline; }
.popup-context { flex: none; padding: 9px 14px 0; color: var(--ink3); font-size: 11px; }
.float .popup-context > span { margin: 0; color: #a4bdc8; font-size: 10px; line-height: 1.5; letter-spacing: 0; }
#boxes .bx { border-radius: 8px; }
#boxes .bx { padding: 7px 6px; }
#boxes .bx .bn { font-size: 10px; }
#boxes .bx .bp { font-size: 16px; padding: 3px 0; }
#boxes #bx-act button { min-height: 36px; }
#boxes #bx-note { line-height: 1.65; font-size: 10px; }
#colony .crow { padding: 8px; border-radius: 8px; }
#colony #envrow label { font-size: 10px; }
#colony #envrow input[type="range"] { min-height: 26px; }
#threats .tbtn { min-height: 38px; border-radius: 7px; }
#report .rp-act { flex: none; padding: 12px 14px; border-top: 1px solid var(--line); }
#report .rp-act button { min-height: 34px; border-radius: 7px; }
#keys.popup-window .body { font-size: 11px; line-height: 2; }
#world-pane #mortality { left: 12px; top: 12px; width: min(290px, calc(100% - 24px));
  max-height: min(520px, calc(100% - 24px)); }
#world-pane #report { max-width: calc(100% - 24px); max-height: calc(100% - 24px); }
#world-pane #report .rp-act { flex-wrap: wrap; }
dialog { color: var(--ink); color-scheme: dark; }
dialog::backdrop { background: #03080dba; backdrop-filter: blur(6px); }
#welcome, #reset-dialog { margin: auto; padding: 0; border: 0; border-radius: 16px;
  background: transparent; width: min(660px, calc(100vw - 32px)); height: auto;
  max-height: calc(100dvh - 32px); overflow-y: auto; inset: 0; }
#welcome:not([open]), #reset-dialog:not([open]) { display: none; }
#welcome[open], #reset-dialog[open] { display: block; }
.wcard { position: relative; max-width: none; padding: 28px; }
.dialog-close { position: absolute; top: 16px; right: 16px; width: 32px; height: 32px;
  border: 1px solid var(--line2); border-radius: 8px; background: var(--panel2); color: var(--ink2); cursor: pointer; font-size: 20px; }
.wcard h1 { padding-right: 32px; margin-bottom: 12px; }
.wcard .lede { color: var(--ink2); line-height: 1.7; }
#reset-dialog { width: min(420px, calc(100vw - 32px)); }
.dialog-card { background: var(--bg2); border: 1px solid var(--line2); border-radius: 16px; padding: 24px; }
.dialog-card h2 { font-size: 19px; margin: 0 0 12px; }
.dialog-card p { color: var(--ink2); font-size: 12px; line-height: 1.7; margin: 0 0 22px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
#mobile-rail, #sidebar-backdrop { display: none; }

@media (max-width: 1000px) and (min-width: 701px) {
  main { grid-template-columns: minmax(0, 1fr) 340px; }
  #topbar, [data-tab-panel] { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 700px) {
  main { grid-template-columns: minmax(0, 1fr) 52px; }
  #brain-pane { position: fixed; right: 52px; top: 0; bottom: 0; z-index: 80;
    width: min(380px, calc(100vw - 80px)); transform: translateX(calc(100% + 52px));
    transition: transform .2s ease; border-right: 1px solid var(--line); }
  body.sidebar-open #brain-pane { transform: none; }
  #mobile-rail { display: flex; position: fixed; right: 0; top: 0; bottom: 0; width: 52px;
    z-index: 90; align-items: center; flex-direction: column; gap: 18px; padding-top: 12px;
    background: var(--bg2); border-left: 1px solid var(--line); }
  #b-mobile-menu { display: grid; place-items: center; width: 40px; height: 42px;
    border: 1px solid var(--line2); border-radius: 9px; color: var(--accent); background: var(--panel2); cursor: pointer; }
  #b-mobile-menu svg { width: 20px; height: 20px; }
  #mobile-rail .rail-label { writing-mode: vertical-rl; color: var(--ink3); font-size: 10px; letter-spacing: .12em; }
  body.sidebar-open #sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 70;
    padding: 0; border: 0; background: #0006; cursor: pointer; }
  #topbar { padding: 18px 16px 14px; }
  [data-tab-panel] { padding: 16px; }
  .menu { width: min(320px, calc(100vw - 76px)); }
  .sidebar-footer { padding-left: 16px; padding-right: 16px; }
  .btn { min-height: 42px; }
  .wcard { padding: 24px 20px; }
  .wtry { grid-template-columns: 1fr; }
  .wfoot .note { min-width: 0; }
  #signals, #optics { max-width: calc(100vw - 76px); }
  #world-pane .float { max-width: calc(100% - 24px); }
  .float.popup-window > h5 { padding: 10px; gap: 5px; }
  .float.popup-window h5 :is(.panel-close, .panel-minimize) { width: 34px; height: 36px; }
  .popup-icon { display: none; }
  .popup-heading-copy small { font-size: 10px; }
  .panel-categories button { min-height: 38px; }
  .popup-reset { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.threat-help { margin: 0 0 9px; color: var(--ink3); font-size: 10px; line-height: 1.5; }
#threats .tbtn.active { border-color: #c27d53; color: #f2d9bd; background: #392a22; }
#threats .tbtn:disabled { cursor: default; opacity: .45; }
#thr-context { margin: 0 0 8px; font-size: 9px; }
#b-thr-view { width: 100%; justify-content: center; margin-top: 5px; }
