:root {
  --bg-ground: #FAFAF9;
  --bg-surface: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-subtle: #F4F4F2;
  --bg-active: rgba(29, 74, 255, 0.08);

  --ink-primary: #0a0a0f;
  --ink-secondary: #6b7280;
  --ink-muted: #6b7280;
  --ink-faint: #6b7280;

  --border-subtle: #e8e8ed;
  --border-strong: #6b7280;
  --border-cyan: rgba(29, 74, 255, 0.4);

  --accent-cyan: #1D4AFF;
  --accent-emerald: #0a0a0f;
  --accent-confirm: #1D4AFF;

  --font-mono: "JetBrains Mono", "Inter Greek", ui-monospace, monospace;
  --font-body: "Inter", "Inter Greek", system-ui, -apple-system, sans-serif;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-panel: 0 12px 32px rgba(0,0,0,0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

html, body {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  background-color: var(--bg-ground);
  color: var(--ink-primary);
  font-family: var(--font-body);
}

.rail-label {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  padding: 0 12px;
}

.morph-chip {
  text-decoration: none;
  color: var(--ink-primary);
}

.morph-chip:hover {
  color: #1D4AFF;
  border-color: rgba(29, 74, 255, 0.4);
}

.morph-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-cyan);
  flex: none;
}

.dot-pulse {
  display: none !important;
}

.model-pick {
  display: flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.model-pick button,
.sit-chip {
  background: transparent;
  border: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--ink-muted);
  cursor: pointer;
  text-transform: capitalize;
}

.model-pick button:hover {
  color: var(--ink-primary);
}

.model-pick button[aria-pressed="true"] {
  background: var(--bg-card);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
}

.workstation-body {
  display: grid;
  grid-template-columns: 180px 1fr;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.rail {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.seat-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.seat-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.seat-list button:hover {
  background: var(--bg-subtle);
}

.seat-list button[aria-selected="true"] {
  background: var(--bg-card);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.seat-icon-wrap {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-primary);
}

.seat-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-primary);
}

.pip {
  display: none !important;
}

.stage {
  --col-l: 24px;
  --col-r: 24px;
  display: flex;
  flex-direction: column;
  background: var(--bg-ground);
  overflow: hidden;
  position: relative;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: pre;
}

.mission-banner-card {
  padding: 14px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.m-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.m-sub {
  font-size: 12px;
  color: var(--ink-secondary);
  margin-top: 3px;
  line-height: 1.4;
}

.flubber-stage-card {
  position: relative;
  flex: 1 1 0;
  margin: 0 var(--col-r) 0 var(--col-l);
  min-height: 380px;
  background: transparent;
  border: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#flubber-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#flubber-canvas:active {
  cursor: grabbing;
}

.sit-turns {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
  flex: 0 0 auto;
  max-height: 220px;
  overflow-y: auto;
  scroll-padding: 0 0 12px;
  padding: 12px var(--col-r) 12px var(--col-l);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.turn-list {
  list-style: none;
  display: grid;
  gap: 4px;
  margin: 2px 0 0;
}

.turn-list li {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.sit-bubble .turn-list code {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-primary);
  background: none;
  padding: 0;
}

.sit-turns:empty {
  display: none;
  padding: 0;
}

.sit-turn {
  display: flex;
  gap: 12px;
  max-width: 860px;
}

.sit-turn[data-who="operator"] {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.turn-face {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.sit-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.turn-model {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.sit-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-primary);
}

.sit-turn[data-who="operator"] .sit-bubble {
  background: var(--bg-card);
  color: var(--ink-primary);
  border: 1px solid var(--accent-confirm);
}

.sit-bubble pre,
.sit-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 4px;
}

.sit-bubble pre {
  padding: 10px;
  margin: 8px 0;
  overflow-x: auto;
}

.turn-receipt-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  display: inline-block;
  margin-top: 6px;
}

.sit-floor {
  padding: 14px var(--col-r) 14px var(--col-l);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.model-knobs {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-primary);
}

.model-knobs input {
  width: 72px;
  font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 4px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--ink-primary);
}

.model-knobs input[type="password"] { width: min(220px, 100%); }

.knob-note {
  margin: 0;
  flex-basis: 100%;
  color: var(--ink-muted);
}

.sit-composer {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 14px;
  box-shadow: var(--shadow-sm);
}

.sit-composer:focus-within {
  border-color: var(--accent-confirm);
  box-shadow: 0 0 0 1px var(--accent-confirm);
}

.sit-composer input,
.sit-composer input:focus,
.sit-composer input:focus-visible {
  width: 100%;
  border: none;
  border-radius: 0;
  background: transparent;
  outline: none;
  box-shadow: none;
  transition: none;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--ink-primary);
}

.btn-send {
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--bg-card);
  color: #1D4AFF;
  border: 1px solid #1D4AFF;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-send[hidden],
[hidden] {
  display: none !important;
}

.btn-send:hover {
  opacity: 0.9;
}

.telemetry-deck {
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.deck-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.deck-card-header {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.presence-spec-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.presence-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border-radius: 6px;
  font-size: 12px;
}

.presence-label {
  color: var(--ink-secondary);
}

.presence-val {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-primary);
}

.telemetry-metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-box {
  background: var(--bg-subtle);
  padding: 10px;
  border-radius: 8px;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-primary);
}

.metric-label {
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.spine-feed-box {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-secondary);
  line-height: 1.5;
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg-subtle);
  padding: 10px;
  border-radius: 8px;
}

.spine-entry {
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.spine-ts { color: #1D4AFF; font-weight: 600; }

@media (max-width: 1024px) {
  .workstation-body {
    grid-template-columns: 240px minmax(0, 1fr);
  }
  .telemetry-deck {
    display: none;
  }
}

#now-face {
  display: inline-flex;
  align-items: center;
  color: #0a0a0f;
}

.wave-line {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: #1D4AFF;
  margin-top: 6px;
}

#spine-feed {
  margin: 0 var(--col-r) 10px var(--col-l);
}

#spine-feed:empty {
  display: none;
}

#alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 var(--col-r) 0 var(--col-l);
}

#alerts:empty {
  display: none;
}

.toast {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  color: #0a0a0f;
  border: 1px solid #e8e8ed;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-icon {
  display: inline-flex;
  align-items: center;
  color: #0a0a0f;
  flex-shrink: 0;
}

.toast-error,
.toast-offline {
  background: var(--bg-card);
  color: #0a0a0f;
  border-color: #0a0a0f;
}

.toast-approval,
.toast-info {
  background: var(--bg-card);
  color: #0a0a0f;
  border-color: #1D4AFF;
}

.toast-approval .toast-icon,
.toast-info .toast-icon {
  color: #1D4AFF;
}

.btn-confirm {
  background: var(--bg-card);
  color: #1D4AFF;
  border: 2px solid #1D4AFF;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.desk-state {
  background: var(--bg-card);
  border: 1px solid #e8e8ed;
  border-radius: 12px;
  padding: 16px 18px;
}

.desk-state-icon {
  display: inline-flex;
  align-items: center;
  color: #1D4AFF;
  margin-bottom: 8px;
}

.desk-state-error .desk-state-icon {
  color: #0a0a0f;
}

.desk-state-title {
  font-size: 14px;
  font-weight: 700;
  color: #0a0a0f;
  margin-bottom: 4px;
}

.desk-state-body {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.5;
}

.desk-state-error .desk-state-title {
  color: #1D4AFF;
}

.desk-state-loading .desk-state-title {
  color: #1D4AFF;
}

@media (prefers-reduced-motion: reduce) {
  .desk-state,
  .toast,
  .btn-confirm {
    animation: none;
    transition: none;
  }
}

body:has(> .th-badge) .stage {
  --col-r: 300px;
}

:focus-visible {
  transition: none;
}

@media (max-width: 1000px) {
  body:has(> .th-badge) .stage {
    --col-r: 24px;
  }
  body:has(> .th-badge) .sit-floor {
    padding-bottom: 76px;
  }
}

@media (max-width: 900px) {
  .tm-status .morph-chip {
    display: none;
  }
}

@media (max-width: 640px) {
  .stage,
  body:has(> .th-badge) .stage {
    --col-l: 12px;
    --col-r: 12px;
  }
  body:has(> .th-badge) .sit-floor {
    padding-bottom: 88px;
  }
  .workstation-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .rail {
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid #e8e8ed;
    padding: 8px 12px;
    overflow-x: auto;
  }
  .rail-label {
    display: none;
  }
  .seat-list {
    flex-direction: row;
    gap: 4px;
  }
  .seat-list button {
    width: auto;
    padding: 8px 10px;
  }
  .mission-banner-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .sit-floor {
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

@media (max-height: 760px), (max-width: 640px) {
  .flubber-stage-card {
    min-height: 96px;
  }
}

@media (max-height: 700px) {
  .sit-turns {
    max-height: min(220px, 34vh);
  }
  .spine-feed-box {
    padding: 6px 10px;
  }
  .spine-feed-box .spine-entry {
    margin: 0;
    padding: 0;
    border: 0;
  }
  .spine-feed-box .spine-entry + .spine-entry {
    display: none;
  }
}

@media (max-width: 400px) {
  .mission-banner-card {
    padding: 6px 12px;
    gap: 2px;
  }
  .flubber-stage-card {
    min-height: 76px;
  }
  .model-knobs {
    gap: 4px;
  }
  .knob-note {
    font-size: 11.5px;
    line-height: 1.1;
  }
  .sit-floor {
    gap: 8px;
  }
  .sit-composer {
    padding: 8px 12px;
  }
  #send span {
    display: none;
  }
  #send {
    padding: 8px 12px;
  }
}

/* Tone bar & toggle */
.tone-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}
.tone-toggle {
  display: inline-flex;
  background: var(--bg-subtle);
  border-radius: 999px;
  padding: 2px;
  border: 1px solid var(--border-subtle);
}
.tone-btn {
  border: none;
  background: transparent;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.tone-btn:hover {
  color: var(--ink-primary);
}
.tone-btn.active {
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  font-weight: 600;
}

/* Thought cloud pill: 60% transparent -> 100% on hover */
.thought-cloud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: color-mix(in srgb, var(--bg-surface) 85%, transparent);
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-secondary);
  opacity: 0.6;
  cursor: pointer;
  margin-top: 6px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.thought-cloud-pill:hover {
  opacity: 1.0;
  transform: translateY(-1px) scale(1.02);
  color: var(--ink-primary);
  border-color: var(--ink-secondary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.thought-cloud-icon {
  width: 14px;
  height: 14px;
}

/* Magic Thought Window: Apple-level animation expansion */
.magic-thought-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: magicFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.magic-thought-overlay[hidden] {
  display: none !important;
}
.magic-thought-modal {
  width: min(640px, 92vw);
  max-height: 80vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: magicScaleUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
.magic-thought-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
}
.magic-thought-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-primary);
}
.magic-close-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-secondary);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: all 0.15s ease;
}
.magic-close-btn:hover {
  background: rgba(0,0,0,0.06);
  color: var(--ink-primary);
}
.magic-thought-stream {
  padding: 18px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-primary);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-ground);
  max-height: 60vh;
}

@keyframes magicFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes magicScaleUp {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

