/* Base styles */
:root {
    --primary-color: #2a3d66;
    --secondary-color: #4f97a3;
    --accent-color: #f26419;
    --background-color: #f5f5f5;
    --text-color: #333;
    --success-color: #4caf50;
    --error-color: #f44336;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

html, body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden; /* Prevent scrolling on the body */
}

/* Header styles */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
}

nav {
    flex: 1;
}

nav ul {
    list-style: none;
    display: flex;
    margin: 0;
    padding: 0;
}

nav li {
    margin-right: 1.5rem;
}

nav li:last-child {
    margin-right: 0;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 0.25rem 0;
    position: relative;
}

nav a:after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: 0;
    left: 0;
    background-color: var(--accent-color);
    transition: width 0.3s;
}

nav a:hover:after {
    width: 100%;
}

/* Main content styles */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    position: relative;
    overflow: hidden; /* Prevent scrolling in the main container */
    height: calc(100% - 60px); /* Adjust based on header height */
}

#scene-container {
    width: 100%;
    background-color: #000;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    
    /* Mobile: take 60% of vertical space */
    height: 60vh;
    flex-shrink: 0; /* Don't let it shrink */
}

#training-panel {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    overflow-y: auto; /* Allow scrolling */
    overflow-x: hidden;
    
    /* Take remaining space and scroll if needed */
    flex: 1;
}

#current-exercise {
    margin-bottom: 1rem;
}

#target-text {
    font-size: 1.5rem;
    margin: 1rem 0;
    padding: 1rem;
    background-color: #f9f9f9;
    border-radius: 5px;
    border-left: 4px solid var(--secondary-color);
}

#user-input {
    font-size: 1.5rem;
    min-height: 3rem;
    padding: 1rem;
    background-color: #f9f9f9;
    border-radius: 5px;
    border-left: 4px solid var(--accent-color);
}

#training-controls, #stats-panel, #session-stats {
    margin-bottom: 1rem;
}

.control-group {
    margin-bottom: 0.5rem;
}

.control-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
}

.button-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.mode-button, .action-button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background-color: #e0e0e0;
    cursor: pointer;
    font-weight: 500;
    flex: 1;
    min-width: 80px;
    transition: all 0.2s ease;
}

.mode-button:hover, .action-button:hover {
    background-color: #d0d0d0;
}

.mode-button.active {
    background-color: var(--secondary-color);
    color: white;
}

.action-button.primary {
    background-color: var(--accent-color);
    color: white;
}

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

#stats-panel, #session-stats {
    margin-bottom: 1rem;
}
#stats-panel h3 {
    font-weight: bold;
    padding-bottom: 0.3rem;
    color: var(--primary-color);
}

#session-stats h3 {
    font-weight: bold;
    padding-bottom: 0.3rem;
    color: var(--primary-color);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.stat {
    text-align: center;
    padding: 0.75rem;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    min-height: 90px;
    transition: all 0.2s ease;
}

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

.stat-label {
    font-weight: bold;
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
    color: #666;
}

.stat-value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 2px 0 6px 0;
    flex: 1;
}

/* Secondary stat styles */
.stat-secondary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #eee;
    padding-top: 0.4rem;
    margin-top: auto;
}

.stat-label-small {
    font-size: 0.75rem;
    font-weight: bold;
    color: #888;
}

.stat-value-small {
    font-size: 1rem;
    font-weight: 600;
    color: var(--secondary-color);
}

.hidden {
    display: none;
}

/* Toggle switch styles */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
}

.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
    width: 100%;
    line-height: 24px; /* Match height of toggle slider */
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    background-color: #ccc;
    border-radius: 24px;
    transition: .4s;
    margin-right: 10px;
    flex-shrink: 0;
    vertical-align: middle;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
}

input:checked + .toggle-slider {
    background-color: var(--secondary-color);
}

input:focus + .toggle-slider {
    box-shadow: 0 0 1px var(--secondary-color);
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.toggle-label {
    font-weight: normal;
    font-size: 0.9rem;
    flex: 1;
    display: inline-block;
    vertical-align: middle;
    line-height: 24px; /* Match height of toggle slider */
}

.hint {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
}

/* Number and Select Input Styles */
.number-input-label, .select-input-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.number-input-label span, .select-input-label span {
    font-size: 0.9rem;
    flex: 2;
}

.number-input, .select-input {
    flex: 1;
    padding: 0.35rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
    max-width: 80px;
    text-align: center;
}

.select-input {
    max-width: 160px;
}

/* Letter generator controls visibility */
#letter-gen-controls {
    display: block; /* Will be toggled based on mode */
    transition: opacity 0.3s ease;
}

/* Footer styles */
footer {
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 1rem;
    margin-top: auto;
}

/* Typing overlay styles */
#typing-overlay {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    user-select: none;
    pointer-events: none;
    width: 80%;
}

#typing-overlay div {
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    padding: 10px 20px;
    margin-bottom: 10px;
    width: 100%;
    text-align: center;
}

#typing-overlay div:last-child {
    background-color: rgba(0, 0, 0, 0.2);
    opacity: 0.5;
}

/* Key ghost animation for incorrect keypresses */
.key-ghost {
    font-family: monospace;
    font-size: 30px;
    text-shadow: 0 0 8px rgba(255, 0, 0, 0.8);
    color: #ff0000;
    position: absolute;
    z-index: 100;
    user-select: none;
    pointer-events: none;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    main {
        flex-direction: row;
        padding: 1rem;
    }

    #scene-container {
        flex: 2; /* Takes 2/3 of the available width */
        height: auto; /* Takes all available height */
    }

    #training-panel {
        flex: 0 0 350px; /* Fixed width, doesn't grow or shrink */
        margin-top: 0;
        margin-left: 1rem;
        max-height: 100%; /* Take all available height */
    }
}

/* Simple height adjustments for compact displays */
@media (max-height: 600px) {
    header {
        padding: 0.25rem 0.75rem;
    }
    
    /* Smaller stats on very short screens */
    .stat {
        min-height: 70px;
        padding: 0.5rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
        margin: 0 0 2px 0;
    }
}