/* ---- Design tokens -------------------------------------------------
   Subject: a disposable inbox. Signature: the classic airmail-envelope
   diagonal red/blue stripe, used as a literal border device, plus a
   postmark stamp that doubles as the real expiry countdown.
   Type: Fraunces (display serif, used sparingly for identity/headings)
   + IBM Plex Mono (addresses, data, countdowns) + IBM Plex Sans (body).
------------------------------------------------------------------- */
:root {
  --ink:        #0A0F1C;   /* background, deep postmark-ink navy */
  --ink-2:      #0D1526;
  --surface:    #131C31;   /* cards */
  --surface-2:  #1B2740;   /* nested surfaces */
  --paper:      #F3EEE1;   /* envelope paper */
  --paper-dim:  #C9C3B2;
  --muted:      #7C8AA8;
  --air-red:    #D6432E;
  --air-blue:   #3D6FCB;
  --line:       #26314B;
  --shadow: 0 20px 50px -20px rgba(0,0,0,.6);

  --font-display: 'Fraunces', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, #17233C 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 100%, #10192C 0%, transparent 55%),
    var(--ink);
  color: var(--paper);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--air-blue); }

::selection { background: var(--air-red); color: var(--paper); }

@media (prefers-reduced-motion: no-preference) {
  .card, .message-item, .btn { transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* Signature stripe: repeating diagonal airmail band along the top edge */
.stripes-top {
  height: 10px;
  width: 100%;
  background: repeating-linear-gradient(
    -45deg,
    var(--air-red) 0 18px,
    var(--paper) 18px 26px,
    var(--air-blue) 26px 44px,
    var(--paper) 44px 52px
  );
}

.topbar {
  max-width: 680px;
  margin: 0 auto;
  padding: 36px 20px 6px;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font-size: 20px;
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 1.5px solid var(--paper);
  border-radius: 50%;
  flex: none;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: 0.01em;
}
.brand-tag {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  letter-spacing: 0.03em;
}

.account { display: flex; align-items: center; gap: 10px; }
.account-email {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

/* ---- Mailbox card ---- */
.mailbox-card {
  padding: 24px;
  display: flex;
  gap: 22px;
  align-items: center;
  position: relative;
  overflow: hidden;
  animation: cardIn .5s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.mailbox-card::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: 18px;
  background: repeating-linear-gradient(-45deg, var(--air-red) 0 10px, transparent 10px 14px, var(--air-blue) 14px 24px, transparent 24px 28px);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: .5;
  pointer-events: none;
}

.postmark {
  flex: none;
  width: 92px; height: 92px;
  position: relative;
  display: grid; place-items: center;
}
.postmark-ring { position: absolute; inset: 0; width: 100%; height: 100%; }
.postmark-ring circle {
  fill: none;
  stroke: var(--paper-dim);
  stroke-width: 1.6;
  stroke-dasharray: 4 3;
}
.postmark-ring-inner { stroke-dasharray: 1.5 3; opacity: .6; }
.postmark-time {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--paper);
}
.postmark-label {
  position: absolute;
  bottom: -6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.mailbox-body { flex: 1; min-width: 0; }
.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.address-row { display: flex; gap: 8px; }
.address-field {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 0.01em;
}
.address-field:focus-visible { outline: 2px solid var(--air-blue); outline-offset: 1px; }

.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0 16px;
  height: 40px;
}
.btn:focus-visible { outline: 2px solid var(--air-blue); outline-offset: 2px; }
.btn-copy {
  background: var(--air-red);
  color: var(--paper);
  border-color: var(--air-red);
}
.btn-copy:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-copy:active { transform: scale(.97); }
.btn-block { width: 100%; }

.actions { display: flex; gap: 8px; margin-top: 14px; }
.btn-ghost {
  background: transparent;
  color: var(--paper);
  padding: 0 14px;
  height: 36px;
}
.btn-ghost:hover { background: var(--surface-2); }

.hint { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---- Section headers ---- */
.inbox-head { display: flex; align-items: baseline; gap: 10px; }
.inbox-head h2 {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  color: var(--muted);
}
.inbox-count {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  color: var(--paper);
}

/* ---- Inbox ---- */
.message-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 14px;
}
.empty-state.small { padding: 22px 16px; }
.empty-icon { font-size: 26px; display: block; margin-bottom: 8px; }
.empty-state p { margin: 0; font-size: 13.5px; }

.message-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--air-blue);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: dropIn .35s ease;
}
.message-item:hover { transform: translateX(2px); border-left-color: var(--air-red); box-shadow: var(--shadow); }
.message-from { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); }
.message-subject { font-size: 14.5px; font-weight: 600; color: var(--paper); }
.message-time { font-size: 11.5px; color: var(--muted); }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- History ---- */
.history-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.history-address {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--paper);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-time { font-size: 11px; color: var(--muted); flex: none; }

/* ---- Reader overlay ---- */
.reader {
  position: fixed; inset: 0;
  background: rgba(6,10,18,.75);
  backdrop-filter: blur(2px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 20;
}
.reader.open { display: flex; }
.reader-panel {
  background: var(--paper);
  color: #1a1a1a;
  max-width: 620px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 14px;
  padding: 28px 26px;
  position: relative;
  font-family: var(--font-sans);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.6);
}
.reader-close {
  position: absolute; top: 14px; right: 14px;
  border: none; background: transparent; font-size: 18px;
  cursor: pointer; color: #555;
}
.reader-from { font-family: var(--font-mono); font-size: 13px; color: #555; margin: 0 0 4px; }
.reader-subject { margin: 0 0 4px; font-family: var(--font-display); font-weight: 600; font-size: 21px; }
.reader-date { font-size: 12px; color: #777; margin: 0 0 14px; }
.reader-body { font-size: 14.5px; line-height: 1.55; word-wrap: break-word; }
.reader-body img { max-width: 100%; }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px;
}

/* ---- Auth pages ---- */
.auth-body { display: flex; flex-direction: column; min-height: 100vh; }
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 34px 30px 28px;
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: 18px;
  background: repeating-linear-gradient(-45deg, var(--air-red) 0 10px, transparent 10px 14px, var(--air-blue) 14px 24px, transparent 24px 28px);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: .5;
  pointer-events: none;
}
.auth-mark {
  width: 44px; height: 44px;
  border: 1.5px solid var(--paper);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px;
  margin: 0 auto 18px;
}
.auth-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  text-align: center;
  margin: 0 0 6px;
}
.auth-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 26px;
  line-height: 1.5;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 14.5px;
}
.field input:focus-visible { outline: 2px solid var(--air-blue); outline-offset: 1px; }
.field small { color: var(--muted); font-size: 11.5px; }
.form-error {
  background: rgba(214,67,46,.12);
  border: 1px solid var(--air-red);
  color: #FF9C8C;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  margin: 0;
}
.auth-switch {
  text-align: center;
  margin: 20px 0 0;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 480px) {
  .mailbox-card { flex-direction: column; align-items: flex-start; }
  .postmark { align-self: center; }
  .account-email { display: none; }
}

.owner-link { text-decoration:none; }
.owner-only { border-color: rgba(214,67,46,.55); color: var(--air-red); }
#refreshBtn.spinning { transform: rotate(180deg); }
.actions { flex-wrap: wrap; }
.reader-body { overflow-wrap:anywhere; }
@media (max-width: 600px) {
  .topbar { padding-top:24px; }
  .account-email { display:none; }
  .mailbox-card { flex-direction:column; align-items:stretch; }
  .postmark { margin:0 auto; }
  .actions .btn { flex:1; min-width:120px; }
}

.admin-wrap { gap: 24px; }
.admin-stats { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; }
.stat { padding:18px; display:flex; flex-direction:column; gap:8px; }
.stat span { color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.08em; }
.stat strong { font:600 26px var(--font-mono); }
.admin-settings { padding:22px; display:flex; justify-content:space-between; align-items:center; gap:20px; }
.admin-settings h2 { margin:0; font:600 22px var(--font-display); }
.ttl-form { display:flex; gap:8px; flex:none; }
.ttl-form input { width:110px; background:var(--surface-2); border:1px solid var(--line); border-radius:10px; color:var(--paper); padding:0 12px; font:500 15px var(--font-mono); }
.admin-table-wrap { overflow:auto; margin-top:14px; }
.admin-table { width:100%; border-collapse:collapse; min-width:700px; }
.admin-table th,.admin-table td { padding:14px 16px; border-bottom:1px solid var(--line); text-align:left; font-size:13px; }
.admin-table th { color:var(--muted); font:500 11px var(--font-mono); text-transform:uppercase; letter-spacing:.07em; }
.mono { font-family:var(--font-mono); }
.status { font:600 10px var(--font-mono); padding:4px 8px; border-radius:999px; border:1px solid var(--line); }
.status.ok { color:#9ed6ae; }
.status.bad { color:#ff9c8e; }
.status.owner { color:#b9c9ff; }
.danger { color:#ff9c8e; }
.admin-table .btn { margin-right:6px; }
@media(max-width:760px){.admin-stats{grid-template-columns:repeat(2,1fr)}.admin-settings{flex-direction:column;align-items:stretch}.ttl-form input{flex:1}.topbar-inner{align-items:flex-start}}
