:root {
  --ink: #1d1d1f; --muted: #6b6b70; --line: #e5e2dd; --bg: #f6f4f0; --card: #ffffff; --soft: #faf7f2;
  --brand: #f39a1e; --brand-deep: #c85e17; --sun: #ffd23f;
  --ok: #2e7d32; --ok-bg: #edf7ee; --bad: #c62828; --bad-bg: #fdecea; --warn-bg: #fff6e5;
  --accent: #c85e17; --accent-ink: #ffffff;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f2f2f4; --muted: #a1a1a8; --line: #38383c; --bg: #121214; --card: #1e1e21; --soft: #26262a;
    --brand-deep: #f5a04a; --ok: #6cc070; --ok-bg: #1d2b1e; --bad: #ff6b60; --bad-bg: #3a1d1b; --warn-bg: #33281a;
    --accent: #e8822e; --accent-ink: #ffffff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand-deep); }

/* Header */
header.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--card); border-bottom: 3px solid var(--brand);
}
header.top .logo { width: 36px; height: 36px; flex: none; }
header.top .titles { flex: 1; min-width: 0; }
header.top .appname { font-weight: 700; font-size: 19px; line-height: 1.1; }
header.top .brand { font-size: 12.5px; color: var(--brand-deep); font-weight: 600; }
.iconbtn {
  flex: none; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink); cursor: pointer;
}
.iconbtn:active { background: var(--soft); }
#backBtn { margin-left: -8px; color: var(--brand-deep); }

main { max-width: 640px; margin: 0 auto; padding: 14px max(16px, env(safe-area-inset-right)) 120px max(16px, env(safe-area-inset-left)); }
.pad { padding: 16px; }
h2 { font-size: 22px; margin: 6px 0 4px; line-height: 1.2; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.card.soft { background: var(--soft); }
.card.ok { background: var(--ok-bg); border-color: transparent; }
.card.bad { background: var(--bad-bg); border-color: var(--bad); }
.card.warn { background: var(--warn-bg); border-color: transparent; }
.card h2 { margin-top: 0; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 10px 0; }
.list > * + * { border-top: 1px solid var(--line); }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 50px; padding: 12px 16px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 17px; text-decoration: none;
}
.btn:active { filter: brightness(.92); }
.btn.secondary { background: var(--soft); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.plain { background: transparent; color: var(--brand-deep); min-height: 44px; }
.btn[disabled] { opacity: .45; }
.btn + .btn { margin-top: 10px; }
.btn.ms { background: #2f2f2f; color: #fff; }
@media (prefers-color-scheme: dark) { .btn.ms { background: #f2f2f2; color: #1d1d1f; } }
.btnrow { display: flex; gap: 10px; }
.btnrow .btn + .btn { margin-top: 0; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--brand-deep); font-weight: 600; cursor: pointer; }

/* Bottom action bar */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.actionbar > div { max-width: 640px; margin: 0 auto; }

/* Segmented control */
.seg { display: flex; background: var(--soft); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; margin: 4px 0 10px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 7px 4px; font-size: 14.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Account bar */
.acctbar { display: flex; align-items: center; gap: 8px; margin: 2px 0 8px; }
.acctbar select { flex: 1; min-width: 0; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 15px; }

/* Message rows */
.msg { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer; background: var(--card); width: 100%; border: 0; text-align: left; }
.msg:active { background: var(--soft); }
.msg .check { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); margin-top: 2px; display: grid; place-items: center; }
.msg[aria-checked="true"] .check { background: var(--accent); border-color: var(--accent); }
.msg[aria-checked="true"] .check::after { content: ""; width: 10px; height: 6px; border: 2.5px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.msg .body { flex: 1; min-width: 0; }
.msg .row1 { display: flex; gap: 8px; align-items: baseline; }
.msg .who { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg .when { flex: none; color: var(--muted); font-size: 13.5px; }
.msg .subj { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.msg .addr { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 20px; background: var(--ok-bg); color: var(--ok); vertical-align: 1px; margin-left: 4px; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--brand-deep); }

/* Options (radio / checkbox rows) */
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer; }
.opt input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); }
.opt .body { flex: 1; min-width: 0; }
.opt .t { font-weight: 600; }
.opt .s { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }
.opt .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-deep); font-weight: 700; }

/* Summary table */
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 4px 0; font-size: 14.5px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
ul.flags { margin: 6px 0 0; padding-left: 20px; }
ul.flags li { margin: 3px 0; }

/* Forms */
label.field { display: block; margin: 12px 0; }
label.field span { display: block; font-size: 14px; color: var(--muted); margin: 0 2px 4px; }
input[type=text], input[type=email], textarea, select.full {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 16px;
}
textarea { min-height: 220px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* Copy fields */
.copyfield { padding: 10px 14px; }
.copyfield .lbl { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; font-size: 14.5px; }
.copyfield .val { margin-top: 4px; color: var(--muted); font-size: 13px; white-space: pre-wrap; max-height: 4.5em; overflow: hidden; overflow-wrap: anywhere; }
.copybtn { flex: none; border: 1px solid var(--line); background: var(--soft); border-radius: 8px; padding: 5px 12px; font-size: 14px; font-weight: 600; cursor: pointer; }
.copybtn.done { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

/* Legitimate warning */
.legit { border: 2px solid var(--bad); background: var(--bad-bg); border-radius: var(--radius); padding: 18px 16px; margin: 10px 0; }
.legit .head { color: var(--bad); font-weight: 800; font-size: 23px; line-height: 1.2; margin-bottom: 8px; }

/* Working */
.working { text-align: center; padding: 60px 20px; }
.spinner { width: 42px; height: 42px; margin: 0 auto 16px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
details.more { margin: 10px 0; }
details.more summary { cursor: pointer; font-weight: 600; padding: 10px 2px; color: var(--brand-deep); }
.hero { text-align: center; padding: 18px 8px 6px; }
.hero img { width: 88px; height: 88px; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1d1d1f; color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14.5px; z-index: 20; max-width: 90vw;
  border: 1px solid rgba(255,255,255,.18); box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.steps { margin: 6px 0; padding-left: 22px; }
.steps li { margin: 6px 0; }
[hidden] { display: none !important; }
