:root {
    --bg-dark: #12131a;
    --panel-bg: #1c1d28;
    --panel-border: #2d3045;
    --gb-body: #d2d0c8;
    --gb-bezel: #686976;
    --gb-screen-bg: #8b956d;
    --gb-btn-ab: #8f1d4f;
    --gb-btn-ab-active: #5f1133;
    --gb-dpad: #2b2b2b;
    --gb-dpad-active: #151515;
    --anarchy-color: #ff3344;
    --democracy-color: #00a2ff;
    --text-main: #f0f2f5;
    --text-muted: #8b92a5;
    --accent-gold: #ffcb05;
    --font-pixel: 'Press Start 2P', monospace;
    --font-term: 'VT323', monospace;
}

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

html {
    overflow-x: hidden;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    scrollbar-color: #2d3045 #12131a;
    -webkit-text-size-adjust: 100%;
}

button, input, select, textarea {
    touch-action: manipulation;
}

.dpad-btn, .action-btn, .sys-btn, .vote-mode-btn, .quick-chip, .subtle-btn, .admin-gear-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Custom persistent scrollbar: eliminates macOS auto-fading overlay twitching */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: #12131a;
}
::-webkit-scrollbar-thumb {
    background: #2d3045;
    border-radius: 5px;
    border: 2px solid #12131a;
}
::-webkit-scrollbar-thumb:hover {
    background: #424666;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    padding: 16px;
    margin: 0;
    overflow-x: hidden;
}

.layout-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
    box-sizing: border-box;
}

/* HEADER */
.app-header {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    min-height: 64px;
    height: 64px;
    overflow: hidden;
}

.header-branding {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.pokeball-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(180deg, #e52521 0%, #e52521 44%, #111 44%, #111 56%, #fff 56%, #fff 100%);
    border: 2px solid #111;
    position: relative;
    flex-shrink: 0;
    display: inline-block;
}

.pokeball-icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    background: #fff;
    border: 2px solid #111;
    border-radius: 50%;
}

.header-branding h1 {
    font-family: var(--font-pixel);
    font-size: 14px;
    letter-spacing: 0.5px;
    color: var(--accent-gold);
    text-shadow: 2px 2px 0px #000;
    white-space: nowrap;
    flex-shrink: 0;
    margin: 0;
    line-height: 1;
}

.badge {
    font-size: 9px;
    font-family: var(--font-pixel);
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: bold;
    white-space: nowrap;
    flex-shrink: 0;
}

.docker-badge {
    background: #0066cc;
    color: #fff;
    border: 1px solid #3399ff;
}

.header-stats {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.stat-pill {
    background: #111219;
    border: 1px solid #31354c;
    border-radius: 6px;
    padding: 6px 10px;
    font-family: var(--font-pixel);
    font-size: 10px;
    display: flex;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    align-items: center;
}

.stat-pill .label {
    color: var(--text-muted);
}

.stat-pill .val {
    color: #00ffaa;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    display: inline-block;
}

#stat-fps { min-width: 32px; text-align: right; }
#stat-viewers { min-width: 14px; text-align: right; }
#stat-total-inputs { min-width: 20px; text-align: right; }
#stat-rom { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* MAIN GRID */
.main-grid {
    display: grid;
    grid-template-columns: 460px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.game-column {
    width: 460px;
    min-width: 460px;
    max-width: 460px;
    flex-shrink: 0;
}


/* GAMEBOY CHASSIS */
.gameboy-chassis {
    background: var(--gb-body);
    border: 3px solid #b5b3aa;
    border-radius: 20px 20px 60px 20px;
    padding: 24px 20px 40px 20px;
    box-shadow: 0 16px 32px rgba(0,0,0,0.6), inset 0 2px 4px rgba(255,255,255,0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 460px;
    max-width: 100%;
    flex-shrink: 0;
}

/* SCREEN BEZEL */
.screen-bezel {
    background: var(--gb-bezel);
    border-radius: 12px 12px 36px 12px;
    padding: 16px 18px;
    width: 100%;
    max-width: 400px;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.5);
}

.bezel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.stripe-line {
    height: 3px;
    width: 24px;
    border-radius: 2px;
}
.stripe-line.blue { background: #264a7f; }
.stripe-line.red { background: #8c2635; }

.bezel-title {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #bbb;
    letter-spacing: 0.5px;
}

.screen-viewport {
    position: relative;
    width: 320px;
    height: 288px;
    max-width: 100%;
    aspect-ratio: 10 / 9;
    margin: 0 auto;
    background: #000;
    border: 4px solid #333;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
    contain: paint layout;
    flex-shrink: 0;
}

#game-stream {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
    display: block;
}

.bezel-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 10px;
    padding: 0 4px;
}

.bezel-sub {
    font-family: var(--font-pixel);
    font-size: 7px;
    color: #888;
}

.subtle-btn {
    background: #4a4b56;
    color: #eee;
    border: 1px solid #666;
    border-radius: 4px;
    font-size: 9px;
    padding: 4px 8px;
    cursor: pointer;
    font-family: var(--font-pixel);
    transition: background 0.1s;
}

.subtle-btn:hover { background: #5a5b68; }
.save-btn { background: #2f6b3b; border-color: #48a05a; }
.save-btn:hover { background: #3b874a; }

/* BRANDING STRIP */
.brand-strip {
    width: 100%;
    padding: 0 16px;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.gameboy-logo {
    font-size: 18px;
    font-weight: 900;
    color: #2c356b;
    letter-spacing: -1px;
}

.color-text {
    font-family: var(--font-pixel);
    font-size: 10px;
    font-weight: bold;
    background: linear-gradient(90deg, #e52521, #0099ff, #fecb00, #43b02a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* CONTROLLER PAD */
.controller-pad {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 10px 0 10px;
}

/* DPAD */
.dpad-container {
    position: relative;
    width: 120px;
    height: 120px;
}

.dpad-btn {
    position: absolute;
    background: var(--gb-dpad);
    color: #777;
    border: none;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
    user-select: none;
    touch-action: manipulation;
}

.dpad-btn:active {
    background: var(--gb-dpad-active);
    color: #fff;
    transform: scale(0.96);
}

.dpad-up {
    top: 0; left: 40px; width: 40px; height: 42px;
    border-radius: 6px 6px 0 0;
}
.dpad-down {
    bottom: 0; left: 40px; width: 40px; height: 42px;
    border-radius: 0 0 6px 6px;
}
.dpad-left {
    top: 40px; left: 0; width: 42px; height: 40px;
    border-radius: 6px 0 0 6px;
}
.dpad-right {
    top: 40px; right: 0; width: 42px; height: 40px;
    border-radius: 0 6px 6px 0;
}
.dpad-center {
    position: absolute;
    top: 40px; left: 40px; width: 40px; height: 40px;
    background: var(--gb-dpad);
}

/* ACTION BUTTONS (A / B) */
.action-buttons {
    display: flex;
    gap: 16px;
    transform: rotate(-25deg);
    padding-top: 10px;
}

.btn-cluster {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gb-btn-ab);
    color: #fff;
    font-family: var(--font-pixel);
    font-size: 16px;
    font-weight: bold;
    border: none;
    box-shadow: 0 6px 8px rgba(0,0,0,0.4), inset 0 2px 4px rgba(255,255,255,0.2);
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
}

.action-btn:active {
    background: var(--gb-btn-ab-active);
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.btn-cluster label {
    font-family: var(--font-pixel);
    font-size: 9px;
    color: #2c356b;
    font-weight: bold;
}

/* SYSTEM BUTTONS (SELECT / START) */
.system-buttons {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 8px;
}

.sys-btn-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transform: rotate(-25deg);
}

.sys-btn {
    width: 54px;
    height: 14px;
    border-radius: 7px;
    background: #6a6a75;
    border: none;
    box-shadow: 0 3px 5px rgba(0,0,0,0.4);
    cursor: pointer;
    font-size: 0;
    user-select: none;
}

.sys-btn:active {
    background: #4a4a55;
    transform: translateY(1px);
}

.sys-btn-wrap label {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: #2c356b;
    font-weight: bold;
}

/* KEYBOARD GUIDE */
.keyboard-guide {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 14px;
}

.keyboard-guide h3 {
    font-size: 12px;
    font-family: var(--font-pixel);
    margin-bottom: 6px;
    color: var(--accent-gold);
}

.keyboard-guide p {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.keyboard-guide span {
    color: #fff;
    background: #2a2c3d;
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: bold;
}

/* SIDEBAR COLUMN */
.sidebar-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.panel-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-pixel);
    font-size: 11px;
    color: #e0e4ec;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 8px;
}

.badge-mini {
    background: #111219;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 9px;
    color: var(--text-muted);
}

/* MODE PANEL & TUG OF WAR */
.mode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.mode-badge {
    font-family: var(--font-pixel);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: bold;
    text-shadow: 1px 1px 0 #000;
}

.mode-badge.anarchy {
    background: var(--anarchy-color);
    color: #fff;
    box-shadow: 0 0 10px rgba(255, 51, 68, 0.4);
}

.mode-badge.democracy {
    background: var(--democracy-color);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 162, 255, 0.4);
}

.mode-vote-actions {
    display: flex;
    gap: 8px;
}

.vote-mode-btn {
    font-family: var(--font-pixel);
    font-size: 9px;
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.1s, opacity 0.1s;
}

.vote-mode-btn:active { transform: scale(0.96); }
.anarchy-btn { background: #55141b; color: #ff8899; border: 1px solid var(--anarchy-color); }
.anarchy-btn:hover { background: var(--anarchy-color); color: #fff; }
.democracy-btn { background: #0c2b4d; color: #88ccff; border: 1px solid var(--democracy-color); }
.democracy-btn:hover { background: var(--democracy-color); color: #fff; }

.meter-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.meter-labels {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-pixel);
    font-size: 9px;
    color: var(--text-muted);
}

.meter-track {
    height: 12px;
    background: #0d0e14;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    border: 1px solid #31354c;
}

.meter-fill-anarchy {
    background: var(--anarchy-color);
    transition: width 0.3s ease;
}

.meter-fill-democracy {
    background: var(--democracy-color);
    transition: width 0.3s ease;
}

/* DEMOCRACY ROUND DETAILS */
.democracy-round-box {
    margin-top: 14px;
    background: #111422;
    border: 1px dashed var(--democracy-color);
    border-radius: 8px;
    padding: 10px;
}

.dem-timer-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-pixel);
    font-size: 10px;
    margin-bottom: 8px;
}

.countdown-clock {
    color: #ffcc00;
    font-size: 14px;
    font-family: var(--font-term);
}

.dem-votes-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dem-vote-item {
    display: flex;
    justify-content: space-between;
    background: #1a1e33;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: var(--font-pixel);
    font-size: 9px;
}

/* LIVE INPUT TICKER */
.input-history-ticker {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
    min-height: 58px;
    height: 58px;
    align-items: center;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: #2d3045 transparent;
}

.input-history-ticker::-webkit-scrollbar {
    height: 4px;
}
.input-history-ticker::-webkit-scrollbar-track {
    background: transparent;
}
.input-history-ticker::-webkit-scrollbar-thumb {
    background: #2d3045;
    border-radius: 2px;
}

.history-item {
    background: #12131c;
    border: 1px solid #2d3045;
    border-radius: 6px;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 72px;
    flex-shrink: 0;
}

.history-cmd {
    font-family: var(--font-pixel);
    font-size: 12px;
    color: #ffcc00;
    font-weight: bold;
}

.history-user {
    font-size: 9px;
    color: var(--text-muted);
    max-width: 65px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-source {
    font-size: 8px;
    text-transform: uppercase;
    color: #727b99;
}

/* CHAT PANEL */
.chat-messages {
    height: 240px;
    min-height: 240px;
    max-height: 240px;
    overflow-y: scroll;
    scrollbar-width: thin;
    scrollbar-color: #2d3045 transparent;
    background: #12131d;
    border: 1px solid #282a3d;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 10px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #2d3045;
    border-radius: 3px;
}

.chat-msg {
    display: flex;
    gap: 6px;
    align-items: baseline;
    word-break: break-word;
}

.chat-msg .time {
    color: #555c73;
    font-size: 11px;
}

.chat-msg .author {
    font-weight: bold;
    color: #00bbff;
}

.chat-msg.system {
    color: #ffb833;
    font-style: italic;
    background: rgba(255, 184, 51, 0.08);
    padding: 4px 6px;
    border-radius: 4px;
}

.quick-commands {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.quick-chip {
    background: #25283b;
    color: #cfd4e6;
    border: 1px solid #393d59;
    border-radius: 4px;
    padding: 5px 9px;
    font-family: var(--font-pixel);
    font-size: 8px;
    cursor: pointer;
}

.quick-chip:hover {
    background: #393d59;
    color: #fff;
}

.quick-chip:active {
    transform: scale(0.95);
}

.chat-input-form {
    display: flex;
    gap: 8px;
}

.user-field {
    width: 90px;
    background: #13141f;
    border: 1px solid #30334c;
    border-radius: 6px;
    color: #00bbff;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: bold;
}

.msg-field {
    flex: 1;
    background: #13141f;
    border: 1px solid #30334c;
    border-radius: 6px;
    color: #fff;
    padding: 8px 12px;
    font-size: 13px;
}

.msg-field:focus, .user-field:focus {
    outline: none;
    border-color: #0088ff;
}

.send-btn {
    background: #0066cc;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0 16px;
    font-family: var(--font-pixel);
    font-size: 9px;
    cursor: pointer;
}

.send-btn:hover { background: #0077ee; }

/* ==========================================================================
   ADMIN CONSOLE STYLES
   ========================================================================== */

.admin-gear-btn {
    background: #25283b;
    color: #ffcb05;
    border: 1px solid #4a4f73;
    border-radius: 6px;
    padding: 6px 10px;
    font-family: var(--font-pixel);
    font-size: 9px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.admin-gear-btn:hover {
    background: #393e5c;
    border-color: #ffcb05;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(255, 203, 5, 0.2);
}

.admin-gear-btn:active {
    transform: translateY(1px);
}

/* Modal Overlay */
.admin-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 9, 14, 0.85);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: adminFadeIn 0.15s ease-out;
}

@keyframes adminFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.admin-modal-container {
    background: #181a26;
    border: 2px solid #3c4161;
    border-radius: 14px;
    width: 600px;
    max-width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.admin-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #13141f;
    border-bottom: 1px solid #2d3045;
}

.admin-modal-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-pixel);
    font-size: 13px;
    color: var(--accent-gold);
    letter-spacing: 0.5px;
}

.admin-close-btn {
    background: transparent;
    color: #8b92a5;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}

.admin-close-btn:hover {
    color: #fff;
    background: #2a2d42;
}

.admin-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: #2d3045 transparent;
}

/* Login View */
.admin-login-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 10px;
    gap: 16px;
}

.admin-login-badge {
    background: #232738;
    color: #00bbff;
    border: 1px solid #393e5c;
    border-radius: 20px;
    padding: 6px 14px;
    font-family: var(--font-pixel);
    font-size: 10px;
}

.admin-login-desc {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
    max-width: 420px;
}

.admin-field-group {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 380px;
}

.admin-input {
    flex: 1;
    background: #111219;
    border: 1px solid #31354c;
    border-radius: 6px;
    color: #fff;
    padding: 10px 14px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.admin-input:focus {
    border-color: #0088ff;
    box-shadow: 0 0 0 2px rgba(0, 136, 255, 0.2);
}

.admin-btn {
    font-family: var(--font-pixel);
    font-size: 10px;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.15s ease;
}

.admin-btn-primary {
    background: #0066cc;
    color: #fff;
}
.admin-btn-primary:hover {
    background: #0077ee;
}

.admin-btn-secondary {
    background: #2a2d42;
    color: #cfd4e6;
    border: 1px solid #3c4161;
}
.admin-btn-secondary:hover {
    background: #393e5c;
    color: #fff;
}

.admin-btn-danger {
    background: #7a1824;
    color: #ff99a8;
    border: 1px solid #a82434;
}
.admin-btn-danger:hover {
    background: #a82434;
    color: #fff;
}

.admin-btn-save {
    background: #1e7039;
    color: #bbf0cc;
    border: 1px solid #2ea155;
}
.admin-btn-save:hover {
    background: #278f4a;
    color: #fff;
}

.admin-btn-logout {
    background: transparent;
    color: #8b92a5;
    border: 1px solid #31354c;
    font-size: 8px;
    padding: 6px 10px;
}
.admin-btn-logout:hover {
    color: #ff5566;
    border-color: #ff5566;
}

.admin-status-msg {
    font-size: 12px;
    min-height: 20px;
    margin-top: 6px;
}
.admin-status-msg.error { color: #ff5566; }
.admin-status-msg.success { color: #00ffaa; }

.admin-hint {
    font-size: 11px;
    color: #656b82;
}
.admin-hint code {
    background: #202333;
    padding: 2px 6px;
    border-radius: 4px;
    color: #ffcb05;
}

/* Tabs */
.admin-tabs {
    display: flex;
    gap: 6px;
    border-bottom: 1px solid #2d3045;
    padding-bottom: 12px;
    margin-bottom: 18px;
    overflow-x: auto;
    scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab-btn {
    background: #111219;
    color: #8b92a5;
    border: 1px solid #2a2d42;
    border-radius: 6px;
    padding: 8px 12px;
    font-family: var(--font-pixel);
    font-size: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.admin-tab-btn:hover {
    color: #fff;
    background: #222538;
}

.admin-tab-btn.active {
    background: #2d324d;
    color: #00e1ff;
    border-color: #00b4cc;
}

/* Tab content */
.admin-tab-content {
    display: none;
}
.admin-tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Cards */
.admin-card {
    background: #12131d;
    border: 1px solid #282a3d;
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-card h4 {
    font-family: var(--font-pixel);
    font-size: 10px;
    color: #e0e4ec;
}

.admin-subtext {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Radio group */
.admin-radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: #cfd4e6;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.1s;
}
.admin-radio-label:hover {
    background: #1c1e2e;
}
.admin-radio-label input[type="radio"] {
    accent-color: #0088ff;
    cursor: pointer;
}

/* Sliders */
.admin-range-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #cfd4e6;
}

.admin-val-badge {
    background: #202438;
    color: #00ffaa;
    border: 1px solid #333a5c;
    border-radius: 4px;
    padding: 3px 8px;
    font-family: var(--font-pixel);
    font-size: 9px;
    font-weight: bold;
}

.admin-range {
    width: 100%;
    accent-color: #ffcb05;
    cursor: pointer;
}

/* Toggle Switch */
.admin-switch-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}
.admin-switch-label input[type="checkbox"] {
    display: none;
}
.admin-switch-slider {
    position: relative;
    width: 38px;
    height: 20px;
    background: #25283b;
    border-radius: 10px;
    border: 1px solid #3a3f5c;
    transition: background 0.2s;
    flex-shrink: 0;
}
.admin-switch-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: #8b92a5;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}
.admin-switch-label input[type="checkbox"]:checked + .admin-switch-slider {
    background: #0066cc;
    border-color: #3399ff;
}
.admin-switch-label input[type="checkbox"]:checked + .admin-switch-slider::before {
    transform: translateX(18px);
    background: #fff;
}
.admin-switch-text {
    font-size: 12px;
    color: #e0e4ec;
}

/* Speed / Multi buttons */
.admin-btn-group, .admin-btn-row {
    display: flex;
    gap: 8px;
}

.admin-toggle-btn {
    flex: 1;
    background: #111219;
    color: #8b92a5;
    border: 1px solid #2a2d42;
    border-radius: 6px;
    padding: 8px 10px;
    font-family: var(--font-pixel);
    font-size: 8px;
    cursor: pointer;
    transition: all 0.15s;
}
.admin-toggle-btn:hover {
    background: #202336;
    color: #fff;
}
.admin-toggle-btn.active {
    background: #2a345c;
    color: #ffcb05;
    border-color: #ffcb05;
}

.admin-rom-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}
.admin-rom-info code {
    background: #1a1c2b;
    color: #00ffaa;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
}

.admin-rom-selector-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
}

.admin-select {
    flex: 1;
    background: #111219;
    border: 1px solid #31354c;
    border-radius: 6px;
    color: #00ffaa;
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
}

.admin-select:focus {
    border-color: #0088ff;
    box-shadow: 0 0 0 2px rgba(0, 136, 255, 0.2);
}

.admin-announcement-form {
    display: flex;
    gap: 8px;
}

.admin-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #cfd4e6;
}

/* Modal Footer */
.admin-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: #13141f;
    border-top: 1px solid #2d3045;
}

.admin-footer-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.admin-save-status {
    font-size: 11px;
    color: #00ffaa;
    font-weight: bold;
}

/* ==========================================================================
   RESPONSIVE DESIGN (TABLETS, SMARTPHONES, PORTRAIT & LANDSCAPE)
   ========================================================================== */

/* Tablets & Medium Screens (<= 900px) */
@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .game-column {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .keyboard-guide {
        width: 100%;
        max-width: 460px;
        box-sizing: border-box;
    }

    .sidebar-column {
        width: 100%;
        max-width: 100%;
    }
}

/* Smartphones (<= 600px) */
@media (max-width: 600px) {
    body {
        padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .layout-container {
        gap: 10px;
    }

    /* HEADER */
    .app-header {
        height: auto;
        min-height: auto;
        padding: 10px 12px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        overflow: visible;
    }

    .header-branding {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        gap: 8px;
    }

    .header-branding h1 {
        font-size: 11px;
        letter-spacing: 0.2px;
    }

    .badge.docker-badge {
        display: none; /* Hide Docker badge on phones for a clean, non-cramped title */
    }

    .header-stats {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    .stat-pill {
        padding: 4px 7px;
        font-size: 8.5px;
        gap: 4px;
        border-radius: 4px;
    }

    #stat-rom {
        max-width: 80px;
    }

    .admin-gear-btn {
        padding: 4px 8px;
        font-size: 8.5px;
        border-radius: 4px;
    }

    /* GAMEBOY CHASSIS & SCREEN */
    .gameboy-chassis {
        width: 100%;
        max-width: 420px;
        padding: 14px 10px 22px 10px;
        border-radius: 14px 14px 44px 14px;
        border-width: 2px;
        gap: 12px;
        box-shadow: 0 10px 24px rgba(0,0,0,0.5);
    }

    .screen-bezel {
        width: 100%;
        max-width: 100%;
        padding: 10px 8px 8px 8px;
        border-radius: 10px 10px 24px 10px;
    }

    .bezel-header {
        margin-bottom: 8px;
        gap: 6px;
    }

    .stripe-line {
        width: 18px;
        height: 2px;
    }

    .bezel-title {
        font-size: 7px;
    }

    .screen-viewport {
        width: 100%;
        max-width: 320px;
        height: auto;
        aspect-ratio: 10 / 9;
        min-width: 0;
        min-height: 0;
        border-width: 3px;
    }

    #game-stream {
        width: 100%;
        height: 100%;
        position: absolute;
        inset: 0;
    }

    .bezel-footer {
        margin-top: 6px;
        padding: 0 2px;
        justify-content: flex-end;
    }

    .subtle-btn {
        padding: 3px 6px;
        font-size: 8px;
    }

    .brand-strip {
        padding: 0 4px;
        justify-content: center;
        gap: 4px;
    }

    .gameboy-logo {
        font-size: 15px;
    }

    .color-text {
        font-size: 8.5px;
    }

    /* CONTROLS (DPAD & BUTTONS) */
    .controller-pad {
        padding: 6px 4px 0 4px;
        justify-content: space-around;
        align-items: center;
    }

    .dpad-container {
        width: 130px;
        height: 130px;
        flex-shrink: 0;
    }

    .dpad-btn {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    .dpad-up {
        top: 0;
        left: 43px;
        width: 44px;
        height: 44px;
        border-radius: 6px 6px 0 0;
    }

    .dpad-down {
        bottom: 0;
        left: 43px;
        width: 44px;
        height: 44px;
        border-radius: 0 0 6px 6px;
    }

    .dpad-left {
        top: 43px;
        left: 0;
        width: 44px;
        height: 44px;
        border-radius: 6px 0 0 6px;
    }

    .dpad-right {
        top: 43px;
        right: 0;
        width: 44px;
        height: 44px;
        border-radius: 0 6px 6px 0;
    }

    .dpad-center {
        top: 43px;
        left: 43px;
        width: 44px;
        height: 44px;
    }

    .action-buttons {
        gap: 12px;
        transform: rotate(-25deg);
        padding-top: 6px;
        flex-shrink: 0;
    }

    .action-btn {
        width: 50px;
        height: 50px;
        font-size: 17px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    .btn-cluster label {
        font-size: 8.5px;
    }

    .system-buttons {
        gap: 26px;
        margin-top: 10px;
    }

    .sys-btn-wrap {
        gap: 4px;
    }

    .sys-btn {
        width: 52px;
        height: 16px;
        border-radius: 8px;
        position: relative;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .sys-btn::before {
        content: '';
        position: absolute;
        top: -14px;
        bottom: -14px;
        left: -10px;
        right: -10px;
    }

    .sys-btn-wrap label {
        font-size: 7.5px;
    }

    .keyboard-guide {
        display: none;
    }

    /* SIDEBAR PANELS */
    .sidebar-column {
        gap: 12px;
    }

    .panel {
        padding: 12px;
        border-radius: 10px;
    }

    .panel-title {
        font-size: 10px;
        margin-bottom: 10px;
        padding-bottom: 6px;
    }

    .mode-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .mode-badge {
        text-align: center;
        font-size: 11px;
        padding: 6px 8px;
    }

    .mode-vote-actions {
        display: flex;
        gap: 6px;
        width: 100%;
    }

    .vote-mode-btn {
        flex: 1;
        padding: 8px 6px;
        font-size: 8.5px;
        min-height: 38px;
    }

    .input-history-ticker {
        min-height: 52px;
        height: 52px;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .history-item {
        min-width: 64px;
        padding: 4px 6px;
    }

    .history-cmd {
        font-size: 11px;
    }

    /* CHAT */
    .chat-messages {
        height: 180px;
        min-height: 160px;
        max-height: 200px;
        padding: 8px;
        font-size: 12px;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .quick-commands {
        gap: 5px;
        margin-bottom: 8px;
    }

    .quick-chip {
        padding: 7px 10px;
        font-size: 8px;
        min-height: 32px;
        touch-action: manipulation;
    }

    .chat-input-form {
        gap: 6px;
    }

    .user-field {
        width: 68px;
        font-size: 16px; /* Prevents iOS auto-zoom on input focus */
        padding: 8px 8px;
    }

    .msg-field {
        font-size: 16px; /* Prevents iOS auto-zoom on input focus */
        padding: 8px 10px;
    }

    .send-btn {
        padding: 0 12px;
        font-size: 8.5px;
        min-height: 38px;
        touch-action: manipulation;
    }

    /* ADMIN MODAL FULLSCREEN DRAWER */
    .admin-modal-overlay {
        padding: 0;
    }

    .admin-modal-container {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    .admin-modal-header {
        padding: 12px 14px;
    }

    .admin-modal-title {
        font-size: 11px;
    }

    .admin-modal-body {
        padding: 12px 14px;
    }

    .admin-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 6px;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .admin-tab-btn {
        flex-shrink: 0;
        font-size: 8px;
        padding: 8px 10px;
        white-space: nowrap;
    }

    .admin-card {
        padding: 12px;
        margin-bottom: 12px;
    }

    .admin-input, .admin-select {
        font-size: 16px; /* Prevents iOS auto-zoom */
        padding: 8px 10px;
    }

    .admin-modal-footer {
        padding: 10px 14px;
        flex-direction: column-reverse;
        gap: 10px;
        align-items: stretch;
    }

    .admin-footer-right {
        justify-content: space-between;
        width: 100%;
    }
}

/* Extra Compact Phones (<= 380px, e.g. iPhone SE, Xperia Compact) */
@media (max-width: 380px) {
    .header-branding h1 {
        font-size: 9.5px;
    }

    .dpad-container {
        width: 118px;
        height: 118px;
    }

    .dpad-up, .dpad-down, .dpad-left, .dpad-right, .dpad-center {
        width: 40px;
        height: 40px;
    }

    .dpad-up { left: 39px; top: 0; }
    .dpad-down { left: 39px; bottom: 0; }
    .dpad-left { left: 0; top: 39px; }
    .dpad-right { right: 0; top: 39px; }
    .dpad-center { left: 39px; top: 39px; }

    .action-btn {
        width: 44px;
        height: 44px;
        font-size: 15px;
    }

    .action-buttons {
        gap: 8px;
    }

    .system-buttons {
        gap: 18px;
    }

    .sys-btn {
        width: 44px;
        height: 14px;
    }
}

/* Phone Landscape Orientation (<= 520px height) */
@media (max-height: 520px) and (orientation: landscape) {
    .main-grid {
        grid-template-columns: auto 1fr;
        gap: 12px;
    }

    .game-column {
        width: auto;
    }

    .gameboy-chassis {
        max-width: 360px;
        padding: 10px 8px 16px 8px;
        gap: 8px;
    }

    .screen-viewport {
        max-width: 220px;
    }

    .dpad-container {
        width: 100px;
        height: 100px;
    }

    .dpad-up, .dpad-down, .dpad-left, .dpad-right, .dpad-center {
        width: 34px;
        height: 34px;
    }

    .dpad-up { left: 33px; top: 0; }
    .dpad-down { left: 33px; bottom: 0; }
    .dpad-left { left: 0; top: 33px; }
    .dpad-right { right: 0; top: 33px; }
    .dpad-center { left: 33px; top: 33px; }

    .action-btn {
        width: 38px;
        height: 38px;
        font-size: 13px;
    }

    .chat-messages {
        height: 130px;
        min-height: 120px;
    }
}


