:root {
    /* Default Theme (Middle) */
    --bg-color: #f0f2f5;
    --sidebar-bg: #ffffff;
    --primary-color: #4a90e2;
    --success-color: #52c41a;
    --error-color: #f5222d;
    --text-color: #2c3e50;
    --btn-radius: 12px;
    --card-shadow: 0 8px 24px rgba(0,0,0,0.08);
    --transition-speed: 0.3s;
    /* Clean Green Blackboard with subtle texture */
    --blackboard-bg: #2d5a27;
    --board-border: #5d4037;
    --option-bg: rgba(255,255,255,0.95);
    --option-text: #333;
    --target-color: #ffd32a;
}

/* Young Theme */
body.theme-young {
    --bg-color: #fff9e6;
    --sidebar-bg: #fffcf2;
    --primary-color: #ff8c94;
    --success-color: #7bed9f;
    --error-color: #ff6b6b;
    --text-color: #5d5d5d;
    --btn-radius: 24px;
    /* Soft Paper/Cardboard style background */
    --blackboard-bg: #aed581;
    --board-border: #8d6e63;
    --option-bg: #fff9c4;
    --option-text: #5d4037;
    --target-color: #ff5252;
    font-family: 'Comic Sans MS', 'zcool-gdt', "Microsoft JhengHei", sans-serif;
}

/* Older Theme */
body.theme-older {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --primary-color: #38bdf8;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --text-color: #f1f5f9;
    --btn-radius: 6px;
    /* Deep Slate/Blue background */
    --blackboard-bg: #1e293b;
    --board-border: #0f172a;
    --option-bg: #334155;
    --option-text: #f1f5f9;
    --target-color: #38bdf8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; background: var(--bg-color); color: var(--text-color); transition: background var(--transition-speed); font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif; }

/* PC Layout */
.app-container { display: flex; height: 100vh; width: 100vw; }
.sidebar { width: 320px; background: var(--sidebar-bg); border-right: 1px solid rgba(0,0,0,0.05); padding: 24px; display: flex; flex-direction: column; z-index: 100; transition: transform 0.3s ease; box-shadow: 4px 0 16px rgba(0,0,0,0.02); overflow-y: auto; }
.main-content { flex: 1; position: relative; display: flex; flex-direction: column; overflow-y: auto; background: #fff; }

/* Mobile Layout Adjustments */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); width: 300px; box-shadow: 8px 0 24px rgba(0,0,0,0.15); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90; backdrop-filter: blur(2px); }
    .sidebar-overlay.active { display: block; }
    .hamburger { display: block !important; }
}

.hamburger { display: none; position: absolute; left: 20px; top: 20px; font-size: 28px; cursor: pointer; z-index: 110; background: #fff; border: none; color: var(--text-color); width: 44px; height: 44px; border-radius: 50%; box-shadow: 0 4px 12px rgba(0,0,0,0.1); line-height: 44px; text-align: center; }

/* Sections */
.section { margin-bottom: 28px; }
.section-title { font-weight: 600; margin-bottom: 12px; font-size: 1.15em; color: #444; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
.choice-btn { border: 2px solid var(--primary-color); background: transparent; color: var(--primary-color); padding: 8px 12px; border-radius: var(--btn-radius); cursor: pointer; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); font-size: 0.9em; font-weight: 600; white-space: nowrap; flex: 1 0 auto; text-align: center; }
.choice-btn:hover { background: rgba(74, 144, 226, 0.08); }
.choice-btn.active { background: var(--primary-color); color: white; box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3); }

.start-btn { 
    background: var(--success-color); 
    color: white; 
    border: none; 
    padding: 16px; 
    border-radius: var(--btn-radius); 
    font-size: 1.25em; 
    font-weight: 700; 
    cursor: pointer; 
    transition: all 0.2s;
    box-shadow: 0 6px 0 #389e0d;
    margin-bottom: 30px;
}
.start-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #389e0d; }
.start-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #389e0d; }

/* Auth & User Buttons */
.auth-btn { background: #f8f9fa; border: 1px solid #ddd; padding: 10px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 0.95em; transition: all 0.2s; }
.auth-btn:hover { background: #e9ecef; }
.user-info { font-size: 0.9em; color: #666; word-break: break-all; margin-bottom: 5px; }

/* Modal Styles */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000; backdrop-filter: blur(5px); align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.active { display: flex; }
.modal-content { background: #fff; width: 100%; max-width: 450px; border-radius: 20px; position: relative; padding: 40px; box-shadow: 0 24px 64px rgba(0,0,0,0.4); animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes modalIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-close { position: absolute; right: 20px; top: 20px; border: none; background: none; font-size: 24px; cursor: pointer; color: #999; }
.modal-title { font-size: 1.8em; font-weight: 800; margin-bottom: 25px; text-align: center; color: var(--primary-color); }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 0.95em; }
.form-group input { width: 100%; padding: 12px 16px; border: 2px solid #eee; border-radius: 10px; font-size: 1em; transition: all 0.2s; }
.form-group input:focus { border-color: var(--primary-color); outline: none; }
.modal-btn { width: 100%; padding: 14px; background: var(--primary-color); color: white; border: none; border-radius: 12px; font-size: 1.1em; font-weight: 700; cursor: pointer; margin-top: 10px; transition: all 0.2s; }
.modal-btn:hover { background: #357abd; }
.modal-link { text-align: center; margin-top: 20px; font-size: 0.9em; }
.modal-link a { color: var(--primary-color); text-decoration: none; font-weight: 600; cursor: pointer; }

/* Game Area - Blackboard Optimization */
.game-area { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    padding: 40px; 
    opacity: 0; 
    transition: opacity 0.5s; 
    pointer-events: none;
    background-color: var(--blackboard-bg);
    border: 15px solid var(--board-border);
    border-radius: 8px;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.2), 0 20px 40px rgba(0,0,0,0.15);
    margin: 20px;
    color: white;
    position: relative;
    overflow: hidden;
}
.game-area::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('https://www.transparenttextures.com/patterns/chalkboard.png');
    opacity: 0.3;
    pointer-events: none;
}
.game-area.active { opacity: 1; pointer-events: all; }

.progress-bar { position: absolute; top: -15px; left: -15px; right: -15px; height: 8px; background: #eee; transition: width 0.3s; width: 100%; z-index: 10; border-radius: 4px 4px 0 0; overflow: hidden; }
.progress-inner { height: 100%; background: var(--primary-color); width: 0%; transition: width 0.3s; }

.stats-top { position: absolute; top: 25px; right: 30px; display: flex; gap: 24px; font-weight: 600; font-size: 1.1em; text-shadow: 1px 1px 2px rgba(0,0,0,0.5); letter-spacing: 1px; }

/* Gameplay Styles */
.question-box { text-align: center; margin-bottom: 50px; position: relative; z-index: 1; }
.target-relation { font-size: 1.6em; margin-bottom: 15px; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); color: var(--target-color); font-weight: 700; }
.target-word { font-size: 5.5em; font-weight: 800; color: #fff; text-shadow: 2px 2px 4px rgba(0,0,0,0.2); }

/* Puzzle Slots */
.puzzle-slots { display: flex; gap: 12px; margin-bottom: 40px; min-height: 70px; flex-wrap: wrap; justify-content: center; position: relative; z-index: 1; }
.slot { width: 70px; height: 70px; border: 3px dashed rgba(255,255,255,0.4); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 2em; font-weight: bold; cursor: pointer; background: rgba(0,0,0,0.1); transition: all 0.2s; }
.puzzle-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; max-width: 600px; position: relative; z-index: 1; }
.char-tile { width: 64px; height: 64px; background: var(--option-bg); border: none; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.8em; font-weight: 700; cursor: pointer; transition: all 0.2s; box-shadow: 0 6px 0 rgba(0,0,0,0.1), 0 8px 16px rgba(0,0,0,0.1); color: var(--option-text); }
.word-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; width: 100%; max-width: 550px; position: relative; z-index: 1; }
.word-option { background: var(--option-bg); border: none; padding: 24px; border-radius: 16px; text-align: center; font-size: 1.4em; font-weight: 700; cursor: pointer; transition: all 0.2s; box-shadow: 0 8px 0 rgba(0,0,0,0.1), 0 12px 24px rgba(0,0,0,0.05); color: var(--option-text); }
.word-option:hover { transform: translateY(-2px); }
.word-option.selected { background: var(--primary-color); color: white; transform: translateY(4px); box-shadow: none; }

.relation-pair { display: flex; align-items: center; gap: 40px; font-size: 3.5em; font-weight: 800; margin-bottom: 50px; text-shadow: 2px 2px 4px rgba(0,0,0,0.2); position: relative; z-index: 1; }
.judgment-btns { display: flex; gap: 25px; width: 100%; max-width: 550px; position: relative; z-index: 1; }
.judge-btn { flex: 1; padding: 30px; font-size: 1.8em; font-weight: 800; border-radius: 20px; border: none; color: white; cursor: pointer; transition: all 0.2s; }
.judge-synonym { background: #00d2d3; box-shadow: 0 10px 0 #01a3a4; }
.judge-antonym { background: #ff9f43; box-shadow: 0 10px 0 #ee5253; }

/* Feedback & Stats Overlay */
.feedback-overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 2000; pointer-events: none; opacity: 0; transition: opacity 0.2s; }
.feedback-content { transform: scale(0.5); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); background: rgba(255,255,255,0.95); padding: 40px; border-radius: 30px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); backdrop-filter: blur(10px); }
.feedback-overlay.show { opacity: 1; }
.feedback-overlay.show .feedback-content { transform: scale(1); }
.feedback-icon { font-size: 10em; line-height: 1; text-align: center; margin-bottom: 10px; }

/* Action Buttons */
.action-btns { margin-top: 60px; display: flex; gap: 24px; position: relative; z-index: 1; }
.submit-btn { background: var(--success-color); color: white; border: none; padding: 14px 44px; border-radius: 14px; font-size: 1.25em; font-weight: 700; cursor: pointer; box-shadow: 0 6px 0 #389e0d; }
.reset-btn { background: #f1f2f6; color: #2f3542; border: none; padding: 14px 44px; border-radius: 14px; font-size: 1.25em; font-weight: 700; cursor: pointer; box-shadow: 0 6px 0 #ced6e0; }

/* 2-Player Split Screen */
.dual-container { display: none; flex-direction: column; width: 100vw; height: 100vh; position: fixed; inset: 0; background: #2f3542; z-index: 500; }
.player-zone { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; background-color: var(--blackboard-bg); border: 8px solid var(--board-border); overflow: hidden; }
.player-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('https://www.transparenttextures.com/patterns/chalkboard.png');
    opacity: 0.3;
}
.player-zone.p1 { transform: rotate(180deg); }
.divider { height: 14px; background: var(--board-border); width: 100%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 2px; }
.ready-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; color: white; z-index: 10; transition: opacity 0.3s; }
.ready-btn { padding: 20px 40px; font-size: 2em; background: var(--primary-color); border: none; color: white; border-radius: 10px; cursor: pointer; }

/* History Table Styles */
.stats-container { background: #fff; color: #333; padding: 40px; border-radius: 24px; max-width: 900px; width: 95%; margin: 20px auto; box-shadow: 0 24px 64px rgba(0,0,0,0.4); overflow-y: auto; max-height: 85vh; position: relative; z-index: 1000; }
.stats-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 30px; border-radius: 12px; overflow: hidden; border: 1px solid #eee; }
.stats-table th, .stats-table td { padding: 16px; text-align: left; border-bottom: 1px solid #eee; }
.stat-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 20px; margin-bottom: 35px; }
.stat-item { background: #f8fafc; padding: 20px; border-radius: 16px; text-align: center; border: 1px solid #f1f5f9; }
.stat-value { font-size: 1.8em; font-weight: 800; color: var(--primary-color); margin-bottom: 4px; }
.history-item { border-bottom: 1px solid #eee; padding: 15px 0; }
.history-header { display: flex; justify-content: space-between; font-weight: bold; margin-bottom: 5px; }

/* Animations */
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-15px); } 75% { transform: translateX(15px); } }
.shake { animation: shake 0.15s 3; }

/* Scrollbar Style */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
