/* ⭕ 圈出分組遊戲 - 畫圈版 */

:root {
    --primary: #4caf50;
    --primary-dark: #388e3c;
    --accent: #ff6b9d;
    --accent-dark: #e91e63;
    --bg-gradient: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 50%, #a5d6a7 100%);
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-dark: #2e7d32;
    --text-light: #66bb6a;
    --success: #4caf50;
    --error: #f44336;
}

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

body {
    font-family: 'Nunito', 'Microsoft JhengHei', sans-serif;
    min-height: 100vh;
    background: var(--bg-gradient);
    overflow-x: hidden;
    touch-action: manipulation;
}

.bg-pattern {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.circle-deco {
    position: absolute;
    border-radius: 50%;
    opacity: 0.15;
    animation: float 10s ease-in-out infinite;
}

.c1 { width: 200px; height: 200px; background: #81c784; top: 5%; left: -50px; }
.c2 { width: 150px; height: 150px; background: #f48fb1; top: 50%; right: -30px; animation-delay: 3s; }
.c3 { width: 100px; height: 100px; background: #4fc3f7; bottom: 10%; left: 30%; animation-delay: 5s; }

@keyframes float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.05); }
}

.game-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.screen {
    display: none;
    width: 100%;
    max-width: 800px;
    animation: fadeIn 0.4s ease-out;
}

.screen.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== 登入畫面 ==================== */

.login-card {
    background: var(--card-bg);
    border-radius: 25px;
    padding: 30px;
    box-shadow: 0 15px 50px rgba(76, 175, 80, 0.25);
}

.login-header { text-align: center; margin-bottom: 20px; }

.title-icon {
    font-size: 55px;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.game-title {
    font-size: 32px;
    font-weight: 800;
    color: var(--text-dark);
    margin: 10px 0 5px;
}

.game-subtitle {
    color: var(--text-light);
    font-size: 15px;
}

.mascot-section { text-align: center; margin-bottom: 18px; }

.mascot-preview { font-size: 55px; }

.section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    margin: 8px 0;
}

.mascot-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding: 10px;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-radius: 15px;
}

.mascot-btn {
    font-size: 24px;
    padding: 8px;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    text-align: center;
}

.mascot-btn:hover { transform: scale(1.1); border-color: var(--primary); }
.mascot-btn.selected { background: var(--primary); border-color: var(--primary-dark); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 18px;
}

.form-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 5px;
}

.form-field select {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 2px solid #c8e6c9;
    border-radius: 10px;
    background: white;
    cursor: pointer;
}

.form-field select:focus {
    outline: none;
    border-color: var(--primary);
}

.start-btn {
    width: 100%;
    padding: 15px;
    font-size: 18px;
    font-weight: 700;
    font-family: inherit;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.35);
}

.start-btn:hover { transform: translateY(-3px); }
.btn-icon { font-size: 22px; }

.login-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 18px;
}

.link-item {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    padding: 8px 15px;
    border-radius: 8px;
    transition: all 0.2s;
}

.link-item:hover { background: rgba(76, 175, 80, 0.1); }

/* ==================== 遊戲畫面 ==================== */

.game-panel {
    background: var(--card-bg);
    border-radius: 25px;
    padding: 20px;
    box-shadow: 0 15px 50px rgba(76, 175, 80, 0.25);
}

.game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 2px dashed #c8e6c9;
}

.player-badge { display: flex; align-items: center; gap: 8px; }
.player-mascot { font-size: 28px; }
.player-info { font-size: 13px; font-weight: 600; color: var(--text-light); }

.progress-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    padding: 6px 18px;
    border-radius: 10px;
}

.progress-label { font-size: 10px; color: var(--text-light); font-weight: 600; }
.progress-num { font-size: 16px; font-weight: 700; color: var(--text-dark); }

.score-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #fff9c4 0%, #ffee58 100%);
    padding: 8px 18px;
    border-radius: 25px;
}

.score-star { font-size: 20px; }
.score-num { font-size: 22px; font-weight: 700; color: #f57f17; }

.question-box {
    background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
    text-align: center;
    border: 2px solid #ffe082;
}

.question-icon { font-size: 35px; margin-bottom: 5px; }

.question-text {
    font-size: 18px;
    font-weight: 700;
    color: #5d4037;
    margin-bottom: 5px;
}

.question-text .highlight {
    display: inline-block;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 20px;
}

.question-hint {
    font-size: 14px;
    color: #8d6e63;
}

/* 畫圈區域 */
.drawing-area {
    position: relative;
    width: 100%;
    aspect-ratio: 5/3;
    background: linear-gradient(180deg, #e8f5e9 0%, #c8e6c9 60%, #a5d6a7 100%);
    border-radius: 18px;
    margin-bottom: 15px;
    overflow: hidden;
    border: 3px solid #81c784;
    touch-action: none;
    cursor: crosshair;
}

#drawingCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

.foods-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.food-item {
    position: absolute;
    font-size: 32px;
    transform: translate(-50%, -50%);
    transition: all 0.3s;
    filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.15));
}

.food-item.hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0);
}

/* 已分組顯示 */
.groups-display {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
    padding: 12px 15px;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-radius: 12px;
    flex-wrap: wrap;
}

.groups-label {
    font-size: 14px;
    font-weight: 700;
    color: #1565c0;
}

.groups-boxes {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.group-box {
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    padding: 6px 12px;
    border-radius: 20px;
    border: 2px solid var(--accent);
    animation: groupPop 0.3s ease-out;
}

@keyframes groupPop {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.group-box .food-icon { font-size: 18px; }
.group-box .count { font-size: 16px; font-weight: 700; color: var(--accent-dark); }

.groups-summary {
    font-size: 18px;
    font-weight: 700;
    color: #0d47a1;
    white-space: nowrap;
}

/* 遊戲按鈕 */
.game-buttons {
    display: flex;
    gap: 12px;
}

.game-btn {
    flex: 1;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.undo-btn {
    background: linear-gradient(135deg, #ffb74d 0%, #ffa726 100%);
    color: white;
}

.check-btn {
    background: linear-gradient(135deg, var(--success) 0%, var(--primary-dark) 100%);
    color: white;
    flex: 2;
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.35);
}

.game-btn:hover { transform: translateY(-2px); }
.game-btn:active { transform: scale(0.98); }

/* ==================== 結果畫面 ==================== */

.result-card {
    background: var(--card-bg);
    border-radius: 25px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 15px 50px rgba(76, 175, 80, 0.25);
}

.result-header { margin-bottom: 18px; }
.trophy-icon { font-size: 65px; }
.result-header h2 { font-size: 28px; color: var(--text-dark); margin-top: 10px; }

.result-player {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 18px;
}

.result-mascot { font-size: 40px; }
.result-name { font-size: 18px; font-weight: 600; color: var(--text-light); }

.stats-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 18px;
}

.stat-box {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    border-radius: 15px;
    padding: 18px 30px;
}

.stat-icon { font-size: 28px; margin-bottom: 6px; }
.stat-val { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: #999; font-weight: 600; }

.result-msg {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 15px;
    color: var(--text-dark);
    margin-bottom: 18px;
    font-weight: 600;
}

.ranking-box {
    background: linear-gradient(135deg, #fff9c4 0%, #ffee58 100%);
    border: 2px solid #ffc107;
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 18px;
    text-align: left;
}

.ranking-box h3 { text-align: center; font-size: 16px; color: #f57f17; margin-bottom: 10px; }

.ranking-list { max-height: 160px; overflow-y: auto; }

.ranking-loading { text-align: center; color: #f57f17; padding: 15px; }

.ranking-item {
    display: flex;
    align-items: center;
    background: white;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 5px;
}

.ranking-item.current-user {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    border: 2px solid #ffc107;
}

.ranking-rank { font-size: 13px; font-weight: 700; min-width: 30px; color: #999; }
.ranking-rank.rank-1::before { content: '🥇 '; }
.ranking-rank.rank-2::before { content: '🥈 '; }
.ranking-rank.rank-3::before { content: '🥉 '; }

.ranking-mascot { font-size: 22px; margin: 0 8px; }
.ranking-info { flex: 1; }
.ranking-student { font-size: 12px; font-weight: 600; color: #333; }
.ranking-details { font-size: 10px; color: #999; }
.ranking-score { font-size: 18px; font-weight: 700; color: var(--primary); }

.result-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.result-btn {
    flex: 1;
    min-width: 90px;
    padding: 12px 15px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.result-btn.primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); color: white; }
.result-btn.secondary { background: linear-gradient(135deg, #4fc3f7 0%, #03a9f4 100%); color: white; }
.result-btn.tertiary { background: linear-gradient(135deg, #bdbdbd 0%, #9e9e9e 100%); color: white; }
.result-btn:hover { transform: translateY(-2px); }

/* ==================== 反饋彈窗 ==================== */

.feedback-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.feedback-overlay.show { display: flex; }

.feedback-modal {
    background: white;
    border-radius: 20px;
    padding: 30px 45px;
    text-align: center;
    animation: popIn 0.3s ease-out;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.feedback-icon { font-size: 55px; margin-bottom: 10px; }
.feedback-text { font-size: 18px; font-weight: 700; color: #333; }

.feedback-modal.correct { border: 4px solid var(--success); }
.feedback-modal.correct .feedback-text { color: var(--success); }
.feedback-modal.incorrect { border: 4px solid var(--error); }
.feedback-modal.incorrect .feedback-text { color: var(--error); }

/* ==================== 響應式 ==================== */

@media (max-width: 768px) {
    .game-container { padding: 10px; align-items: flex-start; padding-top: 15px; }
    .login-card, .game-panel, .result-card { padding: 18px 15px; border-radius: 20px; }
    .title-icon { font-size: 45px; }
    .game-title { font-size: 26px; }
    .mascot-preview { font-size: 45px; }
    .mascot-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .mascot-btn { font-size: 22px; padding: 7px; }
    .form-row { grid-template-columns: 1fr; gap: 10px; }
    .game-topbar { flex-wrap: wrap; gap: 8px; justify-content: center; }
    .question-text { font-size: 16px; }
    .question-text .highlight { font-size: 18px; }
    .drawing-area { aspect-ratio: 4/3; }
    .flower { font-size: 26px; }
    .groups-display { padding: 10px 12px; gap: 8px; }
    .group-box { padding: 5px 10px; }
    .group-box .food-icon { font-size: 16px; }
    .group-box .count { font-size: 14px; }
    .game-btn { padding: 12px; font-size: 15px; }
    .stats-row { gap: 12px; }
    .stat-box { padding: 15px 22px; }
    .stat-val { font-size: 28px; }
    .result-buttons { flex-direction: column; }
}

@media (max-width: 400px) {
    .mascot-grid { grid-template-columns: repeat(3, 1fr); }
    .flower { font-size: 22px; }
    .game-buttons { flex-direction: column; }
}
