/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS变量定义 - 白天模式 */
:root {
    --bg-primary: #f0f8ff;
    --bg-secondary: #f0f4f8;
    --bg-navbar: #f5f5f5;
    --bg-writing-panel: #fff;
    --bg-bubble-container: #f0f4f8;
    --bg-input: #fff;
    --bg-button: #409eff;
    --bg-button-hover: #66b1ff;
    --bg-reset-button: #ff4d4f;
    --bg-reset-button-hover: #ff7875;
    --bg-restart-button: #52c41a;
    --bg-restart-button-hover: #73d13d;
    --text-primary: #333;
    --text-secondary: #666;
    --text-error: #ff4d4f;
    --border-primary: #409eff;
    --border-secondary: #eee;
    --border-input: #ddd;
    --border-input-focus: #409eff;
    --shadow-primary: rgba(0, 0, 0, 0.1);
    --shadow-inset: rgba(0, 0, 0, 0.05);
}

/* CSS变量定义 - 夜间模式 */
body[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-navbar: #0f3460;
    --bg-writing-panel: #16213e;
    --bg-bubble-container: #16213e;
    --bg-input: #0f3460;
    --bg-button: #0f3460;
    --bg-button-hover: #16213e;
    --bg-reset-button: #e94560;
    --bg-reset-button-hover: #ff6b6b;
    --bg-restart-button: #2d5016;
    --bg-restart-button-hover: #3b6620;
    --text-primary: #ffffff;
    --text-secondary: #b8c2cc;
    --text-error: #ff6b6b;
    --border-primary: #0f3460;
    --border-secondary: #0f3460;
    --border-input: #0f3460;
    --border-input-focus: #16213e;
    --shadow-primary: rgba(0, 0, 0, 0.3);
    --shadow-inset: rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 顶部导航栏 */
.navbar {
    height: 60px;
    background-color: var(--bg-navbar);
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px var(--shadow-primary);
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title {
    font-size: 24px;
    color: var(--text-primary);
    font-weight: bold;
    transition: color 0.3s;
}

.progress {
    font-size: 16px;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.reset-btn {
    padding: 8px 16px;
    background-color: var(--bg-reset-button);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    /* 字体大小将在JavaScript中动态设置 */
    transition: background-color 0.3s;
}

.reset-btn:hover {
    background-color: var(--bg-reset-button-hover);
}

/* 主题切换按钮样式 */
.theme-switcher {
    display: flex;
    align-items: center;
    margin-right: 10px;
}

.theme-toggle {
    padding: 8px;
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s, transform 0.3s;
}

.theme-toggle:hover {
    background-color: var(--bg-button-hover);
    transform: scale(1.1);
}

.theme-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--border-primary);
}

/* 单词库选择器 */
.wordbank-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wordbank-selector label {
    font-size: 16px;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: color 0.3s;
}

.wordbank-selector select {
    padding: 6px 8px;
    font-size: 14px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    background-color: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.3s, background-color 0.3s, color 0.3s;
}

.wordbank-selector select:focus {
    outline: none;
    border-color: var(--border-input-focus);
}

/* 主容器（泡泡区域） */
main {
    flex-grow: 1;
    display: flex;
    align-items: stretch;
}

.bubble-container {
    max-width: 1200px;
    width: calc(100% - 40px); /* 左右各留20px边距 */
    min-height: 300px;
    flex-grow: 1;
    background-color: var(--bg-bubble-container);
    border: 3px solid var(--border-primary);
    border-radius: 8px;
    margin: 20px auto;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 10px var(--shadow-inset),
                0 0 0 1px var(--border-primary);
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

/* 泡泡样式 */
.bubble {
    position: absolute;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, width 1s ease, height 1s ease, line-height 1s ease, font-size 1s ease;
    user-select: none;
    /* 字体大小将在JavaScript中动态设置 */
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    overflow: hidden;
}

/* 泡泡内部文本容器 */
.bubble-text {
    white-space: nowrap;
    /* 移除overflow: hidden，允许滚动文本完整显示 */
    font-weight: bold;
}

/* 滚动文本样式 */
.scroll-text {
    animation: scroll 8s linear infinite;
    display: inline-block;
    padding: 0 10px;
    white-space: nowrap;
    /* 确保滚动范围足够大，让完整文本都能滚动显示 */
}

/* 滚动动画 */
@keyframes scroll {
    0% {
        transform: translateX(150%);
    }
    100% {
        transform: translateX(-150%);
    }
}

.bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.6);
}

.bubble.selected {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 10px rgba(255, 215, 0, 0.6);
}

/* 泡泡增长动画 */
@keyframes grow {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

.bubble.growing {
    animation: grow 0.3s ease-in-out forwards;
}

/* 泡泡爆破动画 */
@keyframes burst {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.5);
        opacity: 0.7;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.bubble.bursting {
    animation: burst 0.5s ease-in-out forwards;
}

/* 抄写面板 */
.writing-panel {
    background-color: var(--bg-writing-panel);
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    padding: 10px 0;
    box-shadow: 0 2px 4px var(--shadow-primary);
    flex-shrink: 0;
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.writing-panel .container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
}

.word-display {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-primary);
    text-align: center;
    overflow: hidden;
    line-height: 1.4;
    transition: color 0.3s;
}

.input-group {
    display: flex;
    gap: 10px;
    flex: 1;
}

#inputWord {
    flex: 1;
    padding: 8px 12px;
    font-size: 16px;
    border: 2px solid var(--border-input);
    border-radius: 4px;
    background-color: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.3s, background-color 0.3s, color 0.3s;
}

#inputWord:focus {
    outline: none;
    border-color: var(--border-input-focus);
}

#inputWord:disabled {
    background-color: var(--bg-input);
    opacity: 0.7;
    cursor: not-allowed;
}

.confirm-btn {
    padding: 8px 20px;
    background-color: var(--bg-button);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.confirm-btn:hover:not(:disabled) {
    background-color: var(--bg-button-hover);
}

.confirm-btn:disabled {
    background-color: var(--bg-button);
    opacity: 0.7;
    cursor: not-allowed;
}

.error-message {
    color: var(--text-error);
    font-size: 14px;
    min-width: 150px;
    transition: color 0.3s;
}

/* 加载提示 */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #667eea;
    z-index: 100;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 10px;
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 胜负提示层 */
.result-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.result-modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--bg-writing-panel);
    padding: 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 8px 24px var(--shadow-primary);
    max-width: 400px;
    width: 90%;
    transition: background-color 0.3s, box-shadow 0.3s;
}

#resultTitle {
    font-size: 28px;
    margin-bottom: 20px;
    color: var(--text-primary);
    transition: color 0.3s;
}

#resultMessage {
    font-size: 18px;
    margin-bottom: 30px;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.restart-btn {
    padding: 10px 30px;
    background-color: var(--bg-restart-button);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.restart-btn:hover {
    background-color: var(--bg-restart-button-hover);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .navbar .container {
        flex-wrap: wrap;
        gap: 10px;
    }

    .title {
        font-size: 20px;
    }

    .progress {
        order: 3;
        width: 100%;
        text-align: center;
    }

    .wordbank-selector {
        order: 4;
        width: 100%;
        justify-content: center;
    }

    .writing-panel .container {
        gap: 10px;
        padding: 10px;
    }

    .word-display {
        width: 100%;
        white-space: normal;
    }

    .input-group {
        width: 100%;
    }

    .error-message {
        width: 100%;
        text-align: center;
    }

    .bubble {
        font-size: 12px;
    }
    
    .bubble-container {
        width: calc(100% - 40px); /* 移动端左右各留20px边距 */
    }
}

/* 用户引导样式 */
.guide-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.guide-modal.show {
    display: flex;
}

.guide-content {
    max-width: 500px;
    width: 90%;
    padding: 30px;
}

.guide-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.guide-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 24px;
    transition: color 0.3s;
}

.skip-btn {
    padding: 6px 12px;
    background-color: var(--bg-input);
    color: var(--text-secondary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s, color 0.3s;
}

.skip-btn:hover {
    background-color: var(--bg-button-hover);
    color: var(--text-primary);
}

.guide-steps {
    margin-bottom: 25px;
    min-height: 200px;
}

.guide-step {
    display: none;
    text-align: center;
}

.guide-step.active {
    display: block;
}

.guide-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.guide-step h3 {
    font-size: 20px;
    color: var(--text-primary);
    margin-bottom: 15px;
    transition: color 0.3s;
}

.guide-step p {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
    transition: color 0.3s;
}

.guide-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.nav-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.prev-btn {
    background-color: var(--bg-input);
    color: var(--text-secondary);
}

.prev-btn:hover:not(:disabled) {
    background-color: var(--bg-button-hover);
    color: var(--text-primary);
}

.prev-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.next-btn {
    background-color: var(--bg-button);
    color: white;
}

.next-btn:hover {
    background-color: var(--bg-button-hover);
}

.step-indicator {
    font-size: 14px;
    color: #666;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .guide-content {
        padding: 20px;
    }
    
    .guide-header h2 {
        font-size: 20px;
    }
    
    .guide-icon {
        font-size: 48px;
    }
    
    .guide-step h3 {
        font-size: 18px;
    }
    
    .guide-step p {
        font-size: 14px;
    }
    
    .guide-nav {
        flex-direction: column;
        gap: 10px;
    }
    
    .nav-btn {
        width: 100%;
    }
}