:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #14213d;
  --muted: #5b6478;
  --line: #dadfe7;
  --accent: #2f5bff;
  --accent-ink: #fff;
  --danger: #c4283a;
  --warn: #7a4f00;
  --warn-bg: #fff3d6;
  --star: #e0a100;
  --sel: #e8eeff;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --top-h: 6.1rem;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1830;
    --panel: #16213f;
    --ink: #e8ecf5;
    --muted: #98a2b8;
    --line: #25304d;
    --accent: #6b8cff;
    --accent-ink: #0b1224;
    --danger: #ff7a86;
    --warn: #ffd27a;
    --warn-bg: #3a2c0d;
    --star: #ffc940;
    --sel: #1e2c55;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* No pinch or double-tap zoom: it's an app, not a page. Text sizes are set so iOS never zooms into a field. */
html { -webkit-text-size-adjust: 100%; touch-action: pan-x pan-y; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, .button, input, textarea { font: inherit; color: inherit; }
button, .button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button:disabled { opacity: 0.55; cursor: default; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); }
button.link.small { font-size: 0.85rem; }
.ico { width: 1.2rem; height: 1.2rem; flex-shrink: 0; }
.ibtn { width: 2.5rem; height: 2.5rem; padding: 0; border-radius: 50%; display: inline-grid; place-items: center; color: var(--muted); text-decoration: none; }
.ibtn:hover { color: var(--ink); }
.ibtn.bare { border: 0; background: none; width: 2rem; height: 2rem; min-height: 0; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 0.65rem 0.75rem;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
input[aria-invalid="true"] { border-color: var(--danger); }
textarea { resize: vertical; line-height: 1.5; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; min-height: 1.2em; }
.error:empty { display: none; }
.empty { color: var(--muted); text-align: center; padding: 3rem 1.5rem; max-width: 34rem; margin: 0 auto; }
.boot { display: grid; place-items: center; height: 100vh; font-size: 3rem; color: var(--accent); font-weight: 800; }
.grow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: none), (max-width: 700px) { .desktop-only { display: none !important; } }

.dot {
  display: inline-grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 8px;
  background: #14213d;
  color: #8ea8ff;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1;
}

/* sign-in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.card { width: min(380px, 100%); display: grid; gap: 0.9rem; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1.5rem; }
.card label { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.card p { margin: 0; }
.card .link { justify-self: center; font-size: 0.9rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; margin-bottom: 0.4rem; }
.secret { font: 600 0.95rem/1.4 ui-monospace, Menlo, monospace; letter-spacing: 0.04em; background: var(--bg); padding: 0.6rem; border-radius: 8px; overflow-wrap: anywhere; word-spacing: 0.15em; user-select: all; }

/* header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  /* Solid, not frosted: in the installed iPhone app a backdrop blur smears whatever is above the screen
     into the status bar area. */
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
}
.bar { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.9rem 0.35rem; max-width: 860px; margin: 0 auto; }
.logo { text-decoration: none; }
.search { flex: 1; position: relative; }
.search .ico { position: absolute; left: 0.8rem; top: 50%; translate: 0 -50%; color: var(--muted); width: 1.05rem; height: 1.05rem; pointer-events: none; }
.search input { border-radius: 999px; padding: 0.5rem 0.95rem 0.5rem 2.3rem; }
.folders {
  display: flex; gap: 0.25rem; overflow-x: auto; padding: 0.15rem 0.9rem 0.5rem; max-width: 860px; margin: 0 auto; scrollbar-width: none;
  mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
}
.folders::-webkit-scrollbar { display: none; }
.folders a { text-decoration: none; padding: 0.3rem 0.75rem; border-radius: 999px; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.folders a.on { background: var(--ink); color: var(--bg); }
.folders a:last-child { margin-right: 1.5rem; }

main { max-width: 860px; margin: 0 auto; padding: 0 0 calc(6rem + var(--safe-bottom)); }

/* toolbars */
.toolbar { display: flex; align-items: center; gap: 0.35rem; padding: 0.6rem 0; position: sticky; top: calc(var(--top-h) + var(--safe-top)); z-index: 3; background: var(--bg); }
.toolbar h1 { font-size: 1.2rem; margin: 0; }
.toolbar .tool { padding: 0.4rem 0.75rem; color: var(--muted); }
.toolbar .tool:hover { color: var(--ink); }
.star-btn[aria-pressed="true"] { color: var(--star); border-color: var(--star); }
.star-btn[aria-pressed="true"] .ico { fill: currentColor; }
@media (max-width: 700px) {
  .toolbar .tool { width: 2.5rem; padding: 0; border-radius: 50%; }
  .toolbar .tool span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

/* list */
.results { padding: 0.8rem 1rem 0; margin: 0; font-size: 0.9rem; }
.row { display: block; text-decoration: none; padding: 0.8rem 1rem; border-bottom: 1px solid var(--line); background: var(--bg); touch-action: pan-y; transition: transform 0.2s; outline-offset: -2px; }
.row:hover { background: var(--panel); }
.row.sel { background: var(--sel); }
.line1 { display: flex; align-items: center; gap: 0.45rem; }
.from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row time { color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }
.mark { color: var(--muted); display: inline-flex; }
.mark .ico { width: 0.95rem; height: 0.95rem; }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.95rem; }
.snippet { color: var(--muted); font-size: 0.88rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row.unread .from, .row.unread .subject { font-weight: 650; }
.row.unread { box-shadow: inset 3px 0 0 var(--ink); }
.row.important.unread { box-shadow: inset 3px 0 0 var(--accent); }
.star { color: var(--star); margin-right: 0.3rem; display: inline-flex; vertical-align: -0.12em; }
.star .ico { width: 0.9rem; height: 0.9rem; fill: currentColor; }
.tag { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; flex-shrink: 0; }
.tag.draft { color: var(--danger); border-color: currentColor; }
.tag.important { color: var(--accent); border-color: currentColor; }
.more { display: flex; margin: 1rem auto; }
.sentinel { height: 1px; }

.swipe { position: relative; overflow: hidden; transition: height 0.2s, opacity 0.2s; }
.swipe-bg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; padding: 0 1.4rem; background: var(--muted); color: #fff; font-weight: 600; }
.swipe .row { position: relative; z-index: 1; }
.swipe.armed .swipe-bg { background: var(--accent); }
.swipe.gone { opacity: 0; }

.ptr { height: 0; overflow: visible; display: grid; place-items: center; position: relative; z-index: 2; }
.ptr .ico { position: absolute; top: 0.4rem; color: var(--accent); opacity: calc(var(--pull, 0) / 80); transform: translateY(calc(var(--pull, 0) * 0.5px)) rotate(calc(var(--pull, 0) * 3deg)); }
.ptr.armed .ico { color: var(--ink); }
.ptr.spin .ico { opacity: 1; transform: translateY(30px); animation: spin 0.8s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }

.fab {
  position: fixed;
  right: max(1.1rem, calc((100vw - 860px) / 2 + 1.1rem));
  bottom: calc(1.2rem + var(--safe-bottom));
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  text-decoration: none;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.22);
  z-index: 6;
}
.fab .ico { width: 1.45rem; height: 1.45rem; }

/* message */
.message { padding: 0 1rem calc(6rem + var(--safe-bottom)); }
.message h1 { font-size: 1.35rem; line-height: 1.25; margin: 0.4rem 0 0.7rem; overflow-wrap: anywhere; }
.summary { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.8rem; margin: 0 0 0.8rem; font-size: 0.92rem; display: flex; gap: 0.6rem; align-items: baseline; }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 0.6rem 0.8rem; font-size: 0.9rem; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.8rem; font-size: 0.88rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.chips { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { position: relative; overflow: hidden; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 0.35rem 0.4rem 0.35rem 0.6rem; display: flex; gap: 0.4rem; align-items: center; font-size: 0.88rem; max-width: 100%; }
.chip a { display: inline-flex; gap: 0.4rem; align-items: center; min-width: 0; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip .ico { width: 1rem; height: 1rem; color: var(--muted); }
.chip .bar { position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--p, 0) * 100%); background: var(--accent); display: none; }
.chip.uploading .bar { display: block; }
.chip.uploading .name { color: var(--muted); }
.chip.failed { border-color: var(--danger); color: var(--danger); }
.images-note { font-size: 0.88rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; align-items: baseline; margin: 0 0 0.5rem; }
iframe.body { width: 100%; border: 0; border-radius: var(--radius); background: #fff; min-height: 120px; display: block; }
.textbody { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; font-size: 0.95rem; }
.foot { font-size: 0.8rem; color: var(--muted); }
.replybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; justify-content: center; gap: 0.5rem;
  padding: 0.6rem 1rem calc(0.6rem + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.replybar .button { flex: 1; max-width: 12rem; }

/* compose */
.compose { display: grid; gap: 0.5rem; padding: 0 1rem; }
.compose .from { margin: 0; font-size: 0.85rem; }
.field { display: grid; grid-template-columns: 4.2rem 1fr auto; align-items: center; gap: 0 0.5rem; color: var(--muted); font-size: 0.88rem; }
.field > span:first-child { grid-column: 1; grid-row: 1; }
.field > input { grid-column: 2; grid-row: 1; }
.field > button { grid-column: 3; grid-row: 1; }
.field .field-error { grid-column: 2 / -1; grid-row: 2; color: var(--danger); font-size: 0.82rem; padding-top: 0.2rem; }
.field .field-error:empty { display: none; }
.field[hidden] { display: none; }
.compose textarea { min-height: 45vh; }
.compose.drop { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: var(--radius); }
.compose .chips { margin: 0; }
.compose .chips:empty { display: none; }
.hint { font-size: 0.8rem; margin: 0; }
@media (hover: none) { .hint { display: none; } }

/* settings */
.settings { padding: 0 1rem; }
.settings section { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; margin-bottom: 1rem; display: grid; gap: 0.6rem; justify-items: start; }
.settings section > textarea { justify-self: stretch; }
.settings h2 { font-size: 1rem; margin: 0; }
.settings p { margin: 0; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.9rem; }
.keys dd { margin: 0; color: var(--muted); }
kbd { font: 600 0.8rem/1 ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0.15rem 0.35rem; background: var(--bg); white-space: nowrap; }
dialog.help { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); padding: 1.2rem 1.4rem; max-width: min(28rem, 92vw); }
dialog.help::backdrop { background: rgb(0 0 0 / 0.35); }
dialog.help h2 { margin: 0 0 0.8rem; font-size: 1.1rem; }
dialog.help form { margin-top: 1rem; display: flex; justify-content: flex-end; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(5.2rem + var(--safe-bottom)); z-index: 20;
  transform: translate(-50%, 1rem); opacity: 0; transition: 0.22s;
  display: flex; align-items: center; gap: 0.9rem;
  background: var(--ink); color: var(--bg); padding: 0.55rem 0.6rem 0.55rem 1rem; border-radius: 999px;
  max-width: calc(100vw - 2rem); font-size: 0.9rem; box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
.toast:not(:has(button)) { padding-right: 1rem; }
.toast span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast.err span { white-space: normal; }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 0.2rem 0.4rem; min-height: 0; filter: brightness(1.35); }
.toast.err { background: var(--danger); color: #fff; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

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

/* ---------- contact suggestions (compose) ---------- */
.field { position: relative; }
.suggest {
  position: absolute; z-index: 8; top: calc(100% + 2px); left: 4.7rem; right: 0;
  list-style: none; margin: 0; padding: 0.25rem; max-height: 16rem; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}
.suggest li { display: grid; padding: 0.45rem 0.6rem; border-radius: 8px; cursor: pointer; color: var(--ink); font-size: 0.95rem; }
.suggest li[aria-selected="true"] { background: var(--sel); }
.suggest .addr { color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { .suggest { left: 0; } }

/* ---------- contacts screen ---------- */
.contacts-view { padding: 0 1rem; }
.contacts-view > input[type="search"] { width: 100%; margin: 0.2rem 0 0.4rem; }
.contacts-view .count { margin: 0 0 0.4rem; font-size: 0.85rem; }
.contacts { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.contacts > li + li { border-top: 1px solid var(--line); }
.contact { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.8rem; }
.contact .who { display: grid; min-width: 0; flex: 1; }
.contact .who > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact .name { font-weight: 600; }
.contact .addr, .contact .meta { color: var(--muted); font-size: 0.85rem; }
.contact .actions { display: flex; gap: 0.15rem; flex: none; }
.contact.editing { display: grid; gap: 0.5rem; flex: 1; padding: 0; }
.contact.editing .actions { justify-content: flex-end; gap: 0.4rem; }
.add-contact { display: grid; gap: 0.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; margin-bottom: 0.8rem; }
.add-contact h2 { font-size: 1rem; margin: 0; }
.add-contact .field-error { color: var(--danger); font-size: 0.85rem; }
.add-contact .field-error:empty { display: none; }
.add-contact .actions { display: flex; justify-content: flex-end; gap: 0.4rem; }
.contact .who > .meta { white-space: normal; }
@media (max-width: 700px) { .contact { gap: 0.6rem; padding: 0.65rem; } .contact .actions .ibtn { width: 2.2rem; height: 2.2rem; } }

/* ---------- conversations ---------- */
.row .count, .thread h1 .count { color: var(--muted); font-size: 0.78rem; font-weight: 500; flex-shrink: 0; }
.thread h1 .count { font-size: 0.9rem; margin-left: 0.5rem; vertical-align: 0.1em; }
.row .from .unread-name { font-weight: 650; }
.row.unread .from { font-weight: 400; }
.row.unread .from .unread-name, .row.unread .subject { font-weight: 650; }

.msg { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 0.5rem; overflow: hidden; }
.msg-head {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.6rem; padding: 0.7rem 0.9rem;
}
.msg-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.msg-head .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .name { font-weight: 600; }
.msg-head .addr { color: var(--muted); font-size: 0.85rem; display: none; }
.msg-head time { color: var(--muted); font-size: 0.8rem; }
.msg-head .peek { grid-column: 1 / -1; color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .to { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; display: none; overflow-wrap: anywhere; }
.msg.unread .msg-head .name { font-weight: 750; }
.msg.unread { box-shadow: inset 3px 0 0 var(--accent); }
.msg.open .msg-head .peek { display: none; }
.msg.open .msg-head .addr, .msg.open .msg-head .to { display: inline; }
.msg.open .msg-head .to { display: block; }
.msg-body { display: none; padding: 0 0.9rem 0.4rem; }
.msg.open .msg-body { display: block; }
/* Inside a message card, the body is part of the card, not a box of its own. */
.msg-body .textbody { background: none; border: 0; padding: 0.2rem 0 0.6rem; border-radius: 0; }
.msg-body iframe.body { border: 0; border-radius: 0; margin: 0 -0.9rem; width: calc(100% + 1.8rem); max-width: none; }
.msg-body .summary { background: none; border: 0; border-radius: 0; padding: 0; margin: 0 0 0.6rem; }
.msg-body .foot { display: flex; gap: 1rem; margin: 0.4rem 0 0.4rem; }
.msg-body .foot a { color: var(--muted); }
.msg-body .foot a:hover { color: var(--ink); }
.show-quoted { min-height: 0; padding: 0 0.5rem; font-size: 0.8rem; letter-spacing: 0.1em; color: var(--muted); border-radius: 6px; margin-top: 0.4rem; }
.quoted { color: var(--muted); margin-top: 0.4rem; }
.draft-card { display: flex; gap: 0.6rem; align-items: center; padding: 0.7rem 0.9rem; text-decoration: none; border-style: dashed; }
.draft-card .peek { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field > input { font-size: 1rem; } /* 16px+ so iOS never zooms into the field */

/* ---------- portraits ---------- */
.avatar {
  --size: 2.5rem;
  flex: none; width: var(--size); height: var(--size); border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; font-weight: 650; font-size: calc(var(--size) * 0.42); line-height: 1;
  background: hsl(var(--hue, 220) 55% 90%); color: hsl(var(--hue, 220) 45% 32%);
  user-select: none;
}
@media (prefers-color-scheme: dark) { .avatar { background: hsl(var(--hue, 220) 30% 30%); color: hsl(var(--hue, 220) 70% 88%); } }
.avatar.has-img { background: #fff; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row { display: flex; gap: 0.75rem; align-items: flex-start; }
.row > .avatar { margin-top: 0.1rem; }
.row-main { flex: 1; min-width: 0; }
.msg-head { grid-template-columns: auto 1fr auto; }
.msg-head > .avatar { --size: 2.25rem; grid-row: 1 / span 2; align-self: start; }
.msg-head .peek, .msg-head .to { grid-column: 2 / -1; }
.contact > .avatar { --size: 2.4rem; }

/* A file being copied from the original (forwarding) has no byte progress: show a moving bar instead. */
.chip.copying .bar { width: 35%; animation: copying 1.1s ease-in-out infinite alternate; }
@keyframes copying { from { left: 0; } to { left: 65%; } }
@media (prefers-reduced-motion: reduce) { .chip.copying .bar { animation: none; width: 100%; opacity: 0.5; } }
