/* 2048 Web Game Styles */

/* Base Styles */
body {
    font-family: Arial, sans-serif;
    background: #faf8ef;
    color: #776e65;
    margin: 0;
    padding: 0;
}

h1 {
    text-align: center;
    margin: 20px 0;
}

/* Game Board */
#board {
    display: grid;
    grid-template-columns: repeat(4, 80px);
    grid-gap: 8px;
    margin: 30px auto;
    width: 352px;
    background: #bbada0;
    padding: 10px;
    border-radius: 8px;
    user-select: none; /* Prevent text selection on touch */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none; /* Prevent default touch behaviors */
    transition: transform 0.1s ease;
    -webkit-touch-callout: none; /* Disable callout on iOS */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
}

/* Mobile touch feedback */
@media (hover: none) and (pointer: coarse) {
    /* These styles only apply to touch devices */
    
    #board {
        cursor: grab;
        border: 2px solid #bbada0;
    }
    
    #board:active {
        cursor: grabbing;
    }
    
    .tile {
        /* Slightly larger tiles for easier touch */
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Add visual instructions for mobile users */
    .mobile-instructions {
        display: block;
        text-align: center;
        margin: 10px auto;
        padding: 10px;
        background: #f8f5f0;
        border-radius: 8px;
        font-size: 14px;
        color: #776e65;
        max-width: 300px;
    }
}

/* Hide mobile instructions on desktop */
@media (hover: hover) and (pointer: fine) {
    .mobile-instructions {
        display: none;
    }
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        padding: 10px;
    }
    
    #sidepane {
        width: 100%;
        margin-left: 0;
    }
    
    #controls {
        flex-direction: column;
        gap: 5px;
    }
    
    .tile {
        width: 60px;
        height: 60px;
        font-size: 1.5em;
    }
    
    #board {
        grid-template-columns: repeat(4, 60px);
        width: 272px;
        margin: 20px auto;
        padding: 12px;
        border-radius: 12px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.2em;
    }
    
    .tile-4096 {
        font-size: 1em;
    }
    
    #analysis-panel {
        max-width: 95vw;
        margin-left: 2.5vw;
        margin-right: 2.5vw;
    }
    
    .analysis-tabs {
        flex-direction: column;
        gap: 2px;
    }
    
    .analysis-tab {
        border-radius: 4px;
        margin-bottom: 2px;
    }
    
    .twophase-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .strategy-checkboxes {
        grid-template-columns: 1fr 1fr;
        font-size: 11px;
    }
    
    .strategy-checkboxes label {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .strategy-checkboxes {
        grid-template-columns: 1fr;
    }
    
    .dropdown-panel {
        padding: 16px;
    }
    
    .analysis-tab {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    /* Even better mobile experience */
    #board {
        grid-gap: 6px;
        padding: 8px;
        margin: 15px auto;
    }
    
    .tile {
        border-radius: 4px;
        font-size: 1.3em;
    }
    
    .mobile-instructions {
        font-size: 13px;
        margin: 8px auto;
        padding: 8px;
    }
}

/* Tile Styles */
.tile {
    width: 80px;
    height: 80px;
    background: #cdc1b4;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    border-radius: 4px;
    transition: all 0.15s ease-in-out;
}

/* Tile Colors */
.tile-0 { background: #cdc1b4; color: #cdc1b4; }
.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: #f9f6f2; }
.tile-16 { background: #f59563; color: #f9f6f2; }
.tile-32 { background: #f67c5f; color: #f9f6f2; }
.tile-64 { background: #f65e3b; color: #f9f6f2; }
.tile-128 { background: #edcf72; color: #f9f6f2; }
.tile-256 { background: #edcc61; color: #f9f6f2; }
.tile-512 { background: #edc850; color: #f9f6f2; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 1.5em; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 1.5em; }
.tile-4096 { background: #3c3a32; color: #f9f6f2; font-size: 1.2em; }

/* Controls */
#controls {
    text-align: center;
    margin: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

button {
    margin: 0 5px;
    padding: 10px 20px;
    font-size: 1em;
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover:not(:disabled) {
    background: #9f7a66;
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

select {
    padding: 8px 12px;
    font-size: 1em;
    border: 1px solid #bbada0;
    border-radius: 4px;
    background: white;
}

/* Layout */
.main-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 32px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.game-area {
    min-width: 400px;
}

/* Side Panel */
#sidepane {
    width: 380px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-height: 450px;
    border: 2px solid #f0f0f0;
    overflow: hidden;
}

.tab-container {
    display: flex;
    border-bottom: 2px solid #bbada0;
    background: #e8e8e8;
}

.tab-button {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: #d4d4d4;
    color: #776e65;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.3s ease;
    cursor: pointer;
    border-right: 1px solid #bbb;
    position: relative;
}

.tab-button:last-child {
    border-right: none;
}

.tab-button:hover {
    background: #c8c8c8;
    color: #5a5248;
}

.tab-button.active {
    background: #8f7a66;
    color: #f9f6f2;
    font-weight: bold;
    border-bottom: 3px solid #f2b179;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tab-content {
    padding: 20px;
    background: #ffffff;
    min-height: 300px;
    border-top: none;
}

.tab-content h3 {
    color: #776e65;
    margin-top: 0;
    margin-bottom: 16px;
    border-bottom: 2px solid #f2b179;
    padding-bottom: 8px;
}

.tab-content h4 {
    color: #8f7a66;
    margin-top: 16px;
    margin-bottom: 12px;
}

/* Analysis & Statistics */
#analysis {
    margin: 20px auto;
    width: 352px;
    background: #f7f7f7;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

#log {
    font-size: 0.9em;
    color: #888;
    text-align: center;
    margin: 10px 0;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    background: #eee;
    height: 18px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: #f2b179;
    transition: width 0.2s;
}

/* Charts */
#distChart {
    margin: 10px auto;
    display: block;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Settings Panel */
.settings-panel {
    max-height: 400px;
    overflow-y: auto;
}

.settings-group {
    margin-bottom: 24px;
    padding: 16px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.weight-control {
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.weight-control label {
    font-weight: 500;
    color: #776e65;
    flex: 1;
}

.weight-control input, .weight-control select {
    width: 80px;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

.button-primary {
    background: #8f7a66 !important;
    color: #f9f6f2 !important;
    padding: 10px 20px !important;
    border: none !important;
    border-radius: 6px !important;
    font-weight: bold !important;
    cursor: pointer !important;
    transition: background 0.3s ease !important;
}

.button-primary:hover {
    background: #9f7a66 !important;
}

.info-box {
    background: #e8f4fd;
    border: 1px solid #bee5eb;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 16px;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.settings-group h3, .settings-group h4 {
    margin: 0 0 10px 0;
    color: #776e65;
    font-size: 1.1em;
}

.weight-control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 5px 0;
}

.weight-control label {
    flex: 1;
    font-size: 0.9em;
    color: #776e65;
}

.weight-control input {
    width: 80px;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}

.weight-control select {
    width: 120px;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}

.button-primary {
    background: #776e65;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    margin-top: 10px;
    transition: background 0.2s;
}

.button-primary:hover:not(:disabled) {
    background: #8f7a66;
}

.button-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.nav-button {
    background: #bbada0;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    transition: background 0.2s;
}

.nav-button:hover:not(:disabled) {
    background: #a09890;
}

.nav-button:disabled {
    background: #ddd;
    cursor: not-allowed;
}

/* Button styling improvements */
.nav-button:disabled,
.button-primary:disabled {
    background: #ccc !important;
    color: #999 !important;
    cursor: not-allowed !important;
    opacity: 0.6;
}

.nav-button:disabled:hover,
.button-primary:disabled:hover {
    background: #ccc !important;
    transform: none !important;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.info-box {
    background: #fff3cd;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    border-left: 3px solid #ffc107;
    font-size: 0.85em;
}

.code-block {
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    background: #f8f9fa;
    padding: 8px;
    border-radius: 4px;
    margin: 8px 0;
    border: 1px solid #dee2e6;
}

.performance-result {
    margin: 5px 0;
    font-weight: bold;
    color: #28a745;
}

#optimizationStatus {
    font-size: 0.9em;
    color: #666;
    margin-top: 5px;
}

/* Dropdown Panels */
.dropdown-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    border: 2px solid #bbada0;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 1000;
    margin-top: 10px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

/* Analysis panel needs more width for multiple strategies */
#analysis-panel {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.dropdown-panel h3 {
    margin-top: 0;
    margin-bottom: 16px;
    color: #776e65;
    border-bottom: 2px solid #f2b179;
    padding-bottom: 8px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

.setting-row label {
    font-weight: 500;
    color: #776e65;
    white-space: nowrap;
}

.setting-row input, .setting-row select {
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    min-width: 120px;
}

.button-row {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    justify-content: center;
}

/* Strategy checkboxes - more compact for tab layout */
.strategy-checkboxes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px 8px;
    margin-top: 8px;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.strategy-checkboxes label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.strategy-checkboxes input[type="checkbox"] {
    min-width: auto;
}

/* Controls positioning */
#controls {
    position: relative;
    margin-bottom: 40px;
    transition: margin-bottom 0.3s ease;
}

#controls.panel-open {
    margin-bottom: 200px; /* Extra space when panel is open */
}

/* Button states */
.button-active {
    background: #f2b179 !important;
    color: #ffffff !important;
    font-weight: bold;
}

/* Comparison Results Styling */
.comparison-results {
    margin-top: 20px;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.comparison-table th,
.comparison-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.comparison-table th {
    background: #8f7a66;
    color: white;
    font-weight: bold;
}

.comparison-table tr:hover {
    background: #f5f5f5;
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.best-strategy {
    margin-top: 20px;
    padding: 16px;
    background: linear-gradient(135deg, #f2b179, #f59563);
    color: white;
    border-radius: 8px;
    text-align: center;
}

.best-strategy h4 {
    margin: 0 0 8px 0;
    font-size: 18px;
}

.best-strategy p {
    margin: 0;
    opacity: 0.9;
}

/* Analysis panel specific improvements */
#analysis-panel {
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

/* Analysis tabs styling */
.analysis-tabs {
    display: flex;
    margin-bottom: 16px;
    border-bottom: 2px solid #e0e0e0;
}

.analysis-tab {
    flex: 1;
    padding: 8px 12px;
    background: #f8f9fa;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    transition: all 0.2s ease;
}

.analysis-tab:hover {
    background: #e9ecef;
    color: #333;
}

.analysis-tab.active {
    background: white;
    color: #4a90e2;
    border-bottom-color: #4a90e2;
}

/* Analysis tab content */
.analysis-tab-content {
    display: none;
    min-height: 80px;
}

.analysis-tab-content.active {
    display: block;
}

/* Two-phase grid layout */
.twophase-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.twophase-grid .setting-row:last-child {
    grid-column: 1 / -1;
}

/* Common analysis settings */
.analysis-common {
    margin-top: 16px;
    border-top: 1px solid #e0e0e0;
    padding-top: 16px;
}

.analysis-common .setting-row {
    margin-bottom: 12px;
}

/* Radio group improvements */
.radio-group {
    background: #f8f8f8;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

/* Two-phase strategy settings styling */
#twophase-strategy-settings {
    transition: all 0.3s ease;
    border-top: 1px solid #e0e0e0;
    padding-top: 16px;
    margin-top: 16px;
    background: #f8fffe;
    padding: 16px;
    border-radius: 6px;
    border: 1px solid #d4edda;
}

#twophase-strategy-settings .setting-row {
    margin-bottom: 14px;
}

#twophase-strategy-settings label {
    font-weight: 600;
    color: #155724;
    min-width: 140px;
}

#twophase-strategy-settings select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    background: white;
}

/* Description Panel Styles */
.description-panel {
    padding: 10px;
}

.description-section {
    margin-bottom: 20px;
}

.description-dropdown {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    font-size: 14px;
    margin-top: 8px;
}

.description-content {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 15px;
    margin-top: 15px;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
}

.description-content h4 {
    color: #444;
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.description-content h4:first-child {
    margin-top: 0;
}

.description-content p {
    margin-bottom: 12px;
    color: #555;
}

.description-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.description-content li {
    margin-bottom: 6px;
    color: #555;
}

/* Description Panel Styling */
.heuristics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.heuristic-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    transition: box-shadow 0.2s ease;
}

.heuristic-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.heuristic-item h5 {
    margin: 0 0 8px 0;
    color: #2c3e50;
    font-size: 1.1em;
    font-weight: 600;
}

.heuristic-item p {
    margin: 0;
    color: #6c757d;
    font-size: 0.9em;
    line-height: 1.4;
}

/* Statistics Panel Styling */
.statistics-content {
    padding: 20px;
}

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

.stat-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stat-card h5 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 1.1em;
    font-weight: 600;
    border-bottom: 2px solid #007bff;
    padding-bottom: 8px;
}

.stat-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.stat-card li {
    padding: 5px 0;
    border-bottom: 1px solid #e9ecef;
}

.stat-card li:last-child {
    border-bottom: none;
}

.strategy-ranking {
    list-style: none;
    padding: 0;
}

.strategy-ranking li {
    background: white;
    margin: 10px 0;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #007bff;
}

.strategy-details {
    display: flex;
    gap: 15px;
    margin-top: 8px;
    font-size: 0.9em;
    color: #6c757d;
}

.comparison-table {
    overflow-x: auto;
    margin-top: 15px;
}

.comparison-table table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 6px;
    overflow: hidden;
}

.comparison-table th {
    background: #007bff;
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

.comparison-table td {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
}

.comparison-table tr:nth-child(even) {
    background: #f8f9fa;
}

.comparison-table tr:hover {
    background: #e3f2fd;
}

/* Tile Distribution Visualization */
.tile-distribution {
    margin-top: 10px;
}

.tile-dist-item {
    margin: 8px 0;
}

.tile-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.tile-label strong {
    color: #2c3e50;
    font-size: 1.1em;
}

.tile-label span {
    color: #6c757d;
    font-size: 0.9em;
}

.tile-bar {
    background: #e9ecef;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
}

.tile-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Special colors for high tiles */
.tile-dist-item:first-child .tile-fill {
    background: linear-gradient(90deg, #28a745, #1e7e34);
}

.tile-dist-item:nth-child(2) .tile-fill {
    background: linear-gradient(90deg, #ffc107, #e0a800);
}

.tile-dist-item:nth-child(3) .tile-fill {
    background: linear-gradient(90deg, #fd7e14, #dc6002);
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        padding: 10px;
    }
    
    #sidepane {
        width: 100%;
        margin-left: 0;
    }
    
    #controls {
        flex-direction: column;
        gap: 5px;
    }
    
    .tile {
        width: 60px;
        height: 60px;
        font-size: 1.5em;
    }
    
    #board {
        grid-template-columns: repeat(4, 60px);
        width: 272px;
        margin: 20px auto;
        padding: 12px;
        border-radius: 12px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.2em;
    }
    
    .tile-4096 {
        font-size: 1em;
    }
    
    #analysis-panel {
        max-width: 95vw;
        margin-left: 2.5vw;
        margin-right: 2.5vw;
    }
    
    .analysis-tabs {
        flex-direction: column;
        gap: 2px;
    }
    
    .analysis-tab {
        border-radius: 4px;
        margin-bottom: 2px;
    }
    
    .twophase-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .strategy-checkboxes {
        grid-template-columns: 1fr 1fr;
        font-size: 11px;
    }
    
    .strategy-checkboxes label {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .strategy-checkboxes {
        grid-template-columns: 1fr;
    }
    
    .dropdown-panel {
        padding: 16px;
    }
    
    .analysis-tab {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    /* Even better mobile experience */
    #board {
        grid-gap: 6px;
        padding: 8px;
        margin: 15px auto;
    }
    
    .tile {
        border-radius: 4px;
        font-size: 1.3em;
    }
    
    .mobile-instructions {
        font-size: 13px;
        margin: 8px auto;
        padding: 8px;
    }
}

/* Utility Classes */
.hidden {
    display: none;
}

.text-center {
    text-align: center;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-4 {
    margin-bottom: 16px;
}
