:root {
  --paper: #f5efe3;
  --paper-warm: #efe3d0;
  --ink: #201b17;
  --muted: #71675b;
  --line: #d6c8b6;
  --panel: #fffbf3;
  --accent: #1f5c5f;
  --accent-ink: #eaf5ef;
  --danger: #9b3a30;
  --gold: #8a651f;
  --green: #35684b;
  font-family: Charter, "Iowan Old Style", Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 35vw) 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--paper-warm);
  max-height: 100vh;
  overflow: auto;
}

.masthead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: color-mix(in srgb, var(--paper-warm) 94%, white);
  border-bottom: 1px solid var(--line);
  padding: 22px 18px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.kicker {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1, h2, h3 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.02;
}

h1 {
  max-width: 10ch;
  font-size: clamp(32px, 4vw, 58px);
}

.plain {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 0;
}

.search-panel {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 12px;
  min-height: 88px;
}

input, select {
  padding: 9px 10px;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

button {
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 9px 13px;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--accent);
}

.toggle {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.toggle input {
  width: auto;
}

.filters {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.filters select {
  grid-column: span 2;
}

.stats {
  padding: 12px 18px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.results {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.result {
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
}

.result:hover, .result.active {
  background: var(--panel);
  border-color: var(--accent);
}

.result-title {
  font-weight: 800;
  line-height: 1.16;
}

.meta, .snippet, .ai-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.ai-note {
  color: #51483e;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  font-size: 12px;
}

.pill.good { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.pill.hot { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.pill.gold { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }

.reader {
  max-height: 100vh;
  overflow: auto;
  background: var(--panel);
  padding: clamp(22px, 4vw, 58px);
}

.empty-state {
  max-width: 720px;
  margin-top: 12vh;
}

.empty-state h2 {
  font-size: clamp(34px, 6vw, 82px);
  max-width: 11ch;
}

.empty-state p:last-child {
  max-width: 660px;
  color: var(--muted);
  font-size: 20px;
}

.letter-head {
  max-width: 980px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 22px;
}

.letter-head h2 {
  font-size: clamp(34px, 4.5vw, 72px);
  max-width: 16ch;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.feedback-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.feedback-grid button {
  background: transparent;
  color: var(--accent);
}

.transcript {
  max-width: 940px;
  font-size: clamp(19px, 2.1vw, 31px);
  line-height: 1.58;
  white-space: pre-wrap;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--paper-warm);
}

.login-panel {
  width: min(92vw, 480px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
}

.login-panel h1 {
  max-width: none;
  margin-bottom: 24px;
}

.login-form label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
}

.login-form button {
  margin-top: 12px;
  width: 100%;
}

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

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: none;
    border-right: 0;
  }
  .reader {
    max-height: none;
    min-height: 70vh;
  }
  .masthead {
    position: static;
  }
  h1 {
    max-width: 12ch;
  }
}
