:root {
  --bg: #090a0b;
  --panel: #101214;
  --raised: #17191c;
  --hover: #202328;
  --line: #292d32;
  --line-strong: #3b4148;
  --text: #f0f2f3;
  --muted: #8d969f;
  --soft: #b9c0c7;
  --green: #45d49b;
  --blue: #65b8ff;
  --amber: #f2c96d;
  --red: #f28c8c;
  --mono: ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
}

body {
  min-width: 20rem;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a,
button,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

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

button,
.nav-item,
.primary {
  touch-action: manipulation;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 3.75rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 12, 13, 0.96);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.625rem;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 680;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 1.875rem;
  height: 1.875rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #3e454d;
  border-radius: 0.5rem;
  color: var(--green);
  font: 700 0.625rem var(--mono);
}

.connection {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.6875rem;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.65rem;
}

.topbar-actions form {
  margin: 0;
}

.logout {
  min-height: 2.75rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--soft);
  font-size: 0.6875rem;
  font-weight: 650;
  cursor: pointer;
}

.connection code {
  display: none;
}

.dot {
  width: 0.4375rem;
  height: 0.4375rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--amber);
}

.dot.live {
  background: var(--green);
}

.shell {
  display: flex;
  min-height: calc(100dvh - 3.75rem);
  flex-direction: column;
}

.sidebar {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #0b0c0d;
}

.sidebar > .eyebrow,
.sidebar > h1,
.principle {
  display: none;
}

nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.375rem;
}

.nav-item {
  display: flex;
  min-width: 0;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.4rem;
  border-radius: 0.5rem;
  color: var(--soft);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.nav-item span {
  color: var(--muted);
  font: 0.625rem var(--mono);
}

.nav-item.active {
  background: #17251f;
  color: var(--green);
}

.workspace {
  width: 100%;
  padding: 1.5rem 1rem 2rem;
}

.page-heading {
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font: 600 0.625rem var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-heading h2 {
  margin: 0 0 0.45rem;
  font-size: clamp(1.75rem, 9vw, 2.25rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

.lede {
  max-width: 34rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.model-badge {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 0.2rem 0.5rem;
  margin-top: 1rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--panel);
}

.model-badge span,
.model-badge small {
  color: var(--muted);
  font: 0.5625rem var(--mono);
  letter-spacing: 0.06em;
}

.model-badge strong {
  color: var(--green);
  font-size: 0.75rem;
}

.model-badge small {
  grid-column: 1 / -1;
  letter-spacing: 0;
}

.flash {
  margin-bottom: 1rem;
  padding: 0.75rem 0.875rem;
  border: 1px solid #285541;
  border-radius: 0.5rem;
  background: #10211a;
  color: #b9eed7;
  font-size: 0.8125rem;
}

.intake {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.intake label {
  display: grid;
  gap: 0.45rem;
}

.intake label > span {
  color: var(--soft);
  font-size: 0.75rem;
  font-weight: 650;
}

textarea,
input,
select {
  width: 100%;
  min-height: 2.875rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  outline: none;
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 120ms ease-out, background 120ms ease-out, box-shadow 120ms ease-out;
}

textarea {
  min-height: 8.5rem;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #68717a;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1rem) 50%, calc(100% - 0.7rem) 50%;
  background-repeat: no-repeat;
  background-size: 0.3rem 0.3rem, 0.3rem 0.3rem;
  padding-right: 2.25rem;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  background-color: var(--raised);
  box-shadow: 0 0 0 3px #65b8ff20;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.primary {
  display: flex;
  width: 100%;
  min-height: 3rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.95rem;
  border: 0;
  border-radius: 0.55rem;
  background: var(--green);
  color: #07130e;
  font-weight: 760;
  cursor: pointer;
  transition: filter 120ms ease-out, transform 100ms ease-out;
}

.primary:hover,
.feedback button:hover {
  filter: brightness(1.08);
}

.primary:active,
.feedback button:active,
.nav-item:active {
  transform: scale(0.98);
}

#advice-region:empty {
  display: none;
}

.request-indicator {
  display: none;
  font: 600 0.625rem var(--mono);
}

.htmx-request .request-indicator {
  display: inline;
}

.htmx-request .submit-arrow {
  display: none;
}

.advice-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: var(--panel);
}

.advice-panel.is-streaming {
  border-color: #355746;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

.panel-heading h3 {
  margin: 0;
  font-size: 1rem;
}

.status-pill {
  flex: 0 0 auto;
  padding: 0.25rem 0.45rem;
  border: 1px solid #28664c;
  border-radius: 99px;
  color: var(--green);
  font: 0.625rem var(--mono);
}

.status-pill.waiting {
  border-color: #6a572d;
  color: var(--amber);
}

.status-pill.failed {
  border-color: #704044;
  color: var(--red);
}

.stream-status {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.stream-cursor {
  width: 0.45rem;
  height: 0.45rem;
  flex: 0 0 auto;
  margin-top: 0.3rem;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px #f2c96d18;
}

.advice-copy {
  overflow-wrap: anywhere;
  padding: 1.1rem 1rem;
  color: #dce1e5;
  line-height: 1.62;
}

.advice-copy > :first-child { margin-top: 0; }
.advice-copy > :last-child { margin-bottom: 0; }

.advice-copy h2,
.advice-copy h3 {
  margin: 1.35rem 0 0.45rem;
  color: var(--green);
  font-size: 0.75rem;
  line-height: 1.3;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.advice-copy p,
.advice-copy ul,
.advice-copy ol,
.advice-copy blockquote {
  margin: 0 0 0.85rem;
}

.advice-copy ul,
.advice-copy ol {
  padding-left: 1.25rem;
}

.advice-copy li + li {
  margin-top: 0.35rem;
}

.advice-copy strong {
  color: var(--text);
}

.advice-copy a {
  color: var(--blue);
  text-underline-offset: 0.18em;
}

.advice-copy code {
  padding: 0.1rem 0.3rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: var(--raised);
  font: 0.86em var(--mono);
}

.advice-copy pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #0b0d0f;
  -webkit-overflow-scrolling: touch;
}

.advice-copy pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.advice-copy blockquote {
  padding-left: 0.75rem;
  border-left: 2px solid var(--blue);
  color: var(--soft);
}

.stream-placeholder {
  display: grid;
  gap: 0.625rem;
  padding: 1.25rem 1rem;
}

.stream-placeholder span {
  display: block;
  height: 0.55rem;
  border-radius: 0.3rem;
  background: var(--raised);
}

.stream-placeholder span:nth-child(1) { width: 92%; }
.stream-placeholder span:nth-child(2) { width: 78%; }
.stream-placeholder span:nth-child(3) { width: 60%; }

.stream-error {
  display: grid;
  gap: 0.25rem;
  margin: 1rem;
  padding: 0.8rem 0.875rem;
  border: 1px solid #704044;
  border-radius: 0.5rem;
  background: #251416;
  color: var(--red);
  font-size: 0.75rem;
}

.stream-error span {
  color: #efb5b8;
}

.feedback {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.feedback strong,
.feedback small {
  display: block;
}

.feedback small {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.6875rem;
}

.feedback-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.feedback button {
  min-height: 2.75rem;
  padding: 0.6rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--raised);
  color: var(--soft);
  font-size: 0.75rem;
  cursor: pointer;
  transition: filter 120ms ease-out, transform 100ms ease-out;
}

.feedback button:first-child {
  border-color: #28664c;
  color: var(--green);
}

.feedback-saved {
  padding: 1rem;
  border-top: 1px solid var(--line);
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 650;
}

.memory {
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--line);
  background: #0b0c0d;
}

.memory-heading h2 {
  margin: 0 0 0.3rem;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.memory-heading > p:last-child {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.memory-list {
  display: grid;
  gap: 0.75rem;
}

.memory-item {
  display: flex;
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--panel);
}

.memory-rating {
  display: grid;
  width: 1.4rem;
  height: 1.4rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  font-size: 0.75rem;
}

.memory-rating.good {
  background: #173c2d;
  color: var(--green);
}

.memory-rating.bad {
  background: #422326;
  color: var(--red);
}

.memory-item strong {
  font-size: 0.75rem;
}

.memory-item p {
  margin: 0.2rem 0;
  color: var(--soft);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.memory-item time {
  color: var(--muted);
  font: 0.5625rem var(--mono);
}

.empty {
  padding: 1rem;
  border: 1px dashed var(--line);
  border-radius: 0.55rem;
  color: var(--muted);
}

.empty > span {
  color: var(--green);
  font-size: 1.25rem;
}

.empty p {
  margin: 0.35rem 0 0.1rem;
  color: var(--soft);
  font-weight: 650;
}

.empty small {
  font-size: 0.6875rem;
}

.memory-note {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.6875rem;
}

.memory-note > span {
  display: grid;
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--blue);
}

.memory-note p {
  margin: 0;
}

.auth-body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% 0%, #173328 0, transparent 28rem),
    var(--bg);
}

.auth-shell {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(100%, 27rem);
  padding: 1.35rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: rgba(16, 18, 20, 0.96);
  box-shadow: 0 1.5rem 5rem #0008;
}

.auth-mark {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: 1.5rem;
}

.auth-card h1 {
  margin: 0 0 0.7rem;
  font-size: clamp(1.8rem, 9vw, 2.5rem);
  line-height: 1.04;
  letter-spacing: -0.05em;
}

.auth-intro,
.auth-footnote {
  color: var(--muted);
}

.auth-intro {
  margin: 0 0 1.5rem;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.auth-form label {
  display: grid;
  gap: 0.45rem;
}

.auth-form label > span {
  color: var(--soft);
  font-size: 0.75rem;
  font-weight: 650;
}

.auth-form button:disabled {
  cursor: wait;
  filter: saturate(0.35);
  opacity: 0.75;
}

.auth-status {
  min-height: 1.5rem;
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.auth-status.working {
  color: var(--amber);
}

.auth-status.error {
  color: var(--red);
}

.auth-footnote {
  margin: 1rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.6875rem;
}

@media (min-width: 40rem) {
  .topbar {
    min-height: 4rem;
    padding-inline: 1.5rem;
  }

  .auth-card {
    padding: 2rem;
  }

  .connection code {
    display: block;
    margin-left: 0.3rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--line);
    color: var(--soft);
    font: 0.625rem var(--mono);
  }

  .sidebar {
    padding-inline: 1.5rem;
  }

  .workspace,
  .memory {
    padding-inline: 1.5rem;
  }

  .workspace {
    padding-top: 2rem;
  }

  .page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
  }

  .page-heading h2 {
    font-size: 2rem;
  }

  .model-badge {
    min-width: 9rem;
    margin-top: 0;
  }

  .intake {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .intake .wide {
    grid-column: 1 / -1;
  }

  .memory-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-heading,
  .stream-status,
  .advice-copy,
  .feedback {
    padding-inline: 1.25rem;
  }
}

@media (min-width: 68.75rem) {
  html {
    scroll-padding-top: 4.5rem;
  }

  .topbar {
    min-height: 4.5rem;
    padding-inline: 2rem;
  }

  .shell {
    display: grid;
    min-height: calc(100vh - 4.5rem);
    grid-template-columns: 14.5rem minmax(31.25rem, 1fr) 18.5rem;
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: 4.5rem;
    display: flex;
    height: calc(100vh - 4.5rem);
    flex-direction: column;
    padding: 2.1rem 1.5rem;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    background: transparent;
  }

  .sidebar > .eyebrow,
  .sidebar > h1,
  .principle {
    display: block;
  }

  .sidebar h1 {
    margin: 0 0 2.75rem;
    font-size: 1.375rem;
    line-height: 1.08;
    letter-spacing: -0.04em;
  }

  .sidebar h1 span {
    color: var(--green);
  }

  nav {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.375rem;
  }

  .nav-item {
    justify-content: space-between;
    padding-inline: 0.75rem;
    font-size: 0.8125rem;
    text-align: left;
  }

  .principle {
    margin-top: auto;
    padding-top: 1.1rem;
    border-top: 1px solid var(--line);
    color: var(--soft);
    font-size: 0.75rem;
  }

  .principle p:last-child {
    margin: 0;
  }

  .workspace {
    width: min(100%, 58rem);
    min-height: calc(100vh - 4.5rem);
    justify-self: center;
    padding: 2.4rem clamp(2rem, 4vw, 4rem) 3rem;
  }

  .memory {
    position: sticky;
    top: 4.5rem;
    height: calc(100vh - 4.5rem);
    overflow-y: auto;
    padding: 2.1rem 1.5rem;
    border-top: 0;
    border-left: 1px solid var(--line);
    background: transparent;
  }

  .memory-list {
    grid-template-columns: 1fr;
  }

  .memory-item {
    padding: 0;
    border: 0;
    background: transparent;
  }

  .feedback {
    grid-template-columns: auto 1fr;
    align-items: center;
  }

  .feedback-actions {
    display: flex;
    justify-content: flex-end;
  }

  .feedback button {
    min-width: 6.5rem;
  }

  .feedback input {
    grid-column: 1 / -1;
  }
}

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

@media (prefers-reduced-transparency: reduce) {
  .topbar {
    background: #0b0c0d;
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: #69727d;
    --muted: #b9c0c7;
  }
}
