:root {
  --bg: #f6f6f2;
  --ink: #111;
  --muted: #595959;
  --line: #111;
  --soft: #e4e4df;
  --panel: #fff;
  --ok: #2fd37c;
  --warn: #e0b24a;
  --bad: #ff6a5f;
  --signal: #7db8ff;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  letter-spacing: 0;
}

img {
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

button,
input,
select,
.button-link {
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  letter-spacing: 0;
  padding: 9px 11px;
}

button,
.button-link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  text-transform: uppercase;
  font-weight: 800;
}

button:hover,
.button-link:hover {
  background: var(--ink);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

dialog {
  border: 2px solid var(--line);
  padding: 22px;
  box-shadow: 8px 8px 0 var(--line);
}

dialog::backdrop {
  background: rgba(255, 255, 255, 0.72);
}

#login-form {
  display: grid;
  gap: 10px;
  min-width: 280px;
}

#login-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.google-login {
  display: block;
  border: 2px solid var(--line);
  padding: 10px 12px;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  font-weight: 800;
}

.google-login:hover {
  background: var(--ink);
  color: #fff;
}

.error {
  margin: 0;
  color: #b42318;
}

.gate-body {
  --bg: #101010;
  --ink: #f2f2ee;
  --muted: #9b9b94;
  --line: #eeeeea;
  --soft: #1f1f1d;
  --panel: #151513;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  color: var(--ink);
}

.parked {
  min-height: 100vh;
  display: grid;
  place-content: center;
  padding: 28px;
}

.gate-card {
  display: grid;
  gap: 18px;
  align-items: center;
  width: min(560px, calc(100vw - 42px));
  padding: 22px;
  background: #151513;
  border: 1px solid rgba(242, 242, 238, 0.76);
}

.gate-card h1,
h2 {
  margin: 0;
  line-height: 1.03;
  text-transform: uppercase;
}

.dot-word {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.dot-letter {
  display: grid;
  grid-template-columns: repeat(5, 4px);
  grid-template-rows: repeat(7, 4px);
  gap: 1px;
}

.dot-letter span {
  width: 4px;
  height: 4px;
  background: transparent;
}

.dot-letter .on {
  background: var(--ink);
}

.dot-space {
  width: 12px;
}

.gate-dot {
  margin-bottom: 9px;
}

.brand-dot .dot-letter {
  grid-template-columns: repeat(5, 3px);
  grid-template-rows: repeat(7, 3px);
}

.brand-dot .dot-letter span {
  width: 3px;
  height: 3px;
}

.gate-card h1 {
  margin-top: 3px;
  font-size: clamp(36px, 6vw, 64px);
}

.gate-card p {
  max-width: 42ch;
  color: var(--muted);
  line-height: 1.5;
}

.gate-open {
  width: 100%;
  min-height: 46px;
  border: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.14);
}

.gate-open:hover {
  color: #101010;
  background: var(--ink);
}

.app-page {
  --bg: #101010;
  --ink: #f2f2ee;
  --muted: #9b9b94;
  --line: #eeeeea;
  --soft: #1f1f1d;
  --panel: #151513;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  color: var(--ink);
}

.app-page button,
.app-page .button-link {
  width: auto;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.11);
}

.app-page input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.11);
}

.app-page select {
  min-height: 32px;
  height: 32px;
  width: clamp(340px, 28vw, 520px);
  max-width: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.11);
  font-weight: 800;
}

.app-page button:hover,
.app-page .button-link:hover {
  color: #101010;
  background: var(--ink);
}

.app-page button:focus-visible,
.app-page input:focus-visible,
.app-page select:focus-visible,
.app-page .button-link:focus-visible {
  box-shadow:
    inset 0 0 0 1px rgba(242, 242, 238, 0.42),
    0 0 0 2px rgba(242, 242, 238, 0.18);
}

.app-page input::placeholder {
  color: #77776f;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-content: start;
  width: min(1640px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 12px auto 48px;
}

.app-rail {
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
}

.brand-block {
  display: inline-flex;
  gap: 12px;
  min-height: 34px;
  align-items: center;
  text-decoration: none;
}

.brand-block strong {
  font-size: 19px;
  line-height: 1;
  text-transform: uppercase;
}

.eyebrow,
.field span,
.sub {
  color: var(--muted);
}

.eyebrow,
.field span {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.app-nav button {
  min-height: 32px;
  padding: 0 12px;
  background: transparent;
}

.app-nav button.active {
  color: #101010;
  background: var(--ink);
}

.top-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}

.scenario-picker {
  display: flex;
  align-items: center;
}

.top-actions button,
.top-actions .button-link {
  min-height: 32px;
  min-width: 58px;
  padding: 0 12px;
}

.top-actions .primary-action {
  color: #101010;
  background: var(--ink);
}

.app-main {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
}

.lead {
  max-width: 82ch;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.button-row button,
.button-row .button-link {
  width: 100%;
}

.button-row.split {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-link.compact {
  width: auto;
  min-width: 108px;
  min-height: 38px;
  padding: 0 14px;
}

.sub {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 0 0 10px;
  border: 1px solid rgba(242, 242, 238, 0.76);
  background: rgba(242, 242, 238, 0.76);
}

.status-grid article {
  display: grid;
  gap: 7px;
  min-height: 66px;
  padding: 10px 12px;
  background: #151513;
}

.status-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-grid strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: clamp(17px, 1.7vw, 22px);
  line-height: 1;
  text-transform: uppercase;
}

.ok {
  color: var(--ok);
}

.warn {
  color: var(--warn);
}

.bad {
  color: var(--bad);
}

.workspace-view {
  display: none;
}

.workspace-view.active {
  display: block;
}

.mission-grid,
.log-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(330px, 0.62fr);
  gap: 12px;
  align-items: start;
}

.log-grid {
  display: flex;
  align-items: stretch;
  min-width: 0;
  overflow: hidden;
}

.feed-panel,
.run-panel,
.serial-panel,
.bridge-panel,
.log-grid article {
  min-width: 0;
  background: #151513;
  border: 1px solid rgba(242, 242, 238, 0.72);
}

.feed-panel,
.run-panel,
.serial-panel,
.bridge-panel {
  padding: 12px;
}

.log-grid article {
  flex: 1 1 0;
  padding: 12px;
}

.main-side-stack {
  display: grid;
  gap: 12px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h2,
h2 {
  font-size: 18px;
}

.log-toggle {
  flex: 0 0 auto;
  width: 32px;
  min-width: 32px;
  min-height: 30px;
  padding: 0;
}

.log-panel.collapsed {
  flex: 0 0 max-content;
  width: max-content;
  max-width: 220px;
}

.log-panel.collapsed .panel-head {
  margin-bottom: 0;
}

.log-panel.collapsed pre {
  display: none;
}

.log-panel.collapsed h2 {
  white-space: nowrap;
}

#inline-feed,
.large-feed {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px) 0 0 / 18px 18px,
    #050505;
}

.large-feed {
  max-height: calc(100vh - 190px);
}

.field {
  display: grid;
  gap: 7px;
}

.serial-panel {
  display: grid;
  gap: 12px;
}

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

.kv dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kv dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

pre {
  min-height: 300px;
  max-height: calc(100vh - 210px);
  margin: 0;
  overflow: auto;
  padding: 12px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 18px 18px,
    #10100f;
  border: 1px solid rgba(242, 242, 238, 0.28);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.feed-body {
  --ink: #f2f2ee;
  --line: #eeeeea;
  margin: 0;
  background: #050505;
  color: var(--ink);
}

.feed-page {
  position: relative;
  display: grid;
  width: 100vw;
  height: 100vh;
  place-items: center;
  overflow: hidden;
  background: #050505;
}

#camera-feed {
  display: block;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #050505;
}

@media (max-width: 1180px) {
  .app-rail {
    grid-template-columns: minmax(210px, auto) 1fr;
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .scenario-picker {
    flex: 1 1 auto;
  }

  .app-page select {
    width: 100%;
    flex: 1 1 auto;
  }
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100% - 28px, 1560px);
    margin-top: 14px;
  }

  .app-rail,
  .mission-grid,
  .log-grid {
    grid-template-columns: 1fr;
  }

  .log-grid {
    flex-direction: column;
    overflow: visible;
  }

  .log-panel.collapsed {
    width: auto;
    max-width: none;
  }

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

  .button-row {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button,
  .top-actions .button-link {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .status-grid {
    grid-template-columns: 1fr;
  }

  .kv {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }
}
