/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    min-height: 100vh;
}

.game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: grid;
    grid-template-areas: 
        "header header header"
        "info info info"
        "stats stats stats"
        "left main sidebar";
    grid-template-columns: 300px 1fr 320px;
    gap: 20px;
}

/* 游戏标题 */
.game-header {
    grid-area: header;
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.game-header p {
    font-size: 1.2em;
    opacity: 0.9;
}

/* 游戏信息栏 */
.game-info {
    grid-area: info;
    display: flex;
    justify-content: space-around;
    background: rgba(255,255,255,0.1);
    padding: 15px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

.info-item {
    text-align: center;
}

.info-item .label {
    display: block;
    font-size: 0.9em;
    opacity: 0.8;
    margin-bottom: 5px;
}

.info-item span:last-child {
    font-size: 1.5em;
    font-weight: bold;
    color: #ffd700;
}

/* 考试统计栏 */
.exam-stats {
    grid-area: stats;
    display: flex;
    justify-content: center;
    gap: 30px;
    background: rgba(255,255,255,0.15);
    padding: 12px 20px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.stats-item {
    text-align: center;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stats-item .label {
    font-size: 0.95em;
    opacity: 0.9;
    color: #e8f4fd;
}

.stats-item span:not(.label):not(.percentage) {
    font-size: 1.1em;
    font-weight: bold;
    color: #4fc3f7;
}

.stats-item .percentage {
    font-size: 0.9em;
    color: #81c784;
    font-weight: normal;
}

/* 左侧面板（图片展示区 + 控制区） */
.left-panel {
    grid-area: left;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.left-panel > .image-showcase,
.left-panel > .game-controls {
    background: rgba(255,255,255,0.1);
    padding: 16px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

/* 图片展示区 */
.image-showcase {
    display: grid;
    grid-template-rows: 1fr;
    gap: 8px;
    border: none;
    border-image: none;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.25);
    background: rgba(30, 60, 114, 0.8);
}

.image-showcase .picture {
    width: 100%;
    aspect-ratio: 1 / 1;
    height: 200px;
    background: #2c3e50;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-showcase .picture img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 仅展示图片，不显示翻译和音标 */

/* 游戏主体（仅画布居中） */
.game-main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* 游戏画布 */
#gameCanvas {
    border: 3px solid #ffd700;
    border-radius: 10px;
    background: #0e1f3d; /* 统一深蓝底色，避免色差 */
    box-shadow: 0 0 20px rgba(255,215,0,0.3);
}

/* 游戏控制 */
.game-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.input-section {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    gap: 12px;
    background: rgba(255,255,255,0.1);
    padding: 16px;
    border-radius: 10px;
    align-items: stretch;
}

.input-section label {
    font-weight: bold;
    font-size: 1.1em;
    color: #ffd700;
}

#letterInput {
    padding: 12px 20px;
    border: 2px solid #3498db;
    border-radius: 8px;
    font-size: 1.1em;
    text-align: center;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.95);
    font-weight: bold;
    letter-spacing: 2px;
    transition: all 0.3s;
    width: 100%;
}

#letterInput:focus {
    outline: none;
    border-color: #ffd700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.35);
}

.give-up-btn {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    white-space: nowrap;
}

.give-up-btn:hover {
    background: linear-gradient(135deg, #c0392b, #a93226);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.give-up-btn:active {
    transform: translateY(0);
}

.real-time-preview {
    padding: 10px 15px;
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    border-left: 4px solid #3498db;
    font-size: 1.1em;
    color: #ffd700;
    font-weight: bold;
}

.keyboard-hint {
    padding: 8px 12px;
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid rgba(52, 152, 219, 0.3);
    border-radius: 5px;
    font-size: 0.85em;
    color: #3498db;
    text-align: right;
    line-height: 1.4;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

.control-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2列 */
    grid-auto-rows: 42px;                 /* 高度缩小一半 */
    gap: 12px;
}

.control-buttons button {
    height: 100%;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90%;              /* 宽度缩小10% */
    justify-self: center;    /* 居中显示 */
    white-space: nowrap;      /* 不换行，保证一格一行 */
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

#submitBtn, #startBtn {
    background: #4CAF50;
    color: white;
}

.give-up-btn {
    background: #9e9e9e;
    color: white;
    margin-left: 10px;
}

.toggle-speech {
    background: #2196F3;
    color: white;
    font-size: 0.9em;
}

.toggle-speech.disabled {
    background: #757575;
}

.settings-btn {
    background: #9b59b6;
    color: white;
    font-size: 0.9em;
}

.settings-btn:hover {
    background: #8e44ad;
}

.test-btn {
    background: #204455;
    color: white;
    font-size: 0.9em;
}

.test-btn:hover {
    background: #214b5e;
}

#pauseBtn {
    background: #ff9800;
    color: white;
}

#resetBtn {
    background: #f44336;
    color: white;
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 侧边栏 */
.sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar > div {
    background: rgba(255,255,255,0.1);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

.sidebar h3 {
    margin-bottom: 15px;
    color: #ffd700;
    text-align: center;
}

/* 缓冲区指示器 */
.traffic-lights {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.light {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #333;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.light.red {
    background: #f44336;
}

.light.yellow {
    background: #ffeb3b;
}

.light.green {
    background: #4caf50;
}

.light.active {
    opacity: 1;
    box-shadow: 0 0 10px currentColor;
}

#nextWord {
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    padding: 10px;
    background: rgba(0,0,0,0.3);
    border-radius: 5px;
}

/* 生词本 */
.vocabulary-book {
    max-height: 300px;
}

#vocabularyList {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.vocab-item {
    background: rgba(0,0,0,0.3);
    padding: 8px;
    margin-bottom: 5px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.vocab-word {
    font-weight: bold;
    color: #ffd700;
}

.vocab-count {
    font-size: 0.8em;
    opacity: 0.7;
}


/* 游戏说明 */
.game-instructions ul {
    list-style: none;
    padding-left: 0;
}

.game-instructions li {
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.game-instructions li:before {
    content: "▶ ";
    color: #ffd700;
    font-weight: bold;
}

/* 弹窗样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    margin: 15% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    animation: slideIn 0.3s ease;
    position: relative;
    overflow: visible; /* 改为 visible 确保关闭按钮不被裁剪 */
}

.modal-body {
    padding: 50px 30px 30px 30px;
    position: relative; /* 确保内容不会覆盖关闭按钮 */
}

.close-btn {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    font-size: 36px;
    font-weight: bold;
    color: #ff3333;
    cursor: pointer;
    line-height: 1;
    transition: all 0.3s ease;
    z-index: 10000 !important; /* 提高 z-index 确保在最上层 */
    width: 45px;
    height: 45px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 51, 51, 0.2);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 51, 51, 0.4);
}

.close-btn:hover {
    color: #ffffff !important;
    background: #ff3333 !important;
    transform: scale(1.2) rotate(90deg);
    box-shadow: 0 0 25px rgba(255, 51, 51, 0.8);
    border-color: #ff3333;
}

.modal-content h2 {
    color: #ffd700;
    margin-bottom: 20px;
    font-size: 2em;
}

.modal-content p {
    margin-bottom: 15px;
    font-size: 1.1em;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

.modal-buttons button {
    background: #4CAF50;
    color: white;
    padding: 12px 24px;
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(-50px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scoreFloat {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -80px) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -120px) scale(0.8);
    }
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .game-container {
        grid-template-areas: 
            "header"
            "info"
            "stats"
            "left"
            "main"
            "sidebar";
        grid-template-columns: 1fr;
    }
    
    .game-info {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .info-item {
        flex: 1;
        min-width: 100px;
    }
    
    #gameCanvas { width: 100%; height: auto; }
    
    .input-section { text-align: center; }
    
    .control-buttons {
        flex-wrap: wrap;
    }
}

/* 调试日志面板 */
.debug-panel {
    background: #1e1e1e;
    border-radius: 8px;
    margin-top: 20px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.debug-header {
    background: #2d2d2d;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #3498db;
}

.debug-header h3 {
    margin: 0;
    color: #3498db;
    font-size: 16px;
}

.debug-controls {
    display: flex;
    gap: 8px;
}

.debug-btn {
    background: #3498db;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
}

.debug-btn:hover {
    background: #2980b9;
}

.debug-btn .btn-icon {
    font-size: 14px;
    line-height: 1;
}

.debug-btn .btn-text {
    font-size: 12px;
    font-weight: 500;
}

/* 响应式：小屏幕隐藏文字，只显示图标 */
@media (max-width: 768px) {
    .debug-btn {
        padding: 6px 8px;
        gap: 0;
    }
    
    .debug-btn .btn-text {
        display: none;
    }
    
    .debug-btn .btn-icon {
        font-size: 16px;
    }
}

.debug-console {
    background: #1e1e1e;
    color: #e0e0e0;
    padding: 15px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 12px;
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.6;
}

.debug-console::-webkit-scrollbar {
    width: 8px;
}

.debug-console::-webkit-scrollbar-track {
    background: #2d2d2d;
}

.debug-console::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.debug-console::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.debug-line {
    margin: 3px 0;
    padding: 3px 5px;
    border-left: 3px solid transparent;
}

.debug-line.error {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
    border-left-color: #ff6b6b;
}

.debug-line.success {
    color: #51cf66;
    background: rgba(81, 207, 102, 0.1);
    border-left-color: #51cf66;
}

.debug-line.info {
    color: #74c0fc;
    background: rgba(116, 192, 252, 0.1);
    border-left-color: #74c0fc;
}

.debug-line.warning {
    color: #ffd43b;
    background: rgba(255, 212, 59, 0.1);
    border-left-color: #ffd43b;
}

.debug-panel.hidden .debug-console {
    display: none;
}
