:root {
  --bg: #fff;
  --bg2: #f2f2f7;
  --card: #fff;
  --fg: #111114;
  --muted: #8a8a8f;
  --line: #e4e4e9;
  --accent: #0a7cff;
  --danger: #e5383b;
  --radius: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --side: max(16px, env(safe-area-inset-left, 0px));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --bg2: #0e0e11;
    --card: #17171a;
    --fg: #f2f2f5;
    --muted: #8e8e96;
    --line: #2a2a30;
    --accent: #3b95ff;
    --danger: #ff5d5d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; touch-action: manipulation; }
a { color: var(--accent); }

.app { min-height: 100%; display: flex; flex-direction: column; }

/* ------------------------------------------------------------------ header */
.head {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--top) + 10px) var(--side) 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; min-height: 52px;
}
.head h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .sub { font-size: 12px; font-weight: 400; color: var(--muted); }

/* Address doubles as the copy button — one tap, no extra icon in the bar. */
.addr {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px;
  font-size: 16px; font-weight: 650; letter-spacing: -0.01em;
  padding: 7px 8px; margin-left: -4px; border-radius: 10px; text-align: left;
}
.addr span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addr svg { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: var(--accent);
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.addr:active { background: var(--bg2); }

.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent);
}
.icon-btn:active { background: var(--bg2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.danger { color: var(--danger); }

/* -------------------------------------------------------------------- list */
.wrap { flex: 1; padding: 0 var(--side) calc(24px + var(--bottom)); }
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 4px; border-bottom: 1px solid var(--line);
}
.row:active { background: var(--bg2); }
.row .grow { flex: 1; min-width: 0; }
.row .t1 { display: flex; align-items: baseline; gap: 8px; }
.row .name { font-weight: 600; font-size: 16px; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.row .time { font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.row .t2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t3 { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-top: 1px; }
.row.unread .name, .row.unread .t2 { font-weight: 700; }

.badge {
  flex: 0 0 auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}
.dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.dot.hidden { visibility: hidden; }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--fg); font-size: 17px; margin-bottom: 6px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: block; width: 100%; padding: 14px; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 650; font-size: 16px; text-align: center;
}
.btn:disabled { opacity: .5; }
.btn.sec { background: var(--bg2); color: var(--fg); }
.btn.dan { background: var(--danger); color: #fff; }
.btn:active { filter: brightness(.92); }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px 3px; }
input, select {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); font-size: 16px; /* 16px keeps iOS from zooming */
  appearance: none; -webkit-appearance: none;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.split { display: flex; gap: 8px; }
.split > :first-child { flex: 1; min-width: 0; }
.split > select { flex: 0 1 auto; max-width: 45%; }

.err { color: var(--danger); font-size: 14px; margin: 10px 2px; min-height: 18px; }
.note { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }

/* --------------------------------------------------------------------- auth */
.auth { max-width: 380px; margin: auto; width: 100%; padding: calc(var(--top) + 40px) var(--side) 40px; }
.auth h1 { font-size: 28px; letter-spacing: -0.03em; margin: 0 0 4px; }
.auth p.lead { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.switch { text-align: center; margin-top: 16px; font-size: 15px; color: var(--muted); }
.switch button { color: var(--accent); font-weight: 600; }

/* --------------------------------------------------------------------- code */
.code-card {
  margin: 14px 0; padding: 14px 16px; border-radius: var(--radius); background: var(--bg2);
  display: flex; align-items: center; gap: 12px;
}
.code-card .lbl { font-size: 11px; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
.code-card .val {
  font: 700 28px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .06em; user-select: all; -webkit-user-select: all; word-break: break-all;
}
.code-card .grow { flex: 1; min-width: 0; }
.copy-btn {
  flex: 0 0 auto; padding: 11px 18px; border-radius: 11px; background: var(--accent);
  color: #fff; font-weight: 650; font-size: 15px;
}
.copy-btn:active { filter: brightness(.9); }

/* ------------------------------------------------------------------ message */
.msg-head { padding: 14px 0 12px; border-bottom: 1px solid var(--line); }
.msg-head h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -0.02em; line-height: 1.3; }
.msg-head .meta { font-size: 14px; color: var(--muted); word-break: break-word; }
/* Email HTML always renders on its own light canvas, in both app themes. */
.body-frame { width: 100%; margin-top: 12px; min-height: 240px; display: block;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; }
pre.body-text {
  white-space: pre-wrap; word-break: break-word; font: 15px/1.5 inherit; margin: 12px 0 0;
  user-select: text; -webkit-user-select: text;
}

/* -------------------------------------------------------------------- sheet */
.sheet-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 480px; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px var(--side) calc(20px + var(--bottom));
  max-height: 92dvh; overflow-y: auto; animation: rise .2s ease;
}
@media (min-width: 520px) {
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 20px; padding-bottom: 20px; }
}
.grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; letter-spacing: -0.02em; }
.tabs { display: flex; gap: 4px; background: var(--bg2); padding: 3px; border-radius: 11px; margin-bottom: 14px; }
.tabs button { flex: 1; padding: 9px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(14px) } }

/* -------------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--bottom)); transform: translate(-50%, 12px);
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 20px;
  font-size: 15px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s; z-index: 100; max-width: 80vw; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------- wide screen */
@media (min-width: 760px) {
  .wrap, .head { max-width: 720px; margin-left: auto; margin-right: auto; width: 100%; }
  .head { border-radius: 0; }
  .row { padding: 14px 6px; }
}

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