/* style.css - Updated Footer and Highlight Color */

:root {
    /* --- PALETTE --- */
    --bg-color: #FFFDF7; 
    --text-color: #5D4037; 
    
    /* Card Colors */
    --card-brown: #D7B49E; --card-brown-shadow: #A88673;
    --card-pink: #FF9EAA; --card-pink-shadow: #D67280;
    --card-teal: #78D6C6; --card-teal-shadow: #4DAEA0;
    --card-orange: #FFAB91; --card-orange-shadow: #D67D66;

    --display-bg: #FFFFFF;
    
    /* Button Colors */
    --op-bg: #F5F5F5; --op-shadow: #D6D6D6;
    --bracket-bg: #E3F2FD; --bracket-shadow: #BBDEFB;
    --primary-btn: #81C784; --primary-btn-shadow: #519657;
    
    --custom-btn-bg: #4FC3F7; --custom-btn-shadow: #0288D1;
    
    --radius-l: 24px;
    --radius-m: 16px;
}

* { 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; 
}

body {
    margin: 0; padding: 0;
    font-family: 'Nunito', sans-serif;
    background-color: #F2F4E6; 
    color: var(--text-color);
    height: 100vh; height: 100dvh; 
    display: flex; justify-content: center; align-items: center;
    overflow: hidden; 
    touch-action: manipulation; 
    -webkit-user-select: none; 
    user-select: none; 
}

/* === MAIN LAYOUT === */
.app-container {
    width: 100%; 
    height: 100%;
    max-width: 600px; 
    display: flex; flex-direction: column;
    background: var(--bg-color);
    padding: 10px 15px 0 15px; 
    margin: 0 auto;
    position: relative;
    justify-content: space-between; 
}

/* === TOP SECTION === */
.top-section {
    flex: 1; 
    display: flex; flex-direction: column;
    width: 100%; 
    min-height: 0; 
}

header { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 5px 0 10px 0; flex-shrink: 0;
}

/* กลุ่มแสดงข้อมูล (คะแนน + เวลา) */
.info-group {
    display: flex; align-items: center; gap: 8px;
}

.level-badge {
    background: white; padding: 6px 12px; border-radius: 50px;
    font-weight: 900; color: var(--card-pink-shadow);
    border: 2px solid #F0F0F0; font-size: 0.9rem;
}

.timer-badge {
    background: white; padding: 6px 12px; border-radius: 50px;
    font-weight: 900; color: #29B6F6; border: 2px solid #F0F0F0; 
    font-size: 0.9rem; min-width: 80px; text-align: center;
    font-variant-numeric: tabular-nums;
}

.header-actions { display: flex; gap: 8px; }

/* Buttons */
.shadow-btn { transition: transform 0.1s, box-shadow 0.1s; cursor: pointer; }
.shadow-btn:active { transform: translateY(3px) !important; box-shadow: none !important; }

.skip-btn { 
    background: none; border: none; color: #AAA; font-weight: 800; cursor: pointer; padding: 5px; 
    transition: transform 0.2s;
}
.skip-btn:hover { color: var(--primary-btn); transform: translateX(3px); }

.hint-btn {
    background: #FFD54F; color: white; border: none; width: 32px; height: 32px; border-radius: 50%;
    font-weight: 900; box-shadow: 0 3px 0 #D4A017; display: flex; align-items: center; justify-content: center;
}
.hint-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 #D4A017; }

.custom-btn {
    background: var(--custom-btn-bg); color: white; border: none; width: 32px; height: 32px; border-radius: 50%;
    font-weight: 900; box-shadow: 0 3px 0 var(--custom-btn-shadow); display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.custom-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--custom-btn-shadow); }

/* === DISPLAY BOX === */
.display-box {
    background: var(--display-bg); border-radius: var(--radius-m);
    padding: 5px 10px; margin-bottom: 2vh; min-height: 70px; max-height: 25vh; overflow-y: auto; flex-shrink: 0; 
    display: flex; align-items: center; justify-content: center; flex-wrap: wrap; align-content: center;
    font-size: 2rem; font-weight: 800; color: var(--text-color); border: 3px solid #F2F2F2; cursor: text; 
}
.display-box::-webkit-scrollbar { width: 4px; }
.display-box::-webkit-scrollbar-thumb { background-color: #EEE; border-radius: 4px; }

.expr-item {
    padding: 0 1px; cursor: pointer; border-radius: 4px; transition: background 0.1s;
    display: inline-flex; align-items: center; height: 1.2em;
}
/* Updated Highlight Color to Pastel Yellow */
.expr-item:hover { background-color: #FFF59D; }

.cursor {
    display: inline-block; width: 2px; height: 1.2em; background-color: var(--text-color);
    margin: 0 1px; animation: blink 1s step-end infinite; vertical-align: middle;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* === CARDS AREA === */
.cards-area { 
    flex-grow: 1; position: relative; width: 100%; 
    display: flex; align-items: center; justify-content: center;
    padding-bottom: 10px; min-height: 0;
}

.cards-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
    width: 100%; max-width: 320px; aspect-ratio: 1/1; 
}

.card-btn {
    width: 100%; height: 100%; aspect-ratio: 1/1; border: none; border-radius: var(--radius-l);
    font-size: 3.5rem; font-weight: 900; color: white; cursor: pointer; padding: 0; 
    transition: transform 0.1s, box-shadow 0.1s; user-select: none; 
}
.card-btn:nth-child(1) { background: var(--card-brown); box-shadow: 0 5px 0 var(--card-brown-shadow); }
.card-btn:nth-child(2) { background: var(--card-pink); box-shadow: 0 5px 0 var(--card-pink-shadow); }
.card-btn:nth-child(3) { background: var(--card-teal); box-shadow: 0 5px 0 var(--card-teal-shadow); }
.card-btn:nth-child(4) { background: var(--card-orange); box-shadow: 0 5px 0 var(--card-orange-shadow); }

.card-btn:hover { transform: translateY(-4px); }
.card-btn:nth-child(1):hover { box-shadow: 0 9px 0 var(--card-brown-shadow); }
.card-btn:nth-child(2):hover { box-shadow: 0 9px 0 var(--card-pink-shadow); }
.card-btn:nth-child(3):hover { box-shadow: 0 9px 0 var(--card-teal-shadow); }
.card-btn:nth-child(4):hover { box-shadow: 0 9px 0 var(--card-orange-shadow); }

.card-btn:active { transform: translateY(5px) !important; box-shadow: none !important; }
.card-btn:disabled { opacity: 0.3; transform: translateY(5px); box-shadow: none !important; cursor: default; }

.card-btn.editing {
    border: 4px solid #FFF; box-shadow: 0 0 15px rgba(255, 255, 255, 0.8), 0 5px 0 rgba(0,0,0,0.1) !important;
    transform: scale(1.05); animation: pulse 1s infinite; z-index: 5;
}
.card-btn.empty {
    background: #E0E0E0 !important; box-shadow: 0 5px 0 #BDBDBD !important; color: #9E9E9E !important;
}
.card-btn.empty:hover { transform: none; box-shadow: 0 5px 0 #BDBDBD !important; }

@keyframes pulse { 0% { transform: scale(1.05); } 50% { transform: scale(1.02); } 100% { transform: scale(1.05); } }

.win-container {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    animation: bounceIn 0.5s; position: absolute; top:0; left:0; pointer-events: none; z-index: 20;
}
.win-text {
    font-size: 3rem; font-weight: 900; color: #81C784; text-align: center; text-shadow: 2px 2px 0 #FFF; line-height: 1.2;
}
@keyframes bounceIn { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); } }
.explode { animation: popOut 0.4s forwards; }
@keyframes popOut { to { transform: scale(0); opacity: 0; } }

.feedback-msg { 
    text-align: center; height: 20px; font-weight: 800; color: var(--text-color); flex-shrink: 0; margin-bottom: 5px;
}

/* === BOTTOM SECTION === */
.bottom-section {
    flex-shrink: 0; width: 100%; padding: 15px 15px 20px 15px; 
    background: white; border-top-left-radius: 25px; border-top-right-radius: 25px;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.03); z-index: 10;
}

.controls-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.op-btn {
    background: var(--op-bg); border: none; border-radius: 12px; height: 55px; 
    font-size: 2rem; color: var(--text-color); font-weight: 900;
    display: flex; align-items: center; justify-content: center; line-height: 1;
    box-shadow: 0 4px 0 var(--op-shadow);
}
.op-btn:hover { transform: translateY(-3px); box-shadow: 0 7px 0 var(--op-shadow); }

.op-btn.bracket { background: var(--bracket-bg); box-shadow: 0 4px 0 var(--bracket-shadow); color: #1565C0; }
.op-btn.bracket:hover { box-shadow: 0 7px 0 var(--bracket-shadow); }
.op-btn.warning { color: #FFB74D; font-size: 1.6rem; }
.op-btn.danger { color: #E57373; font-size: 1.6rem; }
.num-input { background: #FFFFFF; color: #5D4037; border: 2px solid #EEE; }

.submit-btn {
    grid-column: 1 / -1; width: 100%; background: var(--primary-btn); color: white; border: none;
    height: 60px; border-radius: 12px; font-size: 1.4rem; font-weight: 900;
    box-shadow: 0 5px 0 var(--primary-btn-shadow);
}
.submit-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 0 var(--primary-btn-shadow); }

.footer-link { margin-top: 10px; text-align: center; }

/* Updated Footer Link Style */
.footer-link a {
    color: #edc0c0;
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 100;
}

.hidden { display: none !important; }

/* Modal */
.modal { position: fixed; top:0; left:0; width:100%; height:100%; background: rgba(93,64,55,0.4); z-index: 999; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(2px); }
.modal-content { background: #FFFDF7; width: 85%; max-width: 400px; border-radius: 30px; padding: 25px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); max-height: 80vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; border-bottom: 2px solid #EEE; padding-bottom: 10px; margin-bottom: 10px; }
.close-modal { font-size: 2rem; color: #AAA; cursor: pointer; }


/* ========================================= */
/* === MOBILE LANDSCAPE MODE === */
/* ========================================= */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 899px) {
    .app-container {
        flex-direction: row; align-items: center; justify-content: center;
        padding: 10px 40px; gap: 30px; max-width: 100%;
    }
    .top-section { flex: 1; height: 100%; justify-content: center; margin-bottom: 0; }
    header { margin-bottom: 5px; padding: 0; }
    .display-box { min-height: 50px; max-height: 60px; font-size: 1.8rem; margin-bottom: 10px; padding: 0 10px; }
    .cards-area { padding: 0; flex-grow: 0; margin-bottom: 0; }
    .cards-grid { width: 200px; gap: 10px; grid-template-columns: 1fr 1fr; }
    .card-btn { font-size: 2.5rem; border-radius: 16px; box-shadow: 0 4px 0 rgba(0,0,0,0.15) !important; }
    .card-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,0.15) !important; }
    .bottom-section {
        flex: 1; height: 100%; width: auto; background: transparent; box-shadow: none;
        padding: 0; border-radius: 0; display: flex; align-items: center; justify-content: center;
    }
    .controls-wrapper { width: 100%; max-width: 450px; }
    .controls-grid { gap: 8px; }
    .op-btn { height: 45px; font-size: 1.4rem; border-radius: 8px; box-shadow: 0 3px 0 var(--op-shadow); }
    .submit-btn { height: 45px; font-size: 1.1rem; border-radius: 8px; box-shadow: 0 3px 0 var(--primary-btn-shadow); }
    .op-btn:hover, .submit-btn:hover { transform: translateY(-2px); }
    .footer-link { display: none; }
}

/* ========================================= */
/* === TABLET TWEAKS (600px - 900px) === */
/* ========================================= */
@media (min-width: 600px) and (max-width: 899px) and (orientation: portrait) {
    .app-container { max-width: 700px; justify-content: center; padding-top: 20px; }
    .display-box { min-height: 90px; font-size: 2.5rem; margin-bottom: 30px; }
    .cards-grid { max-width: 400px; gap: 20px; }
    .card-btn { font-size: 4rem; }
    .op-btn { height: 65px; font-size: 2.2rem; }
}

/* ========================================= */
/* === DESKTOP LAYOUT (> 900px) === */
/* ========================================= */
@media (min-width: 900px) {
    .app-container {
        max-width: 550px; height: auto; border-radius: 40px; box-shadow: none; 
        padding: 40px; justify-content: flex-start; gap: 20px; 
    }
    .top-section { flex: 0 0 auto; padding-top: 0; }
    header { margin-bottom: 20px; }
    .display-box { font-size: 2.5rem; min-height: 90px; margin-bottom: 40px; max-height: none; }
    .cards-area { margin-bottom: 10px; padding: 0; }
    .cards-grid { grid-template-columns: repeat(4, 1fr); max-width: 100%; width: auto; gap: 20px; aspect-ratio: auto; }
    .card-btn {
        height: 100px; width: 100px; font-size: 4rem; border-radius: 20px;
        box-shadow: 0 8px 0 rgba(0,0,0,0.15) !important;
    }
    .card-btn:hover { transform: translateY(-6px); box-shadow: 0 14px 0 rgba(0,0,0,0.15) !important; }
    .bottom-section { background: transparent; box-shadow: none; padding: 0; border-radius: 0; }
    .op-btn { height: 70px; font-size: 2.8rem; }
    .submit-btn { height: 70px; font-size: 1.6rem; }
    .controls-grid { gap: 15px; }
}