/* ===== 全局重置 & 风格 ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    background: #d6c9b5;
    background-image: radial-gradient(#c4b5a0 1px, transparent 1px);
    background-size: 20px 20px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Courier New', Courier, 'Lucida Sans Typewriter', monospace;
    padding: 20px;
    margin: 0;
}

.game-container {
    max-width: 960px;
    width: 100%;
    background: #f5efe6;
    background-image: linear-gradient(145deg, #f5efe6 0%, #e8dfd2 100%);
    border-radius: 32px 32px 24px 24px;
    padding: 32px 28px 36px;
    box-shadow: 0 20px 40px rgba(80, 60, 40, 0.3), inset 0 1px 0 rgba(255, 248, 235, 0.6), inset 0 -2px 0 #b8a694;
    border: 1px solid #c9b9a4;
    position: relative;
    transition: all 0.2s;
}

.game-container::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 6px;
    background: #bcab96;
    border-radius: 4px;
    opacity: 0.3;
}

/* ===== 设置按钮 ===== */
.settings-btn {
    position: absolute;
    top: 16px;
    right: 20px;
    background: transparent;
    border: none;
    color: #6a5a4a;
    cursor: pointer;
    transition: transform 0.2s;
    line-height: 1;
    z-index: 20;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.settings-btn svg {
    width: 26px;
    height: 26px;
    display: block;
}
.settings-btn:hover {
    transform: rotate(60deg);
}
.settings-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* ===== 设置面板 ===== */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(40, 30, 20, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.settings-overlay.active {
    display: flex;
}
.settings-panel {
    background: #f5efe6;
    border-radius: 32px;
    padding: 32px 40px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid #c9b9a4;
}
.settings-panel h2 {
    font-size: 24px;
    text-align: center;
    color: #3f3225;
    margin-bottom: 24px;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.settings-panel h2 svg {
    width: 22px;
    height: 22px;
    color: #6a5a4a;
}
.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #d6c8b8;
    font-size: 18px;
    color: #3f3225;
}
.settings-item:last-child {
    border-bottom: none;
}
.toggle {
    position: relative;
    width: 56px;
    height: 30px;
    background: #c9b9a4;
    border-radius: 30px;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
    border: 2px solid #b8a694;
}
.toggle.on {
    background: #8a7a68;
}
.toggle .knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 22px;
    height: 22px;
    background: #fcf8f2;
    border-radius: 50%;
    transition: left 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.toggle.on .knob {
    left: 28px;
}
.settings-close {
    display: block;
    margin: 24px auto 0;
    padding: 8px 32px;
    background: #dacfc1;
    border: 2px solid #b8a694;
    border-radius: 30px;
    font-size: 18px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    color: #3f3225;
    transition: 0.15s;
}
.settings-close:active {
    transform: scale(0.96);
}

/* ===== 页面通用 ===== */
.page {
    display: none;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.35s ease;
}
.page.active {
    display: flex;
}
@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(12px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.typewriter-title {
    font-size: 44px;
    font-weight: 700;
    letter-spacing: 6px;
    color: #3f3225;
    text-shadow: 3px 3px 0 #d4c3ae, 5px 5px 0 rgba(80, 60, 40, 0.15);
    font-family: 'Courier New', monospace;
    margin-bottom: 8px;
    text-align: center;
}
.typewriter-sub {
    font-size: 16px;
    color: #8a7a68;
    letter-spacing: 8px;
    margin-bottom: 32px;
    border-top: 1px solid #d6c8b8;
    border-bottom: 1px solid #d6c8b8;
    padding: 10px 24px;
    text-transform: uppercase;
    font-weight: 400;
}

.btn {
    background: #dacfc1;
    border: 2px solid #b8a694;
    color: #3f3225;
    font-family: 'Courier New', monospace;
    font-size: 20px;
    font-weight: 600;
    padding: 14px 44px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 4px 0 #a0907e, inset 0 1px 0 #f0e8dc;
    letter-spacing: 1px;
    background: #e3d8cb;
    text-shadow: 0 1px 0 rgba(255, 248, 235, 0.3);
    position: relative;
    touch-action: manipulation;
}
.btn:active {
    transform: translateY(4px);
    box-shadow: 0 0px 0 #a0907e;
}
.btn:disabled {
    opacity: 0.45;
    transform: translateY(2px);
    box-shadow: 0 2px 0 #a0907e;
    cursor: not-allowed;
    pointer-events: none;
}
.btn-primary {
    background: #c9b8a2;
    border-color: #a3907c;
    box-shadow: 0 4px 0 #8a7a68, inset 0 1px 0 #e8ddd0;
    color: #2d241b;
    font-size: 24px;
    padding: 16px 56px;
}
.btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 0px 0 #8a7a68;
}
.btn-small {
    font-size: 17px;
    padding: 10px 28px;
}
.btn-success {
    background: #b8a48c;
    border-color: #9a8774;
    box-shadow: 0 4px 0 #7d6b5a, inset 0 1px 0 #dcd0c2;
    color: #fcf7f0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.btn-danger {
    background: #c9a090;
    border-color: #a87a6a;
    box-shadow: 0 4px 0 #8a6a5a, inset 0 1px 0 #e8d0c8;
    color: #fcf7f0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.timer {
    font-size: 32px;
    font-weight: 700;
    color: #5a4a3a;
    background: #ece3d8;
    padding: 6px 30px;
    border-radius: 40px;
    border: 1px solid #d0c0ae;
    box-shadow: inset 0 2px 4px rgba(80, 60, 40, 0.08);
    font-family: 'Courier New', monospace;
    margin-bottom: 16px;
    letter-spacing: 3px;
    display: inline-block;
    min-width: 100px;
    text-align: center;
}
.timer.warning {
    color: #b5533a;
    animation: pulse 0.8s infinite alternate;
}
@keyframes pulse {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0.5;
    }
}

.stage-title {
    font-size: 26px;
    font-weight: 600;
    color: #4d3e2e;
    letter-spacing: 4px;
    margin-bottom: 8px;
    border-bottom: 2px dotted #cfbfae;
    padding-bottom: 8px;
    width: 100%;
    text-align: center;
}
.stage-desc {
    font-size: 16px;
    color: #7a6a58;
    margin-bottom: 16px;
    text-align: center;
    background: #ece3d8;
    padding: 6px 24px;
    border-radius: 20px;
    border: 1px solid #d6c8b8;
}

/* ===== 禁用字母格子 ===== */
.disabled-grid {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 20px 0 24px;
    flex-wrap: wrap;
}
.disabled-grid .letter-box {
    width: 76px;
    height: 88px;
    background: #fcf8f2;
    border: 4px solid #c9b9a4;
    border-radius: 12px;
    text-align: center;
    font-size: 44px;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: #3f3225;
    box-shadow: inset 0 4px 8px rgba(80, 60, 40, 0.06), 0 2px 0 #b0a08e;
    transition: all 0.15s;
    text-transform: none;
    caret-color: #8a7a68;
    outline: none;
    padding: 0;
    line-height: 88px;
}
.disabled-grid .letter-box:focus {
    border-color: #8a7a68;
    box-shadow: inset 0 4px 8px rgba(80, 60, 40, 0.06), 0 0 0 4px rgba(150, 130, 110, 0.2);
    background: #fffcf7;
}
.disabled-grid .letter-box:disabled {
    background: #e8ddd0;
    color: #7a6a58;
    border-color: #b8a694;
    opacity: 0.7;
}
.disabled-grid .letter-box.filled {
    border-color: #9a8774;
    background: #f0e8dc;
}

/* ===== 目标字母网格 ===== */
.target-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 8px;
    margin: 16px 0 20px;
    width: 100%;
    max-width: 820px;
    justify-content: center;
}
.target-grid .letter-cell {
    aspect-ratio: 1 / 1;
    background: #fcf8f2;
    border: 3px solid #d6c8b8;
    border-radius: 6px;
    text-align: center;
    font-size: 30px;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: #3f3225;
    box-shadow: inset 0 2px 4px rgba(80, 60, 40, 0.04);
    transition: all 0.1s;
    outline: none;
    padding: 0;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: auto;
    caret-color: #8a7a68;
    text-transform: none;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.target-grid .letter-cell:focus {
    border-color: #8a7a68;
    box-shadow: inset 0 2px 4px rgba(80, 60, 40, 0.04), 0 0 0 4px rgba(150, 130, 110, 0.15);
    background: #fffcf7;
    z-index: 1;
}
.target-grid .letter-cell:disabled {
    background: #ece3d8;
    color: #6a5a4a;
    border-color: #c9b9a4;
    opacity: 0.75;
}
.target-grid .letter-cell.filled {
    border-color: #b0a08e;
    background: #f0e8dc;
}
.target-grid .letter-cell.error-input {
    border-color: #c0392b;
    background: #fde8e4;
}

/* ===== 打字网格 ===== */
.typing-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 8px;
    margin: 16px 0 20px;
    width: 100%;
    max-width: 820px;
    justify-content: center;
}
.typing-grid .char-cell {
    aspect-ratio: 1 / 1;
    background: #f5efe6;
    border: 3px solid #d6c8b8;
    border-radius: 6px;
    text-align: center;
    font-size: 34px;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: #b0a090;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: auto;
    line-height: 1;
    box-shadow: inset 0 1px 3px rgba(80, 60, 40, 0.04);
}
.typing-grid .char-cell.correct {
    color: #c98f3a;
    border-color: #c98f3a;
    background: #fcf6ed;
    text-shadow: 0 0 8px rgba(201, 143, 58, 0.2);
}
.typing-grid .char-cell.error-red {
    color: #c0392b;
    border-color: #c0392b;
    background: #fde8e4;
}
.typing-grid .char-cell.cursor-active {
    border-color: #7a6a58;
    box-shadow: 0 0 0 3px rgba(120, 100, 80, 0.2), inset 0 1px 3px rgba(80, 60, 40, 0.04);
    position: relative;
}
.typing-grid .char-cell.cursor-active::after {
    content: '';
    position: absolute;
    right: -3px;
    top: 10%;
    width: 3px;
    height: 80%;
    background: #5a4a3a;
    animation: blink 0.9s step-end infinite;
}
.typing-grid .char-cell.dim {
    opacity: 0.35;
}
@keyframes blink {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
}

/* ===== 进度信息 ===== */
.progress-info {
    font-size: 18px;
    color: #5a4a3a;
    background: #ece3d8;
    padding: 6px 22px;
    border-radius: 30px;
    border: 1px solid #d0c0ae;
    display: inline-block;
    margin-bottom: 8px;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}
.progress-info.opponent {
    background: #dce8d0;
    border-color: #b0c0a0;
}

.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    align-items: center;
    margin-top: 18px;
    width: 100%;
}

/* ===== 打字输入框 ===== */
.typing-input-wrap {
    position: sticky;
    top: 0;
    z-index: 30;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 8px 12px;
    margin: 4px 0 8px;
    background: rgba(245, 239, 230, 0.92);
    backdrop-filter: blur(6px);
    border-radius: 16px;
    border: 1px solid #d6c8b8;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    flex-wrap: wrap;
}
.typing-input-wrap .input-label {
    font-size: 18px;
    color: #7a6a58;
    font-weight: 600;
    letter-spacing: 1px;
    background: #ece3d8;
    padding: 2px 14px;
    border-radius: 20px;
    border: 1px solid #d0c0ae;
    white-space: nowrap;
}
.typing-input-wrap .input-label .target-char {
    color: #c98f3a;
    font-weight: 700;
    font-size: 22px;
}
.typing-input-wrap input {
    width: 72px;
    height: 64px;
    text-align: center;
    font-size: 40px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    border: 4px solid #b8a694;
    border-radius: 14px;
    background: #fcf8f2;
    color: #3f3225;
    outline: none;
    box-shadow: inset 0 4px 8px rgba(80, 60, 40, 0.06);
    caret-color: #5a4a3a;
    letter-spacing: 2px;
    transition: border 0.15s, box-shadow 0.15s;
    padding: 0;
    text-transform: none;
    flex-shrink: 0;
}
.typing-input-wrap input:focus {
    border-color: #7a6a58;
    box-shadow: inset 0 4px 8px rgba(80, 60, 40, 0.06), 0 0 0 4px rgba(150, 130, 110, 0.15);
}
.typing-input-wrap input:disabled {
    background: #e8ddd0;
    border-color: #c9b9a4;
    opacity: 0.6;
}
.typing-input-wrap .input-hint {
    font-size: 15px;
    color: #7a6a58;
    background: #ece3d8;
    padding: 2px 16px;
    border-radius: 30px;
    border: 1px solid #d0c0ae;
    white-space: nowrap;
}

.hint-text {
    font-size: 17px;
    color: #7a6a58;
    background: #ece3d8;
    padding: 8px 24px;
    border-radius: 30px;
    border: 1px solid #d6c8b8;
    margin: 8px 0 12px;
    text-align: center;
    width: 100%;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.5px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.hint-text.error {
    color: #b5533a;
    border-color: #c0392b;
    background: #fde8e4;
}
.hint-text.success {
    color: #8a7a40;
    border-color: #b8a040;
    background: #f5f0e0;
}
.hint-text.waiting {
    color: #6a7a5a;
    border-color: #8aa080;
    background: #e8f0e0;
}

/* ===== 完成统计 ===== */
.finish-stats {
    font-size: 22px;
    color: #3f3225;
    margin: 20px 0;
    padding: 24px 40px;
    background: #ece3d8;
    border-radius: 16px;
    border: 1px solid #d0c0ae;
    text-align: center;
    line-height: 2.2;
    width: 100%;
    max-width: 480px;
}
.finish-stats span {
    font-weight: 700;
    color: #c98f3a;
}
.finish-stats .winner-text {
    color: #2d7a3a;
    font-size: 28px;
}
.finish-stats .loser-text {
    color: #b5533a;
    font-size: 28px;
}

/* ===== 锁定遮罩 ===== */
.lock-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 999;
    display: none;
    pointer-events: none;
}
.lock-overlay.active {
    display: block;
    pointer-events: auto;
}

.scroll-area {
    max-height: 55vh;
    overflow-y: auto;
    width: 100%;
    padding-right: 6px;
    -webkit-overflow-scrolling: touch;
}

/* ===== 虚拟键盘 ===== */
.virtual-keyboard {
    display: none;
    width: 100%;
    margin-top: 6px;
    padding: 8px 4px 6px;
    background: #ece3d8;
    border-radius: 16px;
    border: 1px solid #c9b9a4;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
    flex-direction: column;
    align-items: center;
    gap: 4px;
    touch-action: manipulation;
}
.virtual-keyboard.show {
    display: flex;
}
.vk-row {
    display: flex;
    gap: 4px;
    justify-content: center;
    width: 100%;
}
.vk-key {
    flex: 1;
    max-width: 48px;
    height: 48px;
    background: #fcf8f2;
    border: 2px solid #b8a694;
    border-radius: 8px;
    font-size: 24px;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: #3f3225;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.1s, transform 0.05s;
    box-shadow: 0 2px 0 #a0907e;
    touch-action: manipulation;
    text-transform: none;
}
.vk-key:active {
    transform: translateY(2px);
    box-shadow: 0 0px 0 #a0907e;
    background: #e8ddd0;
}
.vk-key.disabled {
    opacity: 0.3;
    pointer-events: none;
}
.vk-key.caps-key {
    background: #dacfc1;
    border-color: #a0907e;
    font-size: 18px;
    max-width: 56px;
}
/* 金色描边激活状态 */
.vk-key.caps-key.active {
    background: #c9b8a2;
    border-color: #d4af37 !important;
    box-shadow: 0 0 12px #d4af37;
    color: #2d241b;
}
.vk-key.backspace-key {
    background: #dacfc1;
    border-color: #a0907e;
    font-size: 16px;
    max-width: 56px;
}
.vk-key.space-key {
    max-width: 120px;
    font-size: 14px;
    letter-spacing: 2px;
    background: #dacfc1;
    border-color: #a0907e;
}
@media (max-width: 700px) {
    .vk-key {
        max-width: 38px;
        height: 40px;
        font-size: 20px;
    }
    .vk-key.caps-key {
        max-width: 44px;
        font-size: 15px;
    }
    .vk-key.backspace-key {
        max-width: 44px;
        font-size: 13px;
    }
    .vk-key.space-key {
        max-width: 80px;
        font-size: 12px;
    }
    .virtual-keyboard {
        padding: 4px 2px;
    }
    .vk-row {
        gap: 3px;
    }
}
@media (max-width: 450px) {
    .vk-key {
        max-width: 30px;
        height: 34px;
        font-size: 16px;
        border-width: 1.5px;
    }
    .vk-key.caps-key {
        max-width: 34px;
        font-size: 12px;
    }
    .vk-key.backspace-key {
        max-width: 34px;
        font-size: 11px;
    }
    .vk-key.space-key {
        max-width: 60px;
        font-size: 10px;
    }
}

/* ===== 匹配界面 ===== */
.matching-info {
    font-size: 22px;
    color: #3f3225;
    background: #ece3d8;
    padding: 24px 40px;
    border-radius: 16px;
    border: 1px solid #d0c0ae;
    text-align: center;
    line-height: 2.0;
    width: 100%;
    max-width: 480px;
    margin: 16px 0;
}
.matching-info .queue-num {
    font-size: 40px;
    font-weight: 700;
    color: #c98f3a;
}
.matching-info .wait-time {
    font-size: 32px;
    font-weight: 700;
    color: #5a4a3a;
}

/* ===== 观战模式 ===== */
.watch-container {
    width: 100%;
    max-width: 820px;
    margin: 12px 0;
    padding: 16px;
    background: #ece3d8;
    border-radius: 16px;
    border: 1px solid #d0c0ae;
}
.watch-container .watch-title {
    font-size: 20px;
    color: #4d3e2e;
    text-align: center;
    margin-bottom: 10px;
    letter-spacing: 2px;
}
.watch-container .watch-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
    width: 100%;
}
.watch-container .watch-grid .w-cell {
    aspect-ratio: 1 / 1;
    background: #f5efe6;
    border: 2px solid #d6c8b8;
    border-radius: 4px;
    text-align: center;
    font-size: 22px;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: #b0a090;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.15s;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: auto;
    line-height: 1;
}
.watch-container .watch-grid .w-cell.w-correct {
    color: #c98f3a;
    border-color: #c98f3a;
    background: #fcf6ed;
}
.watch-container .watch-grid .w-cell.w-current {
    border-color: #7a6a58;
    box-shadow: 0 0 0 3px rgba(120, 100, 80, 0.2);
}

/* ===== 响应式 ===== */
@media (max-width: 700px) {
    .game-container {
        padding: 20px 14px 24px;
        border-radius: 24px;
    }
    .typewriter-title {
        font-size: 32px;
        letter-spacing: 3px;
    }
    .typewriter-sub {
        font-size: 14px;
        letter-spacing: 5px;
        padding: 6px 16px;
        margin-bottom: 24px;
    }
    .disabled-grid .letter-box {
        width: 56px;
        height: 66px;
        font-size: 32px;
        line-height: 66px;
        border-width: 3px;
    }
    .target-grid,
    .typing-grid {
        gap: 5px;
    }
    .target-grid .letter-cell {
        font-size: 20px;
        border-width: 2px;
        border-radius: 4px;
    }
    .typing-grid .char-cell {
        font-size: 22px;
        border-width: 2px;
        border-radius: 4px;
    }
    .timer {
        font-size: 26px;
        padding: 4px 20px;
        min-width: 80px;
    }
    .btn {
        font-size: 17px;
        padding: 12px 30px;
        min-width: 80px;
    }
    .btn-primary {
        font-size: 20px;
        padding: 14px 40px;
    }
    .stage-title {
        font-size: 22px;
    }
    .typing-input-wrap input {
        width: 60px;
        height: 54px;
        font-size: 34px;
    }
    .typing-input-wrap .input-label {
        font-size: 15px;
        padding: 0 10px;
    }
    .typing-input-wrap .input-hint {
        font-size: 13px;
        padding: 0 12px;
    }
    .progress-info {
        font-size: 16px;
        padding: 4px 16px;
    }
    .finish-stats {
        font-size: 18px;
        padding: 18px 24px;
    }
    .hint-text {
        font-size: 15px;
        padding: 6px 16px;
        min-height: 44px;
    }
    .action-bar {
        gap: 12px;
    }
    .scroll-area {
        max-height: 45vh;
    }
    .settings-btn {
        top: 12px;
        right: 14px;
    }
    .matching-info {
        font-size: 18px;
        padding: 18px 24px;
    }
    .matching-info .queue-num {
        font-size: 32px;
    }
    .matching-info .wait-time {
        font-size: 26px;
    }
    .watch-container .watch-grid .w-cell {
        font-size: 16px;
        border-width: 1.5px;
    }
}

@media (max-width: 450px) {
    .game-container {
        padding: 14px 8px 18px;
        border-radius: 20px;
    }
    .typewriter-title {
        font-size: 26px;
        letter-spacing: 2px;
    }
    .typewriter-sub {
        font-size: 12px;
        letter-spacing: 3px;
        padding: 4px 12px;
        margin-bottom: 18px;
    }
    .disabled-grid .letter-box {
        width: 44px;
        height: 52px;
        font-size: 24px;
        line-height: 52px;
        border-width: 2px;
    }
    .target-grid,
    .typing-grid {
        gap: 4px;
    }
    .target-grid .letter-cell {
        font-size: 15px;
        border-width: 1.5px;
    }
    .typing-grid .char-cell {
        font-size: 16px;
        border-width: 1.5px;
    }
    .timer {
        font-size: 20px;
        padding: 2px 14px;
        min-width: 60px;
    }
    .btn {
        font-size: 14px;
        padding: 8px 18px;
        min-width: 60px;
    }
    .btn-primary {
        font-size: 17px;
        padding: 10px 28px;
    }
    .typing-input-wrap input {
        width: 50px;
        height: 44px;
        font-size: 26px;
        border-width: 3px;
    }
    .typing-input-wrap .input-label {
        font-size: 13px;
        padding: 0 8px;
    }
    .typing-input-wrap .input-hint {
        font-size: 11px;
        padding: 0 8px;
    }
    .stage-title {
        font-size: 18px;
    }
    .hint-text {
        font-size: 13px;
        min-height: 38px;
        padding: 4px 12px;
    }
    .finish-stats {
        font-size: 15px;
        padding: 14px 16px;
    }
    .scroll-area {
        max-height: 38vh;
    }
    .settings-btn {
        top: 10px;
        right: 10px;
    }
    .matching-info {
        font-size: 15px;
        padding: 14px 16px;
    }
    .matching-info .queue-num {
        font-size: 26px;
    }
    .matching-info .wait-time {
        font-size: 22px;
    }
    .watch-container .watch-grid .w-cell {
        font-size: 12px;
        border-width: 1px;
    }
}

/* ===== 滚动条美化 ===== */
.scroll-area::-webkit-scrollbar {
    width: 6px;
}
.scroll-area::-webkit-scrollbar-track {
    background: #e8ddd0;
    border-radius: 4px;
}
.scroll-area::-webkit-scrollbar-thumb {
    background: #c9b9a4;
    border-radius: 4px;
}
.scroll-area::-webkit-scrollbar-thumb:hover {
    background: #b8a694;
}

/* ===== 连接状态 ===== */
.conn-status {
    font-size: 14px;
    color: #8a7a68;
    text-align: center;
    margin-top: 8px;
    padding: 4px 12px;
    border-radius: 20px;
    background: #ece3d8;
    display: inline-block;
    border: 1px solid #d6c8b8;
}
.conn-status.connected {
    color: #4a7a4a;
    border-color: #8aaa7a;
}
.conn-status.disconnected {
    color: #b5533a;
    border-color: #c0392b;
}

/* ===== 双人信息栏 ===== */
.dual-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 820px;
    gap: 20px;
    flex-wrap: wrap;
    margin: 4px 0 12px;
}
.dual-info .player-info {
    flex: 1;
    min-width: 120px;
    background: #ece3d8;
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid #d0c0ae;
    text-align: center;
    font-size: 16px;
    color: #5a4a3a;
}
.dual-info .player-info .label {
    font-weight: 600;
    color: #8a7a68;
    font-size: 13px;
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dual-info .player-info .value {
    font-size: 20px;
    font-weight: 700;
}
.dual-info .player-info .value.ready {
    color: #5a8a4a;
}
.dual-info .player-info .value.waiting {
    color: #c98f3a;
}
.dual-info .player-info .value.done {
    color: #2d7a3a;
}
.dual-info .player-info.me {
    border-color: #8a7a68;
    background: #f0e8dc;
}
.dual-info .player-info.opponent {
    border-color: #8aaa7a;
    background: #e8f0dc;
}

/* ========== 全屏开始菜单 ========== */
.home-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #d6c9b5;
    background-image:
        radial-gradient(#c4b5a0 1px, transparent 1px),
        radial-gradient(circle at 50% -10%, rgba(255, 248, 235, 0.55), transparent 55%);
    background-size: 22px 22px, 100% 100%;
    padding: 40px 20px;
    overflow-y: auto;
}
.home-menu .settings-btn {
    position: absolute;
    top: 16px;
    right: 20px;
}
.home-menu .conn-status {
    margin-top: 14px;
}

.home-title {
    text-align: center;
    margin-bottom: 6px;
    animation: homeGlow 3.2s ease-in-out infinite;
}
@keyframes homeGlow {
    0%,
    100% {
        filter: drop-shadow(0 0 6px rgba(201, 143, 58, 0.15));
    }
    50% {
        filter: drop-shadow(0 0 18px rgba(201, 143, 58, 0.45));
    }
}
.home-title-line1 {
    font-size: clamp(40px, 9vw, 92px);
    font-weight: 900;
    letter-spacing: 4px;
    line-height: 1.12;
    color: #2d241b;
    text-shadow: 3px 3px 0 #e8c06a, 6px 6px 0 #b88a3a, 11px 11px 22px rgba(0, 0, 0, 0.28);
}
.home-title-line1 .accent {
    display: inline-block;
    font-size: 1.38em;
    color: #b8431f;
    text-shadow: 3px 3px 0 #f2d89a, 7px 7px 0 #8a341a, 0 0 26px rgba(184, 67, 31, 0.4);
    transform: rotate(-3deg);
}
.home-title-line2 {
    margin-top: 4px;
    font-size: clamp(26px, 5.6vw, 54px);
    font-weight: 800;
    letter-spacing: 12px;
    color: #3f3225;
    text-shadow: 2px 2px 0 #e8c06a, 5px 5px 0 rgba(90, 70, 50, 0.22);
}
.home-title-line2 .mark {
    display: inline-block;
    font-size: 1.9em;
    color: #c98f3a;
    text-shadow: 2px 2px 0 #f2d89a, 0 0 20px rgba(201, 143, 58, 0.55);
    transform: rotate(6deg);
}
.home-sub {
    margin-top: 14px;
    font-size: 16px;
    color: #8a7a68;
    letter-spacing: 6px;
    text-transform: uppercase;
    border-top: 1px solid #b8a694;
    border-bottom: 1px solid #b8a694;
    padding: 8px 26px;
}

.home-name-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: 26px 0 22px;
}
.home-name-label {
    font-size: 15px;
    color: #8a7a68;
    letter-spacing: 3px;
}
#nameInput {
    width: min(330px, 82vw);
    height: 58px;
    text-align: center;
    font-size: 26px;
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    border: 4px solid #b8a694;
    border-radius: 16px;
    background: #fcf8f2;
    color: #3f3225;
    outline: none;
    box-shadow: 0 4px 0 #a0907e, inset 0 2px 6px rgba(80, 60, 40, 0.08);
    letter-spacing: 2px;
    caret-color: #5a4a3a;
}
#nameInput:focus {
    border-color: #7a6a58;
    box-shadow: 0 4px 0 #a0907e, inset 0 2px 6px rgba(80, 60, 40, 0.08), 0 0 0 4px rgba(150, 130, 110, 0.18);
}
.home-error {
    margin-top: 14px;
    font-size: 15px;
    color: #b5533a;
    min-height: 24px;
    text-align: center;
    letter-spacing: 1px;
}

/* ===== 阶段标题行（标题与计时器水平排列） ===== */
.stage-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 820px;
    gap: 16px;
    flex-wrap: wrap;
    margin: 0 0 10px;
    border-bottom: 2px dotted #cfbfae;
    padding-bottom: 8px;
}
.stage-row .stage-title {
    margin: 0;
    padding-bottom: 0;
    border-bottom: none;
    width: auto;
    flex: 1;
    text-align: center;
    font-size: 24px;
}
.stage-row .timer {
    margin-bottom: 0;
    flex-shrink: 0;
}
.stage-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* ===== 长按退出（描边实时进度） ===== */
.lp-wrap {
    position: relative;
    display: inline-block;
    border-radius: 30px;
    padding: 4px;
    background: conic-gradient(
        #c0392b 0deg,
        #c0392b var(--deg, 0deg),
        rgba(150, 120, 110, 0.28) var(--deg, 0deg),
        rgba(150, 120, 110, 0.28) 360deg
    );
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.lp-wrap .btn {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    box-shadow: 0 2px 0 #8a6a5a, inset 0 1px 0 #e8d0c8;
}
.lp-wrap .btn.pressing {
    background: #b87a6a;
    transform: translateY(2px);
    box-shadow: 0 0px 0 #8a6a5a;
}

/* ===== 观战棋盘复用打字棋盘样式 ===== */
.watch-container .typing-grid {
    max-width: 100%;
    margin-top: 4px;
}

/* ===== 打字阶段隐藏双人信息，但保留标题与计时器 ===== */
#pageTyping.typing-noprogress .dual-info {
    display: none !important;
}

/* ===== 局内聊天 ===== */
.chat-bubble {
    position: fixed;
    right: 12px;
    top: 50%;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(58, 48, 38, 0.78);
    color: #f5efe6;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2000;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    user-select: none;
    touch-action: none;
    transition: transform 0.15s, opacity 0.2s;
}
.chat-bubble svg {
    width: 28px;
    height: 28px;
    display: block;
}
.chat-bubble.dragging {
    transform: scale(1.15);
    opacity: 0.85;
}
.chat-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #c0392b;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    border-radius: 10px;
    text-align: center;
    padding: 0 4px;
    display: none;
}
.chat-bubble-badge.show {
    display: block;
}

.chat-panel {
    position: fixed;
    right: 12px;
    bottom: 80px;
    width: 300px;
    max-width: calc(100vw - 24px);
    height: 380px;
    max-height: 60vh;
    background: #f5efe6;
    border-radius: 16px;
    border: 2px solid #b8a694;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    z-index: 2001;
    overflow: hidden;
    font-family: 'Courier New', Courier, monospace;
}
.chat-panel-header {
    background: #dacfc1;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #b8a694;
    flex-shrink: 0;
}
.chat-panel-title {
    font-size: 16px;
    font-weight: 700;
    color: #3f3225;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.chat-panel-title svg {
    width: 16px;
    height: 16px;
    color: #6a5a4a;
}
.chat-panel-min {
    background: #c9b8a2;
    border: 2px solid #a3907c;
    color: #2d241b;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-panel-min:active {
    transform: scale(0.92);
}
.chat-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: #ece3d8;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.chat-msg {
    max-width: 82%;
    padding: 6px 10px;
    border-radius: 12px;
    font-size: 14px;
    word-break: break-word;
    line-height: 1.4;
}
.chat-msg.mine {
    align-self: flex-end;
    background: #c9b8a2;
    color: #2d241b;
    border-bottom-right-radius: 4px;
}
.chat-msg.theirs {
    align-self: flex-start;
    background: #fcf8f2;
    color: #3f3225;
    border: 1px solid #d6c8b8;
    border-bottom-left-radius: 4px;
}
.chat-msg .chat-msg-name {
    font-size: 11px;
    color: #8a7a68;
    margin-bottom: 2px;
    font-weight: 600;
}
.chat-panel-input-row {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: #f5efe6;
    border-top: 1px solid #d6c8b8;
    flex-shrink: 0;
}
.chat-panel-input-row input {
    flex: 1;
    min-width: 0;
    height: 38px;
    border: 2px solid #b8a694;
    border-radius: 10px;
    padding: 0 10px;
    font-size: 15px;
    font-family: 'Courier New', Courier, monospace;
    outline: none;
    background: #fcf8f2;
    color: #3f3225;
}
.chat-panel-input-row input:focus {
    border-color: #7a6a58;
}
.chat-send-btn {
    background: #c9b8a2;
    border: 2px solid #a3907c;
    color: #2d241b;
    border-radius: 10px;
    padding: 0 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    font-family: 'Courier New', Courier, monospace;
    flex-shrink: 0;
}
.chat-send-btn:active {
    transform: scale(0.95);
}

/* ===== 断线重连遮罩 ===== */
.reconnect-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(40, 30, 20, 0.55);
    backdrop-filter: blur(3px);
    z-index: 1500;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
}
.reconnect-overlay.active {
    display: flex;
}
.reconnect-box {
    background: #f5efe6;
    border-radius: 22px;
    padding: 30px 36px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    border: 2px solid #b8a694;
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.32);
}
.reconnect-box .rc-ico {
    font-size: 40px;
    margin-bottom: 10px;
}
.reconnect-box .rc-title {
    font-size: 20px;
    font-weight: 700;
    color: #3f3225;
    letter-spacing: 1px;
    margin-bottom: 8px;
}
.reconnect-box .rc-sub {
    font-size: 15px;
    color: #7a6a58;
    line-height: 1.6;
}
.reconnect-box .rc-count {
    font-size: 34px;
    font-weight: 700;
    color: #c0392b;
    margin-top: 12px;
    font-family: 'Courier New', monospace;
}
.reconnect-box .rc-note {
    font-size: 13px;
    color: #a0907e;
    margin-top: 8px;
}

.net-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(30, 22, 15, 0.72);
    backdrop-filter: blur(4px);
    z-index: 2500;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
}
.net-overlay.active {
    display: flex;
}
.net-box {
    background: #f5efe6;
    border-radius: 22px;
    padding: 30px 36px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    border: 2px solid #b8a694;
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.35);
}
.net-box .rc-ico {
    font-size: 44px;
    margin-bottom: 10px;
}
.net-box .rc-title {
    font-size: 20px;
    font-weight: 700;
    color: #3f3225;
    margin-bottom: 8px;
}
.net-box .rc-sub {
    font-size: 14px;
    color: #7a6a58;
    line-height: 1.7;
}