:root {
  color-scheme: dark;
  --bg: #030303;
  --panel: rgba(11, 11, 11, 0.88);
  --panel-strong: rgba(18, 18, 18, 0.96);
  --line: rgba(214, 214, 208, 0.18);
  --line-strong: rgba(236, 236, 230, 0.42);
  --text: #ededeb;
  --muted: #bdbdb7;
  --faint: #898984;
  --aqua: #d8d8d2;
  --danger: #ff9f9f;
  --accent: #8393b0;
  --radius: 8px;
  font-family: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 400;
}

* {
  box-sizing: border-box;
}

@media (pointer: fine) {
  *,
  *::before,
  *::after {
    cursor: none !important;
  }
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 22% 18%, rgba(224, 224, 216, 0.08), transparent 32%),
    linear-gradient(135deg, #010101 0%, var(--bg) 48%, #0a0a0a 100%);
  color: var(--text);
  cursor: none;
  overflow: hidden;
}

/* film-grain overlay over the whole page for a printed-paper feel */
body::before {
  position: fixed;
  inset: 0;
  z-index: 999;
  content: "";
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
  opacity: 0.07;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr);
  grid-template-rows: 100%;
  height: 100%;
}

.app-shell.detail-open {
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr) minmax(300px, 380px);
}

.control-panel,
.detail-panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  min-height: 0;
  padding: 22px;
  overflow-y: auto;
  background: var(--panel);
  border-color: var(--line);
  backdrop-filter: blur(16px);
}

.control-panel {
  border-right: 1px solid var(--line);
  box-shadow: 6px 0 22px rgba(0, 0, 0, 0.38);
}

.detail-panel {
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 22px rgba(0, 0, 0, 0.38);
  color: var(--text);
  --muted: #d1d1ca;
  --faint: #a8a8a1;
  --text: #f4f4f0;
}

.detail-panel[hidden] {
  display: none;
}

.brand-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 12px;
  align-items: start;
}

.theme-toggle {
  align-self: start;
  padding: 5px 9px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.brand-mark {
  position: relative;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 50%;
  background:
    radial-gradient(circle at 31% 26%, rgba(255, 255, 255, 0.98) 0 7%, transparent 18%),
    radial-gradient(circle at 38% 34%, #f8f8f2 0%, #c8c8c0 30%, #636360 62%, #151515 100%);
  box-shadow:
    0 0 12px rgba(232, 232, 224, 0.48),
    0 0 28px rgba(160, 160, 154, 0.2);
  animation: brandPulse 2.8s ease-in-out infinite;
}

.brand-mark::after {
  position: absolute;
  inset: 2px 4px auto auto;
  width: 7px;
  height: 4px;
  content: "";
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  filter: blur(1px);
  transform: rotate(-24deg);
}

@keyframes brandPulse {
  0%,
  100% {
    transform: scale(0.94);
    box-shadow:
      0 0 10px rgba(232, 232, 224, 0.36),
      0 0 24px rgba(160, 160, 154, 0.16);
  }
  50% {
    transform: scale(1.08);
    box-shadow:
      0 0 16px rgba(246, 246, 240, 0.62),
      0 0 38px rgba(188, 188, 180, 0.28);
  }
}

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

h1 {
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0;
}

.brand-row p,
.empty-state,
.status-line {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.input-stack {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  padding: 11px 12px;
  color: var(--text);
  background: rgba(1, 3, 3, 0.66);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.42);
}

textarea:focus {
  border-color: var(--aqua);
  box-shadow: 0 0 0 1px rgba(216, 216, 210, 0.18);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  color: #050505;
  background: var(--aqua);
  border: 0;
  border-radius: var(--radius);
  font-weight: 400;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

.primary-button:disabled {
  opacity: 0.55;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background: #050505;
  border-radius: 50%;
}

.status-line {
  min-height: 20px;
}

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

.canvas-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(232, 232, 226, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 232, 226, 0.06) 1px, transparent 1px);
  background-size: 44px 44px;
}

/* vignette so the stage reads like an exposed photographic plate */
.canvas-stage::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  content: "";
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.42) 100%);
}

#cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  width: 20px;
  height: 20px;
  pointer-events: none;
  background:
    radial-gradient(circle at 38% 34%, rgba(255, 255, 255, 0.95) 0%, rgba(214, 214, 208, 0.66) 34%, rgba(120, 120, 116, 0.2) 62%, transparent 74%);
  border-radius: 50%;
  box-shadow:
    0 0 10px rgba(230, 230, 224, 0.5),
    0 0 24px rgba(190, 190, 184, 0.22);
  mix-blend-mode: screen;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: width 0.12s ease, height 0.12s ease, opacity 0.18s ease;
}

#cursor.is-visible {
  opacity: 1;
}

#cursor.big {
  width: 30px;
  height: 30px;
}

#graph-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.horizon-axis {
  position: absolute;
  right: 28px;
  bottom: 24px;
  left: 28px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  color: var(--faint);
  font-size: 11px;
  pointer-events: none;
}

.horizon-axis span {
  border-top: 1px solid rgba(230, 244, 236, 0.16);
  padding-top: 8px;
}

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

.result-block {
  display: grid;
  gap: 9px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.result-block h2 {
  font-size: 14px;
  font-weight: 400;
}

.result-block p,
.result-block li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.result-block ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.selection-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.selection-header {
  display: grid;
  gap: 4px;
}

.selection-header span {
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.selection-header h2 {
  font-size: 15px;
  font-weight: 400;
}

.selection-panel p,
.selection-panel li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.metadata-line {
  color: var(--faint) !important;
  font-size: 11px !important;
  text-transform: uppercase;
}

.mini-list {
  display: grid;
  gap: 5px;
}

.mini-list h3 {
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
}

.mini-list ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 16px;
}

.scenario-list {
  display: grid;
  gap: 6px;
}

.scenario-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  color: var(--text);
  text-align: left;
  background: rgba(1, 3, 3, 0.5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.scenario-row:hover {
  border-color: var(--line-strong);
}

.scenario-row.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(131, 147, 176, 0.35);
}

.scenario-row span {
  font-size: 13px;
  font-weight: 400;
}

.scenario-row small {
  color: var(--faint);
  font-size: 10px;
  text-transform: uppercase;
  white-space: nowrap;
}

.chat-log {
  display: grid;
  max-height: 260px;
  gap: 8px;
  overflow-y: auto;
}

.chat-message {
  max-width: 92%;
  padding: 9px 10px;
  color: #d8d8d2;
  background: rgba(1, 1, 1, 0.46);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.45;
}

.chat-message.user {
  justify-self: end;
  color: #f4f4f0;
  background: rgba(42, 42, 40, 0.62);
  border-color: rgba(236, 236, 230, 0.28);
}

.chat-message.assistant.pending {
  color: #adada6;
}

.chat-message.error {
  color: var(--danger);
}

.chat-form {
  display: grid;
  gap: 8px;
}

.chat-form textarea {
  min-height: 76px;
  max-height: 120px;
}

.detail-panel textarea::placeholder {
  color: #9f9f98;
}

.chat-form button {
  min-height: 38px;
}

.trace-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trace-chip {
  padding: 5px 7px;
  color: var(--muted);
  background: rgba(1, 1, 1, 0.46);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
}

.mobile-results {
  display: none;
}

@media (max-width: 1040px) {
  body {
    overflow: auto;
  }

  .app-shell,
  .app-shell.detail-open {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100%;
  }

  .canvas-stage {
    min-height: 58vh;
    order: -1;
  }

  .control-panel,
  .detail-panel {
    border: 0;
    border-top: 1px solid var(--line);
  }

  #cursor {
    display: none;
  }
}

/* lightweight mobile version: the canvas is replaced by a structured list */
@media (max-width: 760px) {
  .canvas-stage {
    display: none;
  }

  .control-panel,
  .detail-panel {
    backdrop-filter: none;
    box-shadow: none;
  }

  .mobile-results:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 22px;
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
}

@media (pointer: coarse) {
  body,
  button,
  textarea {
    cursor: auto;
  }

  #cursor {
    display: none;
  }
}

/* ---------- light theme ---------- */

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e6e2d8;
  --panel: rgba(236, 232, 223, 0.88);
  --panel-strong: rgba(242, 238, 230, 0.96);
  --line: rgba(41, 41, 36, 0.18);
  --line-strong: rgba(25, 25, 21, 0.42);
  --text: #1d1d18;
  --muted: #4e4e47;
  --faint: #7a7a72;
  --aqua: #2c2c27;
  --danger: #a83232;
}

:root[data-theme="light"] body::before {
  mix-blend-mode: multiply;
  opacity: 0.14;
}

:root[data-theme="light"] .canvas-stage::after {
  background: radial-gradient(ellipse at center, transparent 55%, rgba(92, 80, 58, 0.2) 100%);
}

:root[data-theme="light"] .control-panel {
  box-shadow: 6px 0 22px rgba(92, 80, 58, 0.16);
}

:root[data-theme="light"] .detail-panel {
  box-shadow: -6px 0 22px rgba(92, 80, 58, 0.16);
}

:root[data-theme="light"] .primary-button {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 2px 8px rgba(92, 80, 58, 0.28);
}

:root[data-theme="light"] body {
  background:
    radial-gradient(circle at 22% 18%, rgba(60, 60, 50, 0.06), transparent 32%),
    linear-gradient(135deg, #edeae0 0%, var(--bg) 48%, #dcd7ca 100%);
}

:root[data-theme="light"] .detail-panel {
  --muted: #45453f;
  --faint: #6e6e66;
  --text: #191914;
}

:root[data-theme="light"] .brand-mark {
  background:
    radial-gradient(circle at 31% 26%, rgba(255, 255, 255, 0.95) 0 9%, transparent 24%),
    radial-gradient(circle at 38% 34%, #a8a89e 0%, #6e6e64 28%, #3a3a33 58%, #10100c 82%, #050503 100%);
  box-shadow:
    0 1px 3px rgba(40, 36, 28, 0.4),
    0 0 14px rgba(70, 64, 52, 0.25);
  animation-name: brandPulseLight;
}

@keyframes brandPulseLight {
  0%,
  100% {
    transform: scale(0.94);
    box-shadow:
      0 0 10px rgba(40, 40, 34, 0.22),
      0 0 24px rgba(70, 70, 62, 0.12);
  }
  50% {
    transform: scale(1.08);
    box-shadow:
      0 0 16px rgba(30, 30, 26, 0.34),
      0 0 38px rgba(60, 60, 54, 0.18);
  }
}

:root[data-theme="light"] textarea {
  background: rgba(252, 250, 244, 0.6);
  box-shadow: inset 0 2px 5px rgba(92, 80, 58, 0.16);
}

:root[data-theme="light"] textarea:focus {
  box-shadow: 0 0 0 1px rgba(44, 44, 39, 0.18);
}

:root[data-theme="light"] .primary-button {
  color: #f2efe7;
}

:root[data-theme="light"] .pulse-dot {
  background: #f2efe7;
}

:root[data-theme="light"] .canvas-stage {
  background-image:
    linear-gradient(rgba(35, 35, 30, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(35, 35, 30, 0.07) 1px, transparent 1px);
}

:root[data-theme="light"] #cursor {
  background:
    radial-gradient(circle at 38% 34%, rgba(20, 20, 16, 0.9) 0%, rgba(60, 60, 52, 0.6) 34%, rgba(120, 120, 112, 0.2) 62%, transparent 74%);
  box-shadow:
    0 0 10px rgba(40, 40, 34, 0.3),
    0 0 24px rgba(70, 70, 62, 0.16);
  mix-blend-mode: multiply;
}

:root[data-theme="light"] .horizon-axis span {
  border-top-color: rgba(30, 40, 36, 0.2);
}

:root[data-theme="light"] .scenario-row {
  background: rgba(250, 248, 242, 0.55);
}

:root[data-theme="light"] .chat-message {
  color: #2a2a24;
  background: rgba(250, 248, 242, 0.6);
}

:root[data-theme="light"] .chat-message.user {
  color: #161612;
  background: rgba(215, 210, 198, 0.7);
  border-color: rgba(30, 30, 26, 0.28);
}

:root[data-theme="light"] .chat-message.assistant.pending {
  color: #6e6e66;
}

:root[data-theme="light"] .detail-panel textarea::placeholder {
  color: #83837b;
}

:root[data-theme="light"] .trace-chip {
  background: rgba(250, 248, 242, 0.5);
}
