:root {
    --primary: #00ff00;
    --secondary: #00d4ff;
    --lightning: #f7931a;
    --danger: #ff4d5e;

    --bg: #050810;
    --bg-raised: #0a0e1a;
    --bg-sunken: #070b14;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(0, 255, 0, 0.25);
    --text: #e8edf4;
    --text-dim: rgba(232, 237, 244, 0.55);
    --text-faint: rgba(232, 237, 244, 0.35);
    --bubble-self: rgba(0, 255, 0, 0.10);
    --bubble-bot: rgba(255, 255, 255, 0.05);
    --code-bg: rgba(0, 0, 0, 0.45);

    --mono: 'Courier New', 'Consolas', 'Monaco', monospace;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --radius: 12px;
    --sidebar-w: 280px;
}

@media (prefers-color-scheme: light) {
    :root {
        --primary: #0a7a2f;
        --secondary: #0077a8;
        --bg: #f2f4f7;
        --bg-raised: #ffffff;
        --bg-sunken: #e8ebef;
        --line: rgba(0, 0, 0, 0.10);
        --line-strong: rgba(10, 122, 47, 0.3);
        --text: #10151c;
        --text-dim: rgba(16, 21, 28, 0.6);
        --text-faint: rgba(16, 21, 28, 0.4);
        --bubble-self: rgba(10, 122, 47, 0.10);
        --bubble-bot: rgba(0, 0, 0, 0.05);
        --code-bg: rgba(0, 0, 0, 0.06);
    }
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }
a { color: var(--secondary); }

button, input, select, textarea { font: inherit; color: inherit; }

/* --- onboarding ---------------------------------------------------------- */

.gate {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: var(--bg);
    overflow-y: auto;
    z-index: 40;
}

.gate-card {
    width: min(560px, 100%);
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.75rem;
}

.wordmark {
    font-family: var(--mono);
    font-size: 0.56rem;
    line-height: 1.06;
    color: var(--primary);
    white-space: pre;
    overflow-x: auto;
    scrollbar-width: none;
    margin-bottom: 1.25rem;
}

.gate-title { font-size: 1.35rem; margin-bottom: 0.5rem; }
.gate-lede { color: var(--text-dim); margin-bottom: 1.25rem; }
.gate-foot { color: var(--text-faint); font-size: 0.8rem; margin-top: 1.25rem; }
.gate-error { color: var(--danger); margin-top: 0.75rem; }

.gate-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.gate-import { margin-top: 1.25rem; }

.reveal-label { display: block; margin: 1rem 0 0.35rem; color: var(--text-dim); font-size: 0.85rem; }
.reveal-row { display: flex; gap: 0.4rem; align-items: center; }
.reveal-row input { flex: 1; min-width: 0; }

.hint { color: var(--text-faint); font-size: 0.82rem; margin-top: 0.4rem; }

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

.btn {
    padding: 0.55rem 1rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--line-strong); }
.btn-primary { border-color: var(--primary); color: var(--primary); }
.btn-primary:hover { background: rgba(0, 255, 0, 0.08); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-ghost { color: var(--text-dim); }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.icon-btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1.3rem;
    line-height: 1;
}
.icon-btn:hover { background: var(--bubble-bot); color: var(--text); }

input[type="text"], input[type="password"], input[type="search"],
input[type="number"], select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--line-strong); }
label { display: block; margin: 0.85rem 0 0.3rem; color: var(--text-dim); font-size: 0.85rem; }
label.check { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
label.check input { width: auto; }

/* --- shell --------------------------------------------------------------- */

.shell { display: flex; height: 100dvh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    background: var(--bg-sunken);
    border-right: 1px solid var(--line);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--line);
}

.brand {
    font-family: var(--mono);
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--primary);
}

.sidebar-search { padding: 0.6rem 0.7rem; }

.conv-list { flex: 1; overflow-y: auto; list-style: none; padding: 0 0.45rem 0.5rem; }

.conv-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    text-align: left;
    cursor: pointer;
}
.conv-item:hover { background: var(--bubble-bot); color: var(--text); }
.conv-item.is-active { background: var(--bubble-self); color: var(--text); }
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badge { font-size: 0.65rem; color: var(--secondary); border: 1px solid currentColor; border-radius: 999px; padding: 0 0.3rem; }

.sidebar-foot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.7rem;
    border-top: 1px solid var(--line);
}

.who {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
}
.who-nym { font-family: var(--mono); font-size: 0.85rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.who-balance { font-size: 0.75rem; color: var(--text-faint); }

.relay-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.relay-dot.is-live { background: var(--primary); box-shadow: 0 0 6px var(--primary); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.chat-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--line);
    position: relative;
}
.chat-title { flex: 1; min-width: 0; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-anon { font-size: 0.7rem; color: var(--secondary); border: 1px solid currentColor; border-radius: 999px; padding: 0 0.4rem; }

.menu {
    position: absolute;
    top: 100%;
    right: 0.6rem;
    z-index: 20;
    min-width: 170px;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.3rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}
.menu button {
    display: block;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.menu button:hover { background: var(--bubble-bot); }
.menu button.danger { color: var(--danger); }

/* --- the AI toolbar ------------------------------------------------------ */

.bot-control-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
}
.bot-control-bar::-webkit-scrollbar { display: none; }

.tier-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; flex: 0 0 auto; }
.tier-switch.wide { width: 100%; }
.tier-switch.wide .tier-btn { flex: 1; text-align: center; }

.tier-btn {
    padding: 0.25rem 0.7rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
}
.tier-btn.is-active { background: var(--primary); color: var(--bg); font-weight: 600; }
.bot-control-bar.is-pro .tier-btn.is-active { background: var(--secondary); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.28rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    flex: 0 0 auto;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip.is-active { border-color: var(--secondary); color: var(--secondary); }
.chip-buy { margin-left: auto; border-color: rgba(247, 147, 26, 0.5); color: var(--lightning); }

/* --- messages ------------------------------------------------------------ */

.messages { flex: 1; overflow-y: auto; padding: 1rem 0.85rem 1.5rem; }

.msg { max-width: 760px; margin: 0 auto 1rem; }
.msg-role { font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint); margin-bottom: 0.25rem; }
.msg.is-self .msg-role { color: var(--primary); }
.msg.is-bot .msg-role { color: var(--secondary); }

.msg-body {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius);
    background: var(--bubble-bot);
    overflow-wrap: anywhere;
}
.msg.is-self .msg-body { background: var(--bubble-self); }
.msg.is-note .msg-body { background: transparent; border: 1px dashed var(--line); color: var(--text-dim); }
.msg.is-error .msg-body { border: 1px solid var(--danger); background: transparent; color: var(--danger); }

.msg-body > * + * { margin-top: 0.65rem; }
.msg-body h3, .msg-body h4, .msg-body h5, .msg-body h6 { font-size: 1rem; }
.msg-body ul, .msg-body ol { padding-left: 1.25rem; }
.msg-body code { font-family: var(--mono); background: var(--code-bg); padding: 0.05em 0.35em; border-radius: 4px; font-size: 0.9em; }
.msg-body pre.code { background: var(--code-bg); padding: 0.75rem; border-radius: 8px; overflow-x: auto; }
.msg-body pre.code code { background: none; padding: 0; }
.msg-body blockquote { border-left: 2px solid var(--line-strong); padding: 0.15rem 0 0.15rem 0.75rem; color: var(--text-dim); }
.msg-media { max-width: 100%; border-radius: 8px; display: block; }

.msg-meta { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.35rem; font-size: 0.72rem; color: var(--text-faint); }
.msg-cost { color: var(--lightning); }

.reasoning { margin-bottom: 0.5rem; }
.reasoning summary { cursor: pointer; font-size: 0.78rem; color: var(--text-dim); list-style: none; }
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning-body { margin-top: 0.5rem; padding-left: 0.75rem; border-left: 2px solid var(--line); color: var(--text-dim); font-size: 0.9em; white-space: pre-wrap; }

.thinking { display: flex; align-items: center; gap: 0.4rem; color: var(--text-dim); font-size: 0.85rem; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: bounce 1s infinite; }
.dot:nth-child(3) { animation-delay: 0.15s; }
.dot:nth-child(4) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

.empty { max-width: 560px; margin: 3rem auto; text-align: center; color: var(--text-dim); }
.empty h2 { color: var(--text); font-size: 1.15rem; margin-bottom: 0.5rem; }
.empty-tips { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-top: 1.1rem; }
.empty-tips button { padding: 0.35rem 0.75rem; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 0.85rem; }
.empty-tips button:hover { border-color: var(--line-strong); color: var(--text); }

/* --- composer ------------------------------------------------------------ */

.composer { border-top: 1px solid var(--line); padding: 0.6rem 0.85rem calc(0.6rem + env(safe-area-inset-bottom)); }
.composer-status { max-width: 760px; margin: 0 auto 0.4rem; font-size: 0.8rem; color: var(--text-dim); }
.composer-row { max-width: 760px; margin: 0 auto; display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; }

.send-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--primary);
    border-radius: 50%;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
}
.send-btn:disabled { opacity: 0.4; cursor: default; }

/* --- modals -------------------------------------------------------------- */

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 50; }

.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 1rem; z-index: 60; overflow-y: auto; }
.modal-card {
    width: min(520px, 100%);
    max-height: 90dvh;
    overflow-y: auto;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.modal-card header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.modal-card h2 { font-size: 1.05rem; }
.modal-card footer { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.1rem; }
.modal-lede { color: var(--text-dim); font-size: 0.88rem; margin-bottom: 0.75rem; }
.modal-status { margin-top: 0.6rem; font-size: 0.85rem; color: var(--text-dim); min-height: 1.2em; }
.modal-status.is-warn { color: var(--danger); }
.modal-status.is-ok { color: var(--primary); }

.model-list { max-height: 46vh; overflow-y: auto; margin-top: 0.6rem; }
.model-group { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); margin: 0.85rem 0 0.35rem; }
.model-row { display: flex; gap: 0.5rem; align-items: baseline; width: 100%; padding: 0.5rem 0.6rem; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.model-row:hover { background: var(--bubble-bot); }
.model-row.is-active { background: var(--bubble-self); }
.model-name { flex: 1; min-width: 0; }
.model-desc { display: block; font-size: 0.78rem; color: var(--text-faint); }
.model-cost { font-size: 0.78rem; color: var(--lightning); white-space: nowrap; }

.amount-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin: 0.85rem 0; }
.amount-grid button { padding: 0.4rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; }
.amount-grid button:hover { border-color: var(--line-strong); }

.anon-balances { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 0.85rem 0; font-size: 0.85rem; color: var(--text-dim); }
.anon-move { display: flex; gap: 0.4rem; }
.anon-move input { flex: 1; }
.anon-move select { width: auto; }

.invoice { margin-top: 0.85rem; display: grid; gap: 0.5rem; justify-items: center; }
.invoice canvas { background: #fff; border-radius: 8px; padding: 8px; max-width: 100%; height: auto; }
.invoice textarea { font-family: var(--mono); font-size: 0.72rem; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%);
    z-index: 80;
    padding: 0.6rem 1rem;
    background: var(--bg-raised);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    font-size: 0.85rem;
}

/* --- narrow -------------------------------------------------------------- */

.only-narrow { display: none; }

@media (max-width: 720px) {
    .only-narrow { display: grid; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 55;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .sidebar.is-open { transform: none; }
    .amount-grid { grid-template-columns: repeat(3, 1fr); }
}
