/* ------------------------------------------------------------------
   Design tokens. Light-first; a dark variant maps the same roles so
   a night-time reader is not blinded by a full-white inbox.
------------------------------------------------------------------- */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --ink: #10141f;
  --ink-2: #39415a;
  --muted: #6b7488;
  --line: #e3e7f0;
  --line-strong: #cdd4e3;
  --accent: #4338ca;
  --accent-hover: #372fb0;
  --accent-soft: #eef0fe;
  --accent-ink: #ffffff;
  --ok: #0f7a4d;
  --ok-soft: #e7f6ee;
  --warn: #9a5b00;
  --warn-soft: #fdf3e2;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 20, 31, .06), 0 1px 3px rgba(16, 20, 31, .04);
  --shadow-md: 0 4px 12px rgba(16, 20, 31, .07), 0 2px 4px rgba(16, 20, 31, .04);
  --shadow-lg: 0 18px 44px rgba(16, 20, 31, .12);
  --maxw: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1017;
    --surface: #151a24;
    --surface-2: #1b2130;
    --ink: #eef1f7;
    --ink-2: #c3cad9;
    --muted: #8d97ab;
    --line: #262d3c;
    --line-strong: #35405a;
    --accent: #8b8cf7;
    --accent-hover: #a3a4fb;
    --accent-soft: #1e2140;
    --accent-ink: #0d1017;
    --ok: #4ade9f;
    --ok-soft: #12241c;
    --warn: #f0b45e;
    --warn-soft: #2a2113;
    --danger: #ff8a80;
    --danger-soft: #2c1614;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, .55);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.015em; font-weight: 650; }
h1 { font-size: clamp(1.7rem, 1.2rem + 2vw, 2.5rem); }
h2 { font-size: clamp(1.3rem, 1.1rem + 1vw, 1.75rem); }
h3 { font-size: 1.125rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: .75rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; min-width: 0; }

/* ------------------------------------------------------------- header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.site-header .wrap { display: flex; align-items: center; gap: 20px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; letter-spacing: -.02em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, var(--accent), #7c73ff);
  display: grid; place-items: center; color: #fff; font-size: .95rem; font-weight: 700;
}
.brand img { height: 30px; width: auto; display: block; }
.nav { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.nav a {
  color: var(--ink-2); text-decoration: none; font-size: .935rem; font-weight: 500;
  padding: .5rem .7rem; border-radius: var(--radius-sm);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: .45rem .6rem; color: var(--ink); cursor: pointer; }

@media (max-width: 780px) {
  .nav-toggle { display: block; }
  .nav {
    display: none; position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 12px 14px;
    box-shadow: var(--shadow-md);
  }
  .nav.open { display: flex; }
  .nav a { padding: .8rem .6rem; }
}

/* ---------------------------------------------------------- announcements */
.banner {
  padding: .7rem 0; font-size: .92rem; text-align: center;
  background: var(--accent-soft); color: var(--ink-2); border-bottom: 1px solid var(--line);
}
.banner.warn { background: var(--warn-soft); color: var(--warn); }

/* --------------------------------------------------------------- inbox */
.inbox-shell { padding: 32px 0 8px; }

.address-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 22px;
}
.address-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.address-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.address-value {
  flex: 1 1 320px; min-width: 0;
  font-family: var(--mono); font-size: clamp(1.05rem, .85rem + 1.1vw, 1.5rem);
  font-weight: 600; letter-spacing: -.01em; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem .9rem;
  overflow-x: auto; white-space: nowrap; scrollbar-width: thin;
}
.address-value.loading { color: var(--muted); font-style: italic; font-family: var(--font); font-weight: 400; }
.address-actions { display: flex; gap: 8px; flex: 0 0 auto; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .6rem 1.05rem;
  border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-size: .935rem; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: .35rem .7rem; font-size: .87rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.meta-row {
  display: flex; gap: 10px 18px; flex-wrap: wrap; align-items: center;
  margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--line);
  font-size: .875rem; color: var(--muted);
}
.meta-item { display: inline-flex; align-items: center; gap: .4rem; }
.meta-item strong { color: var(--ink-2); font-weight: 600; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.reconnecting { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.offline { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
@media (prefers-reduced-motion: no-preference) {
  .dot.live { animation: pulse 2.4s ease-in-out infinite; }
  @keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
}

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .18rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.subnav { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 0; }

/* ------------------------------------------------------------ messages */
.panel {
  margin-top: 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.panel-head h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.panel-head .spacer { margin-left: auto; }

.msg-list { list-style: none; margin: 0; padding: 0; }
.msg-item { border-bottom: 1px solid var(--line); }
.msg-item:last-child { border-bottom: 0; }
.msg-btn {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 12px; align-items: start;
  max-width: 100%;
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 15px 18px; font: inherit; color: inherit; min-height: 56px;
}
.msg-btn:hover { background: var(--surface-2); }
.msg-unread-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: .5rem; background: transparent; }
.msg-item.unread .msg-unread-dot { background: var(--accent); }
.msg-item.unread .msg-subject { font-weight: 680; }
.msg-main { display: block; min-width: 0; max-width: 100%; overflow: hidden; }
.msg-from { display: block; max-width: 100%; font-size: .875rem; color: var(--ink-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-subject { display: block; max-width: 100%; font-size: .98rem; color: var(--ink); margin: 1px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-preview { display: block; max-width: 100%; font-size: .875rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-side { display: flex; max-width: 40vw; flex-direction: column; align-items: flex-end; gap: 5px; font-size: .8rem; color: var(--muted); white-space: nowrap; }

.empty-state { padding: 52px 24px; text-align: center; color: var(--muted); }
.empty-state .glyph {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 1.5rem;
}
.empty-state h3 { color: var(--ink); margin-bottom: .35rem; }
.empty-state p { max-width: 42ch; margin: 0 auto; font-size: .94rem; }

/* -------------------------------------------------------------- reader */
.reader-head { padding: 18px; border-bottom: 1px solid var(--line); }
.reader-subject { font-size: 1.2rem; font-weight: 650; margin: 10px 0 8px; word-break: break-word; }
.reader-meta { font-size: .875rem; color: var(--muted); display: grid; gap: 3px; }
.reader-meta .addr { font-family: var(--mono); color: var(--ink-2); word-break: break-all; }
.reader-notice {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 0; padding: 11px 18px; background: var(--warn-soft); color: var(--warn);
  font-size: .875rem; border-bottom: 1px solid var(--line);
}
.reader-frame { width: 100%; border: 0; display: block; background: var(--surface); min-height: 320px; }
.reader-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }

.code-hit {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 0; padding: 12px 18px; background: var(--accent-soft);
  border-bottom: 1px solid var(--line); font-size: .9rem;
}
.code-hit code { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; letter-spacing: .06em; color: var(--accent); }

.attachments { padding: 14px 18px; border-top: 1px solid var(--line); }
.attachment {
  display: flex; align-items: center; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid var(--line); font-size: .9rem;
}
.attachment:last-child { border-bottom: 0; }
.attachment .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .size { color: var(--muted); font-size: .82rem; white-space: nowrap; }

/* -------------------------------------------------------------- dialog */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 0; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lg); max-width: min(560px, calc(100vw - 32px)); width: 100%;
  max-height: min(88vh, 640px); overflow: hidden;
  display: flex; flex-direction: column;
}
dialog:not([open]) { display: none; }
.dialog-body { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.dialog-foot { flex: 0 0 auto; }
dialog::backdrop { background: rgba(10, 13, 20, .5); }
.dialog-head { padding: 18px 20px 0; }
.dialog-head h2 { margin: 0 0 .3rem; font-size: 1.15rem; }
.dialog-body { padding: 12px 20px; }
.dialog-foot { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.secret-box {
  font-family: var(--mono); font-size: 1.05rem; font-weight: 650; letter-spacing: .05em;
  background: var(--accent-soft); color: var(--accent);
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: 14px; text-align: center; word-break: break-all; margin: 4px 0 12px;
}
.hint { font-size: .87rem; color: var(--muted); overflow-wrap: anywhere; }
#recovery-notice, #recovery-notice * { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: .6rem .75rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit; font-size: .95rem;
}
.field textarea { min-height: 110px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .err { color: var(--danger); font-size: .84rem; margin-top: 5px; display: block; }

.alert { padding: 12px 14px; border-radius: var(--radius); font-size: .9rem; margin-bottom: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ------------------------------------------------------------ recents */
.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-item {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 13px 0; border-bottom: 1px solid var(--line);
}
.recent-item:last-child { border-bottom: 0; }
.recent-addr { flex: 1 1 240px; min-width: 0; font-family: var(--mono); font-size: .9rem; word-break: break-all; }
.recent-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* -------------------------------------------------------------- content */
.content-section { padding: 44px 0; }
.content-section + .content-section { border-top: 1px solid var(--line); }
.prose { max-width: 68ch; }
.prose h2 { margin-top: 1.6em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin-bottom: .4em; }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .12em .35em; border-radius: 4px; }

.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
}
.card h3 { margin-bottom: .4rem; }
.card p { margin: 0; color: var(--ink-2); font-size: .94rem; }
.card .num {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; margin-bottom: 12px;
}

details.faq { border-bottom: 1px solid var(--line); padding: 4px 0; }
details.faq summary { cursor: pointer; padding: 14px 0; font-weight: 600; list-style: none; display: flex; gap: 10px; align-items: center; min-height: 44px; }
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::before { content: "+"; color: var(--accent); font-weight: 700; width: 1em; }
details.faq[open] summary::before { content: "\2212"; }
details.faq .answer { padding: 0 0 14px 1.6em; color: var(--ink-2); font-size: .95rem; }

.partner-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.partner {
  display: flex; flex-direction: column; gap: 8px; padding: 16px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  text-decoration: none; color: var(--ink);
}
.partner:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); color: var(--ink); }
.partner img { height: 28px; width: auto; max-width: 140px; object-fit: contain; align-self: flex-start; }
.partner .name { font-weight: 650; font-size: .95rem; }
.partner .desc { font-size: .86rem; color: var(--muted); }

.ad-slot { margin: 22px 0; text-align: center; }
.ad-slot a { display: inline-block; max-width: 100%; }
.ad-slot img { max-width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.ad-slot .label { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.ad-desktop { display: inline-block; }
.ad-mobile { display: none; }
@media (max-width: 700px) {
  .ad-desktop { display: none; }
  .ad-mobile { display: inline-block; }
}

/* -------------------------------------------------------------- footer */
.site-footer { margin-top: 56px; border-top: 1px solid var(--line); background: var(--surface); padding: 34px 0 40px; }
.footer-grid { display: flex; gap: 28px; flex-wrap: wrap; justify-content: space-between; }
.footer-links { display: flex; gap: 8px 20px; flex-wrap: wrap; }
.footer-links a { color: var(--ink-2); text-decoration: none; font-size: .9rem; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }
.footer-note { font-size: .85rem; color: var(--muted); max-width: 48ch; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.toast-region { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  background: var(--ink); color: var(--bg); padding: .7rem 1.1rem; border-radius: 999px;
  font-size: .9rem; font-weight: 550; box-shadow: var(--shadow-lg);
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

[hidden] { display: none !important; }
