:root {
  color-scheme: dark;
  --bg: #181513;
  --bg-soft: #221d1a;
  --panel: rgba(40, 33, 29, 0.9);
  --panel-strong: #302722;
  --line: rgba(218, 197, 170, 0.16);
  --line-strong: rgba(218, 197, 170, 0.28);
  --text: #f2e9dc;
  --muted: #bbaea1;
  --accent: #d4a257;
  --accent-soft: #8fb5a5;
  --danger: #f0a18b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(212, 162, 87, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(143, 181, 165, 0.1), transparent 22%),
    linear-gradient(180deg, #151210 0%, #1d1816 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #17110d;
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(22, 18, 16, 0.88);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

textarea {
  resize: vertical;
}

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.shell {
  min-height: 100vh;
  min-height: 100svh;
}

.login-view {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.app-view {
  height: 100vh;
  height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    calc(94px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow: hidden;
}

.screen-view {
  width: min(1120px, 100%);
  margin: 0 auto;
  height: 100%;
  min-height: 0;
}

.topbar,
.topbar-actions,
.panel-head,
.section-head,
.composer {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.chat-topbar {
  margin-bottom: 14px;
}

.topbar-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

h1,
h2,
h3 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(34px, 7vw, 54px);
  line-height: 0.95;
}

h2 {
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1;
}

h3 {
  font-size: 18px;
}

.eyebrow {
  color: var(--accent-soft);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-pill,
.metric-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(25, 20, 18, 0.82);
  color: var(--muted);
}

.status-pill {
  padding: 0 12px;
}

.metric-pill {
  padding: 0 12px;
  font-size: 12px;
}

.metric-pill strong {
  color: var(--text);
}

.overview-shell,
.persona-shell {
  display: grid;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
  scrollbar-width: none;
}

#overviewView,
#personaView {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
}

.reflection-surface,
.persona-card {
  background: linear-gradient(180deg, rgba(45, 37, 32, 0.92), rgba(31, 25, 22, 0.96));
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.reflection-surface {
  display: grid;
  gap: 28px;
  padding: clamp(22px, 4vw, 36px);
}

.reflection-hero {
  display: grid;
  gap: 12px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.reflection-message,
.milestone-narrative {
  color: var(--text);
  line-height: 1.65;
  font-size: 17px;
  max-width: 78ch;
}

.surface-section {
  display: grid;
  gap: 18px;
}

.history-section {
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.section-head {
  justify-content: space-between;
  gap: 12px;
}

.history-toggle {
  cursor: pointer;
  list-style: none;
}

.history-toggle::-webkit-details-marker {
  display: none;
}

.history-stack {
  display: grid;
  gap: 18px;
}

.urgent-list,
.milestone-stack,
.memory-list,
.history-content {
  display: grid;
  gap: 14px;
}

.urgent-item,
.milestone-card,
.memory-item,
.history-session,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(22, 18, 16, 0.7);
}

.urgent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px 18px;
}

.urgent-copy {
  display: grid;
  gap: 4px;
}

.urgent-copy strong {
  font-size: 16px;
}

.urgent-copy p {
  color: var(--muted);
  font-size: 13px;
}

.urgent-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.compact-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.milestone-card {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.milestone-head {
  display: grid;
  gap: 8px;
}

.milestone-label {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metrics-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.summary-column {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.02);
}

.mini-list {
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--text);
  line-height: 1.5;
}

.open-loop-list li {
  color: var(--accent-soft);
}

.persona-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 18px;
}

.persona-card {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.persona-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
}

.field.full,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.persona-group {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.persona-summary-card {
  padding-top: 0;
  border-top: 0;
}

.memory-item {
  padding: 14px 16px;
}

.memory-item p:first-child {
  line-height: 1.55;
}

.chat-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
}

.chat-messages {
  display: grid;
  align-content: start;
  align-items: start;
  gap: 22px;
  min-height: 0;
  overflow: auto;
  padding: 10px 2px 20px;
  scrollbar-width: none;
}

.overview-shell::-webkit-scrollbar,
.persona-shell::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  display: none;
}

.message {
  align-self: start;
  height: fit-content;
  max-width: min(78%, 720px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(22, 18, 16, 0.76);
  padding: 14px 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.assistant {
  justify-self: center;
  width: min(100%, 72ch);
  max-width: 72ch;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  line-height: inherit;
  white-space: normal;
}

.message.user {
  justify-self: end;
  background: rgba(212, 162, 87, 0.14);
  border-color: rgba(212, 162, 87, 0.32);
}

.message.assistant.working-note {
  border: 1px dashed var(--line);
  border-radius: 24px;
  background: rgba(22, 18, 16, 0.54);
  padding: 14px 16px;
  color: var(--muted);
  white-space: pre-wrap;
}

.markdown-body {
  color: var(--text);
  font-size: 17px;
  line-height: 1.72;
}

.markdown-body > * + * {
  margin-top: 1.05em;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.markdown-body h1 {
  font-size: clamp(34px, 4vw, 46px);
}

.markdown-body h2 {
  font-size: clamp(26px, 3vw, 34px);
}

.markdown-body h3 {
  font-size: 24px;
}

.markdown-body h4 {
  font-size: 20px;
}

.markdown-body p,
.markdown-body li,
.markdown-body blockquote {
  color: var(--text);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.35em;
}

.markdown-body li + li {
  margin-top: 0.35em;
}

.markdown-body a {
  color: var(--accent-soft);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.markdown-body code {
  font-family: "SFMono-Regular", "JetBrains Mono", "Menlo", monospace;
  font-size: 0.92em;
  padding: 0.16em 0.4em;
  border-radius: 8px;
  background: rgba(212, 162, 87, 0.12);
}

.markdown-body pre {
  overflow: auto;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(14, 12, 11, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.markdown-body pre code {
  display: block;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #f7f0e4;
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 18px;
  border-left: 3px solid rgba(143, 181, 165, 0.5);
  color: var(--muted);
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(20, 17, 15, 0.64);
}

.markdown-body th,
.markdown-body td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body thead th {
  color: var(--accent-soft);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.markdown-body tbody tr:last-child td {
  border-bottom: 0;
}

.markdown-body img {
  display: block;
  max-width: 100%;
  border-radius: 18px;
  border: 1px solid var(--line);
}

.markdown-body del {
  color: var(--muted);
}

.composer {
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(28, 23, 20, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.composer input {
  flex: 1;
  min-height: 48px;
  border-radius: 999px;
  border-color: transparent;
  background: transparent;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 28px));
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(24, 20, 18, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

@media (max-width: 860px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 12;
    padding: 4px 0 12px;
    background:
      linear-gradient(180deg, rgba(24, 20, 18, 0.96) 0%, rgba(24, 20, 18, 0.82) 75%, rgba(24, 20, 18, 0) 100%);
    backdrop-filter: blur(14px);
  }

  .app-view.keyboard-open {
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .app-view.keyboard-open .bottom-nav {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(18px);
  }
}

.nav-button {
  min-height: 48px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.nav-button.active {
  background: var(--accent);
  color: #17110d;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: end center;
  padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: min(82vh, 760px);
  overflow: auto;
  padding: 20px;
  border-radius: 30px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(45, 37, 32, 0.96), rgba(31, 25, 22, 0.98));
  box-shadow: var(--shadow);
}

.panel-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.history-session,
.empty-state {
  padding: 16px;
  text-align: left;
  min-height: 0;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .summary-grid,
  .persona-layout,
  .persona-form {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
  }

  .reflection-surface,
  .persona-card,
  .login-panel,
  .modal-panel {
    border-radius: 24px;
  }

  .urgent-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .message {
    max-width: 90%;
  }

  .composer {
    border-radius: 28px;
  }
}
