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

body {
    background: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
    color: #fcfcfc;
    font-family: 'Courier New', monospace;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: rgba(52, 73, 94, 0.9);
    border: 3px solid #5c94fc;
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.retro-title {
    font-family: 'Press Start 2P', monospace;
    color: #fcd444;
    text-shadow: 2px 2px 0px #000;
    font-size: 20px;
    margin-bottom: 10px;
}

.login-subtitle {
    color: #b4d4ec;
    font-size: 14px;
    margin-bottom: 24px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

input[type="password"],
input[type="text"],
input[type="number"],
textarea,
select {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #5c94fc;
    border-radius: 6px;
    color: #fcfcfc;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    padding: 10px 12px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
    border-color: #fcd444;
}

select {
    cursor: pointer;
}

select option {
    background: #2c3e50;
    color: #fcfcfc;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    padding: 10px 20px;
    border: 2px solid #5c94fc;
    border-radius: 6px;
    background: rgba(92, 148, 252, 0.2);
    color: #fcfcfc;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn:hover {
    background: rgba(92, 148, 252, 0.4);
    transform: translateY(-1px);
}

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

.btn-primary {
    background: rgba(252, 212, 68, 0.3);
    border-color: #fcd444;
    color: #fcd444;
}

.btn-primary:hover {
    background: rgba(252, 212, 68, 0.5);
}

.btn-danger {
    border-color: #fc5454;
    color: #fc5454;
}

.btn-danger:hover {
    background: rgba(252, 84, 84, 0.3);
}

.btn-small {
    font-size: 9px;
    padding: 6px 12px;
}

.error-msg {
    color: #fc5454;
    font-size: 12px;
    margin-top: 10px;
}

.back-link {
    display: inline-block;
    margin-top: 16px;
    color: #b4d4ec;
    text-decoration: none;
    font-size: 12px;
}

.back-link:hover {
    color: #fcd444;
}

/* Admin Panel */
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 3px solid #5c94fc;
}

.admin-header .retro-title {
    font-size: 16px;
    margin: 0;
}

.admin-version {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #54fc54;
    text-shadow: none;
    margin-left: 6px;
    vertical-align: middle;
}

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

/* Tab Bar */
.tab-bar {
    display: flex;
    gap: 2px;
    padding: 10px 20px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 8px 14px;
    background: rgba(52, 73, 94, 0.6);
    border: 2px solid #5c94fc;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    color: #b4d4ec;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.tab:hover {
    background: rgba(92, 148, 252, 0.3);
    color: #fcfcfc;
}

.tab.active {
    background: rgba(52, 73, 94, 0.9);
    color: #fcd444;
    border-color: #fcd444;
}

/* Tab Content */
.tab-content {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.tab-pane {
    background: rgba(52, 73, 94, 0.6);
    border: 2px solid #5c94fc;
    border-radius: 0 8px 8px 8px;
    padding: 24px;
}

.tab-pane h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    color: #fcd444;
    margin-bottom: 20px;
}

/* Status Grid */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.status-card {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #5c94fc;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.status-label {
    display: block;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #b4d4ec;
    margin-bottom: 8px;
}

.status-value {
    display: block;
    font-family: 'Press Start 2P', monospace;
    font-size: 18px;
    color: #54fc54;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: #b4d4ec;
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.hint {
    display: block;
    font-size: 11px;
    color: #888;
    margin-top: 4px;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #fcd444;
}

.button-row {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.info-box {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #5c94fc;
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
}

.info-box h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #fcd444;
    margin-bottom: 10px;
}

#network-info-box {
    margin-top: 0;
    margin-bottom: 16px;
}

.network-info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.network-info-table th,
.network-info-table td {
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(92, 148, 252, 0.3);
}

.network-info-table th {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #b4d4ec;
}

.network-info-table td {
    color: #54fc54;
    font-family: 'Courier New', monospace;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(84, 252, 84, 0.9);
    color: #000;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    padding: 12px 24px;
    border-radius: 8px;
    border: 2px solid #54fc54;
    z-index: 1000;
    transition: opacity 0.3s;
}

.toast.error {
    background: rgba(252, 84, 84, 0.9);
    border-color: #fc5454;
    color: #fff;
}

/* Sprite Management */
.sprite-info {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #5c94fc;
    border-radius: 8px;
    padding: 14px 18px;
    margin-bottom: 20px;
}

.sprite-info h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #fcd444;
    margin-bottom: 10px;
}

.sprite-info p {
    font-size: 12px;
    color: #b4d4ec;
    margin-bottom: 4px;
    line-height: 1.6;
}

.sprite-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.sprite-card {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #5c94fc;
    border-radius: 8px;
    padding: 14px;
    text-align: center;
}

.sprite-card h4 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #fcfcfc;
    margin-bottom: 4px;
}

.sprite-card .sprite-categories {
    font-size: 10px;
    color: #888;
    margin-bottom: 10px;
}

.sprite-preview {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #444;
    border-radius: 4px;
    padding: 6px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
}

.sprite-preview img {
    max-width: 100%;
    height: auto;
    max-height: 80px;
    image-rendering: pixelated;
}

.sprite-preview .no-sprite {
    color: #666;
    font-size: 11px;
}

.sprite-upload-label {
    display: inline-block;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 6px 12px;
    border: 2px solid #5c94fc;
    border-radius: 6px;
    background: rgba(92, 148, 252, 0.2);
    color: #fcfcfc;
    cursor: pointer;
    transition: all 0.15s;
}

.sprite-upload-label:hover {
    background: rgba(92, 148, 252, 0.4);
}

.sprite-upload-input {
    display: none;
}

.sprite-btn-row {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Theme Management */
.theme-info {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #5c94fc;
    border-radius: 8px;
    padding: 14px 18px;
    margin-bottom: 20px;
}

.theme-info h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #fcd444;
    margin-bottom: 10px;
}

.theme-info p {
    font-size: 12px;
    color: #b4d4ec;
    margin-bottom: 4px;
    line-height: 1.6;
}

.theme-create-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
}

.theme-create-row input {
    flex: 1;
}

.theme-card {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #5c94fc;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.theme-card-header {
    margin-bottom: 14px;
}

.theme-card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.theme-name-input {
    flex: 1;
    min-width: 150px;
    font-size: 14px;
    font-weight: bold;
}

.theme-active-badge {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    background: rgba(84, 252, 84, 0.25);
    color: #54fc54;
    border: 2px solid #54fc54;
    border-radius: 4px;
    padding: 4px 8px;
    white-space: nowrap;
}

.theme-directions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.theme-dir-cell {
    text-align: center;
}

.theme-dir-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: #b4d4ec;
    margin-bottom: 6px;
}

.theme-dir-preview {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    aspect-ratio: 3/2;
}

.theme-dir-preview img {
    max-width: 100%;
    height: auto;
    max-height: 100%;
    border-radius: 2px;
}

.theme-dir-preview .no-sprite {
    color: #666;
    font-size: 11px;
}

/* ===================================================================
   Receivers tab — status indicators & selectable scan results
   =================================================================== */
.rx-section-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #fcd444;
    margin: 22px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(92, 148, 252, 0.3);
}

.rx-summary {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #b4d4ec;
}

#receiver-status-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.rx-status-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(92, 148, 252, 0.4);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    flex-wrap: wrap;
}

.rx-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}
.rx-dot.green  { background: #54fc54; color: #54fc54; }
.rx-dot.yellow { background: #fcd444; color: #fcd444; }
.rx-dot.red    { background: #fc5454; color: #fc5454; }
.rx-dot.gray   { background: #888;    color: #888; box-shadow: none; }

.rx-ip {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #fcfcfc;
    min-width: 110px;
}

.rx-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
}
.rx-green  { color: #54fc54; }
.rx-yellow { color: #fcd444; }
.rx-red    { color: #fc5454; }
.rx-gray   { color: #888; }

.rx-detail {
    color: #b4d4ec;
    font-size: 11px;
    margin-left: auto;
}

.rx-scan-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    cursor: pointer;
    border-bottom: 1px solid rgba(92, 148, 252, 0.2);
}

.rx-scan-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #fcd444;
    cursor: pointer;
}

.rx-scan-ip {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #fcfcfc;
}

/* ===================================================================
   Pixel Editor
   =================================================================== */
.pe-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

body.pe-open { overflow: hidden; }

.pe-modal {
    background: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
    border: 3px solid #fcd444;
    border-radius: 12px;
    width: 100%;
    max-width: 1100px;
    height: 100%;
    max-height: 760px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.pe-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid #5c94fc;
    flex-wrap: wrap;
    gap: 8px;
}

.pe-header .retro-title {
    font-size: 13px;
    margin: 0;
}

.pe-header-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.pe-body {
    flex: 1;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr;
    min-height: 0;
}

/* Toolbar (left column) */
.pe-toolbar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px 10px;
    background: rgba(0, 0, 0, 0.25);
    border-right: 2px solid #5c94fc;
    overflow-y: auto;
}

.pe-tool-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(92, 148, 252, 0.25);
}

.pe-tool-group:last-child { border-bottom: none; padding-bottom: 0; }

.pe-tool, .pe-icon-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
    line-height: 1;
    border: 2px solid #5c94fc;
    border-radius: 6px;
    background: rgba(92, 148, 252, 0.15);
    color: #fcfcfc;
    cursor: pointer;
    transition: all 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pe-tool:hover, .pe-icon-btn:hover:not(:disabled) {
    background: rgba(92, 148, 252, 0.4);
}

.pe-tool.active {
    background: rgba(252, 212, 68, 0.3);
    border-color: #fcd444;
    color: #fcd444;
}

.pe-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pe-tool-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #b4d4ec;
    text-align: center;
}

.pe-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #b4d4ec;
    cursor: pointer;
}

.pe-check input { width: 16px; height: 16px; accent-color: #fcd444; cursor: pointer; }

.pe-brush-group { align-items: center; }
.pe-brush-group input[type="range"] { width: 44px; accent-color: #fcd444; }

/* Canvas area (center column) */
.pe-canvas-wrap {
    position: relative;
    min-width: 0;
    background: #14202b;
    overflow: hidden;
}

#pe-view {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Sidebar (right column) */
.pe-sidebar {
    width: 150px;
    padding: 14px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-left: 2px solid #5c94fc;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.pe-color-current {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.pe-swatch-large {
    width: 100%;
    height: 48px;
    border: 2px solid #fcfcfc;
    border-radius: 6px;
    background: #5c94fc;
}

#pe-color-input {
    width: 100%;
    height: 32px;
    padding: 2px;
    border: 2px solid #5c94fc;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.pe-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.pe-swatch {
    aspect-ratio: 1;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.1s;
}

.pe-swatch:hover {
    transform: scale(1.12);
    border-color: #fcd444;
}

.pe-readout {
    margin-top: auto;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #b4d4ec;
    line-height: 2.2;
}

.pe-readout span { color: #54fc54; }

/* Sidebar: opacity, palettes, reference */
.pe-opacity-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.pe-opacity-group input[type="range"] { width: 100%; accent-color: #fcd444; }

.pe-subhead {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: #b4d4ec;
    margin-top: 4px;
    letter-spacing: 1px;
}

.pe-mini-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 6px 4px;
    border: 2px solid #5c94fc;
    border-radius: 5px;
    background: rgba(92, 148, 252, 0.15);
    color: #fcfcfc;
    cursor: pointer;
    transition: all 0.12s;
    text-align: center;
}
.pe-mini-btn:hover { background: rgba(92, 148, 252, 0.4); }

#pe-custom-palette:empty::after,
#pe-recent-palette:empty::after {
    content: '—';
    color: #555;
    font-size: 11px;
}

.pe-ref-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.pe-ref-row { display: flex; gap: 6px; }
.pe-ref-row .pe-mini-btn { flex: 1; }
.pe-ref-load { display: inline-block; }
.pe-ref-controls input[type="range"] { width: 100%; accent-color: #fcd444; }

/* Sprite card EDIT button uses primary accent */
.sprite-edit-btn { border-color: #fcd444; color: #fcd444; }
.sprite-edit-btn:hover { background: rgba(252, 212, 68, 0.3); }

@media (max-width: 768px) {
    .pe-modal { max-height: none; border-radius: 0; }
    .pe-body { grid-template-columns: auto 1fr; }
    .pe-sidebar {
        grid-column: 1 / -1;
        grid-row: 2;
        width: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        border-left: none;
        border-top: 2px solid #5c94fc;
    }
    .pe-body { grid-template-rows: 1fr auto; }
    .pe-palette { flex: 1; }
    .pe-readout { margin-top: 0; }
}

/* Mobile */
@media (max-width: 768px) {
    .admin-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .tab-bar {
        padding: 8px 10px 0;
    }

    .tab {
        font-size: 8px;
        padding: 6px 10px;
    }

    .tab-content {
        padding: 10px;
    }

    .tab-pane {
        padding: 16px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .status-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .button-row {
        flex-direction: column;
    }

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

    .sprite-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .theme-directions {
        grid-template-columns: 1fr;
    }

    .theme-create-row {
        flex-direction: column;
    }
}
