/* Courier. Onionskin paper, fountain-pen ink, and one airmail stripe. */

:root {
  --paper: #eff2f6;
  --sheet: #ffffff;
  --ink: #1b2a47;
  --ink-2: #5b6680;
  --rule: #d9dee8;
  --blue: #234aa0;
  --blue-ink: #ffffff;
  --red: #c4343e;
  --select: #e3eaf7;
  --hover: #f3f6fb;
  --focus: #234aa0;
  --shadow: 0 18px 50px rgba(27, 42, 71, 0.18), 0 2px 6px rgba(27, 42, 71, 0.08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --stripe: repeating-linear-gradient(-45deg, var(--red) 0 12px, var(--sheet) 12px 18px, var(--blue) 18px 30px, var(--sheet) 30px 36px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1626;
    --sheet: #151e31;
    --ink: #e5e9f2;
    --ink-2: #98a2b8;
    --rule: #26314a;
    --blue: #7fa2f0;
    --blue-ink: #0f1626;
    --red: #f07b83;
    --select: #1e2b47;
    --hover: #1a2439;
    --focus: #9db8f5;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    --stripe: repeating-linear-gradient(-45deg, #c4343e 0 12px, var(--sheet) 12px 18px, #3b63c4 18px 30px, var(--sheet) 30px 36px);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14.5px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- controls ------------------------------------------------------------------ */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--sheet); color: var(--ink);
  font-weight: 550; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.button:hover { background: var(--hover); }
.button.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.quiet { border-color: transparent; background: transparent; }
.button.quiet:hover { background: var(--hover); }
.button.danger { color: var(--red); }
.button:disabled { opacity: .55; cursor: default; }
.button svg { width: 16px; height: 16px; flex: none; }

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

input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--sheet);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }

/* --- the frame ---------------------------------------------------------------------- */

.shell {
  display: grid; height: 100vh; height: 100dvh;
  grid-template: "bar bar bar" auto "folders list reader" 1fr / 220px minmax(300px, 400px) 1fr;
}
.bar {
  grid-area: bar; position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px 10px; background: var(--sheet); border-bottom: 1px solid var(--rule);
}
.bar::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--stripe); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font: 600 20px/1 var(--serif); letter-spacing: -.01em; }
.brand img { width: 28px; height: 28px; }
.search { flex: 1; max-width: 520px; margin-left: 28px; position: relative; }
.search input { padding-left: 34px; background: var(--paper); border-color: transparent; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.bar .spacer { flex: 1; }
.me {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule);
  background: var(--paper); color: var(--ink); font-weight: 650; font-size: 13px; cursor: pointer;
}
.menu-button { display: none; }

/* --- folders ------------------------------------------------------------------------ */

.folders { grid-area: folders; overflow-y: auto; padding: 12px 8px; border-right: 1px solid var(--rule); }
.folders ul { list-style: none; margin: 0; padding: 0; }
.folder {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer;
}
.folder:hover { background: var(--hover); }
.folder[aria-current=true] { background: var(--select); font-weight: 650; }
.folder .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { color: var(--blue); font-weight: 650; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.folder:disabled { color: var(--ink-2); cursor: default; background: none; }
.folders .group { margin: 16px 10px 6px; color: var(--ink-2); font-size: 12.5px; }

/* --- message list ------------------------------------------------------------------- */

.list { grid-area: list; display: flex; flex-direction: column; min-height: 0; background: var(--sheet); border-right: 1px solid var(--rule); }
.list-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 10px 18px; border-bottom: 1px solid var(--rule); }
.list-head h2 { flex: 1; margin: 0; font: 600 18px/1.2 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-head .total { color: var(--ink-2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.rows { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.row {
  display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; grid-template-areas: "mark who when" ". subject marks";
  column-gap: 6px; row-gap: 1px;
  padding: 10px 14px 10px 8px; border-bottom: 1px solid var(--rule); border-left: 3px solid transparent; cursor: pointer;
}
.row:hover { background: var(--hover); }
.row[aria-selected=true] { background: var(--select); border-left-color: var(--blue); }
.row .mark { grid-area: mark; align-self: center; justify-self: center; width: 7px; height: 7px; transform: rotate(45deg); }
.row.unread .mark { background: var(--red); }
.row .who { grid-area: who; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { grid-area: when; color: var(--ink-2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.row .subject { grid-area: subject; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.row .marks { grid-area: marks; display: flex; gap: 4px; color: var(--ink-2); }
.row .marks svg { width: 14px; height: 14px; }
.row .marks .flag { color: var(--red); }
.row.unread .who, .row.unread .subject { color: var(--ink); font-weight: 650; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--rule); color: var(--ink-2); font-size: 12.5px; }
.empty { padding: 48px 24px; color: var(--ink-2); text-align: center; }
.empty strong { display: block; margin-bottom: 4px; color: var(--ink); font: 600 17px/1.3 var(--serif); }

/* --- reading pane ------------------------------------------------------------------- */

.reader { grid-area: reader; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; }
.tools { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 20px; background: var(--paper); border-bottom: 1px solid var(--rule); }
.tools .gap { flex: 1; }
.tools select { width: auto; min-height: 34px; padding: 0 10px; font-weight: 550; }
.back-button { display: none; }
.letter { display: flex; flex-direction: column; flex: 1; padding: 22px 28px 28px; max-width: 980px; }
.letter h1 { margin: 0 0 14px; font: 600 27px/1.25 var(--serif); letter-spacing: -.01em; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.meta .from strong { font-weight: 650; }
.meta .from span, .meta .to { color: var(--ink-2); overflow-wrap: anywhere; }
.meta time { grid-row: 1; grid-column: 2; color: var(--ink-2); font-size: 13px; text-align: right; }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding: 8px 8px 8px 14px; border-radius: 8px; background: var(--select); color: var(--ink); font-size: 13.5px; }
.attachments { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; padding: 0; }
.attachments a {
  display: flex; align-items: center; gap: 8px; max-width: 300px; padding: 7px 12px 7px 10px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--sheet); color: var(--ink); text-decoration: none;
}
.attachments a:hover { border-color: var(--blue); }
.attachments svg { width: 16px; height: 16px; flex: none; color: var(--ink-2); }
.attachments .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachments .size { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; }
.html-body { flex: 1; width: 100%; min-height: 420px; margin-top: 18px; border: 1px solid var(--rule); border-radius: 12px; background: #fff; }
.text-body { margin-top: 20px; max-width: 72ch; font: 16.5px/1.65 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.text-body blockquote { margin: 4px 0; padding-left: 14px; border-left: 3px solid var(--rule); color: var(--ink-2); }
.reader .empty { margin: auto; }
.view-toggle { margin-top: 10px; align-self: flex-start; }

/* --- compose ------------------------------------------------------------------------ */

.compose {
  position: fixed; right: 24px; bottom: 0; z-index: 20;
  display: flex; flex-direction: column; width: min(620px, calc(100vw - 48px)); height: min(640px, calc(100dvh - 72px));
  background: var(--sheet); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); overflow: hidden;
  animation: rise .22s ease-out;
}
.compose::before { content: ""; height: 6px; flex: none; background: var(--stripe); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.compose-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px 18px; }
.compose-head h2 { flex: 1; margin: 0; font: 600 17px/1.2 var(--serif); }
.field { display: flex; align-items: center; gap: 8px; margin: 0 18px; border-bottom: 1px solid var(--rule); }
.field > span { width: 58px; flex: none; color: var(--ink-2); }
.field input { border: 0; border-radius: 0; padding-left: 0; background: transparent; }
.field input:focus { outline: none; }
.field:focus-within { border-bottom-color: var(--blue); }
.field .button { min-height: 28px; padding: 0 8px; font-size: 13px; }
.compose textarea { flex: 1; min-height: 120px; margin: 0; padding: 14px 18px; border: 0; border-radius: 0; resize: none; font: 16px/1.6 var(--serif); background: transparent; }
.compose textarea:focus { outline: none; }
.files { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0 18px; }
.files li { display: flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 8px; background: var(--paper); font-size: 13px; }
.files li button { width: 24px; height: 24px; }
.compose-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--rule); }
.compose-foot .note { flex: 1; color: var(--ink-2); font-size: 12.5px; }
.compose-error { margin: 8px 18px 0; color: var(--red); font-size: 13.5px; }

/* --- set-up and settings ------------------------------------------------------------ */

.setup { min-height: 100dvh; padding: 0 16px 48px; }
.setup::before { content: ""; display: block; height: 4px; margin: 0 -16px; background: var(--stripe); }
.setup-inner { max-width: 640px; margin: 0 auto; }
.setup header { display: flex; align-items: center; gap: 12px; padding: 22px 0 8px; }
.setup header .brand { flex: 1; }
.setup h1 { margin: 26px 0 6px; font: 600 30px/1.2 var(--serif); letter-spacing: -.01em; }
.setup .lede { margin: 0 0 24px; color: var(--ink-2); max-width: 60ch; }
.setup fieldset { margin: 0 0 18px; padding: 18px 20px 20px; border: 1px solid var(--rule); border-radius: 12px; background: var(--sheet); }
.setup legend { padding: 0 6px; margin-left: -6px; font: 600 16px/1 var(--serif); }
.setup .grid { display: grid; grid-template-columns: 1fr 110px 150px; gap: 12px; }
.setup .grid.two { grid-template-columns: 1fr 1fr; }
.setup label.stack { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.setup label.stack > input, .setup label.stack > select { color: var(--ink); font-size: 14.5px; }
.setup .check { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.setup .hint { margin: 10px 0 0; color: var(--ink-2); font-size: 13px; }
.setup .lock { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 18px; padding: 12px 14px; border-radius: 12px; background: var(--select); font-size: 13.5px; }
.setup .lock svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--blue); }
.setup .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; }
.setup .error { margin: 0 0 16px; padding: 12px 14px; border-left: 3px solid var(--red); border-radius: 8px; background: var(--sheet); color: var(--ink); }
.setup .about { margin-top: 36px; color: var(--ink-2); font-size: 12.5px; }

/* --- toast -------------------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 30; transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 8px;
  background: var(--ink); color: var(--sheet); box-shadow: var(--shadow); font-weight: 550;
}
.toast.error { background: var(--red); color: #fff; }

/* --- signed-out page and message pages: an airmail envelope ------------------------- */

.gate { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.envelope {
  position: relative; width: min(560px, 100%); padding: 44px 44px 40px;
  border: 12px solid; border-image: repeating-linear-gradient(-45deg, #c4343e 0 16px, #fff 16px 24px, #234aa0 24px 40px, #fff 40px 48px) 12;
  background: var(--sheet); box-shadow: var(--shadow);
}
.envelope .stamp { position: absolute; top: 22px; right: 22px; width: 64px; height: 76px; padding: 6px; background: var(--paper); border: 2px dashed var(--rule); transform: rotate(4deg); }
.envelope .stamp img { width: 100%; height: 100%; }
.envelope h1 { margin: 0 0 12px; font: 600 44px/1 var(--serif); letter-spacing: -.02em; }
.envelope p { margin: 0 0 26px; max-width: 34ch; color: var(--ink-2); font-size: 16px; }
.envelope .address { margin: 34px 0 0; padding-top: 16px; border-top: 1px solid var(--rule); color: var(--ink-2); font: italic 14px/1.5 var(--serif); }
.envelope .button { min-height: 42px; padding: 0 20px; font-size: 15px; }
.gate-card { width: min(460px, 100%); padding: 32px; border-radius: 12px; background: var(--sheet); box-shadow: var(--shadow); }
.gate-card::before { content: ""; display: block; height: 6px; margin: -32px -32px 26px; border-radius: 12px 12px 0 0; background: var(--stripe); }
.gate-logo { width: 40px; height: 40px; }
.gate-card h1 { margin: 14px 0 8px; font: 600 24px/1.25 var(--serif); }
.gate-card p { margin: 0 0 22px; color: var(--ink-2); }

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

@media (max-width: 1100px) {
  .shell { grid-template-columns: 200px minmax(280px, 340px) 1fr; }
  .search { margin-left: 8px; }
}

@media (max-width: 860px) {
  .shell { grid-template: "bar" auto "main" 1fr / 1fr; }
  .menu-button { display: inline-grid; }
  .brand span { display: none; }
  .search { margin-left: 0; }
  .list, .reader { grid-area: main; border-right: 0; }
  .shell[data-view=list] .reader, .shell[data-view=reader] .list { display: none; }
  .back-button { display: inline-flex; }
  .folders {
    position: fixed; inset: 0 auto 0 0; z-index: 25; width: min(300px, 85vw); padding-top: 18px;
    background: var(--sheet); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s ease;
  }
  .shell.drawer .folders { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 24; background: rgba(15, 22, 38, .35); }
  .letter { padding: 18px 16px 24px; }
  .letter h1 { font-size: 23px; }
  .tools { padding: 8px 10px; }
  .compose { inset: 0; width: auto; height: auto; border-radius: 0; }
  .setup .grid { grid-template-columns: 1fr 90px; }
  .setup .grid > :nth-child(3) { grid-column: 1 / -1; }
  .envelope { padding: 32px 24px; }
  .envelope h1 { font-size: 36px; }
  .envelope .stamp { width: 48px; height: 58px; }
}

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