:root {
  --bg: #060606;
  --paper: #0d0d0d;
  --ink: #f2f2f2;
  --ink-soft: #d6d6d6;
  --line: #232323;
  --line-strong: #3a3a3a;
  --rule: #2b2b2b;
  --muted: #9c9c9c;
  --faint: #6f6f6f;
  --radius: 12px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --font-sans: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  color-scheme: dark;
}

.wrap {
  max-width: 1160px;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 44px;
  flex-wrap: wrap;
}
.brand { min-width: 0; }
.brand h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink);
}
.logo svg { width: 48px; height: 31px; display: block; }
.brand h1 {
  font-size: 23px;
  font-weight: 900;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--ink);
}
.brand p {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-weight: 600;
}
.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  border: 1px solid var(--rule);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--paper);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

/* ---------- Address bar ---------- */
.address-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  border: 2px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
  background: var(--paper);
}
.address-box {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.address-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 700;
}
.address-text {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
  word-break: break-all;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: color 0.15s ease;
}
.address-text:hover { color: var(--muted); }
.address-view {
  display: flex;
  align-items: center;
  gap: 10px;
}
.edit-btn { padding: 8px 9px; flex-shrink: 0; }
.address-edit {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.address-edit input {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  background: #151515;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 180px;
  flex: 1;
  outline: none;
  letter-spacing: 0.01em;
}
.address-edit input::placeholder { color: var(--faint); font-weight: 500; }
.address-edit input:focus { background: #1a1a1a; border-color: var(--line-strong); }
.address-suffix {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.edit-actions { display: flex; gap: 8px; }
.actions { display: flex; gap: 10px; flex-shrink: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
  line-height: 1;
}
.btn:hover { background: var(--ink); color: #0a0a0a; border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }
.btn.primary {
  background: var(--ink);
  border: 1.5px solid var(--ink);
  color: #0a0a0a;
}
.btn.primary:hover { background: transparent; color: var(--ink); }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { background: var(--ink); color: #0a0a0a; border-color: var(--ink); }
.btn.danger { border-color: var(--line); color: var(--muted); }
.btn.danger:hover { background: var(--ink); color: #0a0a0a; border-color: var(--ink); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.icon-only { padding: 10px 11px; }

.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  align-items: start;
}
.panel {
  background: var(--paper);
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* ---------- Inbox panel ---------- */
.inbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1.5px solid var(--rule);
}
.inbox-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
}
.inbox-title span { color: var(--muted); font-weight: 600; }
.refresh-meta {
  font-size: 10px;
  color: var(--faint);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}

.list { max-height: 620px; overflow-y: auto; }
.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-track { background: #111111; }
.list::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 0; }

.mail-item {
  width: 100%;
  text-align: left;
  display: flex;
  gap: 14px;
  padding: 16px 20px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  color: var(--ink);
  font-family: inherit;
  position: relative;
}
.mail-item:last-child { border-bottom: none; }
.mail-item:hover { background: #161616; }
.mail-item.active { background: var(--ink); color: #0a0a0a; }
.mail-item.active .mail-subject,
.mail-item.active .mail-preview,
.mail-item.active .mail-time { color: rgba(0, 0, 0, 0.62); }
.mail-item.active .mail-sender { color: #0a0a0a; }
.mail-item.active .avatar { background: #0a0a0a; color: var(--ink); }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
  color: #0a0a0a;
  text-transform: uppercase;
  background: var(--ink);
  letter-spacing: 0.02em;
}
.avatar-img {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}
.avatar-fallback {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
}
.mail-body { flex: 1; min-width: 0; }
.mail-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mail-sender {
  font-size: 13px;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  transition: color 0.12s ease;
}
.mail-sender.unread { color: var(--ink); font-weight: 800; }
.mail-time {
  font-size: 10px;
  color: var(--faint);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.mail-subject {
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.12s ease;
}
.mail-preview {
  font-size: 12px;
  color: var(--faint);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.12s ease;
}
.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  flex-shrink: 0;
  margin-top: 7px;
}
.mail-item.active .unread-dot { background: #0a0a0a; }

/* ---------- Reader panel ---------- */
.reader {
  min-height: 620px;
  display: flex;
  flex-direction: column;
}
.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 40px;
  text-align: center;
  color: var(--faint);
}
.reader-empty svg { width: 56px; height: 56px; color: var(--ink); opacity: 0.9; }
.reader-empty h3 {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.reader-empty p { font-size: 13px; max-width: 280px; line-height: 1.6; color: var(--muted); }

.reader-head {
  padding: 22px 24px;
  border-bottom: 1.5px solid var(--rule);
}
.reader-back { display: none; }
.reader-subject {
  font-size: 21px;
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--ink);
  overflow-wrap: break-word;
  word-break: break-word;
}
.reader-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.reader-meta .avatar { width: 44px; height: 44px; border-radius: 4px; }
.reader-from { font-size: 13px; font-weight: 800; color: var(--ink); }
.reader-date {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.reader-body {
  flex: 1;
  padding: 26px 24px;
  overflow: auto;
  word-wrap: break-word;
}
.reader-body pre {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.reader-body iframe {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* ---------- Empty list state ---------- */
.list-empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--faint);
}
.list-empty svg { width: 44px; height: 44px; color: var(--ink); opacity: 0.85; margin-bottom: 16px; }
.list-empty p { font-size: 13px; line-height: 1.6; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(90px);
  background: var(--ink);
  border: 1.5px solid var(--ink);
  color: #0a0a0a;
  padding: 14px 20px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 100;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast svg { width: 15px; height: 15px; color: #0a0a0a; }

/* ---------- Password gate ---------- */
#app { display: none; }
body.unlocked #app { display: block; }

#lock {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 700px at 50% -10%, #141414, var(--bg));
  padding: 24px;
}
.lock-card {
  width: 100%;
  max-width: 360px;
  background: var(--paper);
  border: 1.5px solid var(--rule);
  border-radius: var(--radius);
  padding: 34px 30px;
  box-shadow: var(--shadow);
  text-align: center;
}
.lock-logo { color: var(--ink); margin-bottom: 18px; }
.lock-logo svg { width: 52px; height: 34px; }
.lock-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.lock-sub { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.lock-field { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
.lock-field input {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: #151515;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 13px 14px;
  outline: none;
  letter-spacing: 0.02em;
  text-align: center;
}
.lock-field input:focus { background: #1a1a1a; border-color: var(--line-strong); }
.lock-error {
  font-size: 11px;
  color: #ff6b6b;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  min-height: 14px;
}
.lock-field .btn { justify-content: center; }
.lock-admin {
  margin-top: 12px;
  justify-content: center;
  text-decoration: none;
  width: 100%;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake 0.35s ease; }

/* ---------- Devtools warning ---------- */
#devtools-warning {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 6, 0.94);
  padding: 24px;
}
#devtools-warning .lock-card { border-color: #3a2a2a; }
#devtools-warning h2 {
  color: #ff6b6b;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
#devtools-warning p { font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ---------- Notification bell ---------- */
.bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
  flex-shrink: 0;
}
.bell:hover { border-color: var(--ink); }
.bell svg { width: 17px; height: 17px; }
.bell-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  display: none;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ff4d4d;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 3px var(--bg);
}

/* ---------- New mail notification ---------- */
.notif {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 150;
  width: 340px;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 18px 22px;
  background: var(--paper);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-24px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1), transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}
.notif.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.notif-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #0a0a0a;
}
.notif-icon svg { width: 20px; height: 20px; }
.notif.show .notif-icon svg { animation: notif-ring 0.9s ease; }
@keyframes notif-ring {
  0% { transform: scale(1); }
  30% { transform: scale(1.25) rotate(-8deg); }
  60% { transform: scale(1) rotate(4deg); }
  100% { transform: scale(1); }
}
.notif-body { flex: 1; min-width: 0; }
.notif-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}
.notif-sender {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notif-subject {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notif-close {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s ease;
}
.notif-close:hover { color: var(--ink); background: #1a1a1a; }
.notif-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 3px;
  background: transparent;
}
.notif-progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ink);
}
.notif.show .notif-progress span { animation: notifbar 5.2s linear forwards; }
@keyframes notifbar { from { width: 100%; } to { width: 0%; } }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .wrap { padding: 28px 16px 56px; }
  header { margin-bottom: 28px; }
  .brand p { display: none; }
  .layout { grid-template-columns: 1fr; }
  .address-bar { flex-direction: column; align-items: stretch; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; justify-content: center; }
  .reader {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg);
    border-radius: 0;
    border: none;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  body.reader-open .reader { transform: translateX(0); }
  .reader-back { display: inline-flex; }
  .reader-empty, .list { max-height: none; }
}
