:root {
  --void: #030304;
  --ink: #0a0a0b;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f2ed;
  --muted: #7c7a76;
  --pink: #ff6b9d;
  --green: #3ddc84;
  --red: #ff5c5c;
  --amber: #f5b14a;
  --cyan: #7fd7ff;
  --font-display: "Unbounded", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", monospace;
  --sidebar-w: clamp(260px, 28vw, 320px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--void);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.01em;
}

body {
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(1rem, 2.2vw, 1.75rem) clamp(1rem, 2.5vw, 2rem);
  max-width: 1600px;
  margin: 0 auto;
}

/* ---- Themes (ambient) ---- */
body.theme-idle {
  --accent-glow: rgba(255, 107, 157, 0.12);
}
body.theme-processing {
  --accent-glow: rgba(127, 215, 255, 0.14);
}
body.theme-approved {
  --accent-glow: rgba(61, 220, 132, 0.12);
}
body.theme-blocked {
  --accent-glow: rgba(255, 92, 92, 0.14);
}
body.theme-pending_human {
  --accent-glow: rgba(245, 177, 74, 0.12);
}

body::before {
  content: "";
  position: fixed;
  inset: -20%;
  background: radial-gradient(ellipse 50% 42% at 58% 38%, var(--accent-glow), transparent 72%);
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.8s ease;
}

/* ---- Top bar ---- */
.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand-block {
  min-width: 0;
}

.logo {
  margin: 0;
  line-height: 1;
}

.logo-inner {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 3.2vw, 2.35rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  display: inline-block;
  color: #f6f3ee;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.07);
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .logo-inner {
    background: linear-gradient(102deg, #fff 0%, #e8e4dc 48%, #b8b3a8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: none;
  }
}

.tagline {
  margin: 0.5rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  max-width: 32rem;
  line-height: 1.5;
}

.ws-pill {
  margin: 0.35rem 0 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  flex-shrink: 0;
}

.ws-tick {
  font-variant-numeric: tabular-nums;
  color: #9a9894;
}

.ws-sep {
  opacity: 0.35;
  font-weight: 300;
}

.ws-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

body.ws-live .ws-dot {
  background: var(--green);
  box-shadow: 0 0 12px rgba(61, 220, 132, 0.55);
  animation: ws-pulse 2s ease-in-out infinite;
}

@keyframes ws-pulse {
  50% {
    opacity: 0.45;
  }
}

/* ---- Body: sidebar + main ---- */
.body-grid {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 7.5rem);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 1.25rem 1.25rem 1.25rem 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 0;
  flex: 1;
}

.clock-block {
  flex-shrink: 0;
}

.clock-line {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.2rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: 0.04em;
}

.tz {
  margin: 0.2rem 0 0;
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-transform: uppercase;
}

.meta-grid {
  margin: 0;
  display: grid;
  gap: 0.5rem;
  flex-shrink: 0;
}

.meta-grid > div {
  display: grid;
  gap: 0.08rem;
}

.meta-grid dt {
  margin: 0;
  font-size: 0.52rem;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.meta-grid dd {
  margin: 0;
  font-size: 0.72rem;
  color: #d8d4cc;
  word-break: break-all;
}

.scenario-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.panel-label {
  margin: 0 0 0.45rem;
  font-size: 0.52rem;
  letter-spacing: 0.16em;
  color: var(--muted);
  flex-shrink: 0;
}

.scenario-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow-y: auto;
  flex: 1;
  padding-right: 0.25rem;
}

.scenario-list button {
  width: 100%;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.scenario-list button:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.08);
}

.scenario-list button[aria-selected="true"] {
  background: var(--text);
  color: var(--void);
  border-color: var(--text);
}

.scenario-list button[aria-selected="true"] .scenario-title {
  color: rgba(10, 10, 11, 0.72);
}

.scenario-id {
  display: block;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.scenario-title {
  display: block;
  font-size: 0.62rem;
  opacity: 0.8;
  margin-top: 0.12rem;
  line-height: 1.3;
}

/* ---- Main hero ---- */
.main-area {
  position: relative;
  min-width: 0;
  padding: 0.75rem 0 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
}

.main-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.5rem 6.5rem 1.25rem 0.5rem;
  min-height: 0;
}

.visual-shell {
  width: min(100%, 640px);
  height: min(42vh, 380px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.crystal-label {
  margin: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.48rem;
  letter-spacing: 0.32em;
  color: var(--muted);
  text-transform: uppercase;
  transition: color 0.65s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.55s ease;
}

body[data-status="processing"] .crystal-label {
  color: rgba(127, 215, 255, 0.55);
}
body[data-status="approved"] .crystal-label {
  color: rgba(61, 220, 132, 0.45);
}
body[data-status="blocked"] .crystal-label {
  color: rgba(255, 92, 92, 0.42);
}
body[data-status="pending_human"] .crystal-label {
  color: rgba(245, 177, 74, 0.48);
}

.crystal-zh {
  letter-spacing: 0.12em;
  font-size: 0.5rem;
  opacity: 0.85;
}

#core-canvas {
  display: block;
  max-width: 100%;
  filter: drop-shadow(0 24px 56px rgba(0, 0, 0, 0.5));
  /* 柔化画布边缘与底部，避免 glitch 全幅扫描线贴齐矩形产生「红框电视」感 */
  -webkit-mask-image: radial-gradient(
    ellipse 108% 92% at 50% 42%,
    #000 0%,
    #000 36%,
    rgba(0, 0, 0, 0.82) 55%,
    rgba(0, 0, 0, 0.35) 74%,
    rgba(0, 0, 0, 0.08) 88%,
    transparent 100%
  );
  mask-image: radial-gradient(
    ellipse 108% 92% at 50% 42%,
    #000 0%,
    #000 36%,
    rgba(0, 0, 0, 0.82) 55%,
    rgba(0, 0, 0, 0.35) 74%,
    rgba(0, 0, 0, 0.08) 88%,
    transparent 100%
  );
}

.status-column {
  text-align: center;
  max-width: min(92vw, 40rem);
}

.eyebrow {
  margin: 0;
  font-size: 0.6rem;
  letter-spacing: 0.32em;
  color: var(--muted);
  transition: color 0.65s cubic-bezier(0.22, 1, 0.36, 1), letter-spacing 0.55s ease;
}

body[data-status="processing"] .eyebrow {
  color: rgba(127, 215, 255, 0.42);
}
body[data-status="approved"] .eyebrow {
  color: rgba(61, 220, 132, 0.38);
}
body[data-status="blocked"] .eyebrow {
  color: rgba(255, 92, 92, 0.35);
}
body[data-status="pending_human"] .eyebrow {
  color: rgba(245, 177, 74, 0.4);
}

.status-hero {
  transition: opacity 0.42s cubic-bezier(0.22, 1, 0.36, 1), filter 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, filter, transform;
}

.status-hero.is-text-fading {
  opacity: 0;
  transform: translateY(5px) scale(0.992);
  filter: blur(4px);
}

@media (prefers-reduced-motion: reduce) {
  .status-hero {
    transition-duration: 0.01ms;
  }
  .status-hero.is-text-fading {
    filter: none;
    transform: none;
  }
}

.status-word {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 7.5vw, 4.5rem);
  line-height: 0.98;
  margin: 0.15rem 0 0;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: color 0.72s cubic-bezier(0.22, 1, 0.36, 1), text-shadow 0.72s ease, letter-spacing 0.55s ease;
}

body[data-status="idle"] .status-word {
  color: #c8c4bc;
}
body[data-status="processing"] .status-word {
  color: var(--cyan);
}
body[data-status="approved"] .status-word {
  color: var(--green);
  text-shadow: 0 0 40px rgba(61, 220, 132, 0.32);
}
body[data-status="blocked"] .status-word {
  color: var(--red);
  text-shadow: 0 0 40px rgba(255, 92, 92, 0.32);
}
body[data-status="pending_human"] .status-word {
  color: var(--amber);
  text-shadow: 0 0 36px rgba(245, 177, 74, 0.28);
}

.status-sub {
  margin: 0.55rem 0 0;
  min-height: 2.6em;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  line-height: 1.45;
  opacity: 0.92;
  transition: color 0.65s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease;
}

.telemetry-strip {
  width: 100%;
  max-width: 38rem;
  margin-top: 0.65rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem 1rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 0.55s ease, background 0.55s ease;
}

.tel-cell {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.tel-key {
  font-size: 0.5rem;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.tel-val {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: #e4e0d8;
  word-break: break-all;
  line-height: 1.35;
}

/* 贴视口右下角（固定定位），留安全边距避免贴死边缘 */
.controls-rail {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
  z-index: 20;
  padding: 0;
  margin: 0;
}

.btn {
  font-family: var(--font-mono);
  cursor: pointer;
  border: none;
  background: none;
  padding: 0.35rem 0;
}

.btn.exec {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.62rem;
  letter-spacing: 0.32em;
  padding: 0.68rem 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: var(--text);
  transition: background 0.25s, border-color 0.25s;
}

.btn.exec:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.38);
}

.btn.exec:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn.text {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.56rem;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.btn.text:hover {
  color: var(--text);
}

.btn.icon {
  font-size: 1.35rem;
  line-height: 1;
  padding: 0.15rem 0.5rem;
  color: var(--muted);
}

.btn.icon:hover {
  color: var(--text);
}

@media (max-width: 960px) {
  .body-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 1rem 0;
    max-height: 42vh;
  }

  .main-area {
    padding: 1rem 0 0;
  }

  .main-center {
    padding: 1rem 0 5.5rem;
  }

  .telemetry-strip {
    grid-template-columns: 1fr;
    max-width: none;
  }

  .controls-rail {
    right: max(0.85rem, env(safe-area-inset-right, 0px));
    bottom: max(0.85rem, env(safe-area-inset-bottom, 0px));
    background: rgba(3, 3, 4, 0.82);
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 2px;
    backdrop-filter: blur(10px);
  }
}

/* ---- Drawer ---- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  backdrop-filter: blur(4px);
}

.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(70vh, 560px);
  background: #0b0b0c;
  border-top: 1px solid var(--line);
  z-index: 50;
  transform: translateY(105%);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateY(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.drawer-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
}

.drawer-body {
  padding: 0.85rem 1.1rem 1.25rem;
  overflow: auto;
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 720px) {
  .drawer-body {
    grid-template-columns: 1fr;
  }
}

.drawer-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 500;
}

.trace {
  margin: 0;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.68rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 38vh;
  overflow: auto;
  color: #c5c2bb;
}
