/* letterbox — a calm reading room for newsletters. */

:root {
  --bg: #f5f1ea;
  --pane: #fbf9f5;
  --raised: #ffffff;
  --ink: #1f1c18;
  --ink-soft: #3d3831;
  --muted: #7a7368;
  --line: #e7e0d4;
  --line-strong: #d8cfbf;
  --hover: #f0ebe2;
  --active: #ebe3d6;
  --accent: #b5452b;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3dc;
  --focus: #b5452b;
  --shadow: 0 1px 2px rgb(60 45 25 / 6%), 0 8px 24px -8px rgb(60 45 25 / 14%);
  --avatar-l: 88%;
  --avatar-c: 0.07;
  --avatar-ink-l: 38%;

  --serif: "Iowan Old Style", "Palatino Linotype", Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --list-width: 390px;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --pane: #1b1a17;
    --raised: #23211d;
    --ink: #eeeae3;
    --ink-soft: #cfc9bf;
    --muted: #958e83;
    --line: #2c2a25;
    --line-strong: #3a3731;
    --hover: #24221e;
    --active: #2c2924;
    --accent: #e27a5c;
    --accent-ink: #1b1a17;
    --accent-soft: #3a261f;
    --focus: #e27a5c;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 12px 32px -12px rgb(0 0 0 / 60%);
    --avatar-l: 34%;
    --avatar-c: 0.06;
    --avatar-ink-l: 86%;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

svg { flex: none; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 .4em;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--raised);
  font: 12px/1.6 var(--mono);
  text-align: center;
  color: var(--ink-soft);
}

.muted { color: var(--muted); }

/* ---------- wordmark, buttons ---------- */

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font: italic 600 1.3rem/1 var(--serif);
  letter-spacing: -.01em;
  text-decoration: none;
  color: var(--ink);
}
.wordmark .mark { width: 24px; height: 24px; color: var(--accent); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 40px;
  padding: 0 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
  color: var(--ink);
  font: 500 14px/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.button:hover { background: var(--hover); }
.button:active { transform: translateY(1px); }
.button.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}
.button.primary:hover { filter: brightness(1.06); }

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover { background: var(--hover); color: var(--ink); }
.icon-button svg { width: 19px; height: 19px; }

/* ---------- centred pages: login, not found ---------- */

body.centered {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.card {
  width: 100%;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--pane);
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 360px; }
.card h1 { margin: 20px 0 6px; font: 600 1.4rem/1.25 var(--serif); }

.login .wordmark { margin-bottom: 24px; font-size: 1.6rem; }
.login .wordmark .mark { width: 30px; height: 30px; }
.login form { display: grid; gap: 10px; }
.login label { font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.login input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
  color: var(--ink);
  font: 16px var(--sans);
}
.login input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login input[aria-invalid="true"] { border-color: var(--accent); }
.login .button { margin-top: 8px; height: 44px; }
.error { margin: 0; color: var(--accent); font-size: 13.5px; }

/* ---------- app shell ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--list-width) 1fr;
  height: 100%;
}

.pane { min-width: 0; min-height: 0; }

.list-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--pane);
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px 20px;
}
.list-head form { margin: 0; }

/* sender filter */

.senders { position: relative; margin: 0 12px 6px; }
.senders summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.senders summary::-webkit-details-marker { display: none; }
.senders summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.senders summary:hover { background: var(--hover); }
.senders summary svg { width: 16px; height: 16px; color: var(--muted); transition: transform .2s; }
.senders[open] summary svg { transform: rotate(180deg); }

.menu {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: min(60vh, 420px);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  box-shadow: var(--shadow);
  animation: pop .14s ease-out;
}
.menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 7px;
  text-decoration: none;
  font-size: 14px;
}
.menu a:hover { background: var(--hover); }
.menu a[aria-current] { background: var(--active); font-weight: 600; }
.menu .avatar { width: 24px; height: 24px; font-size: 11px; }
.menu-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.avatar.all { background: var(--active); color: var(--muted); }

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

/* message list */

.list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 8px 16px;
  scrollbar-width: thin;
}

.group h2 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 14px 12px 6px;
  background: linear-gradient(var(--pane) 70%, transparent);
  font: 600 11.5px/1 var(--sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  transition: background .12s;
}
.row + .row { margin-top: 1px; }
.row:hover { background: var(--hover); }
.row.active { background: var(--active); }
.row.unseen::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  width: 5px;
  height: 5px;
  margin-top: -2.5px;
  border-radius: 50%;
  background: var(--accent);
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: oklch(var(--avatar-l) var(--avatar-c) var(--hue, 40));
  color: oklch(var(--avatar-ink-l) calc(var(--avatar-c) * 2) var(--hue, 40));
  font: 600 15px/1 var(--serif);
  flex: none;
  user-select: none;
}

.row-body { display: grid; gap: 2px; min-width: 0; flex: 1; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted);
}
.row time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 500 15px/1.3 var(--serif);
  color: var(--ink-soft);
}
.row.unseen .name { color: var(--ink); font-weight: 600; }
.row.unseen .subject { color: var(--ink); font-weight: 650; }
.row .snippet {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.more {
  display: block;
  margin: 12px 8px 0;
  padding: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  text-decoration: none;
  font-size: 13.5px;
  color: var(--muted);
}
.more:hover { background: var(--hover); color: var(--ink); }
.more[aria-busy="true"] { opacity: .6; pointer-events: none; }

.empty, .placeholder {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
.empty p, .placeholder p { margin: 0; }
.empty .mark, .placeholder .mark { width: 40px; height: 40px; margin-bottom: 12px; color: var(--line-strong); }
.empty strong { color: var(--ink-soft); font: 600 1.05rem var(--serif); }
.placeholder { height: 100%; align-content: center; font: italic 1.05rem var(--serif); }
.placeholder .mark { width: 56px; height: 56px; }

.list-foot {
  padding: 8px 16px 12px;
  border-top: 1px solid var(--line);
}
.hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: 12.5px var(--sans);
  cursor: pointer;
}
.hint:hover { color: var(--ink); }

/* ---------- reader ---------- */

.reader-pane {
  overflow-y: auto;
  scroll-behavior: smooth;
}

.reader {
  max-width: 820px;
  margin: 0 auto;
  padding: 36px 40px 64px;
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: .4; } }

.back {
  display: none;
  align-items: center;
  gap: 2px;
  margin: 0 0 12px -6px;
  padding: 4px 6px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 500;
  color: var(--accent);
}
.back svg { width: 20px; height: 20px; }

.title {
  margin: 0 0 18px;
  font: 600 clamp(1.5rem, 1.1rem + 1.4vw, 2.1rem)/1.2 var(--serif);
  letter-spacing: -.012em;
  text-wrap: balance;
}

.byline { display: flex; align-items: center; gap: 12px; }
.byline .avatar { width: 40px; height: 40px; font-size: 17px; }
.byline .from { font-size: 14.5px; }
.byline .address { color: var(--muted); font-size: 13px; }
.byline time { display: block; font-size: 13px; color: var(--muted); }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 22px 0 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.spacer { flex: 1; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 9px;
  background: var(--active);
}
.segmented a {
  padding: 5px 14px;
  border-radius: 7px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.segmented a:hover { color: var(--ink); }
.segmented a[aria-current] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 10%); }

.tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  color: var(--muted);
}
.tool:hover { background: var(--hover); color: var(--ink); }
.tool svg { width: 16px; height: 16px; }

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--accent-soft);
  font-size: 13px;
  color: var(--ink-soft);
}
.notice svg { width: 17px; height: 17px; color: var(--accent); }
.notice span { flex: 1; }
.notice a { font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.notice a:hover { text-decoration: underline; }

/* The email keeps its own light design on a paper card, in both themes:
   inverting someone else's HTML breaks logos and colours. */
.paper {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}
.email {
  display: block;
  width: 100%;
  height: 75vh;
  border: 0;
  background: #fff;
  color-scheme: light;
}

.prose {
  max-width: 68ch;
  font: 18px/1.7 var(--serif);
  color: var(--ink-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.prose a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* ---------- help ---------- */

dialog {
  width: min(380px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--pane);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(20 15 10 / 35%); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 16px; font: 600 1.15rem var(--serif); }
dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0 0 20px; align-items: center; }
dialog dt { white-space: nowrap; }
dialog dd { margin: 0; color: var(--ink-soft); font-size: 14px; }
dialog form { display: flex; justify-content: flex-end; margin: 0; }

/* ---------- narrow screens: one pane at a time ---------- */

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  body[data-view="reader"] .list-pane { display: none; }
  body[data-view="list"] .reader-pane { display: none; }
  .back { display: inline-flex; }
  .reader { padding: 16px 16px 48px; }
  .toolbar { margin-top: 16px; }
  .paper { margin: 0 -16px; border-radius: 0; border-left: 0; border-right: 0; }
  .prose { font-size: 17px; }
  .list-foot { display: none; }
  .row { padding: 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
