:root {
  color-scheme: dark;
  --ink: #14130f;
  --panel: #1c1a15;
  --line: #3a352b;
  --text: #e9e2d0;
  --muted: #a39a85;
  --accent: #c9a14a;
  --ok: #7fae6a;
  --warn: #d9a441;
  --err: #d4644e;
  --ref: #6fa8c9;
  --flow: #c9a14a;
  --control: #9bb06a;
  --event: #d27a5a;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 13px;
  background: var(--ink);
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; }
html, body, #app { width: 100%; height: 100%; }
#app { display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }
h1, h2, h3, .app-title {
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  margin: 0 0 12px;
  line-height: 1.1;
}
h1, .app-title { font-size: 28px; }
h2 { font-size: 23px; }
h3 { font-size: 19px; }
p { line-height: 1.5; margin: 8px 0 16px; color: var(--muted); }
small { color: var(--muted); font-size: 11px; }
code, pre, .hash, .mono { font-family: "IBM Plex Mono", monospace; font-size: 11px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; line-height: 1.5; }
button, input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  min-height: 28px;
  padding: 4px 8px;
}
button, select, summary { cursor: pointer; }
button { font-weight: 500; }
button:hover:not(:disabled), select:hover:not(:disabled), summary:hover {
  border-color: var(--accent);
  background-color: #29251c;
}
input:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--muted); }
button:active:not(:disabled) { background: #383020; }
button[aria-selected="true"], button[aria-current="true"], button[aria-pressed="true"], .tab.active {
  color: var(--accent);
  border-color: var(--accent);
  background: #29251c;
}
button:disabled, input:disabled, select:disabled, textarea:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--text); }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
label input, label select, label textarea { color: var(--text); }
input[type="checkbox"], input[type="radio"] { width: 28px; height: 28px; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; }
select { max-width: 100%; }
summary { min-height: 28px; padding: 4px 8px; border: 1px solid transparent; border-radius: 3px; }
details { border-top: 1px solid var(--line); padding: 4px 0; }
progress {
  display: block; width: 100%; height: 6px;
  border: 0; border-radius: 0; background: var(--line); accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.topbar, .top-bar, .app-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 16px;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex: 0 0 auto;
}
.app-title { margin: 0; white-space: nowrap; }
.tabs, [role="tablist"], .toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.tabs button, [role="tab"] { min-height: 32px; }
main, .tab-panels { flex: 1; min-height: 0; position: relative; }
.tab-panel, [role="tabpanel"] { height: 100%; min-height: 0; overflow: auto; }
.toolbar { margin: 8px 0 16px; }
.toolbar label { min-width: 100px; }
.toolbar input { max-width: 240px; }
.panel { background: var(--panel); border: 1px solid var(--line); padding: 12px; }
.studio-grid {
  height: 100%; display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(320px, 1fr) minmax(240px, 320px);
  min-height: 0;
}
.studio-grid > * { min-width: 0; overflow: auto; padding: 12px; border-right: 1px solid var(--line); }
.studio-grid > :last-child { border-right: 0; }
.studio-canvas { background: var(--ink); overflow: hidden; position: relative; touch-action: none; }
svg { font-family: "IBM Plex Sans", sans-serif; }
svg text { fill: var(--text); }
svg .node rect { fill: var(--panel); stroke: var(--line); rx: 3px; }
svg .node:hover rect { stroke: var(--muted); }
svg .node.selected rect { stroke: var(--accent); stroke-width: 2px; }
svg .edge { fill: none; stroke: var(--muted); stroke-width: 2px; }
.port-ref, [data-kind="ref"] { --port-color: var(--ref); }
.port-flow, [data-kind="flow"] { --port-color: var(--flow); }
.port-control, [data-kind="control"] { --port-color: var(--control); }
.port-event, [data-kind="event"] { --port-color: var(--event); }
svg .port { fill: var(--port-color, var(--muted)); stroke: var(--ink); }
svg .port-hit { fill: transparent; stroke: transparent; stroke-width: 28px; pointer-events: all; }
svg [tabindex]:focus-visible { outline: 2px solid var(--accent); }
.port-icon { display: inline-block; width: 10px; height: 10px; background: var(--port-color); border-radius: 50%; }
.port-icon[data-type="ManaSourceRef"] { border-radius: 0; transform: rotate(45deg); }
.port-icon[data-kind="event"], .port-icon[data-type="Event"] {
  border-radius: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.inputs-panel, .observatory-panel, .methods-panel { height: 100%; padding: 16px; overflow: auto; }
.inputs-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); border-top: 1px solid var(--line); }
.inputs-grid > nav { padding: 12px 12px 12px 0; border-right: 1px solid var(--line); }
.inputs-grid > nav button { display: block; width: 100%; text-align: left; margin-bottom: 4px; }
.inputs-grid > section { padding: 12px 0 12px 16px; min-width: 0; overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { font-weight: 500; color: var(--muted); }
th, td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
tr.inherited { color: var(--muted); }
tr.conflict { color: var(--err); background: #2c1c17; }
.binding-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.binding-form > label { display: inline-flex; margin: 0 12px 12px 0; min-width: 150px; }
.observation-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-block: 1px solid var(--line); }
.observation-grid > section { min-width: 0; padding: 12px; border-right: 1px solid var(--line); }
.observation-grid > section:last-child { border-right: 0; }
.observation-grid h2 { font-family: "IBM Plex Sans", sans-serif; font-size: 12px; letter-spacing: 0.08em; color: var(--muted); }
.observation-entry { padding: 8px 0; border-top: 1px solid var(--line); }
.observation-entry.changed { border-left: 2px solid var(--accent); padding-left: 8px; }
.observation-entry.changed h3 { color: var(--accent); }
.notebook { margin-top: 16px; }
.arena-panel { position: relative; width: 100%; height: 100%; min-height: 360px; overflow: hidden; }
.arena-viewport { position: absolute; inset: 0; }
.arena-viewport canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.arena-hud { position: absolute; inset: 12px; pointer-events: none; }
.hud-block {
  position: absolute; pointer-events: auto;
  background: var(--panel); border: 1px solid var(--line); padding: 8px 12px;
  max-width: calc(50% - 8px);
}
.arena-stats { left: 0; top: 0; width: 240px; display: grid; gap: 8px; }
.arena-stats label { font-size: 11px; gap: 4px; }
.arena-stats strong { color: var(--accent); font-weight: 500; }
.arena-target { right: 0; top: 0; width: 260px; display: grid; gap: 8px; overflow-wrap: anywhere; }
.arena-events {
  bottom: 0; left: 0; width: 420px; max-height: 28%;
  overflow: auto; list-style: none; margin: 0;
  font-family: "IBM Plex Mono", monospace; font-size: 10px;
}
.arena-events li { padding: 4px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.event-reject, .error, .err { color: var(--err); }
.event-manifest, .event-construct, .ok { color: var(--ok); }
.event-joint { color: var(--accent); }
.event-hit, .warning, .warn { color: var(--warn); }
.arena-controls { right: 0; bottom: 0; width: 320px; display: flex; flex-wrap: wrap; gap: 4px; }
.arena-controls details { flex-basis: 100%; }
.arena-controls details select { width: 100%; margin: 4px 0; }
.toasts, #toasts, .toast-container {
  position: fixed; z-index: 100; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: grid; gap: 8px; width: min(560px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  padding: 12px 16px; background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 3px; overflow-wrap: anywhere; pointer-events: auto;
}
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.err { border-left-color: var(--err); }
dialog { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / 65%); }
@media (max-width: 899px) {
  .studio-grid { height: auto; grid-template-columns: 1fr; }
  .studio-grid > * { border-right: 0; border-bottom: 1px solid var(--line); }
  .studio-canvas { min-height: 440px; }
  .inputs-grid { grid-template-columns: 180px minmax(0, 1fr); }
  .observation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .observation-grid > section { border-bottom: 1px solid var(--line); }
  .arena-stats { width: 200px; gap: 4px; }
  .arena-stats small { display: none; }
}
@media (max-width: 599px) {
  .topbar, .top-bar, .app-header { padding: 8px; gap: 8px; }
  .app-title { font-size: 23px; }
  .tabs, [role="tablist"] { gap: 4px; }
  .inputs-panel, .observatory-panel, .methods-panel { padding: 8px; }
  .inputs-grid { grid-template-columns: 1fr; }
  .inputs-grid > nav { border-right: 0; border-bottom: 1px solid var(--line); }
  .inputs-grid > section { padding-left: 0; }
  .observation-grid { grid-template-columns: 1fr; }
  .arena-hud { inset: 8px; }
  .hud-block { padding: 4px 8px; }
  .arena-target, .arena-controls { width: 190px; }
  .arena-stats { width: 170px; }
  .arena-stats label span { font-size: 10px; }
  .arena-events { max-height: 22%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
