:root {
    --bg: #07111f;
    --surface: #0d1a2b;
    --card: #101f33;
    --text: #edf6ff;
    --muted: #8fa4bb;
    --accent: #00e6a0;
    --accent-2: #55b8ff;
    --danger: #ff657a;
    --glass-border: rgba(255,255,255,.12);
    --border-light: rgba(255,255,255,.18);
    --shadow: rgba(0,0,0,.35);
    --radius: 14px;
    --max-width: 900px;
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --card: #ffffff;
    --text: #132033;
    --muted: #5e6c7d;
    --glass-border: rgba(15,35,55,.14);
    --border-light: rgba(15,35,55,.18);
    --shadow: rgba(15,35,55,.15);
}

[data-theme="retro"] {
    --bg: #17120d;
    --surface: #231a12;
    --card: #2b2016;
    --text: #ffe9b2;
    --muted: #c8a878;
    --accent: #ffb52e;
    --accent-2: #ff6b35;
    --glass-border: rgba(255,181,46,.25);
    --border-light: rgba(255,181,46,.3);
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 50% 0%, rgba(0,230,160,.08), transparent 35%),
        var(--bg);
    color: var(--text);
    font-family: var(--font-family);
    -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(85,184,255,.45);
    outline-offset: 2px;
}

.titlebar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 64px;
    padding: 10px max(16px, env(safe-area-inset-right))
             10px max(16px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
}

.title h1 {
    margin: 0;
    font-size: clamp(20px, 5vw, 25px);
}

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

.menu {
    width: 46px;
    height: 46px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.menu-panel {
    position: fixed;
    top: 70px;
    right: 12px;
    width: min(330px, calc(100vw - 24px));
    padding: 14px;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    background: var(--card);
    box-shadow: 0 16px 45px var(--shadow);
}

.menu-panel-content {
    display: grid;
    gap: 12px;
}

.menu-select {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}

.menu-select select,
.menu-button,
.secondary,
.primary {
    min-height: 44px;
}

.menu-select select,
.menu-button,
.secondary {
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    padding: 9px 12px;
}

.menu-button,
.secondary,
.primary {
    cursor: pointer;
    touch-action: manipulation;
}

.layout {
    width: min(var(--max-width), 100%);
    margin: 0 auto;
    padding: 18px max(14px, env(safe-area-inset-left))
             30px max(14px, env(safe-area-inset-right));
    display: grid;
    gap: 14px;
}

.card {
    background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px var(--shadow);
}

.login,
.game { padding: clamp(18px, 5vw, 28px); }

.login .form {
    display: grid;
    gap: 14px;
    width: min(100%, 440px);
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: .94rem;
}

input,
select {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--surface);
    color: var(--text);
}

.primary {
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    background: linear-gradient(90deg, var(--accent), #00ffa8);
    color: #04120d;
    font-weight: 700;
}

.hint,
.voice-help,
.footer { color: var(--muted); }

.hint { font-size: .82rem; }

#notifications {
    display: grid;
    gap: 8px;
}

.note {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    font-size: .9rem;
}

.note.warning { border-color: rgba(255,101,122,.5); }
.note.message { border-color: rgba(0,230,160,.35); }

.balanceRow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 1fr);
    gap: 28px;
    align-items: start;
}

.balanceBox { padding-top: 8px; }

.balanceBox h3 { margin: 0 0 5px; }

.balance {
    color: var(--accent);
    font-size: clamp(30px, 8vw, 46px);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.speech-area {
    display: grid;
    justify-items: center;
    gap: 9px;
    text-align: center;
}

.sound-bars {
    height: 24px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.bar {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--border-light);
    transition: height .15s ease, background .15s ease;
}

.voice-active .bar:nth-child(1) { height: 12px; }
.voice-active .bar:nth-child(2) { height: 22px; }
.voice-active .bar:nth-child(3) { height: 16px; }
.voice-active .bar:nth-child(4) { height: 24px; }
.voice-active .bar:nth-child(5) { height: 10px; }
.voice-active .bar { background: var(--accent); }

.recognized {
    width: 100%;
    min-height: 2.5em;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--text);
}

.glow {
    width: 82px;
    height: 82px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    font-size: 31px;
    cursor: pointer;
    touch-action: manipulation;
}

#micBtn.active {
    animation: pulseMic 1.25s infinite;
}

@keyframes pulseMic {
    50% {
        transform: scale(1.06);
        box-shadow: 0 0 28px rgba(0,230,160,.55);
    }
}

.voice-help {
    margin: 0;
    font-size: .82rem;
}

.manual-command {
    width: 100%;
    margin-top: 4px;
}

.command-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-top: 6px;
}

.secondary {
    color: var(--accent);
    border-color: var(--accent);
    font-weight: 700;
}

.receipt { margin-top: 18px; padding: 16px; }

.receipt h4 { margin: 0; }

.purchase-list {
    list-style: none;
    padding: 0;
    margin: 12px 0;
    max-height: 340px;
    overflow: auto;
}

.purchase-item {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto 42px;
    align-items: center;
    gap: 8px;
    padding: 10px;
    margin-bottom: 8px;
    border: 1px dashed var(--border-light);
    border-radius: 10px;
}

.item-name { overflow-wrap: anywhere; }

.item-amount {
    color: var(--accent);
    white-space: nowrap;
}

.remove {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--danger);
    font-size: 24px;
    cursor: pointer;
}

.total {
    padding-top: 10px;
    border-top: 1px solid var(--glass-border);
    font-weight: 800;
}

.receipt-footer {
    margin-top: 12px;
    color: var(--muted);
    font-size: .8rem;
}

.footer {
    width: min(var(--max-width), 100%);
    margin: 0 auto;
    padding: 12px 16px 24px;
    text-align: center;
}

.about-dialog {
    width: min(680px, calc(100% - 24px));
    max-height: min(80vh, 700px);
    padding: 0;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    background: var(--card);
    color: var(--text);
    box-shadow: 0 20px 60px var(--shadow);
}

.about-dialog::backdrop {
    background: rgba(0,0,0,.7);
}

.modal-content {
    position: relative;
    padding: 24px;
}

.modal-content h2 { color: var(--accent); }
.modal-content h3 { color: var(--accent-2); }

.btn-close-about {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

[hidden] { display: none !important; }

@media (max-width: 680px) {
    .titlebar {
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .balanceRow {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .speech-area {
        width: 100%;
    }

    .glow {
        width: 88px;
        height: 88px;
    }

    .command-row {
        grid-template-columns: 1fr;
    }

    .command-row button {
        width: 100%;
    }

    .menu-select {
        grid-template-columns: 1fr;
    }
}
