/* Toyman Rater Mock UI - Main Styles */

:root {
    /* Color Palette */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-panel: #0f3460;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-primary: #00d4ff;
    --accent-success: #00ff88;
    --accent-warning: #ffaa00;
    --accent-danger: #ff4444;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    display: grid;
    grid-template-areas:
        "header header header"
        "main main debug"
        "main main debug";
    grid-template-columns: 1fr 1fr 300px;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
}

/* Header */
.header {
    grid-area: header;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.header h1 {
    font-size: 1.5rem;
    color: var(--accent-primary);
}

.header-info {
    display: flex;
    gap: var(--spacing-lg);
}

.header-info span {
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-panel);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

#mode-indicator {
    color: var(--accent-success);
}

/* Main Content */
.main-content {
    grid-area: main;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Two Column Layout */
.left-column {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.right-column {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

@media (min-width: 900px) {
    .main-content {
        display: grid;
        grid-template-columns: minmax(350px, 1fr) minmax(300px, 1fr);
        grid-template-rows: auto auto;
        grid-template-areas:
            "left right"
            "sensors sensors";
    }

    .left-column {
        grid-area: left;
    }

    .right-column {
        grid-area: right;
    }

    .sensor-panel {
        grid-area: sensors;
    }
}

/* Panel Base */
.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.panel h2 {
    font-size: 1rem;
    color: var(--accent-primary);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.panel h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

/* LCD Panel */
.lcd-panel {
    /* LCD is placed in left column above controls */
}

/* Controls Panel */
.controls-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Switch Panel */
.switch-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Sensor Panel */
.sensor-panel {
    /* In 2-column layout, sensors span full width below both columns */
}

/* Debug Panel */
.debug-panel {
    grid-area: debug;
    overflow-y: auto;
    max-height: calc(100vh - 100px);
}

.debug-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.debug-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-panel);
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.debug-btn:hover {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.debug-volume {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.debug-volume label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-width: 50px;
}

.debug-volume input[type="range"] {
    flex: 1;
    height: 6px;
    cursor: pointer;
}

.debug-volume span {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 35px;
    text-align: right;
}

.debug-alarms {
    margin-bottom: var(--spacing-md);
}

.alarm-btn {
    display: block;
    width: 100%;
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
    background: transparent;
    border: 1px solid var(--accent-warning);
    color: var(--accent-warning);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.alarm-btn:hover {
    background: var(--accent-warning);
    color: var(--bg-primary);
}

.alarm-btn.alarm-active {
    background: var(--accent-error);
    border-color: var(--accent-error);
    color: white;
    animation: alarm-pulse 1s infinite;
}

.alarm-btn.alarm-active:hover {
    background: #ff6666;
}

@keyframes alarm-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.debug-log {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    max-height: 200px;
    overflow-y: auto;
}

#event-log {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

/* Keyboard Help Overlay */
.keyboard-help {
    position: fixed;
    bottom: var(--spacing-md);
    right: var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    opacity: 0.9;
    z-index: 100;
    display: none;
}

.keyboard-help.visible {
    display: block;
}

.keyboard-help h3 {
    margin-top: 0;
    color: var(--accent-primary);
}

.keyboard-help table {
    font-size: 0.8rem;
}

.keyboard-help td {
    padding: var(--spacing-xs) var(--spacing-sm);
}

.keyboard-help td:first-child {
    font-family: 'Courier New', monospace;
    color: var(--accent-success);
}

/* Help Toggle Button */
.help-toggle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.help-toggle:hover {
    background: var(--accent-success);
    transform: scale(1.1);
}

/* Help Panel */
.help-panel {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-panel));
    border: 1px solid var(--accent-primary);
    transition: max-height 0.3s ease;
    overflow: hidden;
}

.help-panel.collapsed {
    max-height: 50px;
}

.help-panel.collapsed .help-content {
    display: none;
}

.help-panel.hidden {
    display: none;
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: var(--spacing-md);
}

.help-header h2 {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.help-collapse-icon {
    font-size: 1.2rem;
    color: var(--accent-primary);
    transition: transform 0.3s;
}

.help-panel.collapsed .help-collapse-icon {
    transform: rotate(-90deg);
}

.help-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--spacing-md);
}

.help-section {
    background: rgba(0, 0, 0, 0.2);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-primary);
}

.help-section h3 {
    color: var(--accent-primary);
    margin-top: 0;
    margin-bottom: var(--spacing-sm);
    font-size: 0.9rem;
}

.help-section p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}

.help-section ol,
.help-section ul {
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
    padding-left: var(--spacing-lg);
}

.help-section li {
    margin-bottom: var(--spacing-xs);
}

.help-table {
    width: 100%;
    font-size: 0.8rem;
    border-collapse: collapse;
}

.help-table td {
    padding: var(--spacing-xs) var(--spacing-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.help-table td:first-child {
    color: var(--accent-success);
    white-space: nowrap;
    width: 120px;
}

.help-table kbd {
    background: var(--bg-panel);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.help-mode {
    font-size: 0.8rem;
    padding: var(--spacing-sm);
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
}

.help-mode:last-child {
    margin-bottom: 0;
}

.help-mode strong {
    color: var(--accent-success);
}

/* Screen Help Panel (Dynamic) */
.screen-help-panel {
    background: var(--bg-secondary);
    border-left: 4px solid var(--accent-success);
    padding: var(--spacing-md) var(--spacing-lg);
    /* In right column, above switches */
}

.screen-help-panel h2 {
    font-size: 0.95rem;
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-xs);
}

.screen-help-panel #screen-help-title {
    color: var(--accent-success);
}

.screen-help-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.screen-help-content p {
    margin: 0 0 var(--spacing-sm) 0;
}

.screen-help-content p:last-child {
    margin-bottom: 0;
}

.screen-help-content .help-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.screen-help-content .help-btn-info {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-panel);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.screen-help-content .help-btn-info kbd {
    background: var(--accent-primary);
    color: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
}

.screen-help-content ul {
    margin: var(--spacing-sm) 0;
    padding-left: var(--spacing-lg);
}

.screen-help-content li {
    margin-bottom: var(--spacing-xs);
}

/* Responsive */
@media (max-width: 1200px) {
    #app {
        grid-template-areas:
            "header"
            "main"
            "debug";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .debug-panel {
        max-height: none;
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .lcd-panel {
        grid-column: 1;
    }

    .sensor-panel {
        grid-column: 1;
    }
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
}

.modal-content h3 {
    color: var(--accent-primary);
    margin: 0 0 var(--spacing-md) 0;
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

/* Calibration Modal Specific */
.calibration-modal {
    min-width: 450px;
}

.calibration-modal canvas {
    display: block;
    margin: 0 auto var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
}

.calibration-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.modal-close {
    display: block;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-lg);
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--accent-success);
}
