:root {
    --bg: #110d07;
    --surface: #1a140b;
    --surface2: #221a0e;
    --surface3: #2e2310;
    --border: #33271436;
    --border2: #3d2e15;
    --text: #f7f0e3;
    --text2: #c4b59c;
    --text3: #8a7a60;
    --accent: #f5a623;
    --accent2: #d6890f;
    --accent-dim: rgba(245,166,35,0.12);
    --accent-glow: rgba(245,166,35,0.28);
    --stamp: #c1432f;
    --stamp-dim: rgba(193,67,47,0.14);
    --green: #6fae6c;
    --shadow: rgba(0,0,0,0.5);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 20% 0%, rgba(245,166,35,0.05) 0%, transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(193,67,47,0.04) 0%, transparent 45%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    font-size: 1rem;
    box-shadow: 0 0 18px var(--accent-glow);
    flex-shrink: 0;
}

.brand-name {
    font-family: 'Fraunces', serif;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand-name span { color: var(--accent); }

.topbar-actions { display: flex; gap: 0.5rem; }

.icon-btn {
    background: transparent;
    border: 1px solid var(--border2);
    color: var(--text2);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.icon-btn.spinning i { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem 3rem;
}

.wrap { width: 100%; max-width: 640px; }

.hero {
    text-align: center;
    padding: 1.5rem 0 2rem;
    animation: fadeUp 0.6s ease both;
}

.hero-eyebrow {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.6rem;
}

.hero h1 {
    font-family: 'Fraunces', serif;
    font-size: 2.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    margin-bottom: 0.5rem;
}

.hero h1 em { font-style: italic; color: var(--accent); }

.hero p {
    color: var(--text2);
    font-size: 0.9rem;
    max-width: 360px;
    margin: 0 auto;
    line-height: 1.6;
}

.stamp-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    animation: fadeUp 0.6s 0.1s ease both;
    position: relative;
    overflow: hidden;
}

.stamp-card::before {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 120px;
    height: 120px;
    background: var(--accent-dim);
    border-radius: 50%;
    pointer-events: none;
}

.active-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
    position: relative;
    z-index: 1;
}

.active-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text3);
}

.switch-addr-btn {
    background: transparent;
    border: 1px solid var(--border2);
    color: var(--text2);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.2s;
}

.switch-addr-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.switch-addr-btn.hidden { display: none; }

.active-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.5rem 0.5rem;
    gap: 0.6rem;
    position: relative;
    z-index: 1;
}

.active-empty i { font-size: 1.6rem; color: var(--text3); }

.active-empty p {
    color: var(--text2);
    font-size: 0.85rem;
    max-width: 280px;
    line-height: 1.6;
}

.active-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    position: relative;
    z-index: 1;
    margin-bottom: 1rem;
}

.active-addr {
    flex: 1;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    word-break: break-all;
    min-width: 0;
}

.sq-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: 10px;
    color: var(--text2);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sq-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.sq-btn.copied { border-color: var(--green); color: var(--green); }
.sq-btn.danger:hover { border-color: var(--stamp); color: var(--stamp); background: var(--stamp-dim); }

.gen-actions { display: flex; gap: 0.6rem; position: relative; z-index: 1; }

.btn-primary {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-primary:hover { background: var(--accent2); box-shadow: 0 4px 18px var(--accent-glow); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    color: var(--text2);
    border: 1px solid var(--border2);
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.manual-toggle { margin-top: 0.85rem; position: relative; z-index: 1; }

.manual-toggle-btn {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text3);
    font-size: 0.78rem;
    font-family: 'IBM Plex Mono', monospace;
    cursor: pointer;
    padding: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: color 0.2s;
}

.manual-toggle-btn:hover { color: var(--accent); }

.manual-panel {
    display: none;
    margin-top: 0.75rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    flex-direction: column;
    gap: 0.6rem;
}

.manual-panel.show { display: flex; }

.manual-input-row {
    display: flex;
    align-items: center;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.manual-input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.manual-input-row input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    padding: 0.7rem 0.5rem 0.7rem 0.9rem;
    min-width: 0;
}

.manual-input-row input::placeholder { color: var(--text3); }

.domain-select {
    background: var(--surface3);
    border: none;
    border-left: 1px solid var(--border2);
    color: var(--text2);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    padding: 0.7rem 0.6rem;
    outline: none;
    cursor: pointer;
    max-width: 120px;
}

.manual-msg {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    display: none;
    line-height: 1.5;
}

.manual-msg.show { display: block; }
.manual-msg.err { background: var(--stamp-dim); color: var(--stamp); border: 1px solid rgba(193,67,47,0.25); }
.manual-msg.ok { background: rgba(111,174,108,0.1); color: var(--green); border: 1px solid rgba(111,174,108,0.25); }

.manual-suggest-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.74rem;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    margin-top: 0.3rem;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
    animation: fadeUp 0.6s 0.15s ease both;
}

.section-title { font-family: 'Fraunces', serif; font-size: 1.05rem; font-weight: 600; }

.section-title .count {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    color: var(--text3);
    font-weight: 500;
    margin-left: 0.4rem;
}

.mail-list { display: flex; flex-direction: column; gap: 0.6rem; animation: fadeUp 0.6s 0.2s ease both; }

.mail-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.mail-item:hover { border-color: var(--border2); background: var(--surface2); }

.mail-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    margin-top: 0.4rem;
    box-shadow: 0 0 8px var(--accent-glow);
}

.mail-dot.read { background: var(--border2); box-shadow: none; }

.mail-body { flex: 1; min-width: 0; }

.mail-subject {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mail-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    color: var(--text3);
    display: flex;
    gap: 0.6rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mail-meta .from { color: var(--text2); overflow: hidden; text-overflow: ellipsis; }
.mail-time { font-family: 'IBM Plex Mono', monospace; font-size: 0.7rem; color: var(--text3); flex-shrink: 0; margin-top: 0.05rem; }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 3rem 1rem;
    gap: 0.75rem;
    color: var(--text3);
    animation: fadeUp 0.6s 0.2s ease both;
}

.empty-state i { font-size: 2rem; opacity: 0.5; }
.empty-state p { font-size: 0.85rem; max-width: 280px; line-height: 1.6; }

.reader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.reader-overlay.show { opacity: 1; pointer-events: all; }

.reader-panel {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 18px 18px 0 0;
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.reader-overlay.show .reader-panel { transform: translateY(0); }

@media (min-width: 660px) {
    .reader-overlay { align-items: center; }
    .reader-panel { border-radius: 18px; max-height: 80vh; transform: scale(0.96); }
    .reader-overlay.show .reader-panel { transform: scale(1); }
}

.reader-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 0.75rem;
}

.reader-head-text { min-width: 0; flex: 1; }

.reader-head-title {
    font-family: 'Fraunces', serif;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    word-break: break-word;
    margin-bottom: 0.3rem;
}

.reader-head-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    color: var(--text3);
    line-height: 1.6;
    word-break: break-word;
}

.reader-head-meta b { color: var(--text2); font-weight: 600; }
.reader-head-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.reader-body {
    padding: 1.25rem;
    overflow-y: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text2);
}

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(2rem);
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border2);
    padding: 0.7rem 1.25rem;
    border-radius: 10px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
    z-index: 999;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.confirm-dialog, .switch-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 1rem;
}

.confirm-dialog.hidden, .switch-dialog.hidden { display: none; }

.confirm-box, .switch-box {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 14px;
    padding: 1.5rem;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 20px 60px var(--shadow);
}

.confirm-icon {
    width: 42px;
    height: 42px;
    background: var(--stamp-dim);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--stamp);
    margin-bottom: 1rem;
}

.confirm-title, .switch-title { font-family: 'Fraunces', serif; font-size: 1rem; font-weight: 700; margin-bottom: 0.4rem; }
.confirm-desc { font-size: 0.8rem; color: var(--text2); line-height: 1.5; margin-bottom: 1.25rem; }
.confirm-actions { display: flex; gap: 0.5rem; }

.confirm-cancel {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border2);
    color: var(--text2);
    padding: 0.55rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.confirm-cancel:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.confirm-ok {
    flex: 1;
    background: var(--stamp);
    border: none;
    color: #fff;
    padding: 0.55rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.confirm-ok:hover { background: #a8392a; }

.switch-box { max-height: 70vh; display: flex; flex-direction: column; }

.switch-desc {
    font-size: 0.78rem;
    color: var(--text3);
    margin-bottom: 1rem;
    font-family: 'IBM Plex Mono', monospace;
}

.switch-bulk-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--accent);
}

.switch-bulk-bar.show { display: flex; }

.switch-bulk-del {
    background: var(--stamp);
    border: none;
    color: #fff;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.switch-bulk-del:hover { background: #a8392a; }

.switch-list { display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto; margin-bottom: 1rem; }

.switch-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.switch-item:hover { border-color: var(--accent); background: var(--accent-dim); }
.switch-item.active { border-color: var(--accent); background: var(--accent-dim); }

.switch-item-check-box {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.switch-item-addr {
    flex: 1;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--text);
    word-break: break-all;
    min-width: 0;
}

.switch-item.active .switch-item-addr { color: var(--accent); font-weight: 600; }
.switch-item-check { color: var(--accent); font-size: 0.85rem; flex-shrink: 0; }
.switch-empty { text-align: center; color: var(--text3); font-size: 0.8rem; padding: 1.5rem 0; }

.switch-close {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border2);
    color: var(--text2);
    padding: 0.6rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.switch-close:hover { border-color: var(--accent); color: var(--accent); }

footer {
    text-align: center;
    padding: 1.5rem 1rem 2rem;
    color: var(--text3);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { color: var(--accent2); }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}
