:root {
  color-scheme: dark;
  --bg: #07101d;
  --bg-deep: #040912;
  --surface: #0d1827;
  --surface-2: #132237;
  --surface-3: #192b42;
  --glass: rgba(10, 20, 34, 0.86);
  --text: #f3f7fb;
  --muted: #9aa9bb;
  --faint: #718096;
  --line: rgba(153, 180, 211, 0.18);
  --line-strong: rgba(153, 180, 211, 0.34);
  --gold: #e9bf47;
  --gold-soft: #f6d879;
  --cyan: #43cbd6;
  --green: #50d890;
  --red: #ff7272;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #edf3f8;
  --bg-deep: #dce7f0;
  --surface: #ffffff;
  --surface-2: #f5f8fb;
  --surface-3: #eaf1f7;
  --glass: rgba(255, 255, 255, 0.9);
  --text: #102034;
  --muted: #52647a;
  --faint: #73839a;
  --line: rgba(18, 48, 79, 0.14);
  --line-strong: rgba(18, 48, 79, 0.28);
  --gold: #a87808;
  --gold-soft: #bd8f1b;
  --cyan: #087f91;
  --green: #087c4a;
  --red: #bd3030;
  --shadow: 0 16px 40px rgba(40, 68, 94, 0.12);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(118deg, rgba(233, 191, 71, 0.09), transparent 36%),
    linear-gradient(145deg, var(--bg), var(--bg-deep));
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.eyebrow {
  display: block;
  color: var(--gold);
  font-size: 0.69rem;
  font-weight: 800;
  line-height: 1.25;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(233, 191, 71, 0.55);
  background: linear-gradient(145deg, rgba(233, 191, 71, 0.24), rgba(67, 203, 214, 0.08));
  color: var(--gold-soft);
  font-size: 0.78rem;
  font-weight: 900;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-3);
}

.icon-button.accent {
  border-color: transparent;
  background: var(--gold);
  color: #111722;
}

.icon-button svg,
.button svg,
.primary-nav svg,
.section-nav svg,
.rail-note svg,
.luna-heading svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.8;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  min-height: 100dvh;
  padding: 24px;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(233, 191, 71, 0.12), transparent 45%),
    linear-gradient(145deg, var(--bg), var(--bg-deep));
}

.auth-gate::before,
.topbar::after {
  position: absolute;
  inset: 0 0 auto;
  height: 90px;
  background:
    linear-gradient(172deg, transparent 41%, rgba(233, 191, 71, 0.33) 42%, transparent 43%),
    linear-gradient(177deg, transparent 55%, rgba(67, 203, 214, 0.14) 56%, transparent 57%);
  content: "";
  pointer-events: none;
}

.auth-shell {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(1180px, 100%);
  grid-template-columns: minmax(0, 1fr) minmax(380px, 450px);
  align-items: center;
  gap: clamp(48px, 8vw, 118px);
}

.auth-story {
  min-width: 0;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 58px;
}

.auth-brand > span:last-child {
  display: grid;
}

.auth-brand strong {
  font-size: 1.35rem;
}

.auth-brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.auth-return {
  margin: 18px 0 8px;
  color: var(--gold-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.auth-story h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2.6rem, 5vw, 4.7rem);
  line-height: 0.98;
}

.auth-story > p:last-of-type {
  max-width: 700px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.75;
}

.auth-facts {
  display: grid;
  margin-top: 34px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.auth-facts p {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 17px 16px 17px 0;
}

.auth-facts p + p {
  padding-left: 16px;
  border-left: 1px solid var(--line);
}

.auth-facts strong {
  color: var(--text);
  font-size: 0.8rem;
}

.auth-facts span {
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.5;
}

.auth-panel {
  position: relative;
  width: 100%;
  padding: 34px;
  border: 1px solid var(--line-strong);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.auth-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.auth-panel-top .brand-mark { margin: 0; }
.auth-panel h2 { margin: 7px 0 0; font-size: 1.65rem; line-height: 1.1; }
.auth-panel > p { margin: 0 0 28px; color: var(--muted); line-height: 1.65; }
.auth-panel form { display: grid; gap: 8px; }
.auth-panel label { color: var(--muted); font-size: 0.78rem; font-weight: 700; }

.input-action {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-action input {
  min-width: 0;
  height: 46px;
  flex: 1;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg-deep);
  color: var(--text);
}

.form-message {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.form-message.error { color: var(--red); }
.form-message.success { color: var(--green); }

.console {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: 210px 1fr auto;
  min-height: 64px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(233, 191, 71, 0.12), transparent 52%),
    var(--glass);
  backdrop-filter: blur(20px);
}

.topbar::after {
  height: 64px;
  opacity: 0.28;
}

.brand {
  position: relative;
  z-index: 1;
  display: flex;
  height: 64px;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-right: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.brand > span:last-child {
  display: grid;
  line-height: 1;
}

.brand strong { font-size: 0.96rem; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 0.61rem; text-transform: uppercase; letter-spacing: 0.12em; }

.primary-nav {
  position: relative;
  z-index: 1;
  display: flex;
  height: 64px;
  align-items: stretch;
  justify-content: center;
}

.primary-nav a {
  position: relative;
  display: flex;
  min-width: 120px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
  text-decoration: none;
}

.primary-nav a::after {
  position: absolute;
  right: 22px;
  bottom: 0;
  left: 22px;
  height: 2px;
  background: transparent;
  content: "";
}

.primary-nav a:hover,
.primary-nav a.active { color: var(--text); }
.primary-nav a.active::after { background: var(--gold); }

.top-actions {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 14px;
}

.environment {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 4px;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 850;
}

.environment > span,
.presence {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(80, 216, 144, 0.11);
}

.user-button {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(233, 191, 71, 0.45);
  border-radius: 50%;
  background: linear-gradient(145deg, var(--surface-3), var(--surface));
  color: var(--gold-soft);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 850;
}

.user-menu {
  position: absolute;
  top: 48px;
  right: 14px;
  display: grid;
  min-width: 220px;
  gap: 5px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.user-menu small { color: var(--muted); }
.user-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px -8px -8px;
  padding: 10px 8px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.workspace {
  display: grid;
  min-height: calc(100dvh - 64px);
  grid-template-columns: 228px minmax(0, 1fr) 300px;
}

.module-rail,
.luna-rail {
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100dvh - 64px);
  border-color: var(--line);
  background: rgba(7, 15, 27, 0.55);
  backdrop-filter: blur(14px);
}

html[data-theme="light"] .module-rail,
html[data-theme="light"] .luna-rail {
  background: rgba(238, 244, 249, 0.72);
}

.module-rail {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 26px 18px 18px;
  border-right: 1px solid var(--line);
}

.module-rail h2 { margin: 8px 0 9px; font-size: 1.45rem; }
.module-rail > div:first-child p { margin: 0; color: var(--muted); font-size: 0.78rem; line-height: 1.55; }

.module-prompt {
  margin-top: 18px !important;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  color: var(--gold-soft) !important;
  font-weight: 800;
}

.section-nav {
  display: grid;
  gap: 4px;
}

.section-nav button {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 10px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  text-align: left;
}

.section-nav button:hover { background: rgba(255, 255, 255, 0.03); color: var(--text); }
.section-nav button.active { border-color: rgba(233, 191, 71, 0.2); background: rgba(233, 191, 71, 0.09); color: var(--gold-soft); }

.rail-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.rail-note svg { flex: 0 0 auto; color: var(--gold); }
.rail-note p { display: grid; gap: 4px; margin: 0; font-size: 0.7rem; line-height: 1.35; }
.rail-note strong { color: var(--text); }

.main-content {
  min-width: 0;
  padding: 28px;
}

.luna-rail {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
}

.luna-heading {
  display: flex;
  min-height: 66px;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.luna-heading > div { display: grid; flex: 1; }
.luna-heading small { margin-top: 3px; color: var(--muted); font-size: 0.67rem; }

.luna-greeting {
  margin: 0;
  padding: 18px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 850;
  line-height: 1.35;
}

.luna-thread {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 14px;
}

.luna-thread article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.luna-thread article.user { margin-left: 24px; border-color: rgba(233, 191, 71, 0.28); }
.luna-thread strong { font-size: 0.72rem; color: var(--gold-soft); }
.luna-thread p { margin: 6px 0 0; color: var(--muted); font-size: 0.76rem; line-height: 1.55; }

.luna-thread .luna-empty {
  margin: auto 0;
  color: var(--faint);
  text-align: center;
}

.luna-form {
  position: relative;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.luna-form textarea {
  width: 100%;
  min-height: 86px;
  resize: none;
  padding: 12px 48px 12px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
}

.luna-form button { position: absolute; right: 22px; bottom: 22px; }

#luna-collapse { visibility: hidden; }

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-heading h1 {
  margin: 6px 0 7px;
  font-size: clamp(1.9rem, 4vw, 3rem);
  line-height: 1;
}

.page-heading p {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.page-actions,
.toolbar,
.segmented,
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 750;
  text-decoration: none;
}

.button.primary { border-color: transparent; background: var(--gold); color: #111722; }
.button.secondary:hover { background: var(--surface-3); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }

.metric-strip {
  display: grid;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
  min-width: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.metric:last-child { border-right: 0; }
.metric span { color: var(--muted); font-size: 0.7rem; }
.metric strong { display: block; margin-top: 7px; font-size: 1.55rem; }
.metric small { display: block; margin-top: 4px; overflow: hidden; color: var(--faint); font-size: 0.65rem; text-overflow: ellipsis; white-space: nowrap; }

.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel + .panel { margin-top: 18px; }

.panel-heading {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2,
.panel-heading h3 { margin: 4px 0 0; font-size: 1rem; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 0.72rem; }

.lab-grid {
  display: grid;
  min-height: 620px;
  grid-template-columns: 270px minmax(380px, 1fr) 250px;
}

.source-browser,
.editor-pane {
  border-right: 1px solid var(--line);
}

.pane-heading {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.pane-heading strong { font-size: 0.78rem; }
.pane-heading small { color: var(--muted); font-size: 0.65rem; }

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
}

.search-field svg { width: 15px; color: var(--muted); }
.search-field input { width: 100%; height: 36px; border: 0; outline: 0; background: transparent; font-size: 0.72rem; }

.source-list {
  height: 515px;
  overflow: auto;
  padding: 0 8px 8px;
}

.source-item {
  display: grid;
  width: 100%;
  gap: 3px;
  padding: 9px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.source-item:hover { background: var(--surface-2); }
.source-item.active { border-color: rgba(233, 191, 71, 0.28); background: rgba(233, 191, 71, 0.08); }
.source-item strong { overflow: hidden; font-size: 0.72rem; text-overflow: ellipsis; white-space: nowrap; }
.source-item small { overflow: hidden; color: var(--muted); font-size: 0.61rem; text-overflow: ellipsis; white-space: nowrap; }

.code-editor {
  display: block;
  width: 100%;
  height: 520px;
  resize: none;
  padding: 18px;
  border: 0;
  outline: 0;
  background: #07101b;
  color: #dce8f4;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.74rem;
  line-height: 1.65;
  tab-size: 4;
}

html[data-theme="light"] .code-editor { background: #f6f9fc; color: #102034; }

.editor-footer {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
}

.revision-pane {
  min-width: 0;
  padding: 14px;
}

.revision-pane h3 { margin: 0 0 10px; font-size: 0.9rem; }
.revision-pane p { color: var(--muted); font-size: 0.72rem; line-height: 1.55; }

.detail-list {
  display: grid;
  gap: 1px;
  margin: 14px 0;
  background: var(--line);
}

.detail-list div {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
  padding: 8px;
  background: var(--surface-2);
  font-size: 0.67rem;
}

.detail-list span { color: var(--muted); }
.detail-list code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.version-list {
  display: grid;
  max-height: 220px;
  gap: 7px;
  overflow: auto;
}

.version-list article {
  padding: 9px;
  border-left: 2px solid var(--line-strong);
  background: var(--surface-2);
}

.version-list strong { display: block; font-size: 0.66rem; }
.version-list small { color: var(--muted); font-size: 0.6rem; }

.table-shell {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.62rem;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
td strong { display: block; }
td small { display: block; margin-top: 4px; color: var(--muted); }

.status {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.61rem;
  font-weight: 750;
}

.status.good { border-color: rgba(80, 216, 144, 0.3); color: var(--green); }
.status.warn { border-color: rgba(233, 191, 71, 0.34); color: var(--gold-soft); }
.status.bad { border-color: rgba(255, 114, 114, 0.35); color: var(--red); }

.split-view {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
}

.split-view > * + * { border-left: 1px solid var(--line); }

.chart-area {
  min-height: 420px;
  padding: 18px;
}

.chart-area canvas {
  display: block;
  width: 100%;
  height: 340px;
}

.result-inspector {
  min-width: 0;
  padding: 18px;
}

.result-inspector pre {
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.segmented {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-2);
}

.segmented button {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.67rem;
  font-weight: 750;
}

.segmented button.active { background: var(--surface-3); color: var(--text); }

.model-layout,
.config-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
}

.model-layout > aside,
.config-layout > aside {
  padding: 16px;
  border-left: 1px solid var(--line);
}

.model-layout aside h3,
.config-layout aside h3 { margin: 0 0 14px; }

.model-layout label,
.config-layout label,
.form-grid label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.model-layout input,
.model-layout select,
.config-layout input,
.config-layout select,
.form-grid input,
.form-grid select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface-2);
}

.config-list {
  display: grid;
  min-height: 520px;
  grid-template-columns: 260px 1fr;
}

.config-tree {
  padding: 10px;
  border-right: 1px solid var(--line);
}

.config-tree button {
  display: grid;
  width: 100%;
  gap: 3px;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.config-tree button:hover,
.config-tree button.active { border-color: var(--line); background: var(--surface-2); }
.config-tree small { color: var(--muted); }

.config-editor {
  width: 100%;
  height: 466px;
  resize: none;
  padding: 16px;
  border: 0;
  outline: 0;
  background: #07101b;
  color: #dce8f4;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.6;
}

html[data-theme="light"] .config-editor { background: #f6f9fc; color: #102034; }

.empty-state,
.loading-state {
  display: grid;
  min-height: 300px;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

dialog {
  width: min(680px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(2, 7, 13, 0.76); backdrop-filter: blur(4px); }

.dialog-form { padding: 20px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.dialog-heading h2 { margin: 5px 0 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 0.75rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1240px) {
  .workspace { grid-template-columns: 210px minmax(0, 1fr); }
  .luna-rail {
    position: fixed;
    z-index: 22;
    right: 0;
    bottom: 0;
    width: 310px;
    transform: translateX(calc(100% - 48px));
    transition: transform 180ms ease;
  }
  .luna-rail.open { transform: translateX(0); }
  #luna-collapse { visibility: visible; }
}

@media (max-width: 900px) {
  .auth-gate {
    position: absolute;
    overflow-y: auto;
  }
  .auth-shell {
    width: min(650px, 100%);
    grid-template-columns: 1fr;
    gap: 38px;
    padding: 56px 0;
  }
  .auth-story { text-align: center; }
  .auth-brand { justify-content: center; margin-bottom: 38px; }
  .auth-story > p:last-of-type { margin-right: auto; margin-left: auto; }
  .auth-panel { width: min(520px, 100%); margin: 0 auto; text-align: left; }
  .topbar { grid-template-columns: 180px 1fr auto; }
  .primary-nav a { min-width: 56px; }
  .primary-nav a span { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .module-rail {
    position: static;
    display: grid;
    width: 100%;
    height: auto;
    grid-template-columns: 220px 1fr;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .section-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .rail-note { display: none; }
  .lab-grid { grid-template-columns: 230px minmax(380px, 1fr); }
  .revision-pane { display: none; }
  .model-layout,
  .config-layout { grid-template-columns: 1fr; }
  .model-layout > aside,
  .config-layout > aside { border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 680px) {
  .auth-gate { padding: 16px; }
  .auth-shell { gap: 28px; padding: 28px 0; }
  .auth-brand { margin-bottom: 28px; }
  .auth-story h1 { font-size: 2.35rem; }
  .auth-story > p:last-of-type { font-size: 0.88rem; line-height: 1.65; }
  .auth-facts { grid-template-columns: 1fr; }
  .auth-facts p,
  .auth-facts p + p { padding: 13px 0; border-left: 0; }
  .auth-facts p + p { border-top: 1px solid var(--line); }
  .auth-panel { padding: 24px; }
  .topbar { grid-template-columns: 1fr auto; }
  .brand { border-right: 0; }
  .primary-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    height: 58px;
    border-top: 1px solid var(--line);
    background: var(--surface);
  }
  .primary-nav a { flex: 1; }
  .primary-nav a span { display: inline; font-size: 0.65rem; }
  .top-actions .environment,
  #global-search { display: none; }
  .module-rail { display: block; padding: 18px; }
  .module-rail > div:first-child p { max-width: 520px; }
  .section-nav { display: flex; margin-top: 16px; overflow-x: auto; }
  .section-nav button { flex: 0 0 auto; }
  .main-content { padding: 18px 12px 80px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-actions { width: 100%; }
  .page-actions .button { flex: 1; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .lab-grid { display: block; }
  .source-browser { border-right: 0; border-bottom: 1px solid var(--line); }
  .source-list { height: 220px; }
  .code-editor { height: 420px; }
  .split-view { grid-template-columns: 1fr; }
  .split-view > * + * { border-top: 1px solid var(--line); border-left: 0; }
  .config-list { grid-template-columns: 1fr; }
  .config-tree { border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .luna-rail { bottom: 58px; }
}
