:root {
  color-scheme: dark;
  --bg: #070b12;
  --surface: #0d1420;
  --surface-2: #111b2a;
  --surface-3: #162235;
  --border: #25364e;
  --border-strong: #34506e;
  --text: #edf5ff;
  --muted: #9bb0c8;
  --accent: #46c8ef;
  --accent-soft: rgba(70, 200, 239, 0.13);
  --success: #45db9c;
  --success-soft: rgba(69, 219, 156, 0.12);
  --warning: #f1b84b;
  --warning-soft: rgba(241, 184, 75, 0.12);
  --danger: #ff6f7c;
  --danger-soft: rgba(255, 111, 124, 0.12);
  --locked: #a497ff;
  --locked-soft: rgba(164, 151, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -20%, rgba(32, 116, 153, 0.16), transparent 36rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

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

[hidden] {
  display: none !important;
}

.noscript {
  margin: 1rem;
  padding: 1rem;
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: var(--danger-soft);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 76px;
  padding: 14px clamp(18px, 3vw, 36px);
  border-bottom: 1px solid rgba(46, 68, 96, 0.7);
  background: rgba(7, 11, 18, 0.94);
  backdrop-filter: blur(18px);
}

.brand-block,
.setup-heading,
.topbar-actions,
.panel-title-row,
.engine-badges {
  display: flex;
  align-items: center;
}

.brand-block,
.setup-heading {
  gap: 12px;
}

.brand-mark {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(70, 200, 239, 0.5);
  border-radius: 14px;
  color: #7bdcf7;
  background: rgba(70, 200, 239, 0.12);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand-block p,
.panel-header p,
.section-subtitle,
.setup-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions {
  justify-content: flex-end;
  gap: 10px;
}

.system-clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 96px;
  margin-right: 4px;
}

.eyebrow {
  color: #7bdcf7;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.system-clock strong {
  margin-top: 2px;
  font-size: 14px;
}

.button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 14px;
  color: var(--text);
  background: var(--surface-2);
  font-weight: 700;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.button:hover,
.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(70, 200, 239, 0.32);
  outline-offset: 2px;
}

.button-primary {
  border-color: rgba(70, 200, 239, 0.6);
  color: #03131a;
  background: var(--accent);
}

.button-secondary,
.icon-button {
  border-color: var(--border);
  background: var(--surface-2);
}

.button-danger {
  border-color: rgba(255, 111, 124, 0.42);
  color: #ffc3c9;
  background: var(--danger-soft);
}

.icon-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dashboard {
  display: grid;
  gap: 16px;
  width: min(100%, 1680px);
  margin: 0 auto;
  padding: 16px clamp(18px, 2.4vw, 36px) 36px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13, 20, 32, 0.84);
}

.metric-label,
.metric-detail {
  display: block;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-detail {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-locked {
  color: #c8c0ff;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.chart-panel,
.engine-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(13, 20, 32, 0.92);
  box-shadow: var(--shadow);
}

.panel-header,
.engine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-title-row {
  gap: 10px;
}

.panel-title-row h2,
.engine-header h2 {
  font-size: 16px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.status-idle {
  color: var(--muted);
  background: rgba(155, 176, 200, 0.08);
}

.status-loading {
  color: #79dcf8;
  background: var(--accent-soft);
}

.status-live {
  color: var(--success);
  background: var(--success-soft);
}

.status-warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-error {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-locked {
  color: var(--locked);
  background: var(--locked-soft);
}

.frame-stage {
  position: relative;
  height: min(54vh, 650px);
  min-height: 480px;
  background: #060a10;
}

.source-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #060a10;
}

.frame-placeholder,
.frame-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 9px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: #070c14;
}

.frame-placeholder strong,
.frame-loading strong {
  color: var(--text);
}

.placeholder-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 17px;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 800;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(70, 200, 239, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

.engine-panel {
  padding-bottom: 18px;
}

.engine-header {
  align-items: flex-start;
}

.engine-badges {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.subsection-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 18px 10px;
}

.subsection-heading h3 {
  font-size: 14px;
}

.subsection-heading span {
  color: var(--muted);
  font-size: 11px;
}

.engine-grid {
  display: grid;
  gap: 10px;
  padding: 0 18px;
}

.engine-grid-wide {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.engine-cell {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.engine-cell span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.engine-cell strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice {
  margin: 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.notice-info {
  border-color: rgba(70, 200, 239, 0.35);
  color: #c9f2ff;
  background: var(--accent-soft);
}

.notice-success {
  border-color: rgba(69, 219, 156, 0.35);
  color: #c9ffe8;
  background: var(--success-soft);
}

.notice-warning {
  border-color: rgba(241, 184, 75, 0.35);
  color: #ffe7b4;
  background: var(--warning-soft);
}

.notice-error {
  border-color: rgba(255, 111, 124, 0.38);
  color: #ffd0d5;
  background: var(--danger-soft);
}

.diagnostics {
  margin: 0 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(8, 13, 22, 0.55);
}

.diagnostics summary {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.diagnostics[open] summary {
  border-bottom: 1px solid var(--border);
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.diagnostics-grid div {
  min-width: 0;
  padding: 9px;
  border-radius: 9px;
  background: var(--surface-2);
}

.diagnostics-grid span,
.diagnostics-grid strong {
  display: block;
}

.diagnostics-grid span {
  color: var(--muted);
  font-size: 10px;
}

.diagnostics-grid strong {
  margin-top: 4px;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-log {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0 12px 12px 32px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
}

.strategy-panel {
  box-shadow: none;
}

.strategy-lock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px;
  padding: 16px;
  border: 1px dashed rgba(164, 151, 255, 0.45);
  border-radius: 12px;
  background: var(--locked-soft);
}

.strategy-lock span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  overflow-y: auto;
  place-items: center;
  padding: 24px;
  background: rgba(3, 7, 12, 0.88);
  backdrop-filter: blur(10px);
}

.setup-card {
  width: min(100%, 790px);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.setup-heading {
  align-items: flex-start;
}

.setup-heading h1 {
  margin-top: 5px;
  font-size: clamp(25px, 4vw, 34px);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field {
  display: block;
}

.field-full {
  grid-column: 1 / -1;
}

.field > span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 10px 13px;
  color: var(--text);
  background: #09101a;
}

.field small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.setup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.acceptance-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: #c3d2e3;
  font-size: 12px;
}

.acceptance-list > div {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.check {
  color: var(--success);
  font-weight: 900;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 15px;
  border: 1px solid rgba(69, 219, 156, 0.45);
  border-radius: 12px;
  color: #d8ffee;
  background: #10271f;
  box-shadow: var(--shadow);
  font-size: 13px;
}

@media (max-width: 1450px) {
  .status-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .engine-grid-wide {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .diagnostics-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1080px) {
  .topbar {
    position: static;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .frame-stage {
    height: min(68vh, 700px);
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .system-clock {
    align-items: flex-start;
    width: 100%;
  }

  .status-grid,
  .engine-grid-wide,
  .diagnostics-grid,
  .form-grid,
  .acceptance-list {
    grid-template-columns: 1fr 1fr;
  }

  .field-full {
    grid-column: 1 / -1;
  }

  .panel-header,
  .engine-header,
  .strategy-lock {
    align-items: flex-start;
    flex-direction: column;
  }

  .strategy-lock span {
    text-align: left;
  }

  .frame-stage {
    height: 540px;
    min-height: 420px;
  }
}

@media (max-width: 500px) {
  .status-grid,
  .engine-grid-wide,
  .diagnostics-grid,
  .form-grid,
  .acceptance-list {
    grid-template-columns: 1fr;
  }

  .field-full {
    grid-column: auto;
  }

  .topbar-actions .button,
  .icon-button,
  .setup-actions .button {
    width: 100%;
  }

  .setup-actions {
    flex-direction: column-reverse;
  }

  .subsection-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}
