:root {
  --bg: #0e1018;
  --bg-deep: #0a0c12;
  --panel: #1a1e2b;
  --panel-2: #232839;
  --panel-3: #30374c;
  --text: #f6f4ec;
  --muted: #99a3b8;
  --muted-2: #6f7890;
  --mint: #7de8db;
  --mint-soft: rgba(125, 232, 219, 0.14);
  --lilac: #b299ff;
  --lilac-soft: rgba(178, 153, 255, 0.14);
  --amber: #ffc76b;
  --amber-soft: rgba(255, 199, 107, 0.14);
  --green: #91e08c;
  --line: rgba(153, 163, 184, 0.18);
  --line-strong: rgba(153, 163, 184, 0.3);
  --radius: 14px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 74% -10%, rgba(178, 153, 255, 0.09), transparent 27rem),
    radial-gradient(circle at 5% 24%, rgba(125, 232, 219, 0.05), transparent 24rem),
    var(--bg);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.42; }

a { color: inherit; }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -5rem;
  z-index: 10;
  padding: 0.7rem 1rem;
  border-radius: 0.5rem;
  color: var(--bg);
  background: var(--mint);
}

.skip-link:focus { top: 1rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-shell {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 30px;
}

.site-header,
.site-footer,
.header-actions,
.brand,
.panel-heading,
.composer,
.suggestions,
.meter-heading,
.subheading,
.state-actions,
.hero-route,
.status-badge,
.live-label,
.phase-pill,
.trace-tick {
  display: flex;
  align-items: center;
}

.site-header {
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 48px;
  margin-bottom: 28px;
}

.brand {
  gap: 0.75rem;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--mint);
  border-radius: 50%;
  color: var(--mint);
  font-size: 1.5rem;
  line-height: 1;
  box-shadow: 0 0 0 5px rgba(125, 232, 219, 0.05);
}

.brand-name,
.brand-kicker { display: block; }

.brand-name {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 760;
  letter-spacing: 0.16em;
}

.brand-kicker {
  margin-top: 0.19rem;
  color: var(--muted-2);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
}

.header-actions { gap: 0.75rem; }

.status-badge,
.live-label,
.phase-pill,
.trace-tick {
  gap: 0.42rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.63rem;
  font-weight: 760;
  letter-spacing: 0.12em;
  line-height: 1;
  white-space: nowrap;
}

.status-badge { padding: 0.6rem 0.75rem; }
.status-dot, .live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 4px rgba(125, 232, 219, 0.09);
}

.button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible,
.suggestion:focus-visible,
.send-button:focus-visible,
.text-button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.button-quiet {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

.button-quiet:hover:not(:disabled),
.button-outline:hover:not(:disabled) {
  border-color: var(--mint);
  color: var(--mint);
  background: var(--mint-soft);
}

.button-outline {
  flex: 1;
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  min-height: 222px;
  margin-bottom: 16px;
  padding: 29px 32px;
  overflow: hidden;
  border: 1px solid rgba(125, 232, 219, 0.24);
  border-radius: var(--radius);
  background:
    linear-gradient(118deg, rgba(125, 232, 219, 0.07), transparent 44%),
    linear-gradient(145deg, #1e2930 0%, var(--panel) 58%, #202438 100%);
  box-shadow: var(--shadow);
}

.hero-copy { max-width: 650px; }

.eyebrow,
.section-label,
.vital-label,
.subheading,
.route-number,
.footer-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 760;
  letter-spacing: 0.14em;
}

.eyebrow { color: var(--mint); }
.eyebrow span { margin-left: 0.35rem; }

h1, h2, h3, p { margin-top: 0; }
h1 {
  max-width: 660px;
  margin: 0.9rem 0 0.82rem;
  font-size: clamp(2rem, 4vw, 3.45rem);
  font-weight: 760;
  letter-spacing: -0.055em;
  line-height: 0.98;
}

h1 em {
  color: var(--mint);
  font-style: normal;
}

.hero-lede {
  max-width: 550px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.hero-route {
  align-self: center;
  gap: 0.8rem;
  min-width: 380px;
  padding-top: 0.3rem;
}

.route-step {
  display: grid;
  gap: 0.35rem;
  min-width: 86px;
  color: var(--muted);
  font-size: 0.72rem;
}

.route-step strong { color: var(--text); font-size: 0.8rem; }
.route-number { color: var(--mint); font-size: 0.58rem; }
.route-arrow { color: var(--muted-2); font-size: 1.2rem; }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.08fr) minmax(340px, 1.15fr) minmax(270px, 0.84fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgba(35, 40, 57, 0.6), rgba(26, 30, 43, 0.96));
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.12);
}

.conversation-panel,
.trace-panel,
.state-panel { min-height: 655px; }

.conversation-panel,
.trace-panel { display: flex; flex-direction: column; }

.panel-heading {
  justify-content: space-between;
  gap: 1rem;
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--line);
}

h2 {
  margin: 0.38rem 0 0;
  color: var(--text);
  font-size: 1.13rem;
  font-weight: 690;
  letter-spacing: -0.02em;
}

.live-label { padding: 0.43rem 0.6rem; color: var(--mint); font-size: 0.56rem; }
.trace-tick { padding: 0.42rem 0.58rem; color: var(--lilac); font-size: 0.56rem; }
.phase-pill { padding: 0.47rem 0.64rem; color: var(--green); font-size: 0.56rem; }

.conversation-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 16px;
  min-height: 410px;
  padding: 22px;
  overflow-y: auto;
}

.conversation-empty {
  display: grid;
  flex: 1;
  min-height: 270px;
  place-items: center;
  padding: 1rem;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}

.conversation-empty strong { display: block; margin-bottom: 0.35rem; color: var(--text); }
.conversation-empty p { max-width: 230px; margin-bottom: 0; font-size: 0.76rem; line-height: 1.5; }

.message {
  max-width: 90%;
  animation: rise-in 220ms ease both;
}

.message-user { align-self: flex-end; }
.message-organism { align-self: flex-start; }

.message-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  color: var(--muted-2);
  font-size: 0.6rem;
  font-weight: 750;
  letter-spacing: 0.1em;
}

.message-user .message-meta { justify-content: flex-end; }
.message-kind { color: var(--mint); }
.message-user .message-kind { color: var(--lilac); }

.message-bubble {
  padding: 0.72rem 0.82rem;
  border: 1px solid var(--line);
  border-radius: 11px 11px 11px 3px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.45;
}

.message-user .message-bubble {
  border-color: rgba(178, 153, 255, 0.28);
  border-radius: 11px 11px 3px 11px;
  background: var(--lilac-soft);
}

.message-token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  margin-top: 0.55rem;
}

.token-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.29rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.64rem;
}

.token-chip-known { border-color: rgba(145, 224, 140, 0.25); color: var(--green); }
.token-chip-novel { border-color: rgba(255, 199, 107, 0.27); color: var(--amber); }
.token-chip-uncertain { border-color: rgba(178, 153, 255, 0.25); color: var(--lilac); }

.composer-wrap { padding: 0 18px 18px; }

.composer {
  gap: 0.5rem;
  padding: 0.38rem 0.42rem 0.38rem 0.78rem;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--bg-deep);
}

.composer:focus-within { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(125, 232, 219, 0.08); }

.composer input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
}

.composer input::placeholder { color: var(--muted-2); }
.send-button {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--mint);
  color: var(--bg-deep);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  transition: transform 160ms ease, background 160ms ease;
}
.send-button:hover { transform: translateY(-1px); background: #a1f5eb; }

.suggestions { flex-wrap: wrap; gap: 0.4rem; padding: 0.7rem 0.1rem 0; }
.suggestion {
  border: 0;
  border-radius: 5px;
  padding: 0.4rem 0.52rem;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.64rem;
  transition: color 160ms ease, background 160ms ease;
}
.suggestion:hover { background: var(--mint-soft); color: var(--mint); }

.trace-list {
  display: grid;
  gap: 9px;
  padding: 22px;
}

.trace-step {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.78rem 0.72rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(14, 16, 24, 0.24);
  animation: rise-in 220ms ease both;
}

.trace-index {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 7px;
  background: var(--panel-3);
  color: var(--mint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
}

.trace-step:nth-child(2) .trace-index { color: var(--lilac); }
.trace-step:nth-child(3) .trace-index { color: var(--amber); }
.trace-step:nth-child(4) .trace-index { color: var(--green); }
.trace-name { color: var(--text); font-size: 0.7rem; font-weight: 760; letter-spacing: 0.08em; }
.trace-detail { margin-top: 0.22rem; color: var(--muted); font-size: 0.67rem; line-height: 1.35; }
.trace-value { color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.64rem; text-align: right; }
.trace-step:first-child .trace-value { color: var(--mint); }
.trace-step:nth-child(2) .trace-value { color: var(--lilac); }
.trace-step:nth-child(3) .trace-value { color: var(--amber); }
.trace-step:nth-child(4) .trace-value { color: var(--green); }

.tutor-card {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 0.85rem;
  margin: auto 22px 22px;
  padding: 17px;
  border: 1px solid rgba(178, 153, 255, 0.28);
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(178, 153, 255, 0.12), rgba(125, 232, 219, 0.04));
}

.tutor-icon {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid var(--lilac);
  border-radius: 8px;
  color: var(--lilac);
  font-size: 1rem;
}

.tutor-label { color: var(--lilac); }
.tutor-card h3 { margin: 0.38rem 0 0.45rem; font-size: 0.8rem; line-height: 1.25; }
.tutor-card p { margin-bottom: 0; color: var(--muted); font-size: 0.7rem; line-height: 1.5; }
.text-button {
  margin-top: 0.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--lilac);
  font-size: 0.66rem;
  font-weight: 700;
}
.text-button span { margin-left: 0.25rem; }
.tutor-detail { margin-top: 0.7rem !important; color: var(--text) !important; }

.state-panel { padding-bottom: 18px; }
.state-panel .panel-heading { margin: 0 -1px; }

.vitals-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  margin: 0 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
}

.vital { min-height: 73px; padding: 13px 11px; background: rgba(14, 16, 24, 0.3); }
.vital-label { display: block; color: var(--muted-2); font-size: 0.55rem; }
.vital strong { display: block; margin-top: 0.48rem; color: var(--text); font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.75rem; font-weight: 650; }

.meter-stack { display: grid; gap: 17px; margin: 25px 22px 0; }
.meter-heading { justify-content: space-between; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.61rem; font-weight: 760; letter-spacing: 0.1em; }
.meter-heading output { color: var(--text); font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.67rem; letter-spacing: 0; }
.meter { height: 6px; overflow: hidden; border-radius: 999px; background: var(--panel-3); }
.meter-fill { display: block; height: 100%; border-radius: inherit; transition: width 300ms ease; }
.meter-mint { background: var(--mint); }
.meter-lilac { background: var(--lilac); }

.lexicon-block { margin: 27px 22px 0; }
.subheading { justify-content: space-between; color: var(--muted); font-size: 0.61rem; font-weight: 760; letter-spacing: 0.1em; }
.subheading span:last-child { color: var(--lilac); font-family: "SFMono-Regular", Consolas, monospace; }
.hypothesis-list { display: grid; gap: 8px; margin-top: 11px; }
.hypothesis-item { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.58rem 0.65rem; border: 1px solid var(--line); border-radius: 7px; background: rgba(14, 16, 24, 0.22); }
.hypothesis-token { color: var(--text); font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.68rem; }
.hypothesis-concept { overflow: hidden; color: var(--muted); font-size: 0.65rem; text-overflow: ellipsis; white-space: nowrap; }
.hypothesis-confidence { color: var(--green); font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.61rem; }
.hypothesis-empty { padding: 0.72rem; border: 1px dashed var(--line); border-radius: 7px; color: var(--muted-2); font-size: 0.67rem; line-height: 1.4; }

.state-actions { gap: 8px; margin: 24px 22px 0; }
.local-note { margin: 20px 22px 0; color: var(--muted-2); font-size: 0.62rem; line-height: 1.45; }
.local-note span { margin-right: 0.25rem; color: var(--mint); }

.site-footer {
  justify-content: space-between;
  gap: 1rem;
  margin-top: 24px;
  padding: 0 4px;
  color: var(--muted-2);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--mint); }
.site-footer a span { margin-left: 0.25rem; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  max-width: min(340px, calc(100vw - 44px));
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.72rem;
  box-shadow: var(--shadow);
  animation: rise-in 180ms ease both;
}

@keyframes rise-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1120px) {
  .hero-card { flex-direction: column; min-height: auto; }
  .hero-route { align-self: flex-start; }
  .workspace-grid { grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr); }
  .state-panel { grid-column: 1 / -1; min-height: auto; }
  .state-panel .panel-heading { border-bottom: 1px solid var(--line); }
  .state-panel { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .state-panel .panel-heading { grid-column: 1 / -1; }
  .state-panel .vitals-grid { margin-top: 22px; }
  .state-panel .meter-stack, .state-panel .lexicon-block { margin-top: 22px; }
  .state-panel .state-actions, .state-panel .local-note { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .page-shell { width: min(100% - 28px, 620px); padding-top: 18px; }
  .site-header { align-items: flex-start; margin-bottom: 20px; }
  .header-actions { flex-direction: column-reverse; align-items: flex-end; gap: 0.5rem; }
  .status-badge { font-size: 0.55rem; }
  .button-quiet { padding: 0.4rem 0; border-color: transparent; }
  .hero-card { gap: 1.4rem; padding: 24px 20px; }
  h1 { font-size: clamp(2rem, 11vw, 3rem); }
  .hero-lede { font-size: 0.82rem; }
  .hero-route { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; width: 100%; min-width: 0; gap: 0.45rem; }
  .route-step { min-width: 0; font-size: 0.63rem; }
  .route-step strong { font-size: 0.7rem; }
  .route-arrow { font-size: 0.95rem; }
  .workspace-grid { display: flex; flex-direction: column; gap: 12px; }
  .conversation-panel, .trace-panel, .state-panel { width: 100%; min-height: auto; }
  .conversation-log { min-height: 330px; max-height: 500px; }
  .state-panel { display: block; }
  .state-panel .panel-heading { margin: 0; }
  .state-panel .vitals-grid { margin-top: 22px; }
  .state-panel .meter-stack, .state-panel .lexicon-block { margin-top: 25px; }
  .state-panel .state-actions, .state-panel .local-note { grid-column: auto; }
  .site-footer { align-items: flex-start; flex-direction: column; gap: 0.6rem; line-height: 1.4; }
}

@media (max-width: 420px) {
  .brand-kicker { display: none; }
  .hero-route { gap: 0.25rem; }
  .route-step strong { font-size: 0.64rem; }
  .panel-heading { padding: 18px 16px 15px; }
  .conversation-log, .trace-list { padding: 16px; }
  .composer-wrap { padding: 0 12px 14px; }
  .tutor-card { margin: auto 16px 16px; }
  .vitals-grid, .meter-stack, .lexicon-block { margin-left: 16px; margin-right: 16px; }
  .state-actions, .local-note { margin-left: 16px; margin-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
