:root {
  color-scheme: dark;
  --bg: oklch(0.11 0.035 300);
  --surface: oklch(0.16 0.045 300 / 0.9);
  --surface-solid: oklch(0.18 0.05 300);
  --surface-raised: oklch(0.22 0.065 300);
  --ink: oklch(0.95 0.018 300);
  --dim: oklch(0.73 0.04 300);
  --purple: oklch(0.7 0.25 305);
  --purple-bright: oklch(0.79 0.2 307);
  --pink: oklch(0.72 0.27 340);
  --cyan: oklch(0.82 0.15 215);
  --lime: oklch(0.87 0.2 125);
  --star: oklch(0.88 0.18 95);
  --danger: oklch(0.72 0.22 20);
  --viz-trail-full: oklch(0.11 0.035 300 / 0.24);
  --viz-trail-medium: oklch(0.11 0.035 300 / 0.14);
  --viz-trail-ambient: oklch(0.11 0.035 300 / 0.05);
  --line: oklch(0.7 0.22 305 / 0.42);
  --hairline: oklch(0.95 0.02 300 / 0.12);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --z-content: 1;
  --z-header: 2;
}

* { box-sizing: border-box; }

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

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.48 "Aptos", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { touch-action: manipulation; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }

#viz {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  background: radial-gradient(90% 80% at 15% 0%, oklch(0.25 0.12 305) 0%, transparent 58%), var(--bg);
}

.topbar {
  position: relative;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 68px;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--hairline);
  background: oklch(0.11 0.035 300 / 0.82);
  backdrop-filter: blur(12px);
}

.brand-lockup { display: flex; align-items: center; gap: 0.85rem; flex: none; }
.brand-note { color: var(--dim); font-size: 0.73rem; max-width: 9ch; line-height: 1.15; }

.logo {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  margin: 0;
  font-family: "Bahnschrift", "Arial Black", Impact, sans-serif;
  font-size: 1.55rem;
  font-style: italic;
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 1;
  transform: skewX(-3deg);
  isolation: isolate;
}

.logo::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -0.35rem;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--purple), var(--pink) 72%, transparent);
  box-shadow: 0 0 8px var(--pink);
}

.logo-edm {
  color: var(--purple-bright);
  text-shadow: 0 0 6px oklch(0.72 0.27 305 / 0.9), 0 0 18px oklch(0.63 0.3 305 / 0.5);
}
.logo-issions { color: var(--ink); text-shadow: 0 0 8px oklch(0.72 0.27 340 / 0.35); }

.modes { display: flex; gap: 0.35rem; margin-left: auto; }
.modes button {
  padding: 0.38rem 0.82rem;
  color: var(--dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.79rem;
  font-weight: 650;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease, transform 140ms var(--ease-out);
}
.modes button.active { color: var(--ink); background: oklch(0.7 0.25 305 / 0.16); border-color: var(--purple); }

.account { display: flex; align-items: center; gap: 0.7rem; }
.welcome {
  display: inline-block;
  color: var(--purple-bright);
  font-family: "Bahnschrift", "Arial Black", Impact, sans-serif;
  font-size: 0.94rem;
  font-style: italic;
  font-weight: 850;
  letter-spacing: -0.025em;
  text-shadow: 0 0 6px oklch(0.72 0.27 305 / 0.85), 0 0 12px oklch(0.72 0.27 340 / 0.4);
  transform: skewX(-3deg);
  white-space: nowrap;
}

.grid {
  position: relative;
  z-index: var(--z-content);
  display: grid;
  gap: 0.85rem;
  padding: 0.85rem 1.2rem 1.2rem;
  grid-template-columns: minmax(250px, 0.92fr) minmax(350px, 1.28fr) minmax(280px, 1fr);
  grid-template-areas: "player notes feed" "campaigns notes tasks";
}

#panel-player { grid-area: player; }
#panel-notes { grid-area: notes; max-height: calc(100vh - 86px); }
#panel-feed { grid-area: feed; }
#panel-campaigns { grid-area: campaigns; }
#panel-tasks { grid-area: tasks; }

.panel {
  min-height: 220px;
  max-height: calc((100vh - 100px) / 2);
  overflow: auto;
  padding: 0.95rem 1rem 1rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  backdrop-filter: blur(10px);
}

.panel-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.panel-title h2 { margin: 0; font-size: 1rem; font-weight: 750; letter-spacing: -0.015em; }
.panel-title span { color: var(--purple-bright); font-size: 0.73rem; }

.btn {
  min-height: 34px;
  padding: 0.38rem 0.78rem;
  color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.83rem;
  font-weight: 650;
  transition: transform 140ms var(--ease-out), border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}
.btn:active, .modes button:active, .history-row:active { transform: scale(0.97); }
.btn:disabled { cursor: not-allowed; opacity: 0.48; transform: none; }
.btn-neon { background: oklch(0.54 0.24 305); border-color: var(--purple-bright); box-shadow: 0 0 8px oklch(0.68 0.28 305 / 0.42); }
.btn-ghost { color: var(--dim); background: transparent; }
.btn-icon { min-width: 30px; min-height: 30px; padding: 0.2rem 0.4rem; color: var(--dim); background: transparent; border: 0; border-radius: 6px; cursor: pointer; font-size: 1rem; }
.starred { color: var(--star); }

input, textarea, select {
  width: 100%;
  padding: 0.5rem 0.62rem;
  color: var(--ink);
  background: oklch(0.1 0.03 300 / 0.72);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  font-size: 0.88rem;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: oklch(0.7 0.035 300); opacity: 1; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--purple-bright); box-shadow: 0 0 0 3px oklch(0.7 0.25 305 / 0.14); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.field { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 0.3rem; color: var(--ink); font-size: 0.77rem; font-weight: 700; }
.field small { color: var(--dim); font-size: 0.7rem; font-weight: 450; line-height: 1.35; }
.code-input, .output-area { font-family: "Cascadia Code", Consolas, monospace; font-size: 0.78rem; }

.muted { color: var(--dim); font-size: 0.86rem; }
.error { margin: 0.25rem 0; color: var(--danger); font-size: 0.83rem; }
.meta { color: var(--dim); font-size: 0.74rem; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 0.62rem; }
.push-right { margin-left: auto; }

.pill {
  display: inline-block;
  padding: 0.13rem 0.55rem;
  color: var(--dim);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  cursor: default;
  font-size: 0.7rem;
}
button.pill { appearance: none; background: transparent; cursor: pointer; }
.pill.active { color: var(--bg); background: var(--purple-bright); border-color: var(--purple-bright); }
.pill.badge { color: var(--lime); border-color: oklch(0.87 0.2 125 / 0.38); cursor: default; }

.list-item { padding: 0.62rem 0.12rem; border-bottom: 1px solid var(--hairline); }
.list-item:last-child { border-bottom: 0; }
.list-item a { color: var(--ink); text-decoration: none; }
.list-item .meta { margin-top: 0.18rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.form-grid-compact { grid-template-columns: minmax(85px, 0.35fr) minmax(180px, 1fr); }
.campaign-memory { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.65rem 0.72rem; background: oklch(0.7 0.25 305 / 0.1); border-radius: 9px; }
.campaign-memory div { display: flex; min-width: 0; flex-direction: column; }
.campaign-memory strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.84rem; }
.campaign-memory span { color: var(--dim); font-size: 0.71rem; }
.campaign-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.settings-intro { margin-bottom: 0.15rem; }
.text-button { align-self: flex-start; padding: 0; color: var(--purple-bright); background: none; border: 0; cursor: pointer; font-size: 0.76rem; }
.campaign-history h3 { margin: 0.45rem 0 0.18rem; color: var(--dim); font-size: 0.75rem; font-weight: 650; }
.history-row { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 0.8rem; padding: 0.52rem 0; color: var(--ink); background: transparent; border: 0; border-bottom: 1px solid var(--hairline); cursor: pointer; text-align: left; transition: color 160ms ease, transform 140ms var(--ease-out); }
.history-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-row small { flex: none; color: var(--dim); }
.operation-status { margin-bottom: 0.45rem; }

.task-check { display: grid; width: 30px; height: 30px; flex: none; cursor: pointer; place-items: center; }
.task-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--purple-bright); }

.research-chat { margin-bottom: 0.85rem; padding: 0.78rem; background: oklch(0.7 0.25 305 / 0.1); border-radius: 11px; }
.chat-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.8rem; }
.chat-heading h3 { margin: 0; font-size: 0.9rem; }
.chat-heading p { margin: 0.12rem 0 0.6rem; color: var(--dim); font-size: 0.76rem; }
.pulse-dot { width: 8px; height: 8px; flex: none; margin-top: 0.25rem; background: var(--pink); border-radius: 50%; box-shadow: 0 0 8px var(--pink); }
.chat-composer { display: grid; grid-template-columns: 1fr auto; gap: 0.45rem; align-items: end; }
.chat-composer textarea { min-height: 64px; }
.chat-response { margin-top: 0.72rem; padding-top: 0.72rem; border-top: 1px solid var(--hairline); }
.chat-response strong { display: block; margin-bottom: 0.35rem; font-size: 0.8rem; }
.chat-response p { max-width: 72ch; margin-bottom: 0.5rem; white-space: pre-wrap; font-size: 0.84rem; }
.notes-divider { display: flex; align-items: center; gap: 0.55rem; margin: 0.2rem 0 0.6rem; color: var(--dim); font-size: 0.72rem; }
.notes-divider::after { content: ""; height: 1px; flex: 1; background: var(--hairline); }

.login-body { position: relative; display: grid; min-height: 100vh; overflow: hidden; place-items: center; background: radial-gradient(70% 60% at 50% 0%, oklch(0.32 0.18 305), transparent 65%), var(--bg); isolation: isolate; }
.login-body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: linear-gradient(180deg, oklch(0.08 0.035 300 / 0.56), oklch(0.08 0.035 300 / 0.84)), radial-gradient(70% 80% at 50% 30%, oklch(0.48 0.24 305 / 0.22), transparent 70%); }
.login-video { position: fixed; inset: 0; z-index: -2; width: 100%; height: 100%; object-fit: cover; opacity: 0.38; }
.login-card { position: relative; display: flex; width: min(350px, calc(100vw - 2rem)); flex-direction: column; gap: 0.85rem; padding: 2rem; background: oklch(0.18 0.05 300 / 0.94); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 8px oklch(0.05 0.03 300 / 0.5); }
.login-card .logo { align-self: center; font-size: 2rem; }
.login-card > .muted { margin: 0.2rem 0 0.3rem; text-align: center; }
.login-credit { margin: 0.1rem 0 -0.4rem; color: var(--dim); font-size: 0.65rem; text-align: center; }
.login-credit a { color: var(--purple-bright); }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { border-color: var(--purple-bright); background-color: oklch(0.28 0.09 305); }
  .btn-ghost:hover { color: var(--ink); background-color: oklch(0.7 0.25 305 / 0.08); }
  .modes button:hover { color: var(--ink); background: oklch(0.7 0.25 305 / 0.08); }
  .list-item a:hover, .text-button:hover, .history-row:hover { color: var(--cyan); }
  .btn-icon:hover { color: var(--ink); background: oklch(0.7 0.25 305 / 0.1); }
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr 1fr; grid-template-areas: "player feed" "notes notes" "campaigns tasks"; }
  #panel-notes { max-height: 62vh; }
  .panel { max-height: 48vh; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 0.65rem; padding: 0.75rem; }
  .brand-note { display: none; }
  .modes { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .account { margin-left: auto; }
  .welcome { font-size: 0.84rem; }
  .modes button { flex: 1 0 auto; }
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "player" "notes" "feed" "campaigns" "tasks"; padding: 0.7rem; }
  .panel { min-width: 0; }
  .panel, #panel-notes { max-height: none; overflow: visible; }
  #panel-feed { max-height: 70vh; overflow: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .chat-composer { grid-template-columns: 1fr; }
  .chat-composer .btn { justify-self: end; }
  .btn, .btn-icon, .modes button, button.pill, .text-button, .history-row { min-height: 44px; }
  .btn-icon, button.pill { min-width: 44px; }
  input:not([type="checkbox"]), textarea, select { min-height: 44px; }
  input[type="range"] { min-height: 44px; }
  .task-check { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .login-video { display: none; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
