:root {
    --ink: #17223B;
    --ink-soft: #3C4A6B;
    --paper: #FBF8F2;
    --paper-dim: #F0EBE0;
    --air-red: #C1443A;
    --air-blue: #2F5FA3;
    --muted: #8A8478;
    --line: #E4DDCC;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(23,34,59,0.04), 0 8px 24px rgba(23,34,59,0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper-dim);
    background-image:
        radial-gradient(circle at 100% 0%, rgba(47,95,163,0.06), transparent 45%),
        radial-gradient(circle at 0% 100%, rgba(193,68,58,0.05), transparent 45%);
    color: var(--ink);
    font-family: 'Inter', -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 560px;
    margin: 0 auto;
    padding: 32px 20px 60px;
}

/* ---------- Header ---------- */
.topbar { margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 34px; height: 34px; color: var(--air-red); flex-shrink: 0; }
.brand h1 {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 24px;
    margin: 0;
    letter-spacing: -0.01em;
}
.tagline {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--muted);
}

/* ---------- Stamp card (address box) ---------- */
.stamp-card {
    position: relative;
    background: var(--paper);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--line);
    margin-bottom: 24px;
}
.stripe-edge {
    height: 6px;
    background: repeating-linear-gradient(
        -45deg,
        var(--air-red) 0 10px,
        var(--paper) 10px 14px,
        var(--air-blue) 14px 24px,
        var(--paper) 24px 28px
    );
}
.stamp-card-inner { padding: 22px 22px 20px; }

.field-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 8px;
}

.address-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}
#mailboxAddress {
    flex: 1;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14.5px;
    color: var(--ink);
}
.address-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
    width: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .15s, color .15s, transform .1s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--air-blue); color: var(--air-blue); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.success { border-color: #2f9e6e; color: #2f9e6e; }

/* ---------- Expiry / fuse bar ---------- */
.expiry-block { margin-top: 16px; }
.expiry-row {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 6px;
}
.fuse-track {
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    overflow: hidden;
}
.fuse-fill {
    height: 100%;
    width: 100%;
    background: var(--air-blue);
    border-radius: 2px;
    transition: width 1s linear, background-color .4s;
}
.fuse-fill.warn { background: #D3A017; }
.fuse-fill.danger { background: var(--air-red); }

/* ---------- Inbox ---------- */
.inbox {
    background: var(--paper);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.inbox-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.inbox-head h2 {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}
.live-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #2f9e6e;
    box-shadow: 0 0 0 0 rgba(47,158,110,0.5);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(47,158,110,0.45); }
    70% { box-shadow: 0 0 0 6px rgba(47,158,110,0); }
    100% { box-shadow: 0 0 0 0 rgba(47,158,110,0); }
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
}
.empty-state svg { width: 44px; height: 44px; margin-bottom: 12px; opacity: 0.6; }
.empty-state p { margin: 0; font-size: 13.5px; line-height: 1.6; }

.msg-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    transition: background .12s;
    animation: slideIn .3s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.msg-item:last-child { border-bottom: none; }
.msg-item:hover { background: var(--paper-dim); }
.msg-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--air-red);
    margin-top: 6px;
    flex-shrink: 0;
}
.msg-item.read .msg-dot { background: transparent; }
.msg-body { flex: 1; min-width: 0; }
.msg-from {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-item.read .msg-from { font-weight: 500; color: var(--ink-soft); }
.msg-subject {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px;
}
.msg-time {
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
    font-family: 'IBM Plex Mono', monospace;
}

/* ---------- Modals ---------- */
.modal {
    position: fixed; inset: 0;
    background: rgba(23,34,59,0.45);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--paper);
    border-radius: var(--radius);
    max-width: 600px; width: 100%;
    max-height: 82vh; overflow-y: auto;
    padding: 26px;
    position: relative;
    box-shadow: 0 20px 60px rgba(23,34,59,0.25);
    animation: pop .18s ease;
}
@keyframes pop {
    from { opacity: 0; transform: scale(0.97) translateY(4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-close {
    position: absolute; top: 14px; right: 16px;
    border: none; background: none;
    font-size: 22px; line-height: 1; cursor: pointer;
    color: var(--muted);
    width: 28px; height: 28px;
    border-radius: 50%;
}
.modal-close:hover { background: var(--paper-dim); color: var(--ink); }

#messageDetail h3 {
    font-family: 'Fraunces', serif;
    font-size: 19px;
    margin: 0 0 12px;
    padding-right: 24px;
}
#messageDetail .meta-row {
    font-size: 13px;
    color: var(--ink-soft);
    margin: 4px 0;
}
#messageDetail hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.msg-html-body { font-size: 14px; line-height: 1.6; }

.qr-modal-content { text-align: center; max-width: 320px; }
.qr-modal-content h3 { font-family: 'Fraunces', serif; margin: 0 0 4px; font-size: 16px; }
#qrCodeBox { display: flex; justify-content: center; margin: 18px 0; }
#qrCodeBox img { border-radius: 8px; border: 1px solid var(--line); }
.qr-address {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12.5px;
    color: var(--muted);
    word-break: break-all;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(0);
    background: var(--ink);
    color: var(--paper);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    z-index: 100;
    transition: opacity .25s, transform .25s;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(8px); pointer-events: none; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    .wrap { padding: 20px 14px 48px; }
    .brand h1 { font-size: 20px; }
    .address-row { flex-wrap: wrap; }
    #mailboxAddress { width: 100%; flex-basis: 100%; font-size: 13.5px; }
    .address-actions { width: 100%; }
    .icon-btn { flex: 1; }
    .stamp-card-inner { padding: 18px 16px; }
    .inbox-head { padding: 14px 16px; }
    .msg-item { padding: 12px 16px; }
}

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

:focus-visible {
    outline: 2px solid var(--air-blue);
    outline-offset: 2px;
}
