html, body {
    height: 100%;
    overscroll-behavior: none;
}
body { font-family: sans-serif; display: flex; flex-direction: column; align-items: center; margin: 0; background-color: #333; color: #fff; }
h1 { font-size: 1.6em; margin: 5px 0; }
.content { max-width: 800px; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; }
#board {
    width: 90vw;
    max-width: min(800px, calc(100vh - 330px));
    margin-top: 5px;
    touch-action: none;
}
.controls { margin-top: 5px; }
button { font-size: 1.2em; padding: 10px 20px; cursor: pointer; border-radius: 5px; border: none; background-color: #555; color: white; }

@media (max-height: 700px) {
    h1 { font-size: 1.2em; margin: 2px 0; }
    .user-info-bar { padding: 2px 0; margin-bottom: 2px; }
    #session-info { font-size: 1em; margin-bottom: 2px; }
    #board { margin-top: 2px; max-width: min(800px, calc(100vh - 230px)); }
    #status { margin-top: 2px; font-size: 1em; height: 2.2em; }
    #turn-indicator { margin-top: 2px; font-size: 1.1em; height: 1.1em; }
    .controls { margin-top: 5px; }
}

@media (max-width: 600px) {
    html, body {
        overflow: hidden;
    }
    h1, .user-info-bar { display: none !important; }
    #session-info { font-size: 1em; margin-bottom: 5px; }
    button { font-size: 1em; padding: 8px 12px; }
    .controls { display: flex; gap: 5px; justify-content: center; }
    #board { max-width: min(800px, calc(100vh - 180px)); }
}
#next-tactic { background-color: #28a745; }
button:hover { background-color: #777; }
#turn-indicator { margin-top: 5px; font-size: 1.2em; font-weight: bold; height: 1.2em; overflow: hidden; }
#status { margin-top: 5px; font-size: 1.1em; height: 2.6em; text-align: center; overflow: hidden; }
#elo-info { margin-top: 5px; font-size: 1em; height: 1.2em; overflow: hidden; }
#rated-status {
    margin-top: 10px;
    cursor: pointer;
    text-decoration: underline;
    color: #aaa;
}
#rated-status:hover {
    color: #fff;
}
/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 2000; /* Sit on top of everything */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
    padding-top: 60px;
}
.modal-content {
    background-color: #444;
    margin: 5% auto; /* 5% from the top and centered */
    padding: 30px;
    border: 1px solid #888;
    width: 80%; /* Could be more or less, depending on screen size */
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    color: #fff;
}
.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}
.close-button:hover,
.close-button:focus {
    color: #fff;
    text-decoration: none;
    cursor: pointer;
}
.setting-item {
    margin-bottom: 15px;
}
.setting-item label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}
.setting-item input[type="number"],
.setting-item input[type="text"],
.setting-item select {
    width: calc(100% - 20px);
    padding: 8px 10px;
    margin-top: 5px;
    border-radius: 4px;
    border: 1px solid #555;
    background-color: #333;
    color: #fff;
}
.setting-item input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.2);
}
.setting-item .description {
    font-size: 0.9em;
    color: #bbb;
    margin-top: 5px;
}
#save-settings {
    background-color: #007bff;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 20px;
}
#save-settings:hover {
    background-color: #0056b3;
}
.user-info-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #555;
    margin-bottom: 10px;
}

/* Race Mode Styles */
#analysis-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
}

#analysis-controls button {
    font-size: 0.9em;
    padding: 8px 12px;
}

#engine-status {
    color: gold;
    font-weight: bold;
}

#race-top-bar {
    display: none;
    width: 100%;
    background: #222;
    padding: 10px 0;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
    font-size: 1.1em;
    justify-content: space-around;
    font-weight: bold;
    color: #ffcc00;
    border-bottom: 2px solid #444;
}

@media (min-width: 600px) {
    #race-top-bar {
        font-size: 1.5em;
    }
}

#race-overlay {
    z-index: 100;
}

#race-overlay .modal-content {
    text-align: center;
    max-width: 400px;
}

#race-overlay-info {
    font-size: 1.1em;
    line-height: 1.5em;
    margin-bottom: 20px;
}

@media (min-width: 600px) {
    #race-overlay-info {
        font-size: 1.2em;
        line-height: 1.6em;
    }
}

#race-countdown {
    font-size: 4em;
    margin: 15px 0;
    color: #ffcc00;
    font-weight: bold;
}

@media (min-width: 600px) {
    #race-countdown {
        font-size: 5em;
        margin: 20px 0;
    }
}

#race-result {
    display: none;
}

.race-active #next-tactic,
.race-active #analyze-tactic,
.race-active #analysis-controls,
.race-active #prev-tactic,
.race-active #open-history,
.race-active #new-session,
.race-active #start-race,
.race-active .user-info-bar,
.race-active h1,
.race-active #session-info {
    display: none !important;
}

.race-active .content {
    margin-top: 60px;
}

.highlight-selected {
    box-shadow: inset 0 0 3px 3px yellow;
}
.highlight-incorrect {
    box-shadow: inset 0 0 3px 3px red;
}
.highlight-correct {
    box-shadow: inset 0 0 3px 3px green;
}

/* Home Screen Styles */
#home-screen {
    background-color: #333;
    padding-top: 0;
    z-index: 1000; /* Below other modals but above base content */
}
#home-screen .modal-content {
    background-color: #333;
    border: none;
    margin: 0 auto;
    top: 50%;
    transform: translateY(-50%);
    box-shadow: none;
}
.home-content {
    text-align: center;
    padding: 50px 20px;
}
.home-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 30px;
}
.home-button {
    font-size: 1.5em;
    padding: 20px;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    background-color: #444;
    border: 2px solid #666;
    transition: background-color 0.2s, transform 0.1s;
}
.home-button:hover {
    background-color: #555;
    transform: translateY(-2px);
}
.home-button:active {
    transform: translateY(0);
}
#home-free-play { background-color: #28a745; border-color: #1e7e34; }
#home-themes { background-color: #007bff; border-color: #0062cc; }
#home-race { background-color: #e67e22; border-color: #d35400; }

/* Themes Menu Styles */
.themes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.theme-item {
    background-color: #555;
    padding: 15px 10px;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s;
    font-weight: bold;
    font-size: 0.9em;
}
.theme-item:hover {
    background-color: #666;
}
.theme-item.current {
    background-color: #007bff;
    border: 2px solid #0056b3;
    font-size: 1.1em;
    padding: 20px;
}

.theme-item.active-goal {
    border: 2px solid #007bff;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
}

.theme-item.locked {
    opacity: 0.5;
    background-color: #333;
    cursor: not-allowed;
    border: 1px dashed #666;
}

.theme-item.completed {
    background-color: #28a745 !important;
    border: 2px solid #1e7e34;
    color: #fff;
}

.theme-item.completed .stage-info {
    color: #dfd;
    font-weight: bold;
}

.theme-item.golden {
    background-color: #f1c40f !important;
    color: #000;
    border: 2px solid #d4af37;
}

.theme-item.golden .stage-info {
    color: #333;
}

.theme-item.golden .record-info {
    color: #8b4513;
}
.theme-item .stage-info {
    display: block;
    font-size: 0.8em;
    color: #ccc;
    margin-top: 5px;
    font-weight: normal;
}

.theme-item .record-info {
    display: block;
    font-size: 0.8em;
    color: #ffcc00;
    margin-top: 5px;
    font-weight: bold;
}

#theme-race-toggle-btn.active {
    background-color: #e67e22 !important;
    border-color: #d35400 !important;
    color: #fff;
}

.themes-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-right: 30px;
}

.themes-menu-header h2 {
    margin: 0;
}

.toggle-button {
    background-color: #555;
    padding: 5px 15px;
    font-size: 0.9em;
    border: 2px solid #777;
    cursor: pointer;
    border-radius: 5px;
    color: #fff;
}

/* History Styles */
.history-container {
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 20px;
}

.history-item {
    display: flex;
    align-items: center;
    background-color: #555;
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-item:hover {
    background-color: #666;
}

.history-mini-board {
    width: 120px;
    height: 120px;
    margin-right: 20px;
    flex-shrink: 0;
}

.history-info {
    flex-grow: 1;
}

.history-info .tactic-id {
    font-weight: bold;
    color: #ffcc00;
}

.history-info .result {
    font-weight: bold;
}

.history-info .result.correct { color: #28a745; }
.history-info .result.incorrect { color: #dc3545; }

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.pagination-controls button {
    padding: 5px 15px;
    font-size: 0.9em;
}
