/* ==============================================
   CSS变量定义
   ============================================== */
:root {
    /* 主色调 */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #8b5cf6;
    --accent-color: #f59e0b;
    --danger-color: #ef4444;
    
    /* 背景颜色 */
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e293b;
    --card-bg: #1e293b;
    --overlay-bg: rgba(0, 0, 0, 0.8);
    
    /* 文字颜色 */
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-light: #94a3b8;
    
    /* 状态颜色 */
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    
    /* 阴影 */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.5);
    
    /* 圆角 */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* 过渡 */
    --transition-fast: 150ms ease-in-out;
    --transition-base: 300ms ease-in-out;
    --transition-slow: 500ms ease-in-out;
}

/* ==============================================
   基础样式重置
   ============================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 
                 'Microsoft YaHei', 'Consolas', 'Monaco', monospace;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
}

/* ==============================================
   页面切换
   ============================================== */
.page {
    display: none;
    min-height: 100vh;
    padding: 0.5rem;
    animation: fadeIn var(--transition-base);
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==============================================
   设置页面
   ============================================== */
.settings-container {
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    justify-content: center;
    padding: 0.25rem 0;
}

.game-title {
    font-size: 2rem;
    text-align: center;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
}

.game-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

.settings-card {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    padding: 0.4375rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(59, 130, 246, 0.2);
    max-height: calc(100vh - 0.875rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.setting-group {
    margin-bottom: 0.875rem;
}

.setting-group label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.setting-icon {
    font-size: 1.25rem;
}

.setting-label {
    flex: 1;
}

.setting-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 2px solid #334155;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    background: #0f172a;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.setting-select:hover {
    border-color: var(--primary-color);
}

.setting-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* 切换开关 */
.toggle-label {
    position: relative;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    width: 44px;
    height: 22px;
    background: #334155;
    border-radius: 11px;
    position: relative;
    transition: background var(--transition-base);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.toggle-label input:checked + .toggle-slider {
    background: var(--primary-color);
}

.toggle-label input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* 按钮样式 */
.primary-btn,
.secondary-btn {
    width: 100%;
    padding: 0.5rem;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: var(--shadow-md);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.secondary-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* ==============================================
   游戏页面
   ============================================== */
#game-page {
    padding: 1rem;
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.icon-btn {
    background: transparent;
    border: 2px solid #334155;
    border-radius: var(--radius-md);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 1.25rem;
}

.icon-btn:hover {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
    box-shadow: var(--shadow-glow);
}

.game-stats {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

/* 游戏画布 */
.game-canvas {
    flex: 1;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg), inset 0 0 100px rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.words-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.word-object {
    position: absolute;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.9), rgba(139, 92, 246, 0.9));
    color: white;
    border-radius: var(--radius-lg);
    font-size: 1.25rem;
    font-weight: 700;
    box-shadow: var(--shadow-lg), 0 0 20px rgba(59, 130, 246, 0.6);
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    letter-spacing: 0.05em;
}

.word-object.matched {
    background: linear-gradient(135deg, var(--success-color), #059669);
    animation: wordDestroy 0.5s ease-out forwards;
}

.word-object.missed {
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
    animation: wordMissed 0.5s ease-out forwards;
}

@keyframes wordDestroy {
    0% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: scale(2) rotate(360deg);
        opacity: 0;
    }
}

@keyframes wordMissed {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(20px);
        opacity: 0;
    }
}

/* 粒子效果 */
.particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--primary-color);
    animation: particleFloat 1s ease-out forwards;
}

@keyframes particleFloat {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* 输入区域 */
.input-area {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 4rem);
    max-width: 600px;
}

.word-input {
    width: 100%;
    padding: 1rem 1.5rem;
    background: rgba(30, 41, 59, 0.95);
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    outline: none;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
    letter-spacing: 0.05em;
}

.word-input:focus {
    border-color: var(--secondary-color);
    box-shadow: var(--shadow-xl), 0 0 30px rgba(139, 92, 246, 0.6);
}

.word-input::placeholder {
    color: var(--text-light);
}

.input-hint {
    text-align: center;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    min-height: 1.5rem;
}

/* 游戏提示 */
.game-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 20px rgba(245, 158, 11, 0.8);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.game-hint.show {
    opacity: 1;
    animation: hintPulse 0.5s ease-out;
}

@keyframes hintPulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
    }
}

/* ==============================================
   模态框
   ============================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn var(--transition-base);
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: slideUp var(--transition-base);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 2rem 2rem 1rem;
    text-align: center;
}

.modal-header h2 {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-body {
    padding: 1rem 2rem;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.result-item {
    text-align: center;
    padding: 1rem;
    background: rgba(59, 130, 246, 0.1);
    border-radius: var(--radius-md);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.result-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.result-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.result-message {
    text-align: center;
    font-size: 1.125rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.pause-message {
    text-align: center;
    font-size: 1.25rem;
    color: var(--text-secondary);
    padding: 2rem 0;
}

.modal-footer {
    padding: 1rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modal-footer .primary-btn,
.modal-footer .secondary-btn {
    margin: 0;
}

/* 操作说明 */
.controls-info {
    color: var(--text-secondary);
}

.controls-info h3 {
    color: var(--primary-color);
    margin: 1.5rem 0 0.75rem;
}

.controls-info h3:first-child {
    margin-top: 0;
}

.controls-info ul {
    list-style-position: inside;
    padding-left: 0;
}

.controls-info li {
    margin: 0.5rem 0;
    line-height: 1.6;
}

.controls-info strong {
    color: var(--text-primary);
}

/* ==============================================
   加载提示
   ============================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(59, 130, 246, 0.3);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-message {
    margin-top: 1.5rem;
    color: var(--text-primary);
    font-size: 1.125rem;
}

/* ==============================================
   响应式设计
   ============================================== */
@media (max-width: 768px) {
    .game-title {
        font-size: 1.8rem;
    }
    
    .game-header {
        padding: 1rem;
    }
    
    .game-stats {
        gap: 1rem;
        width: 100%;
        justify-content: space-around;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .word-object {
        font-size: 1rem;
        padding: 0.5rem 1rem;
    }
    
    .word-input {
        font-size: 1.25rem;
        padding: 0.75rem 1rem;
    }
    
    .game-hint {
        font-size: 2rem;
    }
    
    .result-stats {
        grid-template-columns: 1fr;
    }
    
    .settings-container {
        min-height: 100vh;
        padding: 0.125rem;
    }
    
    .settings-card {
        padding: 0.75rem;
    }
    
    .setting-group {
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 480px) {
    .page {
        padding: 0.375rem;
    }
    
    .settings-container {
        min-height: 100vh;
        padding: 0rem;
    }
    
    .settings-card {
        padding: 0.4375rem;
    }
    
    .game-container {
        height: calc(100vh - 1rem);
    }
    
    .input-area {
        width: calc(100% - 2rem);
    }
    
    .setting-group {
        margin-bottom: 0.5rem;
    }
    
    .game-title {
        font-size: 1.5rem;
    }
    
    .game-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1rem;
    }
    
    .primary-btn,
    .secondary-btn {
        padding: 0.375rem;
        font-size: 0.8125rem;
        margin-top: 0.375rem;
    }
    
    .setting-select {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .setting-group label {
        font-size: 0.875rem;
    }
    
    .setting-icon {
        font-size: 1.125rem;
    }
}

/* ==============================================
   可访问性增强
   ============================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
