/* Envelope palette: cool paper, navy ink, airmail red + blue. */
:root {
  --bg: #edf1f5;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #5e6a7d;
  --rule: #d5dce6;
  --blue: #1d4ed8;
  --blue-ink: #ffffff;
  --blue-soft: #e5ecfd;
  --red: #c8242b;
  --ok: #15803d;
  --warn: #b45309;
  --cell: #f4f7fb;
  --mono: "Cascadia Mono", "JetBrains Mono", "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, sans-serif;
  --radius-lg: 14px;
  --radius: 9px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1522;
    --surface: #182134;
    --ink: #e6ebf3;
    --muted: #9aa6b8;
    --rule: #28344b;
    --blue: #7ea2ff;
    --blue-ink: #0f1522;
    --blue-soft: #1f2c48;
    --red: #ff6b6f;
    --ok: #4ade80;
    --warn: #fbbf24;
    --cell: #111a2b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
}
main { flex: 1; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

.wrap { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; z-index: 30; background: var(--surface); padding: .5rem .8rem; border-radius: var(--radius); }

/* ---------- header */
.site-header { padding: 1.1rem 0; }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; font-weight: 650; font-size: 1.05rem; }
.brand-icon { width: 1.6rem; height: 1.6rem; }
.brand-icon rect { fill: var(--blue); }
.brand-icon path { stroke: var(--blue-ink); stroke-width: 2.4; fill: none; stroke-linejoin: round; }
.status { display: inline-flex; align-items: center; gap: .5rem; font-size: .875rem; color: var(--muted); }
.status-dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); }
.status[data-kind="ok"] .status-dot { background: var(--ok); }
.status[data-kind="warn"] .status-dot { background: var(--warn); }
.status[data-kind="error"] .status-dot { background: var(--red); }
.status[data-kind="error"] { color: var(--red); }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.6rem; padding: 0 1.05rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: .92rem; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--blue); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--rule); }
.btn-danger { background: transparent; color: var(--red); }
.btn-danger:hover { border-color: var(--red); }

/* ---------- address card: the envelope */
.address-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.6rem;
  border: 1px solid var(--rule);
  overflow: hidden;
}
.address-card::before { /* airmail edge */
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 6px;
  background: repeating-linear-gradient(135deg,
    var(--red) 0 14px, transparent 14px 22px, var(--blue) 22px 36px, transparent 36px 44px);
}
.address-label { color: var(--muted); font-size: .92rem; margin-bottom: .55rem; }
.address {
  font-family: var(--mono);
  font-size: clamp(1.35rem, 4.2vw, 2.45rem);
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.address-domain { color: var(--muted); font-weight: 500; }
#address-local, .address-domain { display: inline-block; max-width: 100%; } /* wrap at the @, not mid-word */
.domain-switch {
  display: inline-flex; flex-wrap: wrap; gap: 3px; margin-top: .9rem; padding: 3px;
  background: var(--bg); border: 1px solid var(--rule); border-radius: 10px;
}
.domain-option {
  border: 0; background: transparent; border-radius: 7px; padding: .4rem .8rem; cursor: pointer;
  font-family: var(--mono); font-size: .85rem; color: var(--muted);
}
.domain-option:hover { color: var(--ink); }
.domain-option[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(23, 32, 51, .12); }
.address-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 1.25rem; }

.address-form { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; }
.local-input, .domain-select {
  min-height: 3rem; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--cell); font-family: var(--mono); font-size: 1.15rem; padding: 0 .85rem;
}
.local-input { flex: 1 1 14rem; min-width: 0; }
.domain-select { flex: 0 1 auto; color: var(--muted); }
.form-error { flex-basis: 100%; color: var(--red); font-size: .9rem; }

.recent { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: 1.35rem; padding-top: 1.1rem; border-top: 1px solid var(--rule); }
.recent-label { color: var(--muted); font-size: .85rem; margin-right: .2rem; }
.recent-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  border: 1px solid var(--rule); background: var(--bg); border-radius: 999px;
  padding: .25rem .75rem; font-family: var(--mono); font-size: .8rem; cursor: pointer; color: var(--muted);
}
.chip:hover { color: var(--ink); border-color: var(--blue); }

/* ---------- code panel: the one loud thing */
.code-panel {
  margin-top: 1.25rem;
  padding: 1.6rem 2rem 1.8rem;
  border-radius: var(--radius-lg);
  background: var(--blue-soft);
  border: 1px solid transparent;
}
.code-panel.waiting { background: transparent; border: 1px dashed var(--rule); }
.code-title { font-size: 1.2rem; font-weight: 650; }
.code-from { color: var(--muted); margin-top: .25rem; max-width: 70ch; }
.code-panel.waiting .code-title::before {
  content: ""; display: inline-block; width: .6rem; height: .6rem; margin-right: .6rem; border-radius: 50%;
  background: var(--blue); vertical-align: .12em; animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: .25; } }

.code-cells {
  display: inline-flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.25rem;
  padding: 0; border: 0; background: none; cursor: copy;
}
.cell {
  display: grid; place-items: center;
  width: clamp(2.6rem, 9vw, 3.6rem); height: clamp(3.3rem, 11vw, 4.4rem);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px;
  font-family: var(--mono); font-size: clamp(1.6rem, 5.5vw, 2.4rem); font-weight: 700; color: var(--ink);
  box-shadow: 0 1px 0 var(--rule);
}
.code-cells:hover .cell { border-color: var(--blue); }
.code-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 1.25rem; }
.code-actions:not(:has(:not([hidden]))) { display: none; }

.code-panel.arrived .cell { animation: drop .42s cubic-bezier(.2, .9, .3, 1.2) both; }
.code-panel.arrived .cell:nth-child(2) { animation-delay: .04s; }
.code-panel.arrived .cell:nth-child(3) { animation-delay: .08s; }
.code-panel.arrived .cell:nth-child(4) { animation-delay: .12s; }
.code-panel.arrived .cell:nth-child(5) { animation-delay: .16s; }
.code-panel.arrived .cell:nth-child(6) { animation-delay: .2s; }
.code-panel.arrived .cell:nth-child(n+7) { animation-delay: .24s; }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }

/* ---------- mailbox */
.mailbox {
  display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 1.25rem;
  margin: 1.25rem 0 2.5rem; align-items: start;
}
.mail-column { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); overflow: hidden; }
.column-title { font-size: 1rem; font-weight: 650; padding: 1rem 1.15rem; border-bottom: 1px solid var(--rule); display: flex; align-items: center; gap: .5rem; }
.count:not(:empty) { font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); border-radius: 999px; padding: .05rem .5rem; }
.mail-list { list-style: none; margin: 0; padding: 0; max-height: 34rem; overflow: auto; }
.mail-list li + li { border-top: 1px solid var(--rule); }
.mail-item {
  display: grid; gap: .15rem; width: 100%; text-align: left; padding: .85rem 1.15rem;
  border: 0; background: transparent; cursor: pointer; border-left: 3px solid transparent;
}
.mail-item:hover { background: var(--bg); }
.mail-item.is-open { background: var(--blue-soft); border-left-color: var(--blue); }
.mail-top { display: flex; justify-content: space-between; gap: .75rem; }
.mail-sender { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-time { color: var(--muted); font-size: .8rem; flex-shrink: 0; }
.mail-subject { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-bottom { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-code { font-family: var(--mono); font-weight: 700; color: var(--blue); letter-spacing: .06em; }
.mail-link { color: var(--blue); font-weight: 600; }
.mail-empty { padding: 2rem 1.15rem; color: var(--muted); }
.mail-empty .hint { font-size: .85rem; margin-top: .2rem; }

.reader { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); min-height: 18rem; }
.reader-empty { display: grid; place-items: center; min-height: 18rem; color: var(--muted); padding: 2rem; text-align: center; }
.reader-head { padding: 1.3rem 1.5rem 1rem; border-bottom: 1px solid var(--rule); }
.reader-subject { font-size: 1.2rem; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.reader-from { margin-top: .35rem; overflow-wrap: anywhere; }
.reader-time { color: var(--muted); font-size: .85rem; }
.reader-links { padding: .9rem 1.5rem; border-bottom: 1px solid var(--rule); display: grid; gap: .35rem; max-height: 13rem; overflow: auto; }
.links-title { color: var(--muted); font-size: .85rem; margin-bottom: .15rem; }
.link-row { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: .75rem; text-decoration: none; color: var(--muted); font-size: .85rem; padding: .3rem .5rem; border-radius: 6px; }
.link-row:hover { background: var(--bg); }
.link-row.is-best { background: var(--blue-soft); color: var(--ink); }
.link-host { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-url { font-family: var(--mono); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: center; }
.reader-body {
  margin: 0; padding: 1.3rem 1.5rem; font-family: var(--sans); font-size: .95rem; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere; max-width: 75ch; max-height: 32rem; overflow: auto;
}
.reader-foot { padding: .9rem 1.5rem 1.2rem; border-top: 1px solid var(--rule); }

/* ---------- api docs */
.docs { max-width: 820px; padding-bottom: 3rem; }
.docs h1 { font-size: 2rem; margin: 1rem 0 .5rem; }
.docs h2 { font-size: 1.2rem; margin: 2.2rem 0 .7rem; }
.docs h3 { font-family: var(--mono); font-size: .95rem; margin-bottom: .4rem; overflow-wrap: anywhere; }
.docs p, .docs li { max-width: 70ch; }
.docs p + p, .docs p + pre, .docs pre + p { margin-top: .7rem; }
.docs .lead { color: var(--muted); font-size: 1.05rem; }
.docs code { font-family: var(--mono); font-size: .88em; }
.docs p code, .docs li code, .docs td code { background: var(--surface); border: 1px solid var(--rule); border-radius: 5px; padding: .05rem .3rem; }
.docs pre.code {
  margin: .6rem 0 0; padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); overflow: auto; line-height: 1.55; font-size: .9rem;
}
.steps { padding-left: 1.3rem; display: grid; gap: .3rem; }
.endpoint { padding: 1.1rem 0; border-top: 1px solid var(--rule); }
.verb { display: inline-block; min-width: 3.6rem; color: var(--ok); font-weight: 700; }
.verb-delete { color: var(--red); }
.params { border-collapse: collapse; margin-top: .6rem; width: 100%; font-size: .92rem; }
.params th { text-align: left; font-family: var(--mono); font-weight: 600; padding: .45rem .9rem .45rem 0; vertical-align: top; white-space: nowrap; }
.params td { padding: .45rem 0; color: var(--muted); }
.params tr + tr { border-top: 1px solid var(--rule); }
.site-footer a { color: inherit; }

/* ---------- footer + toast */
.site-footer { padding: 1.5rem 0 2rem; color: var(--muted); font-size: .85rem; }
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%); z-index: 40;
  background: var(--ink); color: var(--bg); padding: .7rem 1.1rem; border-radius: var(--radius);
  font-weight: 600; font-size: .92rem; box-shadow: 0 10px 30px rgba(15, 21, 34, .25);
}
.toast.is-error { background: var(--red); color: #fff; }

/* ---------- small screens */
@media (max-width: 860px) {
  .mailbox { grid-template-columns: 1fr; }
  .mail-list { max-height: 22rem; }
  .reader:not(.is-active) { display: none; }
}
@media (max-width: 560px) {
  .wrap { width: calc(100% - 1.5rem); }
  .address-card { padding: 1.6rem 1.15rem 1.3rem; }
  .code-panel { padding: 1.3rem 1.15rem 1.5rem; }
  .address-actions .btn, .code-actions .btn { flex: 1 1 auto; }
  .status-text, #status-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

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