:root {
  --paper: #F5F1E8;
  --ink: #191713;
  --muted: #6E675C;
  --line: #DCD5C6;
  --mark: #B23A2C;
  --mono: ui-monospace, "Cascadia Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #17150F; --ink: #EAE4D6; --muted: #9A9184; --line: #3A362C; --mark: #D96A54; }
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
  min-height: 100dvh;
}
a { color: inherit; }
button {
  font: inherit;
  background: var(--ink); color: var(--paper);
  border: 0; border-radius: 2px;
  padding: 9px 16px;
  cursor: pointer;
}
button.quiet { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--mark); border: 1px solid var(--mark); }
input, textarea, select {
  font: inherit; color: inherit;
  background: transparent;
  border: 1px solid var(--line); border-radius: 2px;
  padding: 9px 10px;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--mark); outline-offset: -1px; }

/* Wordmark carries the cancellation-line motif */
.wordmark {
  font-weight: 800; letter-spacing: -0.02em; text-decoration: none;
  position: relative; padding-right: 34px; white-space: nowrap;
}
.wordmark::after {
  content: ""; position: absolute; right: 0; top: 52%; width: 28px; height: 9px;
  background: repeating-linear-gradient(to bottom, var(--mark) 0 1.5px, transparent 1.5px 4px);
  transform: translateY(-50%); opacity: 0.85;
}

/* Gate */
#gate { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.gate-card { width: min(380px, 100%); border: 1px solid var(--line); padding: 28px; background: var(--paper); }
.gate-card h1 { font-size: 22px; margin-bottom: 6px; }
.gate-note { color: var(--muted); margin-bottom: 18px; }
.gate-card input { margin-bottom: 12px; }
.flash { color: var(--mark); margin-top: 12px; }

/* Shell */
.topbar {
  display: flex; align-items: baseline; gap: 24px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.topbar nav a {
  text-decoration: none; color: var(--muted);
  padding: 4px 10px; border-radius: 2px;
}
.topbar nav a.active { color: var(--ink); border-bottom: 2px solid var(--mark); }
.topbar nav a.write { color: var(--mark); font-weight: 700; }
main { max-width: 860px; margin: 0 auto; padding: 18px 20px 60px; }

/* Chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  text-decoration: none; color: var(--muted);
  border: 1px solid var(--line); border-radius: 2px; padding: 3px 10px; font-size: 14px;
}
.chip.on { color: var(--ink); border-color: var(--ink); }
.chip b { color: var(--mark); margin-left: 6px; }

/* Ledger rows */
.rows { list-style: none; }
.rows a {
  display: grid;
  grid-template-columns: 26px 180px 1fr auto auto;
  gap: 12px; align-items: baseline;
  padding: 12px 8px; text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.rows .who { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .snip { color: var(--muted); margin-left: 8px; }
.rows time { color: var(--muted); font-size: 14px; }
.rows .clip { color: var(--muted); font-size: 13px; }

/* The postmark: circular date-stamp on unread rows only */
.stamp { width: 18px; height: 18px; justify-self: center; align-self: center; }
.row.unread .stamp {
  border: 1.5px solid var(--mark); border-radius: 50%;
  background:
    repeating-linear-gradient(to bottom, transparent 0 3px, var(--mark) 3px 4px);
  background-size: 60% 60%; background-position: center; background-repeat: no-repeat;
  opacity: 0.9;
}
.row.unread .who, .row.unread .subj { font-weight: 800; }

.empty { color: var(--muted); padding: 40px 8px; }
.more { padding: 16px 8px; }
.more button { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* Message + forms (used from T14 on) */
.msg-head { padding: 6px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.msg-head h2 { font-size: 20px; margin-bottom: 6px; }
.msg-meta { color: var(--muted); font-size: 14px; }
.msg-meta .addr { font-family: var(--mono); font-size: 13px; }
.msg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.mailframe { width: 100%; min-height: 55vh; border: 1px solid var(--line); background: #fff; }
.plain { white-space: pre-wrap; font: 15px/1.5 var(--mono); overflow-x: auto; }
.att-list { list-style: none; margin-top: 14px; border-top: 1px solid var(--line); }
.att-list a {
  display: flex; gap: 10px; padding: 9px 4px; text-decoration: none;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
.att-list .size { color: var(--muted); margin-left: auto; }

.form-grid { display: grid; gap: 12px; max-width: 640px; }
.form-grid label { font-size: 13px; font-weight: 700; color: var(--muted); display: block; margin-bottom: 4px; }
.form-grid textarea { min-height: 40vh; resize: vertical; }
.form-row { display: flex; gap: 10px; align-items: center; }

.status { font-size: 13px; font-weight: 700; padding: 2px 8px; border: 1px solid var(--line); border-radius: 2px; }
.status.delivered { border-color: var(--ink); }
.status.failed, .status.bounced, .status.complained { color: var(--mark); border-color: var(--mark); }

.view-title { font-size: 20px; margin-bottom: 14px; }
.out-detail { padding: 10px 8px 16px 38px; border-bottom: 1px solid var(--line); }
.out-detail .plain { margin-bottom: 10px; }
.rows .who.addr { font-family: var(--mono); font-weight: 600; font-size: 14px; }

.hint { color: var(--muted); margin-bottom: 16px; max-width: 560px; }
.addr-row { display: flex; gap: 10px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.addr-row .addr { font-family: var(--mono); font-size: 14px; }
.addr-row.off .addr { color: var(--muted); text-decoration: line-through; }
.addr-row input { width: 140px; }
.addr-row .counts { color: var(--muted); font-size: 13px; margin-left: auto; }
.addr-add { margin-top: 18px; flex-wrap: wrap; }
.addr-add input { width: 160px; }

.flash.okay { color: var(--ink); }
.signout { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); }
.push-box { margin-top: 28px; display: grid; gap: 8px; justify-items: start; }

@media (max-width: 640px) {
  .rows a { grid-template-columns: 22px 1fr auto; grid-auto-rows: auto; }
  .rows .what { grid-column: 2 / -1; grid-row: 2; }
  .rows a:has(.status) .what { grid-column: 2; }
  .rows a:has(.status) time { grid-column: 3; grid-row: 2; justify-self: end; white-space: nowrap; }
  .rows .clip { display: none; }
  .out-detail { padding-left: 12px; }
  main { padding: 14px 12px 60px; }
}
