/*
 * style.css - ธีมธรรมชาติ Forest Adventure สำหรับเกมพิมพ์โค้ด
 */

:root {
    --wood-dark: #4a2e18;
    --wood-medium: #7e4a24;
    --wood-light: #ab6d39;
    --wood-border: #331f0f;
    --gold: #f8c035;
    --gold-dark: #b87b00;
    --green-leaf: #599d28;
    --green-bright: #43d43b;
    --green-glow: rgba(67, 212, 59, 0.4);
    --forest-sky: #a4ddf5;
    --ground-brown: #3f2819;
    --code-bg: rgba(255, 255, 255, 0.94);
    --char-correct: #168a35;
    --char-pending: #475569;
    --char-mistake: #dc2626;
    --font-ui: 'Kanit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-code: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

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

body {
    font-family: var(--font-ui);
    background: #193319 url('../images/bg_forest.jpg') no-repeat center center fixed;
    background-size: cover;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    color: #333;
}

/* Background Nature Atmosphere */
.nature-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.08) 0%, rgba(12, 28, 10, 0.5) 100%);
    backdrop-filter: blur(1.5px);
}

.tree-left, .tree-right {
    position: absolute;
    bottom: 120px;
    width: 200px;
    height: 380px;
    background-repeat: no-repeat;
    background-size: contain;
    opacity: 0.85;
}

.tree-left {
    left: 10px;
    background-image: radial-gradient(circle at 50% 30%, #58962b 30%, #3e6d1c 65%, transparent 70%);
}

.tree-right {
    right: 10px;
    background-image: radial-gradient(circle at 50% 30%, #58962b 30%, #3e6d1c 65%, transparent 70%);
}

.clouds {
    position: absolute;
    top: 30px;
    left: 0;
    width: 200%;
    height: 100px;
    background: radial-gradient(ellipse at center, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 70%);
    animation: driftClouds 80s linear infinite;
}

@keyframes driftClouds {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

/* Main Game Layout Container */
.game-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1100px;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px 16px;
    overflow: hidden;
}

/* ===================================================
   TOP HEADER BAR
=================================================== */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 8px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Wooden Buttons */
.wood-btn {
    background: linear-gradient(180deg, #9b5a2b 0%, #683616 100%);
    border: 3px solid #3d1c08;
    border-radius: 12px;
    color: #fff;
    font-family: var(--font-ui);
    font-size: 15px;
    font-weight: 700;
    padding: 8px 14px;
    cursor: pointer;
    box-shadow: 0 4px 0 #281003, inset 0 2px 2px rgba(255, 255, 255, 0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.1s ease;
}

.wood-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.wood-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #281003;
}

.wood-btn.btn-circle {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 20px;
}

.wood-btn.btn-green {
    background: linear-gradient(180deg, #62b82f 0%, #3d791b 100%);
    border-color: #21470c;
    box-shadow: 0 4px 0 #142e06, inset 0 2px 2px rgba(255, 255, 255, 0.4);
}

/* School Brand & Developer Credit Badge */
.brand-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(180deg, #44240d 0%, #2b1506 100%);
    border: 2.5px solid #f8c035;
    padding: 3px 10px 3px 4px;
    border-radius: 24px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.2);
    backdrop-filter: blur(4px);
}

.school-logo {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #f8c035;
    box-shadow: 0 2px 5px rgba(0,0,0,0.35);
    display: block;
}

.brand-info {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: left;
}

.brand-school {
    font-size: 11px;
    font-weight: 800;
    color: #fce3a6;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.brand-credit {
    font-size: 11px;
    font-weight: 700;
    color: #4ade80;
    white-space: nowrap;
}

/* Score Wooden Badge */
.score-badge {
    background: linear-gradient(180deg, #6c3b1a 0%, #44220b 100%);
    border: 3px solid #f8c035;
    border-radius: 14px;
    padding: 6px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 2px 4px rgba(0,0,0,0.4);
}

.score-badge .score-label {
    font-size: 11px;
    color: #f7d58b;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.score-badge .score-number {
    font-size: 24px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.6);
    line-height: 1.1;
}

/* Top Progress Track */
.progress-container {
    flex: 1;
    position: relative;
    background: #3a2211;
    border: 3px solid #704423;
    border-radius: 20px;
    height: 32px;
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    padding: 3px 5px;
}

.progress-track {
    width: 100%;
    height: 100%;
    position: relative;
    border-radius: 14px;
    overflow: visible;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(180deg, #6de847 0%, #3bb81d 100%);
    border-radius: 14px;
    box-shadow: inset 0 2px 3px rgba(255,255,255,0.6);
    transition: width 0.2s ease-out;
}

.progress-clock {
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    background: #fff;
    border: 3px solid #704423;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
    z-index: 2;
}

.progress-mascot {
    position: absolute;
    top: -14px;
    left: 0%;
    width: 44px;
    height: 44px;
    transition: left 0.2s ease-out;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
    z-index: 3;
    animation: mascotBob 0.7s infinite alternate ease-in-out;
}

.mascot-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid #f8c035;
    background: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    display: block;
}

@keyframes mascotBob {
    0% { transform: translateY(0); }
    100% { transform: translateY(-5px); }
}

.timer-tag {
    position: absolute;
    right: 12px;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    background: rgba(0,0,0,0.4);
    padding: 2px 8px;
    border-radius: 10px;
}

/* ===================================================
   CENTER PLAY AREA (LEFT SIDEBAR + CODE DISPLAY)
=================================================== */
.game-center {
    display: flex;
    gap: 14px;
    flex: 1;
    min-height: 0;
    position: relative;
}

/* Left Sidebar (Combo Meter & Speedometer) */
.left-meters {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100px;
}

/* Combo Tube Gauge (Glass Liquid Meter) */
.combo-meter-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.meter-glass {
    position: relative;
    width: 34px;
    height: 140px;
    background: rgba(255, 255, 255, 0.25);
    border: 4px solid #633b19;
    border-radius: 20px;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.4), 0 4px 8px rgba(0,0,0,0.2);
    overflow: hidden;
    display: flex;
    align-items: flex-end;
}

.meter-fill {
    width: 100%;
    height: 0%;
    background: linear-gradient(180deg, #76f03d 0%, #38a815 100%);
    box-shadow: 0 0 10px rgba(118, 240, 61, 0.8);
    transition: height 0.3s ease;
    border-radius: 0 0 14px 14px;
}

.meter-fill.fire {
    background: linear-gradient(180deg, #ffc107 0%, #f44336 100%);
    box-shadow: 0 0 16px rgba(255, 87, 34, 0.9);
    animation: pulseFire 0.4s infinite alternate;
}

@keyframes pulseFire {
    0% { filter: brightness(1); }
    100% { filter: brightness(1.3); }
}

.combo-text {
    font-size: 13px;
    font-weight: 800;
    color: #4a280c;
    background: #fbd66e;
    padding: 2px 8px;
    border-radius: 8px;
    border: 2px solid #824b17;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.streak-tag {
    font-size: 11px;
    font-weight: 700;
    color: #3b200b;
}

/* Speedometer Circle Badge (Bottom Left) */
.speedometer-badge {
    width: 72px;
    height: 72px;
    background: radial-gradient(circle, #3e7323 50%, #20440e 100%);
    border: 4px solid #c89547;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 5px 10px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4);
}

.speedometer-badge .wpm-val {
    font-size: 20px;
    font-weight: 900;
    line-height: 1;
    color: #f7ea48;
    text-shadow: 0 2px 3px rgba(0,0,0,0.6);
}

.speedometer-badge .wpm-lbl {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.speedometer-badge .acc-val {
    font-size: 10px;
    font-weight: 600;
    color: #bbf7d0;
}

/* Center Code Stage (Wooden Board & Parchment) */
.code-stage {
    flex: 1;
    background: #5d3618;
    border: 6px solid #3c1e09;
    border-radius: 16px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.4), inset 0 2px 4px rgba(255,255,255,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.code-header {
    background: #47260e;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 3px solid #2e1505;
}

.badge {
    font-size: 12px;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 10px;
    color: #fff;
    letter-spacing: 0.5px;
}

.badge.lang-c {
    background: #1976d2;
}

.badge.lang-python {
    background: #f59e0b;
    color: #261502;
}

.badge.lang-custom {
    background: #9333ea;
}

.level-title-display {
    color: #fce3a6;
    font-size: 16px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.snippet-counter {
    color: #d1b18a;
    font-size: 13px;
    font-weight: 600;
}

/* Code Display Box */
.code-arena {
    flex: 1;
    background: var(--code-bg);
    margin: 8px;
    border-radius: 10px;
    padding: 16px 20px;
    overflow-y: auto;
    font-family: var(--font-code);
    font-size: 22px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
    border: 2px solid #dfc6a5;
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.15);
}

/* Individual Character Styling in Code */
.char {
    position: relative;
    transition: color 0.1s ease;
}

.char.pending {
    color: var(--char-pending);
}

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

.char.current {
    background-color: #fde047;
    color: #000;
    font-weight: 700;
    border-radius: 3px;
    box-shadow: 0 0 8px rgba(250, 204, 21, 0.8);
    animation: cursorPulse 1s infinite alternate;
}

@keyframes cursorPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

.char.mistake {
    background-color: #fee2e2;
    color: var(--char-mistake);
    text-decoration: underline;
    animation: shakeMistake 0.25s ease-in-out;
}

@keyframes shakeMistake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.char-newline {
    color: #94a3b8;
    font-size: 16px;
}

.explanation-footer {
    background: #3e220c;
    padding: 6px 16px;
    color: #ecd5ba;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 2px solid #2d1606;
}

.explanation-footer .tip-icon {
    font-size: 16px;
}

/* ===================================================
   MODALS (Level Select, Victory, Custom Code, Pause)
=================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: #5d3618;
    border: 5px solid #ab6d39;
    outline: 4px solid #331f0f;
    border-radius: 20px;
    padding: 24px;
    width: 90%;
    max-width: 580px;
    color: #fff;
    box-shadow: 0 15px 30px rgba(0,0,0,0.6);
    position: relative;
    animation: modalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    border-bottom: 2px solid #7c4820;
    padding-bottom: 10px;
}

.modal-header h2 {
    font-size: 22px;
    color: #fbd66e;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.btn-close {
    background: none;
    border: none;
    color: #eed4b7;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

/* Language Tabs */
.lang-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.lang-tab-btn {
    flex: 1;
    padding: 10px;
    font-size: 15px;
    font-weight: 700;
    border: 2px solid #44240d;
    background: #47260e;
    color: #d1b18a;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.lang-tab-btn.active {
    background: #f8c035;
    color: #3b200b;
    border-color: #b87b00;
    box-shadow: 0 3px 0 #8b5d00;
}

.level-list {
    max-height: 340px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 4px;
}

.level-card {
    background: #44240d;
    border: 2px solid #78451f;
    border-radius: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.level-card:hover {
    background: #542d11;
    border-color: #f8c035;
    transform: translateX(4px);
}

.level-card.active-level {
    border-color: #43d43b;
    background: #393b16;
}

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

.card-num {
    font-weight: 800;
    color: #fbd66e;
    font-size: 14px;
}

.card-stars .card-star {
    font-size: 16px;
    color: #644122;
}

.card-stars .card-star.earned {
    color: #f8c035;
    text-shadow: 0 0 6px rgba(248, 192, 53, 0.8);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 2px;
}

.card-desc {
    font-size: 12px;
    color: #c9ab88;
}

.card-best {
    font-size: 11px;
    color: #8be385;
    margin-top: 4px;
}

/* Victory Modal */
.confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.victory-content {
    text-align: center;
    padding: 10px 0;
    position: relative;
    z-index: 2;
}

.victory-trophy-img {
    width: 110px;
    height: 110px;
    object-fit: contain;
    border-radius: 20px;
    margin: 0 auto 10px auto;
    display: block;
    filter: drop-shadow(0 8px 16px rgba(248, 192, 53, 0.45));
    animation: trophyBounce 1.8s infinite alternate ease-in-out;
}

@keyframes trophyBounce {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-8px) scale(1.04); }
}

.victory-stars {
    font-size: 38px;
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.star-icon {
    color: #492e18;
}

.star-icon.earned {
    color: #f8c035;
    text-shadow: 0 0 15px rgba(248, 192, 53, 0.9);
    animation: starPulse 0.6s ease-in-out;
}

@keyframes starPulse {
    0% { transform: scale(0.4); opacity: 0; }
    80% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.victory-stats {
    background: #3d200b;
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    color: #d1b18a;
}

.stat-row strong {
    color: #fff;
    font-size: 16px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Custom Code Input */
.custom-code-area {
    width: 100%;
    height: 160px;
    background: #fff;
    color: #1e293b;
    font-family: var(--font-code);
    font-size: 14px;
    padding: 12px;
    border-radius: 10px;
    border: 3px solid #7c4820;
    resize: vertical;
    margin-bottom: 16px;
}

/* Thai Keyboard Notification Toast */
.thai-notice {
    position: absolute;
    top: 6px;
    right: 16px;
    background: rgba(30, 41, 59, 0.92);
    border: 2px solid #38bdf8;
    color: #f0fdf4;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: none;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10;
    pointer-events: none;
    animation: fadeInDown 0.3s ease;
}

.thai-notice.visible {
    display: flex;
}

@keyframes fadeInDown {
    0% { transform: translateY(-8px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Start Hint Floating Banner */
.start-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(43, 22, 9, 0.92);
    border: 3px solid #f8c035;
    color: #fff;
    padding: 10px 20px;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 8;
    pointer-events: none;
    transition: opacity 0.3s ease;
    text-align: center;
    animation: pulseHint 1.5s infinite alternate;
}

@keyframes pulseHint {
    0% { transform: translate(-50%, -50%) scale(1); }
    100% { transform: translate(-50%, -50%) scale(1.04); }
}

/* Responsive adjustments for compact screens (e.g. 1366x768 or laptops) */
@media (max-height: 760px) {
    .game-wrapper {
        padding: 4px 10px;
    }
    .game-header {
        margin-bottom: 4px;
    }
    .wood-btn {
        padding: 5px 10px;
        font-size: 13px;
    }
    .wood-btn.btn-circle {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    .score-badge {
        padding: 3px 12px;
    }
    .score-badge .score-number {
        font-size: 18px;
    }
    .progress-container {
        height: 26px;
    }
    .progress-clock {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
    .progress-mascot {
        font-size: 22px;
        top: -8px;
    }
    .meter-glass {
        height: 100px;
        width: 28px;
    }
    .speedometer-badge {
        width: 58px;
        height: 58px;
    }
    .speedometer-badge .wpm-val {
        font-size: 16px;
    }
    .code-arena {
        font-size: 18px;
        padding: 10px 14px;
        line-height: 1.5;
    }
    .explanation-footer {
        padding: 4px 12px;
        font-size: 12px;
    }
}

/* Footer Credit */
.game-footer-credit {
    text-align: center;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
    padding: 2px 0 0 0;
    font-weight: 500;
}

.game-footer-credit a {
    color: #fbd66e;
    text-decoration: none;
    font-weight: 700;
}

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

