/* ============================================================
   CSS Custom Properties — 調整主色系只需改這裡
   ============================================================ */
:root {
    --color-primary: #5bb8e8;
    --color-text: #1a5f7a;
    --color-text-muted: #4a8fa8;
    --color-bg: #d4edf7;
    --color-modal: rgba(255, 255, 255, 0.95);
    --color-modal-border: rgba(91, 184, 232, 0.3);
    --color-divider: rgba(91, 184, 232, 0.2);
    --game-w: 380px;
    --game-h: 680px;
}

/* ============================================================
   Reset & Base
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--color-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100svh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ============================================================
   Responsive Container
   ============================================================ */
#main-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100svh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container {
    position: relative;
    width: var(--game-w);
    height: var(--game-h);
    transform-origin: top center;
    overflow: hidden;
}

/* ============================================================
   Loading Screen
   ============================================================ */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 999;
    gap: 12px;
    color: var(--color-text);
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(91, 184, 232, 0.3);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   In-Game UI Layer
   ============================================================ */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    z-index: 10;
    pointer-events: none;
}

#score-board {
    font-size: 16px;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
    pointer-events: none;
    background: rgba(0,0,0,0.15);
    padding: 4px 10px;
    border-radius: 14px;
}

.top-controls {
    display: flex;
    gap: 6px;
    pointer-events: all;
    margin-left: auto;
}

.top-controls button {
    background: rgba(255,255,255,0.25);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    backdrop-filter: blur(4px);
}

.top-controls button:hover { background: rgba(255,255,255,0.4); }

/* ============================================================
   Game Header / Footer
   ============================================================ */
#game-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    text-align: center;
    padding: 12px;
    color: white;
    z-index: 10;
}

#game-header h1 {
    font-size: 28px;
    color: #ff6b6b;
    text-shadow: 0 0 12px rgba(255,107,107,0.6);
}

#game-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    z-index: 10;
}

#game-footer button {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    background: rgba(255,255,255,0.25);
    color: white;
    font-size: 14px;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background 0.2s;
}

#game-footer button:hover { background: rgba(255,255,255,0.4); }

.support-links-mini {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 12px;
}

.support-links-mini a {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    text-decoration: none;
}

.support-links-mini a:hover { color: white; }

.hidden { display: none !important; }

/* ============================================================
   Settings Modal
   ============================================================ */
#settings-modal {
    position: absolute;
    inset: 0;
    background: rgba(91, 184, 232, 0.4);
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: var(--color-modal);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid var(--color-modal-border);
    text-align: center;
    color: var(--color-text);
    width: 80%;
    max-width: 280px;
    max-height: 82svh;
    overflow-y: auto;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
}

.modal-content h2 {
    margin: 0 0 15px;
    font-size: 20px;
    color: var(--color-text);
}

.setting-item { margin: 12px 0; }

.setting-item label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: bold;
    color: var(--color-text);
}

/* Toggle Switch */
.toggle-setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

.toggle-setting label { margin-bottom: 0; }

.toggle-setting input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 20px;
    background: var(--color-divider);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    outline: none;
    flex-shrink: 0;
}

.toggle-setting input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.toggle-setting input[type="checkbox"]:checked { background: var(--color-primary); }
.toggle-setting input[type="checkbox"]:checked::before { transform: translateX(20px); }

/* Range Slider */
.setting-item input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--color-divider);
    border-radius: 10px;
    outline: none;
    cursor: pointer;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.setting-item input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
}

/* Language Select */
.lang-select-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    margin-bottom: 4px;
}

.lang-select-row label { margin-bottom: 0; }

#lang-select {
    -webkit-appearance: none;
    appearance: none;
    background: rgba(91,184,232,0.1)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235bb8e8'/%3E%3C/svg%3E")
        no-repeat right 10px center;
    border: 1px solid rgba(91,184,232,0.4);
    border-radius: 8px;
    color: var(--color-text);
    font-size: 13px;
    padding: 6px 28px 6px 10px;
    cursor: pointer;
    outline: none;
}

/* Settings Sections */
.settings-section {
    margin: 10px 0 0;
    padding: 10px 0 0;
    border-top: 1px solid var(--color-divider);
    text-align: left;
}

.settings-section-title {
    font-size: 10px;
    font-weight: bold;
    color: var(--color-primary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

/* Save Buttons */
.save-btns { display: flex; gap: 8px; }

.settings-action-btn {
    flex: 1;
    padding: 8px 4px;
    background: rgba(91,184,232,0.1);
    border: 1px solid rgba(91,184,232,0.3);
    border-radius: 10px;
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-action-btn:hover {
    background: rgba(91,184,232,0.25);
    transform: translateY(-1px);
}

/* Close Button */
#close-settings {
    margin-top: 15px;
    padding: 8px 25px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

#close-settings:hover { background: #3da0d0; }

/* Credits */
.support-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--color-divider);
}

.support-section p {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.support-btns { display: flex; gap: 8px; }

.support-btn {
    flex: 1;
    background: rgba(91,184,232,0.1);
    color: var(--color-text);
    padding: 8px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 13px;
    border: 1px solid rgba(91,184,232,0.2);
    transition: all 0.2s;
}

.support-btn:hover {
    background: rgba(91,184,232,0.2);
    transform: translateY(-2px);
}

/* ============================================================
   Sound Permission Prompt
   ============================================================ */
#sound-prompt {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 60;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(6px);
    animation: fadeIn 0.25s ease-out;
}

.sound-prompt-box {
    background: rgba(255,255,255,0.97);
    border-radius: 20px;
    padding: 28px 24px 22px;
    width: 72%;
    max-width: 240px;
    text-align: center;
    box-shadow: 0 14px 40px rgba(0,0,0,0.25);
}

.sound-prompt-icon {
    font-size: 36px;
    margin-bottom: 10px;
}

.sound-prompt-box p {
    color: var(--color-text);
    font-size: 16px;
    font-weight: bold;
    margin: 0 0 18px;
}

.sound-prompt-btns {
    display: flex;
    gap: 10px;
}

.sound-prompt-btns button {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.15s;
}

#sound-no-btn  { background: #e0e0e0; color: #666; }
#sound-yes-btn { background: var(--color-primary); color: white; }
.sound-prompt-btns button:hover { opacity: 0.85; }

/* ============================================================
   Confirm Reset Modal
   ============================================================ */
#confirm-reset-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.confirm-box {
    background: rgba(255,255,255,0.97);
    border-radius: 16px;
    padding: 24px 20px 18px;
    width: 72%;
    max-width: 240px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.confirm-box p {
    color: var(--color-text);
    font-size: 15px;
    font-weight: bold;
    margin: 0 0 16px;
}

.confirm-btns { display: flex; gap: 10px; }

.confirm-btns button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

#confirm-cancel-btn {
    background: rgba(91,184,232,0.15);
    color: var(--color-text);
}

#confirm-ok-btn { background: var(--color-primary); color: white; }
#confirm-cancel-btn:hover { background: rgba(91,184,232,0.3); }
#confirm-ok-btn:hover { background: #3da0d0; }

/* ============================================================
   Game End Modal
   ============================================================ */
.game-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    aspect-ratio: 30 / 36;
    width: 90%;
    max-width: 300px;
    max-height: 80svh;
    background-size: cover;
    background-position: center;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 3px solid white;
    overflow: hidden;
}

.close-modal-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.4);
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-modal-btn:hover { background: rgba(0,0,0,0.6); }

/* 新動物解鎖通知（沿用 Game End Modal 的 #end-modal / #end-box） */
#end-box {
    background: linear-gradient(180deg, var(--color-bg), #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
}
#end-box-content:empty { display: none; }
.unlock-popup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 32px 20px 24px;
    text-align: center;
}
.unlock-popup-title {
    font-size: 20px;
    font-weight: bold;
    color: var(--color-text);
}
.unlock-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
}
.unlock-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(91,184,232,0.12);
    border: 2px solid var(--color-primary);
    border-radius: 12px;
    padding: 12px 16px;
}
.unlock-card img { width: 56px; height: 56px; image-rendering: pixelated; }
.unlock-card-name { font-size: 14px; font-weight: bold; color: var(--color-text); }
.unlock-card-no { font-size: 11px; color: var(--color-text-muted); }
.unlock-popup-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

/* ============================================================
   Challenge (Health Quiz) Modal
   ============================================================ */
#challenge-modal {
    position: absolute;
    inset: 0;
    background: rgba(15, 40, 70, 0.88);
    z-index: 30;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease-out;
}

.challenge-box {
    background: white;
    border-radius: 20px;
    padding: 18px 16px 20px;
    width: 88%;
    max-width: 310px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
    border: 2px solid rgba(91,184,232,0.3);
    position: relative;
}

.ch-header {
    margin-bottom: 10px;
}

.ch-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--color-text);
    margin-bottom: 8px;
}

#ch-timer-wrap {
    position: relative;
    height: 20px;
    background: #e8f4fc;
    border-radius: 10px;
    overflow: hidden;
    margin: 0 4px;
}

#ch-timer-fill {
    height: 100%;
    background: linear-gradient(90deg, #5bb8e8, #3da0d0);
    border-radius: 10px;
    transition: width 0.2s linear;
    width: 100%;
}

#ch-timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: bold;
    color: white;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

#ch-progress {
    font-size: 13px;
    color: var(--color-text-muted);
    margin: 6px 0 8px;
    font-weight: bold;
}

#ch-question {
    font-size: 14px;
    color: var(--color-text);
    line-height: 1.5;
    margin-bottom: 14px;
    font-weight: bold;
    min-height: 42px;
    text-align: left;
}

#ch-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.ch-opt {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid rgba(91,184,232,0.35);
    border-radius: 12px;
    background: rgba(91,184,232,0.06);
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    line-height: 1.4;
}

.ch-opt:hover:not(:disabled) {
    background: rgba(91,184,232,0.18);
    border-color: var(--color-primary);
}

.ch-opt.correct {
    background: rgba(76,175,80,0.15);
    border-color: #4caf50;
    color: #2e7d32;
}

.ch-opt.wrong {
    background: rgba(244,67,54,0.1);
    border-color: #f44336;
    color: #c62828;
}

.ch-opt:disabled { cursor: default; }

#ch-result {
    font-size: 20px;
    font-weight: bold;
    color: #1a3a6b;
    margin-top: 4px;
    min-height: 28px;
}

#ch-result.failed {
    color: #1a3a6b;
    animation: chShake 0.4s ease-out, chDrop 0.5s ease-in 0.35s forwards;
}

@keyframes chShake {
    0%,100% { transform: translateX(0); }
    20%      { transform: translateX(-8px); }
    40%      { transform: translateX(8px); }
    60%      { transform: translateX(-5px); }
    80%      { transform: translateX(5px); }
}

@keyframes chDrop {
    to { transform: translateY(30px); opacity: 0; }
}

/* ============================================================
   Canvas-layer overlay for challenge "failed" text
   ============================================================ */
#canvas-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}
