/* Titip: paper, ink and one airmail stripe. Tokens first; components use only tokens. */
:root {
  --paper: #f4efe6;
  --card: #fffdf8;
  --ink: #16202b;
  --muted: #55606c;
  --line: #d9cfbd;
  --accent: #1d4f91;        /* airmail blue: links, primary buttons */
  --on-accent: #ffffff;
  --stamp: #b3261e;         /* airmail red: the stripe, the unread mark, errors */
  --wash: #e9e1d2;          /* pressed / selected rows */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --tap: 48px;
  --radius: 10px;
  --ui: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --letter: Georgia, "Iowan Old Style", "Times New Roman", serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #12171d;
  --card: #1a2129;
  --ink: #eef0f2;
  --muted: #a6b0bb;
  --line: #313c47;
  --accent: #2c69b8;
  --on-accent: #ffffff;
  --stamp: #f08a80;
  --wash: #232c36;
  color-scheme: dark;
}
:root[data-theme="dark"] .link,
:root[data-theme="dark"] .tabs a[aria-current="page"],
:root[data-theme="dark"] .back { color: #9cc2f5; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--ui);
  min-height: 100dvh;
  overflow-wrap: anywhere;
}
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
:root[data-theme="dark"] :focus-visible { outline-color: #9cc2f5; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s4);
  padding-top: max(var(--s3), env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.bar::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: repeating-linear-gradient(135deg, #b3261e 0 14px, #fffdf8 14px 22px, #1d4f91 22px 36px, #fffdf8 36px 44px);
}
.brand {
  display: flex; align-items: center; gap: var(--s2);
  font: 700 20px/1 var(--letter); letter-spacing: 0.01em;
}
.brand img { display: block; }
.tools { margin-left: auto; display: flex; gap: var(--s1); }
.icon {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%;
}
.icon:hover, .icon[aria-expanded="true"] { background: var(--wash); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.busy svg { animation: turn 0.9s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: var(--s1); }
.tabs a {
  min-height: var(--tap); padding: 0 var(--s4);
  display: inline-flex; align-items: center; gap: var(--s2);
  color: var(--muted); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: currentColor; }
.count {
  min-width: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--wash); color: var(--ink); font-size: 13px; line-height: 22px; text-align: center;
}

.search { padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line); background: var(--paper); }
.search input, .field input, .field textarea {
  width: 100%; min-height: var(--tap);
  padding: var(--s2) var(--s3);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.demo {
  padding: var(--s2) var(--s4); font-size: 14px; color: var(--muted);
  border-bottom: 1px dashed var(--line);
}

/* ---------- list */
.panes { display: block; }
.state { padding: var(--s6) var(--s4); color: var(--muted); text-align: center; }
.state:empty { display: none; }
.state strong { display: block; color: var(--ink); font: 700 18px/1.3 var(--letter); margin-bottom: var(--s1); }
.state button, .more, .composeFoot button, .actions button {
  min-height: var(--tap); padding: 0 var(--s4);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); font-weight: 600;
}
.state button { margin-top: var(--s3); }
.more { display: block; margin: var(--s4) auto var(--s6); }

.row {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; column-gap: var(--s2);
  width: 100%; padding: var(--s3) var(--s4) var(--s3) var(--s2);
  text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
}
.row:hover, .row[aria-current="true"] { background: var(--wash); }
.row .mark { grid-row: 1 / span 3; align-self: start; margin-top: 8px; width: 8px; height: 8px; border-radius: 50%; }
.row.unread .mark { background: var(--stamp); }
.row .who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .who, .row.unread .subject { font-weight: 700; }
.row.unread .time { color: var(--ink); font-weight: 600; }
.row .time { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row .subject { grid-column: 2 / span 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .preview {
  grid-column: 2 / span 2; color: var(--muted); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row .clip { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }
.skeleton { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.skeleton i { display: block; height: 12px; margin: 6px 0; border-radius: 6px; background: var(--wash); }
.skeleton i:first-child { width: 38%; } .skeleton i:nth-child(2) { width: 72%; } .skeleton i:last-child { width: 90%; }

/* ---------- reader */
.reader { display: none; padding: var(--s3) var(--s4) calc(var(--tap) + var(--s6)); }
.hint, .wait { color: var(--muted); padding: var(--s6) 0; text-align: center; }
#letter.opening .meta, #letter.opening .files, #letter.opening .view, #letter.opening .actions { display: none; }
.back, .link {
  min-height: var(--tap); padding: 0 var(--s2) 0 0;
  display: inline-flex; align-items: center; gap: var(--s1);
  background: none; border: 0; color: var(--accent); font-weight: 600;
}
.reader h2 { font: 700 22px/1.3 var(--letter); margin: var(--s2) 0 var(--s3); }
.meta { font-size: 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: var(--s2) 0; }
.meta div { display: grid; grid-template-columns: 52px minmax(0, 1fr); padding: 2px 0; }
.meta dt { color: var(--muted); }
.files { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.files a {
  min-height: var(--tap); padding: 0 var(--s3); max-width: 100%;
  display: inline-flex; align-items: center; gap: var(--s2);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; font-size: 14px;
}
.files small { color: var(--muted); font-size: 13px; white-space: nowrap; }
.view { display: flex; justify-content: flex-end; }
.view .link { font-size: 14px; }
.body { margin-top: var(--s2); }
.body pre {
  margin: 0; white-space: pre-wrap; font: 16px/1.6 var(--letter); max-width: 68ch;
}
.body iframe { display: block; width: 100%; min-height: 200px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; gap: var(--s2); padding: var(--s2) var(--s4);
  padding-bottom: max(var(--s2), env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line);
}
.actions button { flex: 1; padding: 0 var(--s2); }
.primary, .actions .primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button:disabled { opacity: 0.55; cursor: default; }

/* ---------- write button + composer */
.write {
  position: fixed; right: var(--s4); bottom: calc(var(--tap) + var(--s5) + env(safe-area-inset-bottom)); z-index: 4;
  min-height: 52px; padding: 0 var(--s5) 0 var(--s4);
  display: inline-flex; align-items: center; gap: var(--s2);
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 26px; font-weight: 700;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}
.composer {
  position: fixed; inset: 0; z-index: 10; background: var(--card);
  display: flex; flex-direction: column; overflow: auto;
}
.stripe {
  flex: none; height: 8px;
  background: repeating-linear-gradient(135deg, #b3261e 0 14px, #fffdf8 14px 22px, #1d4f91 22px 36px, #fffdf8 36px 44px);
}
.composer form { flex: 1; display: flex; flex-direction: column; gap: var(--s3); padding: var(--s2) var(--s4) var(--s4); }
.composeBar { display: flex; align-items: center; gap: var(--s3); }
.composeBar h2 { flex: 1; font: 700 18px/1.2 var(--letter); text-align: center; }
.composeBar .primary { min-height: var(--tap); padding: 0 var(--s5); border: 0; border-radius: var(--radius); font-weight: 700; }
.field { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; }
.field > span { color: var(--muted); font-size: 14px; }
.field.grow { flex: 1; grid-template-columns: minmax(0, 1fr); align-items: stretch; }
.field textarea { height: 100%; min-height: 180px; resize: none; font: 16px/1.6 var(--letter); }
.note { font-size: 14px; color: var(--muted); }
.error { font-size: 14px; color: var(--stamp); font-weight: 600; }
.composeFoot { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.footNote { color: var(--muted); font-size: 13px; }

/* ---------- toast */
.toast {
  position: fixed; left: var(--s4); right: var(--s4); bottom: calc(var(--tap) + var(--s5) + 52px + var(--s3) + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  min-height: 52px; padding: var(--s1) var(--s2) var(--s1) var(--s4);
  background: var(--ink); color: var(--paper); border-radius: var(--radius);
}
.toast button { min-height: 44px; padding: 0 var(--s4); background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; }

/* ---------- phone: folders at the thumb, one pane at a time */
@media (max-width: 859px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
    justify-content: space-around; gap: 0;
    background: var(--paper); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs a { flex: 1; justify-content: center; min-height: 56px; border-bottom: 0; border-top: 3px solid transparent; }
  .tabs a[aria-current="page"] { border-top-color: currentColor; }
  .list { padding-bottom: calc(56px + 76px); }
  body.reading .list, body.reading .tabs, body.reading .write, body.reading .search, body.reading .demo { display: none; }
  body.reading .reader { display: block; }
  body.reading .hint { display: none; }
  body.reading .toast, body.composing .toast { bottom: calc(var(--tap) + var(--s5) + env(safe-area-inset-bottom)); }
}

/* ---------- wide screens: list and letter side by side */
@media (min-width: 860px) {
  .bar { padding-left: var(--s5); padding-right: var(--s5); }
  .tabs { margin-left: var(--s5); }
  body { display: flex; flex-direction: column; height: 100dvh; }
  .panes { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .list { overflow: auto; border-right: 1px solid var(--line); }
  .reader { display: block; overflow: auto; padding: var(--s5) var(--s6) 0; }
  .reader #letter { max-width: 820px; }
  .back { display: none; }
  .actions { position: sticky; bottom: 0; z-index: 2; margin-top: var(--s5); padding: var(--s3) 0; justify-content: flex-start; }
  .actions button { flex: 0 1 132px; }
  .write { bottom: var(--s5); right: var(--s5); }
  .composer { inset: auto var(--s5) 0 auto; width: 520px; max-height: 86dvh; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; box-shadow: 0 8px 30px rgb(0 0 0 / 0.25); }
  .toast { left: auto; right: var(--s5); bottom: calc(var(--s5) + 52px + var(--s3)); min-width: 340px; }
  body.composing .write { display: none; }
}

@media (prefers-reduced-motion: reduce) { .icon.busy svg { animation: none; } }

/* ---------- pairing and desk pages */
.sheet { max-width: 560px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }
.sheet h1 { font: 700 28px/1.2 var(--letter); margin: var(--s4) 0 var(--s2); }
.sheet h2 { font: 700 18px/1.3 var(--letter); margin: var(--s5) 0 var(--s2); }
.sheet p { margin: var(--s2) 0; }
.sheet .soft { color: var(--muted); font-size: 14px; }
.sheet .qr { display: grid; place-items: center; margin-top: var(--s4); padding: var(--s4); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); min-height: 260px; }
/* the code is drawn as 1-unit lines: undo the icon stroke settings or the squares bleed into each other */
.sheet .qr svg { width: min(260px, 100%); height: auto; stroke-width: 1; stroke-linecap: butt; stroke-linejoin: miter; }
.sheet button { min-height: var(--tap); padding: 0 var(--s4); border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.sheet button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.sheet .rowline { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-top: var(--s3); }
.sheet li { padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.sheet code { font: 14px/1.4 ui-monospace, Consolas, monospace; background: var(--wash); padding: 2px 6px; border-radius: 4px; }
.good { color: #1f6b3a; font-weight: 600; }
.bad { color: var(--stamp); font-weight: 600; }
:root[data-theme="dark"] .good { color: #7fd6a0; }

/* ---------- autopilot page */
.sheet.wide { max-width: 720px; }
body.auto { display: block; height: auto; }
body.auto .sheet { padding-bottom: calc(56px + var(--s6) + env(safe-area-inset-bottom)); }
.lamp { display: flex; align-items: center; gap: var(--s3); font: 700 28px/1.2 var(--letter); }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.dot.on { background: #1f6b3a; }
:root[data-theme="dark"] .dot.on { background: #7fd6a0; }
.now { color: var(--accent); font-weight: 600; }
:root[data-theme="dark"] .now { color: #9cc2f5; }
.choice { margin: var(--s4) 0 0; padding: var(--s1) var(--s4); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.choice legend { padding: 0 var(--s2); color: var(--muted); font-size: 14px; }
.choice label { display: flex; align-items: flex-start; gap: var(--s3); min-height: var(--tap); padding: var(--s3) 0; cursor: pointer; }
.choice label + label { border-top: 1px solid var(--line); }
.choice input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.choice span { color: var(--muted); font-size: 14px; }
.choice strong { display: block; color: var(--ink); font-size: 16px; }
.letter h3 { margin: 2px 0 var(--s1); font: 700 18px/1.3 var(--letter); }
.letter .who, .entry .about { color: var(--muted); font-size: 14px; }
.letter .why { color: var(--stamp); font-size: 14px; font-weight: 600; }
.letter textarea {
  display: block; width: 100%; margin-top: var(--s2); padding: var(--s3);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  font: 16px/1.6 var(--letter); resize: vertical;
}
.sheet .letter { padding: var(--s4) 0; }
.feed { margin: 0; padding: 0; list-style: none; }
.entry .head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); margin: 0; }
.entry .tag { font-size: 14px; font-weight: 700; }
.entry.sent .tag { color: #1f6b3a; }
:root[data-theme="dark"] .entry.sent .tag { color: #7fd6a0; }
.entry.held .tag, .entry.error .tag { color: var(--stamp); }
.entry time { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry .about, .entry .what { margin: 2px 0 0; }
.entry blockquote { margin: var(--s2) 0 0; padding-left: var(--s3); border-left: 3px solid var(--line); white-space: pre-wrap; font: 15px/1.6 var(--letter); }
.plain li { position: relative; padding: 2px 0 2px var(--s4); border: 0; color: var(--muted); font-size: 14px; }
.plain li::before { content: "\2013"; position: absolute; left: 0; }
.sheet .link { min-height: var(--tap); padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; }
:root[data-theme="dark"] .sheet .link { color: #9cc2f5; }
body.auto .toast { bottom: calc(56px + var(--s4) + env(safe-area-inset-bottom)); }
@media (min-width: 860px) {
  body.auto .sheet { padding-bottom: var(--s6); }
  body.auto .toast { bottom: var(--s5); }
}
.sheet .go {
  min-height: var(--tap); padding: 0 var(--s4); display: inline-flex; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); font-weight: 600; text-decoration: none;
}
