:root {
    --charcoal: #2C3F43;
    --purple: #311087;
    --bloo: #2E3088;
    --saffron: #DE4827;
    --grain: #B79885;
    --pulp: #EED5C0;
    --besan: #FAF2EB;
    --steel: #8C8C90;
    --indigo: #1E1E2E;
    --white: #FFFFFF;
    --success: #4CAF50;
    --warning: #FFC107;
}

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

body {
    font-family: 'Rethink Sans', sans-serif;
    background: var(--charcoal);
    color: var(--besan);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--besan);
    margin-bottom: 20px;
}

h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--purple);
    margin-bottom: 15px;
    border-bottom: 2px solid var(--purple);
    padding-bottom: 8px;
}

.status-bar {
    display: flex;
    justify-content: center;
    gap: 25px;
    flex-wrap: wrap;
    background: var(--indigo);
    padding: 15px;
    border-radius: 8px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-item-clickable {
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.status-item-clickable:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.status-item-clickable:active {
    transform: translateY(0);
}

.status-label {
    font-weight: 600;
    color: var(--besan);
}

.status-indicator {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-indicator.online {
    background: #2d5f2e;
    color: white;
}

.status-indicator.offline {
    background: #6b6b6b;
    color: white;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr 500px;
    gap: 20px;
    align-items: start;
}

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.console-container {
    position: sticky;
    top: 20px;
    height: calc(100vh - 250px);
    min-height: 600px;
}

.panel {
    background: var(--besan);
    border: 1px solid var(--pulp);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.position-display {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 10px;
}

.position-item {
    text-align: center;
    background: var(--purple);
    padding: 15px 10px;
    border-radius: 8px;
    min-width: 0;
}

.position-label {
    display: block;
    font-size: 0.9rem;
    color: var(--besan);
    margin-bottom: 5px;
}

.position-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--besan);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    hyphens: auto;
    line-height: 1.3;
}

.button-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.points-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-family: 'Rethink Sans', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--purple);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #4a1ac1;
}

.btn-secondary {
    background: var(--grain);
    color: var(--charcoal);
}

.btn-secondary:hover:not(:disabled) {
    background: #c9aa95;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #45a049;
}

.btn-danger {
    background: var(--saffron);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c73d1f;
}

.btn-warning {
    background: var(--warning);
    color: var(--charcoal);
}

.btn-warning:hover:not(:disabled) {
    background: #ffb300;
}

.btn-info {
    background: var(--bloo);
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #3d40a8;
}

.btn-fun {
    background: var(--purple);
    color: white;
}

.btn-fun:hover:not(:disabled) {
    background: #4a1ac1;
}

.btn-point {
    background: var(--saffron);
    color: white;
    font-size: 1.2rem;
    aspect-ratio: 1;
}

.btn-point:hover:not(:disabled) {
    background: #ff5533;
}

.effect-controls {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.effect-controls label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--charcoal);
    font-size: 0.9rem;
}

.effect-controls input {
    width: 80px;
    padding: 6px;
    border: 1px solid var(--grain);
    border-radius: 4px;
    background: white;
    color: var(--charcoal);
    font-family: 'Rethink Sans', sans-serif;
}

.d-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    max-width: 200px;
    margin: 0 auto 15px;
}

.d-btn {
    aspect-ratio: 1;
    padding: 15px;
    border: none;
    border-radius: 8px;
    background: var(--bloo);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.d-btn:hover:not(:disabled) {
    background: #3d40a8;
    transform: scale(1.05);
}

.d-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.d-btn:disabled {
    background: transparent;
    cursor: default;
}

.movement-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.movement-controls label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: var(--charcoal);
    font-size: 0.9rem;
}

.movement-controls input {
    padding: 6px;
    border: 1px solid var(--grain);
    border-radius: 4px;
    background: white;
    color: var(--charcoal);
    font-family: 'Rethink Sans', sans-serif;
}

.custom-gcode {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.custom-gcode input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--grain);
    border-radius: 4px;
    background: white;
    color: var(--charcoal);
    font-family: 'Rethink Sans', sans-serif;
    font-size: 1rem;
}

.console-panel {
    background: var(--besan);
    border: 1px solid var(--pulp);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    height: 75%;
}

.console {
    background: rgba(0, 0, 0, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 15px;
    flex: 1;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    margin-bottom: 15px;
    /* max-height: 400px; */
}

.console-input-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

.console-input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--grain);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.console-input::placeholder {
    color: #888;
}

.console-input:focus {
    outline: none;
    border-color: var(--purple);
    background: rgba(0, 0, 0, 0.5);
}

.console-line {
    margin-bottom: 5px;
    padding: 3px 0;
    color: #e0e0e0;
}

.console-line.error {
    color: #ff6b6b;
}

.console-line.success {
    color: #51cf66;
}

.console-line.info {
    color: #a8dadc;
}

.console-line.command {
    color: #74c0fc;
    font-weight: 600;
}

.console::-webkit-scrollbar {
    width: 8px;
}

.console::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.console::-webkit-scrollbar-thumb {
    background: var(--purple);
    border-radius: 4px;
}

.console::-webkit-scrollbar-thumb:hover {
    background: #4a1ac1;
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .console-container {
        position: relative;
        height: 400px;
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 2rem;
    }

    .status-bar {
        flex-direction: column;
        gap: 10px;
    }

    .dashboard {
        grid-template-columns: 1fr;
    }

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

/* Board Visualizer */
.board-visualizer-panel {
    grid-column: 1 / -1;
}

.board-info {
    margin-bottom: 10px;
}

.board-coord-display {
    background: var(--indigo);
    padding: 10px;
    border-radius: 6px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: var(--besan);
}

.board-coord-display span {
    color: var(--saffron);
    font-weight: 700;
}

#board-canvas {
    width: 100%;
    height: auto;
    border: 2px solid var(--purple);
    border-radius: 8px;
    cursor: crosshair;
    background: var(--indigo);
    display: block;
}

/* G-Code Reference */
.gcode-reference {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.gcode-reference-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.gcode-item {
    display: grid;
    grid-template-columns: 100px 1fr;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--pulp);
    border-radius: 4px;
    border-left: 3px solid var(--purple);
}

.gcode-item code {
    background: var(--indigo);
    color: var(--saffron);
    padding: 6px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    font-weight: 600;
}

.gcode-item span {
    color: var(--charcoal);
    font-size: 0.85rem;
}

@media (max-width: 1400px) {
    .gcode-reference-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .gcode-reference-grid {
        grid-template-columns: 1fr;
    }
}

/* MQTT Feed */
.mqtt-feed {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    height: 250px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.mqtt-message {
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 4px;
    border-left: 3px solid var(--purple);
    background: rgba(49, 16, 135, 0.1);
}

.mqtt-message.command {
    border-left-color: var(--saffron);
    background: rgba(222, 72, 39, 0.1);
}

.mqtt-message.vote {
    border-left-color: var(--success);
    background: rgba(76, 175, 80, 0.1);
}

.mqtt-timestamp {
    color: #888;
    font-size: 0.75rem;
    margin-bottom: 3px;
}

.mqtt-topic {
    color: var(--saffron);
    font-weight: 600;
    margin-bottom: 3px;
}

.mqtt-data {
    color: #e0e0e0;
    word-wrap: break-word;
}

.mqtt-feed::-webkit-scrollbar {
    width: 8px;
}

.mqtt-feed::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.mqtt-feed::-webkit-scrollbar-thumb {
    background: var(--purple);
    border-radius: 4px;
}

.mqtt-feed::-webkit-scrollbar-thumb:hover {
    background: #4a1ac1;
}

/* Voting Panel */
.voting-panel {
    grid-column: 1 / -1;
}

.voting-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 12px;
    background: var(--indigo);
    border-radius: 6px;
}

.total-votes, .bounding-box-info {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--besan);
}

.total-votes span, .bounding-box-info span {
    color: var(--saffron);
    font-size: 1.3rem;
}

.vote-spots {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    margin-top: 15px;
}

.vote-spot {
    background: var(--pulp);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.vote-spot-number {
    font-size: 2rem;
    font-weight: 800;
    color: var(--purple);
    margin-bottom: 10px;
}

.vote-spot-bar {
    width: 100%;
    height: 30px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 8px;
}

.vote-spot-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--purple), var(--saffron));
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
}

.vote-spot-count {
    font-size: 0.9rem;
    color: var(--charcoal);
    font-weight: 600;
    margin-bottom: 8px;
}

.vote-percent {
    color: var(--purple);
    margin-left: 5px;
}

.btn-lock {
    width: 100%;
    background: var(--saffron);
    color: white;
    padding: 8px;
    font-size: 0.85rem;
}

.btn-lock:hover {
    background: #ff5533;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.85rem;
}

@media (max-width: 1200px) {
    .vote-spots {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .vote-spots {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* G-Code Queue */
.queue-panel {
    background: var(--besan);
    border: 1px solid var(--pulp);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    margin-bottom: 20px;
}

.gcode-queue {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.queue-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin-bottom: 5px;
    background: rgba(49, 16, 135, 0.1);
    border-left: 3px solid var(--purple);
    border-radius: 4px;
}

.queue-item.processing {
    border-left-color: var(--saffron);
    background: rgba(222, 72, 39, 0.2);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.queue-item-code {
    color: #e0e0e0;
    flex: 1;
}

.queue-item-status {
    color: #888;
    font-size: 0.75rem;
    margin-left: 10px;
}

.gcode-queue::-webkit-scrollbar {
    width: 8px;
}

.gcode-queue::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.gcode-queue::-webkit-scrollbar-thumb {
    background: var(--purple);
    border-radius: 4px;
}

.gcode-queue::-webkit-scrollbar-thumb:hover {
    background: #4a1ac1;
}

/* ==================== Gamepad Control Styles ==================== */

.gamepad-info {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.info-text {
    color: var(--besan);
    font-size: 0.95rem;
    line-height: 1.4;
    margin: 0;
    opacity: 0.9;
}

.info-text.small {
    font-size: 0.85rem;
    color: var(--steel);
    font-style: italic;
    text-align: center;
    margin-top: 5px;
}

.gamepad-controls-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.gamepad-control-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(49, 16, 135, 0.15);
    border-radius: 6px;
    transition: background 0.2s ease;
}

.gamepad-control-item:hover {
    background: rgba(49, 16, 135, 0.25);
}

.gamepad-icon {
    font-size: 1.3rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.gamepad-label {
    color: var(--besan);
    font-size: 0.9rem;
    flex: 1;
}

/* Gamepad status indicator - connected state */
#gamepad-status.online {
    color: var(--success);
}

/* Active gamepad button feedback */
.gamepad-control-item.active {
    background: rgba(49, 16, 135, 0.4);
    box-shadow: 0 0 10px rgba(49, 16, 135, 0.5);
}

/* Responsive adjustments for gamepad panel */
@media (max-width: 768px) {
    .gamepad-controls-list {
        gap: 8px;
        padding: 8px;
    }

    .gamepad-control-item {
        padding: 6px 10px;
    }

    .gamepad-icon {
        font-size: 1.1rem;
        width: 24px;
    }

    .gamepad-label {
        font-size: 0.85rem;
    }
}
