:root {
    --bg: #08080e;
    --surface: #111119;
    --surface-2: #1a1a26;
    --border: #2a2a3c;
    --text: #d8d8e8;
    --text-dim: #7878a0;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, .25);
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --radius: 10px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── top bar ──────────────────────────────────────────────── */

header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

.logo {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .5px;
    color: var(--accent);
}

.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-dim); transition: background .3s;
}
.status-dot.ok   { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.err  { background: var(--error);   box-shadow: 0 0 6px var(--error); }
.status-dot.warn { background: var(--warning); box-shadow: 0 0 6px var(--warning); }

#statusText { font-size: 13px; color: var(--text-dim); flex: 1; }
#deviceName { font-size: 13px; font-family: var(--mono); color: var(--text-dim); }

.btn {
    padding: 6px 16px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface-2); color: var(--text); font-size: 13px;
    cursor: pointer; transition: all .15s;
}
.btn:hover { border-color: var(--accent); background: var(--accent-glow); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-sm { padding: 4px 10px; font-size: 11px; }

.btn-primary {
    background: var(--accent); border-color: var(--accent);
    color: #fff; font-weight: 600;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:disabled { opacity: .4; }

.btn-run { padding: 6px 20px; }

/* ── workspace: screen + side panel ──────────────────────── */

#workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

#screenArea {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    min-width: 0;
}

#screen, #videoFallback {
    max-width: 100%; max-height: 100%;
    object-fit: contain; touch-action: none;
    cursor: crosshair; image-rendering: auto;
}
#videoFallback { display: none; background: #000; }

/* ── overlay ──────────────────────────────────────────────── */

#overlay {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 16px;
    background: rgba(8, 8, 14, .85);
    transition: opacity .3s; z-index: 5;
}
#overlay.hidden { opacity: 0; pointer-events: none; }

#overlay .spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#overlay .msg { font-size: 15px; color: var(--text-dim); }

/* ── right control panel ─────────────────────────────────── */

#controlPanel {
    width: 340px;
    flex-shrink: 0;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-section {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.panel-section.panel-log-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--accent);
    margin-bottom: 8px;
}

.panel-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

#accountsArea {
    width: 100%;
    height: 100px;
    resize: vertical;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text);
    outline: none;
    transition: border-color .2s;
    user-select: text;
    -webkit-user-select: text;
}
#accountsArea:focus { border-color: var(--accent); }

#accountsCount {
    font-size: 12px;
    color: var(--text-dim);
    font-family: var(--mono);
}

#spinCount {
    width: 56px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    font-family: var(--mono);
    text-align: center;
    outline: none;
}
#spinCount:focus { border-color: var(--accent); }

label {
    font-size: 12px;
    color: var(--text-dim);
}

#progressText {
    font-size: 12px;
    font-family: var(--mono);
    color: var(--success);
}

/* ── prep log messages ───────────────────────────────────── */

#prepMessages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    font-family: var(--mono);
    color: var(--text-dim);
    min-height: 0;
}
#prepMessages .prep-line { line-height: 1.5; word-break: break-word; }
#prepMessages .prep-line.ok { color: var(--success); }
#prepMessages .prep-line.err { color: var(--error); }
#prepMessages .prep-line.info { color: var(--accent); }

/* ── code modal ──────────────────────────────────────────── */

#codeModal {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(8, 8, 14, .8); z-index: 20;
    transition: opacity .3s;
}
#codeModal.hidden { opacity: 0; pointer-events: none; }

.modal-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 28px 32px;
    display: flex; flex-direction: column; align-items: center;
    gap: 12px; min-width: 300px;
}
.modal-title { font-size: 18px; font-weight: 600; color: var(--accent); }
.modal-desc { font-size: 13px; color: var(--text-dim); text-align: center; }
#codeInput {
    width: 180px; padding: 10px 16px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface-2); color: var(--text);
    font-size: 20px; font-family: var(--mono); text-align: center;
    outline: none; transition: border-color .2s;
}
#codeInput:focus { border-color: var(--accent); }

/* ── floating card bind button ────────────────────────────── */

#btnCardBind {
    display: none;
    position: fixed;
    bottom: 40px; right: 20px;
    padding: 12px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    z-index: 15;
    box-shadow: 0 4px 20px rgba(99, 102, 241, .4);
    transition: opacity .2s, transform .2s;
}
#btnCardBind:hover { opacity: .9; transform: scale(1.03); }
#btnCardBind:active { transform: scale(.97); }
body.guest-mobile #btnCardBind { bottom: 16px; right: 12px; font-size: 13px; padding: 10px 16px; }

/* ── card modal ──────────────────────────────────────────── */

#cardModal {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(8, 8, 14, .85); z-index: 25;
    transition: opacity .3s;
}
#cardModal.hidden { opacity: 0; pointer-events: none; }

.card-modal-box { min-width: 340px; }

.card-row { display: flex; gap: 12px; width: 100%; }

#cardNumber, #cardExpiry, #cardCvv {
    width: 100%; padding: 12px 16px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface-2); color: var(--text);
    font-size: 18px; font-family: var(--mono); text-align: center;
    outline: none; transition: border-color .2s;
}
#cardExpiry { max-width: 120px; }
#cardCvv { max-width: 100px; }
#cardNumber:focus, #cardExpiry:focus, #cardCvv:focus { border-color: var(--accent); }

.card-btns { display: flex; gap: 12px; width: 100%; }
.card-btns .btn { flex: 1; }

/* ── QR modal ────────────────────────────────────────────── */

#qrModal {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(8, 8, 14, .9); z-index: 30;
    transition: opacity .3s;
}
#qrModal.hidden { opacity: 0; pointer-events: none; }

.qr-modal-box {
    min-width: 320px; max-width: 380px;
}

#qrCanvas {
    background: #fff; border-radius: 12px; padding: 16px;
    display: flex; align-items: center; justify-content: center;
}
#qrCanvas img, #qrCanvas canvas { display: block; }

.qr-link {
    color: var(--accent); font-size: 13px;
    text-decoration: none; word-break: break-all;
    text-align: center;
}
.qr-link:hover { text-decoration: underline; }

/* ── log bar (bottom) ────────────────────────────────────── */

#logBar {
    height: 28px; padding: 0 20px;
    display: flex; align-items: center;
    background: var(--surface); border-top: 1px solid var(--border);
    font-size: 12px; font-family: var(--mono); color: var(--text-dim);
    overflow: hidden; white-space: nowrap; flex-shrink: 0;
}

/* ── fullscreen ──────────────────────────────────────────── */

:fullscreen header, :fullscreen #logBar, :fullscreen #controlPanel { display: none; }
:fullscreen #workspace { height: 100vh; }

/* ── guest mobile: hide chrome, maximize screen ─────────── */

body.guest-mobile header { display: none; }
body.guest-mobile #logBar { display: none; }
body.guest-mobile #app { height: 100vh; height: 100dvh; }
body.guest-mobile #workspace { height: 100vh; height: 100dvh; }
body.guest-mobile #screenArea { border-radius: 0; }
