/* ── Nino Streaming — Modern Remote Game Client ──────────────────────────── */
:root {
    --bg-primary: #0c0c0e;
    --bg-secondary: #141418;
    --bg-card: #1a1a1f;
    --bg-elevated: #222228;
    --border: #2a2a30;
    --border-focus: #0078d4;
    --text-primary: #eee;
    --text-secondary: #888;
    --text-muted: #555;
    --accent: #0078d4;
    --accent-hover: #005a9e;
    --success: #00c853;
    --danger: #c43b00;
    --glow: rgba(0, 200, 83, 0.15);
    --glass-bg: rgba(14, 14, 18, 0.82);
    --glass-border: rgba(255, 255, 255, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --vpad-stick: min(150px, 22vw);
    --vpad-btn: min(60px, 9vw);
    --vpad-btn-lg: min(66px, 10vw);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ── Top bar ────────────────────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar .logo {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.3px;
    white-space: nowrap;
}
.topbar .logo span { color: var(--success); }
.topbar .spacer { flex: 1; }
.topbar-group {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.topbar input[type="text"] {
    padding: 6px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 260px;
    max-width: 40vw;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    white-space: nowrap;
    user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a33000; }
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }
.btn-active {
    background: var(--success) !important;
    color: #000 !important;
}
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ── Status ─────────────────────────────────────────────────────────────── */
#status {
    padding: 8px 14px;
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin: 0 16px 10px;
}
#status.hook { border-left-color: var(--success); }
#status.err { border-left-color: var(--danger); }

/* ── Quality bar ────────────────────────────────────────────────────────── */
.quality-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.quality-bar-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    flex-shrink: 0;
}
.quality-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}
.qb-btn {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.qb-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.qb-btn.active {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    font-weight: 700;
}
.qb-btn .qb-name { font-weight: 600; }
.qb-btn .qb-info { font-size: 9px; opacity: 0.8; }
.qb-abr {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    margin-right: 4px;
}
.qb-abr:hover { background: var(--accent); color: #fff; }
.qb-abr.active {
    background: var(--accent);
    color: #fff;
}

/* ── Main content ───────────────────────────────────────────────────────── */
.main-content { padding: 0 16px 16px; }

/* ── Window picker ──────────────────────────────────────────────────────── */
#picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.card.hook { border-left: 3px solid var(--success); }
.card .name { font-weight: 600; font-size: 14px; }
.card .pid { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
.card .badge {
    display: inline-block;
    padding: 2px 6px;
    background: var(--accent);
    color: white;
    border-radius: 3px;
    font-size: 10px;
    margin-left: 4px;
    vertical-align: middle;
}
.card .badge.hook { background: var(--success); }

/* ── Video container ────────────────────────────────────────────────────── */
#video-container {
    position: relative;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    display: none;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}
#video {
    width: 100%;
    display: block;
}
#audio { display: none; }
#video-overlay {
    position: absolute;
    inset: 0;
    cursor: crosshair;
    z-index: 50;
    outline: none;
}

/* ── Virtual cursor ─────────────────────────────────────────────────────── */
#virtual-cursor {
    position: absolute;
    width: 18px;
    height: 18px;
    pointer-events: none;
    display: none;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.9));
    z-index: 60;
}
#virtual-cursor .arrow {
    position: absolute;
    left: 0; top: 0;
    width: 0; height: 0;
    border-left: 12px solid #fff;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    transform: rotate(45deg);
}
#virtual-cursor .arrow-inner {
    position: absolute;
    left: 2px; top: 2px;
    width: 0; height: 0;
    border-left: 8px solid #111;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    transform: rotate(45deg);
}

/* ── Stats ──────────────────────────────────────────────────────────────── */
#stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 6px;
    margin-top: 8px;
    padding: 0 16px;
}
.stat-box {
    background: var(--bg-card);
    padding: 8px 6px;
    border-radius: var(--radius-sm);
    text-align: center;
}
.stat-box .label { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-box .value { font-size: 14px; font-weight: 700; color: var(--success); }
#stats2 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
    margin-top: 6px;
    padding: 0 16px 8px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* ── Log ────────────────────────────────────────────────────────────────── */
#log {
    max-height: 180px;
    overflow-y: auto;
    padding: 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    margin: 0 16px 16px;
    white-space: pre-wrap;
}

/* ── Virtual pad layer ──────────────────────────────────────────────────── */
#virtual-pad-layer {
    position: absolute;
    inset: 0;
    z-index: 170;
    pointer-events: none;
    display: none;
}
#virtual-pad-layer.enabled { display: block; }

.vpad-control {
    position: absolute;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: rgba(8, 18, 28, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s;
}
.vpad-control.active {
    border-color: var(--success);
    background: rgba(0, 120, 212, 0.35);
}
.vpad-control.editing {
    border-style: dashed;
    border-color: #ffd84d;
}
.vpad-control .vpad-label {
    pointer-events: none;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.15;
    text-shadow: 0 1px 3px #000;
    padding: 6px;
}
.vpad-stick-knob {
    position: absolute;
    width: 36%;
    height: 36%;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 14px rgba(0, 255, 136, 0.4);
    pointer-events: none;
}

/* ── Virtual pad config panel ───────────────────────────────────────────── */
#vpad-panel {
    position: fixed;
    left: 50%;
    bottom: -520px;
    transform: translateX(-50%);
    width: min(720px, calc(100vw - 20px));
    max-height: 520px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    z-index: 5200;
    transition: bottom 0.25s ease;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}
#vpad-panel.open { bottom: 0; }
.vpad-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.vpad-panel-head .btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
#vpad-list { padding: 12px; max-height: 370px; overflow-y: auto; }
.vpad-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-bottom: 10px;
}
.vpad-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.vpad-item input, .vpad-item select {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    background: var(--bg-card);
    color: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* ── Virtual pad picker ─────────────────────────────────────────────────── */
#vpad-picker {
    position: fixed;
    inset: 0;
    z-index: 6100;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.vpad-picker-card {
    width: min(620px, 96vw);
    max-height: 88vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}
.vpad-picker-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.vpad-choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
    gap: 7px;
}
.vpad-choice {
    padding: 10px 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    text-align: center;
    transition: background 0.12s;
}
.vpad-choice:hover { background: var(--bg-card); }
.vpad-choice.selected { background: var(--accent); border-color: #fff; }

/* ── Gamepad calibration wizard ─────────────────────────────────────────── */
#gp-wizard {
    position: fixed;
    inset: 0;
    z-index: 8000;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
}
.gp-title { font-size: 20px; font-weight: 700; margin-bottom: 10px; }
.gp-target { font-size: 28px; font-weight: 800; color: var(--success); margin-bottom: 14px; }
.gp-feedback { font-size: 16px; color: #ffd84d; min-height: 24px; margin-bottom: 12px; }
.gp-part { fill: #333; transition: fill 0.2s; }
.gp-active { fill: var(--success) !important; }
#gp-wizard svg { max-width: 400px; width: 100%; height: auto; }

/* ── Settings modal ─────────────────────────────────────────────────────── */
#settings-modal {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
#settings-modal.open { display: flex; }
.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.settings-panel {
    position: relative;
    width: min(480px, 94vw);
    max-height: 85vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}
.settings-header h2 { font-size: 16px; font-weight: 700; }
.settings-body { padding: 8px 0; }
.settings-section {
    border-bottom: 1px solid var(--border);
    padding: 12px 18px;
}
.settings-section:last-child { border-bottom: none; }
.settings-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    gap: 12px;
}
.setting-row .setting-label { font-size: 13px; }
.setting-row .setting-value { font-size: 12px; color: var(--text-secondary); }

/* Toggle switch */
.toggle {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
    position: absolute;
    inset: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}
.toggle .slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    background: #666;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}
.toggle input:checked + .slider { background: var(--success); border-color: var(--success); }
.toggle input:checked + .slider::after { transform: translateX(18px); background: #fff; }

/* Quality profile selector */
.quality-profiles {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 6px 0;
}
.quality-profile {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.quality-profile:hover { border-color: var(--accent); color: var(--text-primary); }
.quality-profile.active {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    font-weight: 700;
}
.quality-profile .qp-name { display: block; font-weight: 600; }
.quality-profile .qp-info { display: block; font-size: 9px; opacity: 0.8; margin-top: 1px; }

/* Stats in modal */
.modal-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.modal-stat {
    background: var(--bg-card);
    padding: 8px;
    border-radius: var(--radius-sm);
    text-align: center;
}
.modal-stat .label { font-size: 9px; color: var(--text-secondary); text-transform: uppercase; }
.modal-stat .value { font-size: 13px; font-weight: 700; color: var(--success); }

/* Log in modal */
.modal-log {
    max-height: 160px;
    overflow-y: auto;
    padding: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 10px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    margin-top: 6px;
}

/* Show floating menu in fullscreen landscape (any device) */
#floating-menu-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: #fff;
    font-size: 22px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s, background 0.15s;
    padding-bottom: var(--safe-bottom);
}
#floating-menu-btn:active { transform: scale(0.9); }
#floating-menu-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* ── Fullscreen button (topbar) ─────────────────────────────────────────── */
#btnFullscreen {
    display: inline-flex !important;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .topbar { padding: 8px 12px; gap: 6px; }
    .topbar .logo { font-size: 14px; }
    .topbar input[type="text"] { width: 140px; font-size: 12px; }
    .btn { padding: 6px 10px; font-size: 12px; }
    .topbar-group .btn-desktop { display: none; }
    #stats { grid-template-columns: repeat(3, 1fr); padding: 0 12px; }
    #stats2 { padding: 0 12px 6px; }
    #log { margin: 0 12px 12px; }
    #status { margin: 0 12px 8px; }
    .main-content { padding: 0 12px 12px; }
}

/* Touch device optimizations */
body.is-touch #stats,
body.is-touch #stats2 { display: none; }
body.is-touch #log { display: none; }

/* ── Fullscreen mode ────────────────────────────────────────────────────── */
#video-container:fullscreen,
#video-container:-webkit-full-screen {
    max-width: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}
#video-container:fullscreen #video,
#video-container:-webkit-full-screen #video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
}
#video-container:fullscreen #video-overlay,
#video-container:-webkit-full-screen #video-overlay {
    position: absolute;
    inset: 0;
    cursor: none;
}

/* Hide topbar in fullscreen on touch */
body.is-touch.is-fullscreen .topbar { display: none; }
body.is-touch.is-fullscreen #status { display: none; }
body.is-touch.is-fullscreen .main-content { padding: 0; }
body.is-touch.is-fullscreen #video-container {
    max-width: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
body.is-touch.is-fullscreen #video {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    object-fit: contain;
}
body.is-touch.is-fullscreen #video-overlay {
    position: absolute;
    inset: 0;
    cursor: none;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
