* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #ffffff;
    --panel: #f8f9fa;
    --border: #dee2e6;
    --green: #28a745;
    --blue: #007bff;
    --red: #dc3545;
    --orange: #fd7e14;
    --purple: #6f42c1;
    --yellow: #ffc107;
    --pink: #e83e8c;
    --cyan: #17a2b8;
    --text: #212529;
    --dim: #6c757d;
    --light: #f1f3f4;
    --px: 'Press Start 2P', monospace;
    --cn: 'Noto Sans TC', sans-serif;
}

html, body {
    min-height: 100%;
    min-height: 100dvh;
    font-family: var(--cn);
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    padding: 2rem;
    padding: calc(2rem + env(safe-area-inset-top, 0px)) calc(2rem + env(safe-area-inset-right, 0px)) calc(2rem + env(safe-area-inset-bottom, 0px)) calc(2rem + env(safe-area-inset-left, 0px));
    z-index: 1;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.screen.active {
    display: flex;
}

/* 彩虹效果 */
.rainbow-text {
    background: linear-gradient(45deg, var(--red), var(--orange), var(--yellow), var(--green), var(--blue), var(--purple), var(--pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: rainbow-move 3s linear infinite;
}

@keyframes rainbow-move {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.arcade {
    font-family: var(--px);
    letter-spacing: .05em;
}

.title-big { font-size: clamp(1.5rem, 5vw, 3rem); }
.title-md { font-size: clamp(1.2rem, 4vw, 2.2rem); }
.title-sm { font-size: clamp(.8rem, 3vw, 1.5rem); }
.title-xs { font-size: clamp(.6rem, 2vw, 1rem); }

/* 動畫效果 */
@keyframes bounce {
    0%, 20%, 60%, 100% { transform: translateY(0); }
    40% { transform: translateY(-20px); }
    80% { transform: translateY(-10px); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

@keyframes fly-in {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.bounce { animation: bounce 2s infinite; }
.pulse { animation: pulse 2s infinite; }
.shake { animation: shake .5s ease-in-out; }
.fly-in { animation: fly-in .6s ease-out; }

/* ========== 主選單 ========== */
.title-logo {
    margin-bottom: 3rem;
    text-align: center;
}

.logo-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.title-main {
    margin-bottom: 1rem;
}

.title-sub {
    color: var(--dim);
    margin-bottom: 2rem;
    font-size: clamp(1rem, 3.2vw, 1.2rem);
    line-height: 1.6;
    max-width: 36rem;
    margin-left: auto;
    margin-right: auto;
}

.start-btn {
    font-size: clamp(0.92rem, 2.8vw, 1.2rem);
    color: white;
    cursor: pointer;
    padding: clamp(1rem, 3vw, 1.5rem) clamp(1.25rem, 6vw, 3rem);
    border: none;
    background: linear-gradient(45deg, var(--blue), var(--purple));
    font-family: var(--px);
    letter-spacing: .1em;
    border-radius: 15px;
    transition: all .3s ease;
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.3);
    text-transform: uppercase;
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(0, 123, 255, 0.4);
}


/* ========== 名稱輸入 ========== */
.name-entry {
    text-align: center;
    background: white;
    padding: clamp(1.5rem, 5vw, 3rem);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    border: 3px solid var(--blue);
    width: min(520px, 100%);
}

.name-title {
    font-family: var(--px);
    font-size: clamp(1rem, 3.8vw, 1.5rem);
    color: var(--blue);
    margin-bottom: 2rem;
}

.name-input {
    font-size: clamp(1.15rem, 4vw, 1.5rem);
    padding: 1rem;
    border: 3px solid var(--border);
    border-radius: 10px;
    text-align: center;
    font-family: var(--cn);
    font-weight: bold;
    width: min(300px, 100%);
    max-width: 100%;
    margin-bottom: 2rem;
    background: var(--light);
}

.name-input:focus {
    outline: none;
    border-color: var(--blue);
    background: white;
}

.name-note {
    font-size: 1rem;
    color: var(--dim);
    margin-bottom: 2rem;
}

/* ========== 難度選擇 ========== */
.mode-selection {
    text-align: center;
    max-width: 1000px;
    width: 100%;
}

.mode-title {
    font-family: var(--px);
    font-size: clamp(1.1rem, 4.5vw, 2rem);
    color: var(--blue);
    margin-bottom: 3rem;
}

.mode-btns {
    display: flex;
    gap: 2rem;
    margin-top: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.mode-btn {
    padding: clamp(1.25rem, 4vw, 2rem);
    border: 4px solid;
    background: white;
    cursor: pointer;
    text-align: center;
    flex: 1 1 240px;
    max-width: 320px;
    transition: all .3s ease;
    border-radius: 20px;
    position: relative;
    overflow: hidden;
}

.mode-btn.easy {
    border-color: var(--green);
    box-shadow: 0 8px 25px rgba(40, 167, 69, 0.2);
}

.mode-btn.normal {
    border-color: var(--orange);
    box-shadow: 0 8px 25px rgba(253, 126, 20, 0.2);
}

.mode-btn.hard {
    border-color: var(--red);
    box-shadow: 0 8px 25px rgba(220, 53, 69, 0.2);
}

.mode-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.mode-btn .icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.mode-btn .label {
    font-family: var(--px);
    font-size: 1.2rem;
    margin-bottom: 1rem;
    font-weight: bold;
}

.mode-btn .time {
    font-family: var(--px);
    font-size: 1rem;
    margin-bottom: 1rem;
    opacity: .8;
}

.mode-btn .desc {
    font-size: 1.1rem;
    color: var(--dim);
    line-height: 1.4;
}

/* ========== 課本範圍選擇 ========== */
.curriculum-box {
    max-width: 920px;
}

.curriculum-hint {
    color: var(--dim);
    font-size: clamp(0.85rem, 2.6vw, 1.05rem);
    line-height: 1.6;
    margin-bottom: 1.5rem;
    text-align: center;
}

.curriculum-loading {
    text-align: center;
    color: var(--dim);
    padding: 2rem;
    font-size: 1rem;
}

.curriculum-form {
    background: white;
    border: 3px solid var(--blue);
    border-radius: 18px;
    padding: clamp(1rem, 3vw, 1.6rem);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.12);
    text-align: left;
}

.cur-label-lesson {
    align-items: flex-start;
}

.cur-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: start;
    gap: 0.75rem 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px dashed var(--border);
}

.cur-row:last-of-type {
    border-bottom: none;
}

.cur-label {
    font-family: var(--px);
    font-size: 0.85rem;
    color: var(--purple);
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.cur-mini {
    border: 2px solid var(--dim);
    background: white;
    color: var(--dim);
    font-family: var(--cn);
    font-size: 0.85rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cur-mini:hover:not(:disabled) {
    background: var(--dim);
    color: white;
}

.cur-mini:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.cur-mini.active {
    background: var(--purple);
    border-color: var(--purple);
    color: white;
}

.cur-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cur-lessons {
    gap: 0.45rem;
}

.cur-chip {
    background: white;
    border: 2px solid var(--border);
    color: var(--text);
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    font-family: var(--cn);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1.2;
}

.cur-chip:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.cur-chip.active {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.25);
}

.cur-lesson {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: 5.2rem;
    padding: 0.4rem 0.7rem;
    gap: 0.15rem;
}

.cur-lesson .cur-lesson-num {
    font-weight: 700;
}

.cur-lesson .cur-lesson-meta {
    font-size: 0.72rem;
    color: var(--dim);
}

.cur-lesson.active .cur-lesson-meta {
    color: rgba(255, 255, 255, 0.85);
}

.cur-lesson.no-question {
    opacity: 0.5;
}

.cur-lesson.no-question:not(.active) {
    border-style: dashed;
}

.cur-empty {
    color: var(--dim);
    padding: 0.4rem 0;
}

.btn.disabled,
.btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

@media (max-width: 560px) {
    .cur-row {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
    .cur-label {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .cur-label-lesson {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }
}

/* ========== HUD ========== */
.hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    min-height: 80px;
    height: auto;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 3px solid var(--border);
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: calc(10px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) 10px calc(14px + env(safe-area-inset-left, 0px));
    z-index: 100;
    font-family: var(--px);
    font-size: clamp(0.65rem, 2.8vw, 1rem);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    gap: 0.35rem 0.75rem;
    flex-wrap: wrap;
}

.hud.on {
    display: flex;
}

.hud-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.hud-lives {
    display: flex;
    gap: .5rem;
    font-size: clamp(1.15rem, 5vw, 1.8rem);
}

.hud-stage {
    color: var(--blue);
    font-size: 1rem;
}

.hud-score {
    color: var(--orange);
    font-size: 1rem;
}

.hud-combo {
    color: var(--purple);
    font-size: 1rem;
}

.hud-player {
    color: var(--green);
    font-size: 1rem;
}

/* ========== 遊戲區域 ========== */
.game-box {
    max-width: 1000px;
    width: 100%;
    text-align: center;
    padding-top: calc(env(safe-area-inset-top, 0px) + 112px);
    position: relative;
}

.game-loading {
    position: absolute;
    inset: 0;
    top: clamp(72px, 18vw, 90px);
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    z-index: 20;
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--blue);
    border-radius: 15px;
}

.game-loading.on {
    display: flex;
}

/* 時間條 */
.timer-container {
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border: 3px solid var(--blue);
}

.timer-bar {
    flex: 1 1 200px;
    width: min(400px, 100%);
    max-width: 100%;
    min-width: 0;
    height: 15px;
    background: var(--light);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 2px solid var(--border);
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), var(--yellow));
    transition: width .1s linear;
    border-radius: 6px;
    position: relative;
}

.timer-fill.warn {
    background: linear-gradient(90deg, var(--orange), var(--yellow));
}

.timer-fill.danger {
    background: linear-gradient(90deg, var(--red), var(--orange));
    animation: pulse 1s infinite;
}

.timer-text {
    font-family: var(--px);
    font-size: clamp(0.75rem, 3vw, 1.2rem);
    color: var(--text);
    font-weight: bold;
}

/* 題目區域 */
.question-area {
    background: white;
    border: 4px solid var(--blue);
    border-radius: 20px;
    padding: clamp(1.25rem, 5vw, 3rem);
    margin-bottom: 2rem;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 123, 255, 0.2);
}

.q-badges {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.q-type, .q-diff {
    font-family: var(--px);
    font-size: clamp(0.65rem, 2.8vw, 1rem);
    padding: clamp(0.45rem, 2vw, 0.8rem) clamp(0.75rem, 3vw, 1.5rem);
    border-radius: 25px;
    display: inline-block;
    font-weight: bold;
}

.q-type {
    background: var(--cyan);
    color: white;
}

.q-diff {
    background: var(--purple);
    color: white;
}

.q-text {
    font-size: clamp(1.1rem, 4.2vw, 1.8rem);
    font-weight: 700;
    line-height: 1.75;
    margin-bottom: 2rem;
    min-height: 3em;
    color: var(--text);
    overflow-wrap: anywhere;
    word-break: normal;
}

/* 空格樣式 */
.blank-space {
    display: inline-block;
    min-width: min(150px, 42vw);
    max-width: 100%;
    height: clamp(48px, 12vw, 60px);
    background: var(--light);
    border: 4px dashed var(--blue);
    border-radius: 15px;
    text-align: center;
    line-height: 1.2;
    margin: 0 .5rem;
    vertical-align: middle;
    position: relative;
    cursor: default;
    transition: all .3s ease;
    font-weight: bold;
    font-size: clamp(1rem, 3.8vw, 1.4rem);
}

.blank-space.filled {
    background: var(--green);
    border-color: var(--green);
    color: white;
    border-style: solid;
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

/* 選項區域 */
.options-area {
    background: white;
    border: 4px solid var(--orange);
    border-radius: 20px;
    padding: clamp(1.25rem, 4vw, 2rem);
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px rgba(253, 126, 20, 0.2);
}

.options-title {
    font-family: var(--px);
    font-size: clamp(0.72rem, 3.2vw, 1.2rem);
    color: var(--orange);
    margin-bottom: 1.5rem;
    text-align: center;
}

.draggable-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
    min-height: 120px;
    align-items: flex-start;
    align-content: flex-start;
}

.draggable-item {
    background: linear-gradient(45deg, var(--purple), var(--pink));
    color: white;
    padding: clamp(0.85rem, 3vw, 1.2rem) clamp(1rem, 4vw, 2rem);
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    transition: all .3s ease;
    user-select: none;
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    border: 3px solid transparent;
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(111, 66, 193, 0.4);
    font-family: var(--cn);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.draggable-item.option-btn {
    appearance: none;
}

.draggable-item:hover:not(.used) {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 10px 30px rgba(111, 66, 193, 0.6);
    border-color: rgba(255, 255, 255, .3);
}

.draggable-item.used {
    background: var(--dim);
    color: white;
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
    box-shadow: none;
    pointer-events: none;
}

.draggable-item:active:not(.used) {
    transform: scale(0.98);
}

/* 反饋消息 */
.feedback-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: clamp(1.25rem, 4vw, 2rem) clamp(1.25rem, 6vw, 3rem);
    border-radius: 20px;
    font-family: var(--cn);
    font-size: clamp(0.82rem, 3.2vw, 1.2rem);
    font-weight: bold;
    display: none;
    z-index: 1000;
    text-align: left;
    max-width: min(90vw, 28rem);
    backdrop-filter: blur(10px);
    border: 4px solid;
    white-space: pre-line;
}

.feedback-message.show {
    display: block;
    opacity: 1;
    transform: translate(-50%, -50%);
    cursor: pointer;
}

.feedback-message.show::after {
    content: '點一下關閉';
    display: block;
    margin-top: 1.25rem;
    font-size: 0.72em;
    font-weight: 700;
    opacity: 0.92;
    text-align: left;
}

.feedback-message.success {
    background: var(--green);
    color: white;
    border-color: darkgreen;
    box-shadow: 0 0 30px rgba(40, 167, 69, 0.6);
}

.feedback-message.error {
    background: var(--red);
    color: white;
    border-color: darkred;
    box-shadow: 0 0 30px rgba(220, 53, 69, 0.6);
}

/* 控制按鈕 */
.game-controls {
    text-align: center;
    margin-top: 2rem;
}

.btn {
    background: white;
    color: var(--blue);
    border: 3px solid var(--blue);
    padding: clamp(0.72rem, 2.5vw, 1rem) clamp(0.85rem, 4vw, 2rem);
    border-radius: 15px;
    font-family: var(--px);
    font-size: clamp(0.72rem, 2.6vw, 1rem);
    cursor: pointer;
    transition: all .3s ease;
    margin: 0 .5rem;
    text-transform: uppercase;
    letter-spacing: .1em;
}

.btn:hover {
    background: var(--blue);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 123, 255, 0.3);
}

/* ========== 結果頁面 ========== */
.result-box {
    text-align: center;
    max-width: 800px;
    width: 100%;
    background: white;
    border: 4px solid var(--purple);
    border-radius: 25px;
    padding: clamp(1.35rem, 5vw, 3rem);
    position: relative;
    overflow: hidden;
    box-shadow: 0 15px 50px rgba(111, 66, 193, 0.3);
}

.result-title {
    font-family: var(--px);
    font-size: clamp(1.1rem, 4.5vw, 2rem);
    margin-bottom: 1rem;
    color: var(--purple);
}

.result-score {
    font-family: var(--px);
    font-size: clamp(1.85rem, 9vw, 3rem);
    margin: 1rem 0;
    color: var(--orange);
}

.result-details {
    font-size: clamp(1.1rem, 3.8vw, 1.5rem);
    margin: 1rem 0;
    color: var(--text);
}

.result-message {
    font-size: clamp(1rem, 3.2vw, 1.2rem);
    margin: 2rem 0;
    line-height: 1.6;
    color: var(--dim);
}

.result-history {
    background: var(--light);
    border-radius: 15px;
    padding: clamp(1rem, 3.5vw, 2rem);
    margin: 2rem 0;
    max-height: min(300px, 40vh);
    overflow-y: auto;
    text-align: left;
    border: 2px solid var(--border);
}

.result-history h4 {
    font-family: var(--px);
    font-size: 1rem;
    color: var(--blue);
    margin-bottom: 1rem;
    text-align: center;
}

.history-item {
    background: white;
    border-radius: 10px;
    padding: 1rem;
    margin: .8rem 0;
    border-left: 4px solid;
    font-size: 1rem;
}

.history-item.correct {
    border-left-color: var(--green);
}

.history-item.incorrect {
    border-left-color: var(--red);
}

.result-controls {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========== 排行榜 ========== */
.lb-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.lb-table-wrap .lb-table {
    min-width: 520px;
}

.leaderboard-box {
    max-width: 800px;
    width: 100%;
    background: white;
    border: 4px solid var(--green);
    border-radius: 20px;
    padding: clamp(1.15rem, 4vw, 2rem);
    box-shadow: 0 10px 30px rgba(40, 167, 69, 0.2);
}

.lb-title {
    font-family: var(--px);
    font-size: clamp(1.05rem, 4vw, 1.8rem);
    color: var(--green);
    margin-bottom: 2rem;
    text-align: center;
}

.lb-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.lb-tab {
    padding: clamp(0.65rem, 2.5vw, 1rem) clamp(0.85rem, 3vw, 1.5rem);
    border: 3px solid var(--border);
    background: white;
    cursor: pointer;
    border-radius: 15px;
    font-family: var(--px);
    font-size: 0.9rem;
    transition: all .3s ease;
    min-width: min(120px, 28vw);
    text-align: center;
}

.lb-tab.active {
    border-color: var(--green);
    background: var(--green);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

.lb-tab:hover:not(.active) {
    border-color: var(--green);
    background: rgba(40, 167, 69, 0.1);
}

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1.1rem;
}

.lb-table th {
    font-family: var(--px);
    font-size: 1rem;
    color: var(--text);
    text-align: left;
    padding: 1rem;
    border-bottom: 2px solid var(--border);
    background: var(--light);
}

.lb-table td {
    font-family: var(--cn);
    font-size: 1.1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.lb-table tr:hover {
    background: var(--light);
}

.lb-table tr.me {
    background: rgba(40, 167, 69, 0.1);
    font-weight: bold;
}

.lb-rank {
    min-width: 60px;
    font-weight: bold;
}

.lb-rank.gold { color: #ffd700; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }

.lb-score {
    color: var(--orange);
    font-weight: bold;
    text-align: right !important;
}

.lb-empty {
    text-align: center;
    color: var(--dim);
    padding: 2rem;
    font-size: 1.1rem;
}

/* 音效／背景音樂切換 */
.audio-controls {
    position: fixed;
    bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    right: calc(2rem + env(safe-area-inset-right, 0px));
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.sound-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid var(--blue);
    background: white;
    color: var(--blue);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .3s ease;
    box-shadow: 0 5px 15px rgba(0, 123, 255, 0.3);
}

.sound-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.4);
}

.sound-btn.muted {
    background: var(--red);
    color: white;
    border-color: var(--red);
}

/* 響應式設計 */
@media (max-width: 900px) {
    .timer-container {
        padding: 1.15rem clamp(1rem, 4vw, 1.5rem);
    }

    .logo-icon {
        font-size: clamp(2.75rem, 12vw, 4rem);
    }
}

@media (max-width: 720px) {
    .hud {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        row-gap: 0.35rem;
    }

    .hud-section {
        justify-content: space-between;
        width: 100%;
        flex-wrap: wrap;
        gap: 0.35rem 0.75rem;
    }

    .hud-section:first-child {
        justify-content: center;
    }

    .hud-player {
        text-align: center;
        overflow-wrap: anywhere;
        max-width: 100%;
    }

    #scr-game.screen.active .game-box {
        padding-top: calc(env(safe-area-inset-top, 0px) + 168px);
    }
}

@media (max-width: 768px) {
    .screen {
        padding:
            calc(1rem + env(safe-area-inset-top, 0px))
            calc(1rem + env(safe-area-inset-right, 0px))
            calc(1rem + env(safe-area-inset-bottom, 0px))
            calc(1rem + env(safe-area-inset-left, 0px));
        justify-content: flex-start;
        padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
    }

    /* 主選單等仍可大致置中（內容比較矮）*/
    #scr-title.screen.active,
    #scr-name.screen.active,
    #scr-difficulty.screen.active {
        justify-content: safe center;
    }

    /* 遊戲／結果／排行榜較長，由上往下排才不會裁切 */
    #scr-game.screen.active,
    #scr-result.screen.active,
    #scr-leaderboard.screen.active {
        justify-content: flex-start;
    }

    #scr-game.screen.active .game-box {
        padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
    }

    .mode-btns {
        flex-direction: column;
        align-items: center;
        gap: clamp(1rem, 4vw, 2rem);
    }

    .mode-btn {
        width: min(100%, 360px);
    }

    .mode-btn .icon {
        font-size: clamp(2.5rem, 12vw, 4rem);
    }

    .mode-btn .label {
        font-size: clamp(0.85rem, 3vw, 1.2rem);
    }

    .mode-btn .time {
        font-size: clamp(0.72rem, 2.6vw, 1rem);
    }

    .mode-btn .desc {
        font-size: clamp(0.95rem, 3.2vw, 1.1rem);
    }

    .timer-bar {
        flex-basis: 100%;
        order: 1;
        width: 100%;
        max-width: 100%;
    }

    /* 時間列：標籌與秒數在第一列，計時條獨占下一列較清楚 */
    .timer-container > .timer-text:first-child {
        order: 0;
        flex-basis: auto;
    }

    #timer-text.timer-text {
        order: 0;
    }

    .timer-container > .timer-text:last-child {
        order: 0;
    }

    .timer-container {
        justify-content: center;
        row-gap: 0.85rem;
    }

    .result-controls .btn {
        width: min(280px, 100%);
        margin: 0.25rem 0;
    }

    .audio-controls {
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        right: calc(1rem + env(safe-area-inset-right, 0px));
        gap: 0.35rem;
    }

    .audio-controls .sound-btn {
        width: 52px;
        height: 52px;
        font-size: 1.25rem;
    }
}

@media (max-width: 480px) {
    .title-main {
        line-height: 1.35;
    }

    .blank-space {
        min-width: min(100px, 38vw);
        margin: 0.25rem 0.25rem;
    }

    .draggable-options {
        gap: 0.85rem;
    }

    .lb-table th,
    .lb-table td {
        padding: 0.65rem 0.75rem;
        font-size: clamp(0.88rem, 3.2vw, 1.05rem);
    }

    .lb-table th {
        font-size: clamp(0.62rem, 2.4vw, 0.85rem);
    }

    .game-controls .btn {
        display: block;
        width: min(100%, 280px);
        margin: 0.5rem auto;
    }
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--light);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--dim);
}
