:root {
  --bg: #f2eee3;
  --gold: #f3b936;
  --gold-d: #e8ac2e;
  --card: #fbf8ef;
  --ink: #302820;
  --ink2: #786f63;
  --line: #b78a35;
  --soft: #e3d9c0;
  --green: #438653;
  --red: #b5402f;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans);
  min-height: 100vh; min-height: 100dvh; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.app { max-width: 520px; margin: 0 auto; padding: 14px 16px 48px; }
@media (min-width: 900px) { .app { max-width: 640px; padding-top: 28px; } }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 26px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand b { font-size: 23px; font-weight: 650; letter-spacing: -0.3px; white-space: nowrap; }
.icon-row { display: flex; gap: 10px; }
.icon-btn {
  width: 50px; height: 50px; border-radius: 50%; border: 1px solid var(--soft); background: var(--card);
  display: grid; place-items: center; text-decoration: none; box-shadow: 0 1px 0 rgba(0,0,0,.04);
}
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active, .btn:active { transform: translateY(1px); }
@media (max-width: 380px) { .brand b { font-size: 19px; } .brand svg { width: 28px; height: 28px; } .icon-btn { width: 44px; height: 44px; } }

/* ---------- address stamp ---------- */
.stamp-wrap { position: relative; margin-top: 6px; }
.stamp {
  position: relative; background: var(--gold); padding: 12px;
  filter: drop-shadow(0 7px 0 rgba(120, 90, 30, 0.13));
}
.stamp::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 7px 0, var(--bg) 5px, transparent 5.6px) 0 0 / 14px 12px space no-repeat,
    radial-gradient(circle at 7px 100%, var(--bg) 5px, transparent 5.6px) 0 100% / 14px 12px space no-repeat,
    radial-gradient(circle at 0 7px, var(--bg) 5px, transparent 5.6px) 0 0 / 12px 14px no-repeat space,
    radial-gradient(circle at 100% 7px, var(--bg) 5px, transparent 5.6px) 100% 0 / 12px 14px no-repeat space;
}
.stamp-inner { position: relative; border: 1.5px solid var(--line); border-radius: 10px; padding: 14px 14px 16px; }
.meta { display: flex; gap: 10px; font-family: var(--mono); font-size: 12.5px; letter-spacing: 1.6px; color: #6b5420; padding-right: 84px; }
.addr {
  font-family: var(--mono); font-size: clamp(14px, 4.7vw, 25px); line-height: 1.25; margin: 40px 0 18px;
  overflow-wrap: anywhere; word-break: break-all; min-height: 1.3em; color: var(--ink);
}
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 6px;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--gold-d); font-weight: 600; font-size: 16px;
}
.btn:disabled { opacity: .55; cursor: default; }
.badge {
  position: absolute; top: -16px; right: -6px; width: 88px; height: 88px; border-radius: 50%; z-index: 3;
  background: var(--card); border: 3px solid var(--ink); display: grid; place-items: center;
  box-shadow: 0 0 0 4px var(--gold), 0 0 0 6px var(--ink);
}
.badge div { text-align: center; line-height: 1.15; }
.badge b { display: block; font-family: var(--mono); font-weight: 500; font-size: 19px; }
.badge small { font-family: var(--mono); font-size: 11px; letter-spacing: 2px; color: var(--ink2); }
.badge.expired b { color: var(--red); }
@media (max-width: 380px) { .badge { width: 76px; height: 76px; right: -4px; } .badge b { font-size: 16px; } }

/* ---------- info strip ---------- */
.strip {
  margin: -4px 4px 0; padding: 22px 18px 14px; background: var(--card); border: 1px solid var(--soft);
  border-top: 0; border-radius: 0 0 20px 20px; position: relative; z-index: 0;
}
.strip .l1 { display: flex; align-items: center; gap: 12px; font-weight: 650; font-size: 18px; }
.strip .l1 svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.8; }
.strip .l2 { margin: 8px 0 0 3px; font-family: var(--mono); font-size: 12.5px; letter-spacing: 1.8px; color: var(--ink2); }

/* ---------- inbox ---------- */
.inbox-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 6px; }
.inbox-head h2 { font-size: 36px; font-weight: 600; letter-spacing: -0.6px; margin: 0; }
.status { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 16px; color: var(--ink2); }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--ink2); }
.status[data-state="live"] .dot { background: var(--green); }
.status[data-state="connecting"] .dot { background: var(--gold); animation: pulse 1s infinite; }
.status[data-state="offline"] .dot, .status[data-state="error"] .dot, .status[data-state="expired"] .dot { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }
.mini {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--soft); background: var(--card); display: grid; place-items: center;
}
.mini svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.mini.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { margin: 10px 0; padding: 12px 14px; border-radius: 14px; background: #f7e4df; border: 1px solid #e4b9b0; font-size: 15px; }
.notice.warn { background: #f8ecc9; border-color: #e6cd86; }

.empty { text-align: center; padding: 34px 10px 10px; }
.empty svg { width: 190px; height: auto; }
.empty h3 { margin: 22px 0 10px; font-size: 24px; font-weight: 650; }
.empty p { margin: 0 auto; max-width: 340px; color: var(--ink2); font-size: 17px; line-height: 1.5; }

.list { display: grid; gap: 10px; margin-top: 12px; }
.msg {
  display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 12px; align-items: start; padding: 14px 14px 14px 12px;
  background: var(--card); border: 1px solid var(--soft); border-radius: 16px; text-decoration: none;
}
.msg .u { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; }
.msg.unread .u { background: var(--gold-d); border: 1px solid var(--line); }
.msg .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .from, .msg.unread .subj { font-weight: 750; }
.msg .time { font-family: var(--mono); font-size: 12.5px; color: var(--ink2); padding-top: 3px; white-space: nowrap; }
.msg .subj, .msg .prev { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .prev { color: var(--ink2); font-size: 14.5px; }

/* ---------- reader / settings pages ---------- */
.back { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 600; margin: 6px 0 16px; padding: 8px 0; }
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.paper { background: var(--card); border: 1px solid var(--soft); border-radius: 18px; padding: 18px; }
.paper h1 { font-size: 22px; margin: 0 0 14px; overflow-wrap: anywhere; line-height: 1.25; }
.kv { display: grid; grid-template-columns: 64px 1fr; gap: 6px 10px; font-size: 15px; margin-bottom: 14px; }
.kv dt { font-family: var(--mono); font-size: 12px; letter-spacing: 1.2px; color: var(--ink2); padding-top: 3px; text-transform: uppercase; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 8px; margin: 6px 0 12px; }
.tab { padding: 8px 16px; border-radius: 999px; border: 1.5px solid var(--line); background: transparent; font-weight: 600; }
.tab[aria-selected="true"] { background: var(--gold); }
.frame { width: 100%; height: 62vh; min-height: 320px; border: 1px solid var(--soft); border-radius: 12px; background: #fff; display: block; }
pre.text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 14px; line-height: 1.55; margin: 0; padding: 14px; background: #fff; border: 1px solid var(--soft); border-radius: 12px; max-height: 70vh; overflow: auto; }
.hint { color: var(--ink2); font-size: 13.5px; margin: 10px 2px 0; line-height: 1.45; }
.card-list { display: grid; gap: 12px; }
.row-btn { width: 100%; text-align: left; padding: 15px 16px; border-radius: 16px; border: 1px solid var(--soft); background: var(--card); font-weight: 600; font-size: 16px; display: flex; justify-content: space-between; gap: 10px; }
.row-btn.danger { color: var(--red); }
.row-btn small { font-weight: 400; color: var(--ink2); display: block; margin-top: 3px; font-size: 13.5px; }
h1.page { font-size: 30px; margin: 4px 0 18px; letter-spacing: -.4px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px;
  border-radius: 999px; font-size: 15px; z-index: 50; max-width: 90vw; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* ---------- admin ---------- */
.admin { max-width: 980px; margin: 0 auto; padding: 18px 16px 60px; }
.admin h1 { font-size: 26px; margin: 8px 0 16px; }
.admin h2 { font-size: 18px; margin: 28px 0 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--soft); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 26px; font-family: var(--mono); font-weight: 500; }
.stat span { font-size: 13px; color: var(--ink2); }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.field { display: grid; gap: 5px; font-size: 14px; }
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field input[type="search"] {
  min-height: 44px; padding: 0 12px; border: 1.5px solid var(--soft); border-radius: 12px; background: #fff; font: inherit; min-width: 0;
}
.pill { display: inline-block; padding: 8px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--gold-d); font-weight: 600; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--soft); border-radius: 14px; }
table.t { border-collapse: collapse; width: 100%; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--soft); white-space: nowrap; }
table.t th { font-family: var(--mono); font-size: 12px; letter-spacing: 1px; color: var(--ink2); }
table.t td.addr-cell { font-family: var(--mono); }
.small-btn { padding: 6px 12px; border-radius: 10px; border: 1.5px solid var(--red); background: transparent; color: var(--red); font-weight: 600; }
.err { color: var(--red); min-height: 1.3em; font-size: 14px; margin: 8px 0 0; }
.ok { color: var(--green); }
