/**
 * TAMER Web - Stylesheet
 */

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    padding: 10px;
    background-color: #f5f5f5;
    color: #333;
}

.container {
    max-width: 1100px;
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 10px;
    flex-shrink: 0;
}

header h1 {
    margin: 0;
    font-size: 1.4em;
    color: #1976D2;
}

header p {
    margin: 2px 0 0 0;
    color: #666;
    font-size: 0.85em;
}

.main-content {
    display: flex;
    gap: 15px;
    flex: 1;
    min-height: 0;
    overflow: visible;
}

.canvas-container {
    position: relative;
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.canvas-container canvas#game-canvas {
    display: block;
    border: none;
    border-radius: 4px;
    /* Size is controlled dynamically by JavaScript to maintain square aspect ratio */
    /* Center horizontally within flex column container */
    align-self: center;
}

/* Action values canvas in sidebar */
.panel canvas#action-values-canvas {
    display: block;
    width: 100%;
    height: auto;
}

/* Tetris thumbnails grid */
#tetris-thumbnails-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 300px;
    overflow-y: auto;
    padding: 2px;
}

.tetris-thumbnail {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tetris-thumbnail canvas {
    display: block;
}

.tetris-thumbnail .h-bar {
    display: block;
    margin-top: 1px;
    border: none;
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.panel {
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 10px;
    flex-shrink: 0;
}

.panel h2 {
    margin: 0 0 8px 0;
    font-size: 0.9em;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 6px;
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.controls button {
    padding: 6px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.controls button.primary {
    background-color: #2196F3;
    color: white;
}

.controls button.primary:hover {
    background-color: #1976D2;
}

.controls button.pulse {
    animation: pulse-btn 1.5s ease-in-out infinite;
}

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(33, 150, 243, 0); }
}

.controls button.secondary {
    background-color: #e0e0e0;
    color: #333;
}

.controls button.secondary:hover {
    background-color: #bdbdbd;
}

.controls button.danger {
    background-color: #f44336;
    color: white;
}

.controls button.danger:hover {
    background-color: #d32f2f;
}

/* Status indicators */
.status {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.status-item {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 12px;
}

.status-item:last-child {
    border-bottom: none;
}

.status-label {
    color: #666;
}

.status-value {
    font-weight: 500;
}

/* Training indicator */
#training-indicator {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    transition: background-color 0.15s, transform 0.15s;
}

.training-on {
    background-color: #4CAF50;
    color: white;
}

.training-off {
    background-color: #f44336;
    color: white;
}

.training-off-flash {
    background-color: #ff8a80;
    transform: scale(1.15);
}

/* Mode indicator (TAMER vs Manual) */
#mode-indicator {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.mode-tamer {
    background-color: #2196F3;
    color: white;
}

.mode-human {
    background-color: #FF9800;
    color: white;
}

/* Reward indicator */
#reward-indicator {
    width: 100%;
    height: 24px;
    border-radius: 4px;
    transition: background-color 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 12px;
    background-color: #f5f5f5;
}

.flash-positive {
    background-color: #4CAF50 !important;
    color: white;
}

.flash-negative {
    background-color: #f44336 !important;
    color: white;
}

/* Instructions */
.instructions {
    font-size: 11px;
    line-height: 1.4;
}

.instructions h3 {
    margin: 0 0 4px 0;
    font-size: 12px;
    color: #333;
}

.key-list {
    list-style: none;
    padding: 0;
    margin: 0 0 8px 0;
}

.key-list li {
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.key {
    display: inline-block;
    min-width: 32px;
    padding: 2px 5px;
    background: #e0e0e0;
    border-radius: 3px;
    font-family: monospace;
    font-size: 10px;
    text-align: center;
}

/* Two-column key layout */
.key-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

/* Settings */
.settings label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
}

.settings label span {
    margin-bottom: 4px;
    color: #666;
}

.settings select,
.settings input[type="range"] {
    width: 100%;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

.settings input[type="range"] {
    padding: 0;
}

/* Environment selector */
.env-selector {
    margin-bottom: 10px;
    flex-shrink: 0;
    width: 100%;
    align-self: stretch;
}

.env-selector label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.env-selector select {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid #ddd;
    border-radius: 6px;
    background-color: white;
    color: #333;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: all 0.3s ease;
}

.env-selector select:hover {
    border-color: #999;
}

.env-selector select:focus {
    outline: none;
    border-color: #1976D2;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

/* Highlighted state for first-time users */
.env-selector select.highlight {
    border: 2px solid #1976D2;
    background-color: #f0f7ff;
    color: #1565C0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231976D2' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.env-selector select.highlight:hover {
    background-color: #e3f2fd;
    border-color: #1565C0;
}

/* Speed display */
#speed-indicator {
    font-family: monospace;
}

/* Footer */
footer {
    text-align: center;
    padding: 8px 0;
    color: #666;
    font-size: 11px;
    flex-shrink: 0;
}

footer p {
    margin: 2px 0;
}

footer a {
    color: #1976D2;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .canvas-container {
        min-height: 300px;
    }
}

@media (max-height: 700px) {
    header h1 {
        font-size: 1.2em;
    }

    header p {
        display: none;
    }

    .panel {
        padding: 8px;
    }

    .panel h2 {
        margin-bottom: 6px;
        padding-bottom: 4px;
    }
}

/* ===================== */
/* Intro/Landing Page    */
/* ===================== */

.intro-page {
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 40px 20px;
}

.intro-container {
    max-width: 600px;
    width: 100%;
}

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

.intro-header h1 {
    font-size: 2.2em;
    color: #1976D2;
    margin: 0 0 10px 0;
}

.intro-header .tagline {
    font-size: 1.1em;
    color: #555;
    margin: 0;
}

.intro-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 30px;
}

.intro-content section {
    margin-bottom: 25px;
}

.intro-content section:last-of-type {
    margin-bottom: 30px;
}

.intro-content h2 {
    font-size: 1.1em;
    color: #333;
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.how-it-works ol {
    margin: 0 0 15px 0;
    padding-left: 24px;
}

.how-it-works li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.how-it-works p {
    margin: 0;
    color: #555;
    line-height: 1.5;
}

.tip {
    background: #f8f9fa;
    border-left: 3px solid #1976D2;
    padding: 15px;
    border-radius: 0 6px 6px 0;
}

.tip p {
    margin: 0;
    color: #555;
    line-height: 1.6;
}

.keys-section .keys-grid {
    display: flex;
    gap: 40px;
}

.keys-group h3 {
    font-size: 0.9em;
    color: #666;
    margin: 0 0 8px 0;
    font-weight: 500;
}

.keys-group > div {
    margin-bottom: 6px;
    font-size: 0.95em;
}

.intro-content .key {
    min-width: 40px;
}

.start-button {
    display: block;
    width: 100%;
    padding: 16px 32px;
    font-size: 1.2em;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    color: white;
    background-color: #1976D2;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.start-button:hover {
    background-color: #1565C0;
}

.intro-footer {
    text-align: center;
    margin-top: 20px;
    color: #888;
    font-size: 0.85em;
}

.intro-footer a {
    color: #1976D2;
    text-decoration: none;
}

.intro-footer a:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    .intro-page {
        padding: 20px 15px;
    }

    .intro-content {
        padding: 20px;
    }

    .keys-section .keys-grid {
        flex-direction: column;
        gap: 20px;
    }
}
