/* CSS Reset & Variables */
:root {
    --font-primary: 'Quicksand', sans-serif;
    --font-heading: 'Fredoka One', cursive;
    --font-mono: 'Share Tech Mono', monospace;
    --bg-color: #f7f9fa;
    --color-correct: #2ecc71;
    --color-incorrect: #e74c3c;
    --color-current: #f1c40f;
    --color-text-dim: #7f8c8d;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-primary);
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    user-select: none;
}

#app-container {
    position: relative;
    width: 1024px;
    height: 600px;
    background: #ffffff;
    border: 8px solid #ffffff;
    border-radius: 28px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Confetti */
#confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

/* HUD HEADER */
#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: #f1f2f6;
    border-bottom: 4px solid #dfe6e9;
    z-index: 50;
}

.hud-btn {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    padding: 8px 18px;
    border: 3px solid #718093;
    border-radius: 15px;
    background-color: #ffffff;
    cursor: pointer;
    box-shadow: 0 4px 0 #718093;
    transition: transform 0.1s, box-shadow 0.1s;
}

.hud-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #718093;
}

.hud-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #718093;
}

.config-btn {
    background-color: #ffeaa7;
    border-color: #d35400;
    box-shadow: 0 4px 0 #d35400;
}

.config-btn:hover {
    box-shadow: 0 6px 0 #d35400;
}

.hud-badge {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: #2f3542;
    background-color: #ffffff;
    padding: 5px 20px;
    border-radius: 20px;
    border: 3px solid #2f3542;
}

/* OVERLAYS */
.screen-overlay {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

/* SCREEN 1: WELCOME SCREEN */
#screen-welcome {
    background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
    color: #ffffff;
}

.welcome-box {
    background-color: rgba(255, 255, 255, 0.96);
    color: #2f3542;
    padding: 40px;
    border-radius: 28px;
    width: 600px;
    text-align: center;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    border: 6px solid #ffeaa7;
}

.welcome-badge {
    display: inline-block;
    background-color: #ff7675;
    color: #ffffff;
    font-family: var(--font-heading);
    padding: 6px 18px;
    border-radius: 12px;
    font-size: 1.1rem;
    transform: rotate(-3deg);
    margin-bottom: 15px;
    box-shadow: 0 4px 0 #c23616;
}

.welcome-title {
    font-family: var(--font-heading);
    font-size: 2.8rem;
    margin: 5px 0;
    color: #0984e3;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.08);
}

.welcome-subtitle {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: #718093;
    font-weight: bold;
}

.grade-selection-row {
    display: flex;
    justify-content: center;
    gap: 30px;
}

.grade-btn {
    flex: 1;
    padding: 20px;
    border-radius: 24px;
    border: 4px solid;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.grade-btn:hover {
    transform: translateY(-8px);
}

.btn-2nd {
    background-color: #ffeaa7;
    border-color: #fdcb6e;
    color: #b33939;
    box-shadow: 0 8px 0 #fdcb6e;
}
.btn-2nd:hover {
    box-shadow: 0 12px 0 #fdcb6e;
}

.btn-3rd {
    background-color: #dff9fb;
    border-color: #c7ecee;
    color: #2c3a47;
    box-shadow: 0 8px 0 #c7ecee;
}
.btn-3rd:hover {
    box-shadow: 0 12px 0 #c7ecee;
}

.btn-emoji {
    font-size: 3.5rem;
    margin-bottom: 8px;
}

.btn-text {
    font-family: var(--font-heading);
    font-size: 1.4rem;
}

.btn-subtext {
    font-size: 0.85rem;
    font-weight: bold;
    opacity: 0.7;
    margin-top: 5px;
}

/* SCREEN 2: TEACHER SETUP */
#screen-teacher {
    background-color: #dfe6e9;
}

.teacher-box {
    background: #ffffff;
    width: 750px;
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border: 5px solid #2f3542;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.teacher-title {
    font-family: var(--font-heading);
    color: #2f3542;
    font-size: 1.8rem;
    margin: 0;
}

.teacher-subtitle {
    color: #718093;
    font-size: 1.05rem;
    margin: 0;
}

#teacher-custom-text {
    width: 100%;
    height: 140px;
    padding: 15px;
    font-size: 1.15rem;
    border: 3px solid #b2bec3;
    border-radius: 15px;
    font-family: var(--font-primary);
    resize: none;
    outline: none;
    box-sizing: border-box;
}

#teacher-custom-text:focus {
    border-color: #0984e3;
}

.preset-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preset-label {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: #2f3542;
}

.preset-btn {
    font-family: var(--font-primary);
    font-weight: bold;
    padding: 8px 15px;
    border: 2px solid #b2bec3;
    border-radius: 12px;
    background-color: #ffffff;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.1s;
}

.preset-btn:hover {
    background-color: #f1f2f6;
    border-color: #718093;
}

.teacher-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 10px;
}

.save-btn, .cancel-btn {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    padding: 10px 25px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}

.save-btn {
    background-color: #2ecc71;
    color: #ffffff;
}

.cancel-btn {
    background-color: #e74c3c;
    color: #ffffff;
}

/* SCREEN 3: GAMEPLAY LAYOUT */
#screen-gameplay {
    background-color: #f7f9fa;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 15px;
    gap: 12px;
}

/* PROJECTED AREA */
.projected-text-panel {
    width: 100%;
    height: 180px;
    background-color: #ffffff;
    border: 4px solid #b2bec3;
    border-radius: 20px;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.05);
}

.text-char-wrapper {
    font-family: var(--font-mono);
    font-size: 2.2rem;
    line-height: 1.5;
    word-spacing: 5px;
    white-space: pre-wrap;
}

/* CHARACTER COLORED STATES */
.char {
    display: inline-block;
    color: #95a5a6;
    border-bottom: 3px solid transparent;
    transition: all 0.1s;
}

.char.correct {
    color: var(--color-correct);
    font-weight: bold;
}

.char.incorrect {
    color: var(--color-incorrect);
    background-color: rgba(231, 76, 60, 0.15);
    border-bottom: 3px solid var(--color-incorrect);
}

.char.current {
    color: #2c3e50;
    background-color: #ffeaa7;
    border-bottom: 3px solid var(--color-current);
    animation: cursorBlink 0.8s infinite alternate;
}

@keyframes cursorBlink {
    0% { border-bottom-color: transparent; }
    100% { border-bottom-color: var(--color-current); }
}

/* RACETRACK (2ND GRADE) */
.racetrack-container {
    width: 100%;
    height: 50px;
    background-color: #dfe6e9;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border: 3px solid #718093;
}

.track-line {
    position: relative;
    width: calc(100% - 60px);
    margin: 0 30px;
    height: 100%;
    display: flex;
    align-items: center;
}

.car-sprite {
    position: absolute;
    left: 0;
    font-size: 2.2rem;
    transition: left 0.2s ease-out;
    z-index: 10;
}

.flag-sprite {
    position: absolute;
    right: 0;
    font-size: 2rem;
}

/* METRICS HUD (3RD GRADE) */
.metrics-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    width: 100%;
}

.metric-card {
    background-color: #ffffff;
    border: 3px solid #74b9ff;
    border-radius: 15px;
    padding: 8px 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.metric-icon {
    font-size: 1.8rem;
}

.metric-value {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: #2d3436;
}

/* STUDENT INPUT PANEL */
.input-panel {
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#student-input {
    width: 100%;
    height: 120px;
    padding: 15px;
    font-size: 1.3rem;
    font-family: var(--font-primary);
    border: 4px solid #74b9ff;
    border-radius: 20px;
    outline: none;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
    background-color: #fffdf9;
    resize: none;
    box-sizing: border-box;
}

#student-input::placeholder {
    color: #b2bec3;
    font-weight: bold;
}

.input-focus-tip {
    font-size: 0.85rem;
    color: #7f8c8d;
    font-weight: bold;
    margin-top: 4px;
}

/* VIRTUAL KEYBOARD ASSISTANCE */
.virtual-keyboard {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background-color: #dfe6e9;
    padding: 8px;
    border-radius: 16px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key {
    background-color: #ffffff;
    border: 2px solid #b2bec3;
    border-radius: 8px;
    width: 40px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-heading);
    font-size: 1rem;
    color: #2d3436;
    box-shadow: 0 2px 0 #b2bec3;
    transition: all 0.1s;
}

.key.space-key {
    width: 180px;
}

.key.highlighted {
    background-color: #fdcb6e;
    border-color: #e1b12c;
    box-shadow: 0 4px 0 #e1b12c;
    transform: scale(1.08) translateY(-2px);
    z-index: 10;
}

/* SCREEN 4: VICTORY */
#screen-victory {
    background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 100%);
}

.victory-box {
    background: #ffffff;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
    border: 6px solid #fdcb6e;
    max-width: 500px;
    z-index: 10;
}

.victory-trophy {
    font-size: 6rem;
    animation: bounce 1s infinite alternate ease-in-out;
}

@keyframes bounce {
    0% { transform: scale(0.9); }
    100% { transform: scale(1.1); }
}

.victory-title {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    color: #2ecc71;
    margin: 15px 0 5px;
}

.victory-subtitle {
    font-size: 1.2rem;
    color: #7f8c8d;
    margin-bottom: 25px;
    font-weight: bold;
}

#victory-stats-row {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin-bottom: 30px;
    background-color: #f7f9fa;
    padding: 15px 25px;
    border-radius: 20px;
    border: 2px dashed #b2bec3;
}

.victory-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.victory-stat-val {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    color: #0984e3;
}

.victory-stat-lbl {
    font-size: 0.85rem;
    color: #718093;
    font-weight: bold;
    margin-top: 4px;
}

.action-btn {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    padding: 12px 40px;
    border: 4px solid #27ae60;
    border-radius: 20px;
    background-color: #2ecc71;
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 6px 0 #27ae60;
    transition: transform 0.1s, box-shadow 0.1s;
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 9px 0 #27ae60;
}

.action-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #27ae60;
}
