:root {
    --bg: #0b1120;
    --panel: #111a2e;
    --panel2: #16213a;
    --border: #22304d;
    --text: #e2e8f0;
    --muted: #8fa1bd;
    --accent: #38bdf8;
    --keep: #4ade80;
    --spam: #f87171;
    --warn: #fbbf24;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 32px;
    background: radial-gradient(1200px 600px at 50% -10%, #1e2a4a 0%, var(--bg) 60%);
}

/* ---------- masthead ---------- */

.masthead { text-align: center; margin-bottom: 18px; }

.logo {
    font-size: clamp(34px, 6vw, 54px);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1;
}

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

.beta {
    display: inline-block;
    font-size: 0.3em;
    vertical-align: super;
    background: var(--warn);
    color: #111;
    padding: 3px 7px;
    border-radius: 6px;
    margin-left: 8px;
    letter-spacing: 0.12em;
    transform: rotate(-8deg);
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.35);
}

.tagline { color: var(--muted); margin: 8px 0 0; }

/* ---------- mail client ---------- */

.client {
    position: relative;
    width: min(920px, 100%);
    min-height: 580px;
    display: grid;
    grid-template-columns: 200px 1fr;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

.client.shake { animation: shake 0.3s; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

.sidebar {
    background: var(--panel2);
    border-right: 1px solid var(--border);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.compose {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: 1px dashed var(--border);
    background: none;
    color: var(--muted);
    font-size: 13px;
    cursor: not-allowed;
}

.sidebar ul { list-style: none; margin: 0; padding: 0; }

.sidebar li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
}

.sidebar li.active { background: rgba(56, 189, 248, 0.12); color: var(--text); }

.pill {
    background: var(--border);
    border-radius: 999px;
    padding: 0 8px;
    font-size: 12px;
    line-height: 20px;
    font-variant-numeric: tabular-nums;
}

.pill.hot { background: var(--spam); color: #111; font-weight: 700; }

.stats {
    margin-top: auto;
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.stats div { display: flex; justify-content: space-between; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- pane ---------- */

.pane {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.lives { letter-spacing: 2px; font-size: 16px; }
.lives .lost { opacity: 0.25; filter: grayscale(1); }

.meter {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.meter div {
    height: 100%;
    width: 0;
    background: var(--keep);
    transition: width 0.2s, background 0.2s;
}

.icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
}

/* ---------- mail list ---------- */

.list {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.row {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 10px;
    opacity: 0.7;
    animation: slideIn 0.25s ease-out;
    transition: transform 0.22s, opacity 0.22s, height 0.22s, padding 0.22s, margin 0.22s;
}

.row.active {
    opacity: 1;
    background: rgba(56, 189, 248, 0.08);
    border-color: rgba(56, 189, 248, 0.5);
    padding: 14px;
    cursor: grab;
}

.row.dragging { transition: none; cursor: grabbing; }

.row.out-left, .row.out-right {
    opacity: 0;
    height: 0 !important;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -6px;
    border-width: 0;
    overflow: hidden;
}

.row.out-left { transform: translateX(-120%) rotate(-4deg); }
.row.out-right { transform: translateX(120%) rotate(4deg); }

@keyframes slideIn {
    from { transform: translateY(12px); opacity: 0; }
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #0b1120;
    flex-shrink: 0;
}

.row.injected .avatar { background: var(--spam) !important; }

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

.line1 {
    display: flex;
    gap: 8px;
    align-items: baseline;
    min-width: 0;
}

.from { font-weight: 600; white-space: nowrap; }

.addr {
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subject {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.preview {
    display: none;
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.row.active .preview { display: block; }

/* ---------- controls ---------- */

.controls {
    display: flex;
    gap: 10px;
    padding: 10px 12px 14px;
    border-top: 1px solid var(--border);
}

.ctl {
    flex: 1;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel2);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, transform 0.05s;
}

.ctl:active { transform: scale(0.97); }
.ctl.keep:hover, .ctl.keep:active { border-color: var(--keep); color: var(--keep); }
.ctl.spam:hover, .ctl.spam:active { border-color: var(--spam); color: var(--spam); }

/* ---------- bugs and effects ---------- */

.bugs, .fx {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.bug {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: auto;
    background: none;
    border: none;
    font-size: 30px;
    line-height: 1;
    padding: 4px;
    cursor: crosshair;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
}

.bug.flip { transform: scaleX(-1); }

.bug.splat {
    pointer-events: none;
    animation: splat 0.4s forwards;
}

@keyframes splat {
    to { transform: scale(1.8); opacity: 0; }
}

.float {
    position: absolute;
    font-weight: 800;
    font-size: 18px;
    white-space: nowrap;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
    animation: floatUp 0.9s ease-out forwards;
}

.float.good { color: var(--keep); }
.float.bad { color: var(--spam); }
.float.bonus { color: var(--warn); }

@keyframes floatUp {
    from { transform: translate(-50%, -50%); opacity: 1; }
    to { transform: translate(-50%, -160%); opacity: 0; }
}

/* ---------- overlay ---------- */

.overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(11, 17, 32, 0.86);
    backdrop-filter: blur(4px);
}

.overlay[hidden] { display: none; }

.card {
    width: min(440px, 100%);
    padding: 28px;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.card h2 { margin: 0 0 8px; font-size: 28px; }
.card p { margin: 8px 0; color: var(--muted); }
.card p.reason { color: var(--text); }
.card .small { font-size: 13px; }

.how {
    list-style: none;
    padding: 0;
    margin: 16px 0;
    display: grid;
    gap: 8px;
    text-align: left;
}

kbd {
    background: var(--border);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
}

.primary {
    width: 100%;
    margin-top: 12px;
    padding: 14px;
    background: var(--accent);
    color: #0b1120;
    font-weight: 800;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

.primary:hover { filter: brightness(1.1); }

.final {
    display: flex;
    justify-content: space-around;
    margin: 16px 0;
    color: var(--muted);
    font-size: 13px;
}

.final b {
    display: block;
    color: var(--text);
    font-size: 26px;
    font-variant-numeric: tabular-nums;
}

.newbest { color: var(--warn); font-weight: 700; }

/* ---------- toast and footer ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 10;
    transform: translateX(-50%) translateY(20px);
    max-width: 90vw;
    padding: 10px 16px;
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-align: center;
    opacity: 0;
    transition: 0.25s;
    pointer-events: none;
}

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

footer {
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
    body { padding: 16px 12px 24px; }

    .client { grid-template-columns: 1fr; min-height: 0; }

    .sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        padding: 10px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .compose { display: none; }

    .sidebar ul { display: flex; gap: 4px; flex: 1; }
    .sidebar li { padding: 4px 8px; font-size: 12px; gap: 6px; }

    .stats {
        margin: 0;
        width: 100%;
        grid-auto-flow: column;
        gap: 10px;
    }

    .stats div { gap: 6px; }

    .list { min-height: 400px; }

    .addr { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .client.shake, .row, .float, .bug.splat { animation: none; }
    .row { transition: none; }
}
