:root {
  --bg: #0b0d12;
  --panel: #10131a;
  --panel-2: #151a23;
  --line: #222a38;
  --line-soft: #1a212c;
  --text: #e7ebf3;
  --muted: #8b95a9;
  --dim: #5d677a;
  --accent: #4dd4ac;
  --accent-soft: rgba(77, 212, 172, 0.12);
  --warn: #f0b429;
  --danger: #ff6b6b;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Several controls below set an explicit display, which outranks the [hidden]
   rule in the user-agent sheet. One global restatement keeps hidden honest. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 13, 18, 0.9);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand strong { color: var(--text); font-weight: 600; }

.topnav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
}
.topnav a { color: var(--muted); }
.topnav a:hover { color: var(--text); text-decoration: none; }

.pill {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(77, 212, 172, 0.22);
  border-radius: 999px;
  padding: 3px 9px;
}

/* ---------- layout ---------- */

main {
  display: grid;
  grid-template-columns: 336px minmax(0, 1fr);
  /* One explicit row that fills the frame. Without the minmax the row sizes to
     the panel's content, which pushes the stage taller than the viewport and
     drags its absolutely-positioned overlays out of sight. */
  grid-template-rows: minmax(0, 1fr);
  flex: 0 0 auto;
  height: calc(100vh - 84px);
  min-height: 540px;
}

.panel {
  border-right: 1px solid var(--line-soft);
  background: var(--panel);
  /* Two rows: everything scrolls, the action does not. A sticky button over
     scrolling content hides the last report line, which is exactly the line
     that explains why the mesh looks the way it does. */
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.panel-scroll {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
}

.panel-footer {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel);
}

.block { display: flex; flex-direction: column; gap: 9px; }

h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- drop target ---------- */

.drop-target {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  outline: none;
}
.drop-target:hover,
.drop-target:focus-visible { border-color: var(--accent); }
.drop-target.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-icon {
  color: var(--accent);
  display: flex;
  flex: 0 0 auto;
}

.drop-text { display: flex; flex-direction: column; min-width: 0; }
.drop-text strong { font-size: 13px; font-weight: 600; }
.drop-text span {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- controls ---------- */

.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: color .15s, border-color .15s;
}
.ghost:hover { color: var(--text); border-color: var(--dim); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}
.segmented button {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.segmented button.active {
  background: var(--line);
  color: var(--text);
}

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.row output {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  outline: none;
  margin: 3px 0 6px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--panel);
}

select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

/* ---------- report ---------- */

.report { gap: 8px; }

.report-empty {
  font-size: 12.5px;
  color: var(--dim);
  padding: 10px 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow: hidden;
}
.stat {
  background: var(--panel);
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stat b {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}
.stat span {
  font-size: 10.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--dim);
}

.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.badge {
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge.ok {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(77, 212, 172, 0.2);
}
.badge.bad {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.25);
}

.notes-list { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 0; padding: 0; list-style: none; }
.notes-list li {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--warn);
  padding-left: 12px;
  position: relative;
}
.notes-list li::before {
  content: '';
  position: absolute;
  left: 0; top: 6px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
}
.notes-list li.info { color: var(--muted); }
.notes-list li.error { color: var(--danger); }

/* ---------- buttons ---------- */

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  background: var(--accent);
  color: #06211a;
  border: 0;
  border-radius: 9px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
  transition: filter .15s, opacity .15s;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary:disabled {
  background: var(--panel-2);
  color: var(--dim);
  cursor: default;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  min-height: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, #141a24 0%, transparent 70%),
    #080a0e;
  overflow: hidden;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
#view:active { cursor: grabbing; }

.stage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--dim);
  pointer-events: none;
}
.stage-empty p { margin: 0; font-size: 13px; }
.stage-empty.hidden { display: none; }

.hud {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: none;
}
/* An explicit display value beats the [hidden] UA rule, so restate it. */
.hud[hidden] { display: none; }
.hud span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: rgba(16, 19, 26, 0.82);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 3px 7px;
  backdrop-filter: blur(6px);
}

.stagemark {
  position: absolute;
  right: 14px;
  bottom: 14px;
  font-size: 11px;
  color: #3d4657;
  pointer-events: none;
}

.viewmode {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(16, 19, 26, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}
.viewmode button {
  background: none;
  border: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: 11.5px;
  padding: 4px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.viewmode button.active {
  background: var(--line);
  color: var(--text);
}

/* ---------- notes / footer ---------- */

.notes {
  border-top: 1px solid var(--line-soft);
  background: var(--panel);
  padding: 34px 20px 38px;
  flex: 0 0 auto;
}
.notes-inner { max-width: 1080px; margin: 0 auto; }
.notes h2 {
  font-size: 15px;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 16px;
}
.cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 22px;
}
.cols p {
  margin: 0;
  font-size: 13px;
  line-height: 1.62;
  color: var(--muted);
}
.cols p strong { color: var(--text); font-weight: 600; }
.cols code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 1px 4px;
  color: var(--text);
}
.aside-col {
  border-left: 1px solid var(--line);
  padding-left: 22px;
}

footer {
  border-top: 1px solid var(--line-soft);
  padding: 14px 20px;
  flex: 0 0 auto;
}
.foot-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--dim);
}
.foot-inner a { color: var(--muted); }
.foot-inner a:hover { color: var(--accent); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    /* A fixed frame height is right on desktop and wrong here: the panel needs
       to grow with its content instead of being clipped. */
    height: auto;
    min-height: 0;
  }
  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    grid-template-rows: auto auto;
  }
  .panel-scroll { overflow: visible; }
  .panel-footer { border-top: 0; padding: 0 16px 16px; }
  .stage { height: 54vh; min-height: 300px; order: -1; }
  .stagemark { display: none; }
  .aside-col { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 18px; }
  .notes { padding: 26px 16px 30px; }
  .hud { left: 10px; bottom: 10px; }
  .viewmode { top: 10px; right: 10px; }
}
