:root {
  /* 主色调 */
  --primary-color: #4A90E2;
  --secondary-color: #F5A623;
  --success-color: #7ED321;
  --error-color: #FF6B6B;
  
  /* 背景色 */
  --bg-main: #F8F9FA;
  --bg-card: #FFFFFF;
  
  /* 文字色 */
  --text-primary: #333333;
  --text-secondary: #666666;
  
  /* 圆角 */
  --border-radius: 16px;
  
  /* 阴影 */
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-hover: 0 6px 16px rgba(0,0,0,0.15);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none; /* Safari */
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.container {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 40px;
  box-shadow: var(--shadow);
  max-width: 600px;
  width: 100%;
  text-align: center;
}

.title {
  font-size: 36px;
  color: var(--text-primary);
  margin-bottom: 20px;
  font-weight: bold;
}

.star-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  padding: 4px 12px;
  border-radius: 20px;
  border: 2px solid var(--border-color);
  font-size: 1.2em;
  font-weight: bold;
  color: var(--text-color);
  margin-bottom: 20px;
  justify-content: center;
}

.star-icon {
    color: #ffd700;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.1));
}

/* 飞入的星星 - 增强版 */
/* 飞入的星星 - 增强版 */
.flying-star {
    position: fixed;
    font-size: 2.5rem; /* 稍微调小 (3.5 -> 2.5) */
    color: #ffd700;
    pointer-events: none;
    z-index: 9999;
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.8)); /* 更强光晕 */
    /* 移除CSS animation, 改用JS控制transform以配合抛物线 */
    will-change: transform, left, top;
}

/* 拖尾粒子 */
.star-particle {
    position: fixed;
    width: 6px;
    height: 6px;
    background: #ffd700;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9998;
    opacity: 0.8;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
    animation: fadeOut 0.5s linear forwards;
}

@keyframes fadeOut {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

/* 目标位置震动反馈 */
.star-display.bump {
    animation: bump 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: #fff9db; /* 闪光 */
    border-color: #ffd700;
}

@keyframes bump {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.game-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

.game-buttons .game-button:last-child {
  grid-column: 1 / -1;
  max-width: 300px;
  margin: 0 auto;
  width: 100%;
}

.game-button {
  padding: 30px 20px;
  border: none;
  border-radius: var(--border-radius);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.game-button:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.game-button:active {
  transform: translateY(-2px);
}

.button-icon {
  font-size: 48px;
}

.button-text {
  font-size: 24px;
  font-weight: bold;
}

/* 游戏页面样式 */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 100;
}

.back-button {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #ddd;
  border-radius: 20px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

/* 关卡指示器 */
.level-badge {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 15px;
    border-radius: 20px;
    border: 2px solid #eee;
}

.back-button:hover {
  background: rgba(255, 255, 255, 1);
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.star-counter {
  font-size: 24px;
  font-weight: bold;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.game-content {
  margin-top: 100px;
  padding: 20px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* 星星飞入动画 */
.star-fly {
  position: fixed;
  font-size: 40px;
  pointer-events: none;
  z-index: 9999;
  transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* 脉冲动画 */
.pulse {
  animation: pulse 0.6s ease-in-out;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .container {
    padding: 30px 20px;
  }
  
  .title {
    font-size: 28px;
  }
}

/* 手机端深度优化 */
@media (max-width: 480px) {
  .game-content {
      margin-top: 60px; /* 压缩顶部空间 (原100px) */
      padding: 10px;
  }

  .title {
    font-size: 24px;
    margin-bottom: 20px;
  }

  /* 首页按钮紧凑化 */
  .game-button {
    padding: 12px 8px; /* 进一步减小内边距 */
    margin-bottom: 12px;
    gap: 6px;
  }

  .button-icon {
    font-size: 28px; /* 原32px, 减小 */
    margin-bottom: 2px;
  }

  .button-text {
    font-size: 14px; /* 原16px, 减小 */
  }
  
  /* 模态框适配 */
  .modal-content {
      padding: 20px;
      width: 90%;
  }
  
  .modal-title {
      font-size: 20px;
  }
  
  .modal-btn {
      padding: 10px 20px;
      font-size: 16px;
  }
}

/* 错误时的抖动动画 */
.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* 自定义模态框样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 1;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    text-align: center;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.8);
}

.modal-title {
    font-size: 24px;
    color: #333;
    margin-bottom: 15px;
}

.modal-message {
    font-size: 18px;
    color: #666;
    margin-bottom: 30px;
}

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

.modal-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

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

.btn-cancel {
    background: #f0f0f0;
    color: #666;
}

.btn-confirm {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* 设置按钮 */
.settings-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.settings-btn:hover {
    transform: rotate(90deg);
    box-shadow: var(--shadow-hover);
}

.settings-btn:active {
    transform: rotate(90deg);
    box-shadow: var(--shadow);
}

/* 设置弹窗内容 */
.settings-content {
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 2px solid #f0f0f0;
}

.settings-title {
    font-size: 24px;
    color: var(--text-primary);
    margin: 0;
}

.close-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #f0f0f0;
    color: #666;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: #e0e0e0;
    transform: rotate(90deg);
}

.settings-body {
    flex: 1;
    padding: 20px 30px;
    overflow-y: auto;
}

/* 搜索框 */
.search-box {
    margin-bottom: 20px;
    position: relative;
}

.hanzi-search {
    width: 100%;
    padding: 12px 45px 12px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: all 0.3s;
}

.hanzi-search:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.clear-search-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    background: #ddd;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.clear-search-btn:hover {
    background: #ccc;
    color: #333;
}

/* 统计信息 */
.hanzi-stats {
    text-align: center;
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 15px;
    font-weight: bold;
}

.hanzi-stats span {
    color: var(--primary-color);
}

/* 操作按钮 */
.hanzi-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 15px;
}

.action-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: #f0f0f0;
    color: #666;
}

.action-btn:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
}

/* 汉字网格 */
.hanzi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
    gap: 6px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
}

.hanzi-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    font-weight: 500;
    user-select: none;
}

.hanzi-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.hanzi-item.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: white;
}

.hanzi-char {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 4px;
}

.hanzi-category {
    font-size: 10px;
    color: #999;
    text-align: center;
}

.hanzi-item.selected .hanzi-category {
    color: rgba(255, 255, 255, 0.8);
}

/* 设置底部按钮 */
.settings-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 20px 30px;
    border-top: 2px solid #f0f0f0;
}

.settings-btn-primary,
.settings-btn-secondary {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.settings-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.settings-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.settings-btn-secondary {
    background: #f0f0f0;
    color: #666;
}

.settings-btn-secondary:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
}

/* 手机端适配 */
@media (max-width: 768px) {
    .settings-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .settings-header,
    .settings-body,
    .settings-footer {
        padding: 15px 20px;
    }
    
    .settings-title {
        font-size: 20px;
    }
    
    .hanzi-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
        gap: 8px;
        max-height: 300px;
    }
    
    .hanzi-char {
        font-size: 20px;
    }
    
    .settings-btn {
        width: 45px;
        height: 45px;
        font-size: 20px;
        top: 15px;
        right: 15px;
    }
}

@media (max-width: 480px) {
    .hanzi-grid {
        grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
        gap: 6px;
    }
    
    .hanzi-char {
        font-size: 18px;
    }
    
    .hanzi-category {
        font-size: 9px;
    }
}

/* Tab导航样式 */
.settings-tabs {
    display: flex;
    gap: 10px;
    border-bottom: 2px solid #f0f0f0;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    position: relative;
    top: 2px;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: bold;
}

/* Tab内容区域 */
.tab-content {
    min-height: 400px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 汉字位置信息 */
.hanzi-position {
    font-size: 9px;
    color: #999;
    margin-top: 2px;
    font-family: monospace;
}

.hanzi-item.selected .hanzi-position {
    color: rgba(255, 255, 255, 0.7);
}

/* 关卡数设置区域 */
.level-limit-section {
    margin: 20px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 12px;
}

.section-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.level-limit-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
}

.radio-option input[type="radio"] {
    cursor: pointer;
}

.radio-option input[type="number"] {
    width: 80px;
    padding: 4px 8px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    text-align: center;
}

.radio-option input[type="number"]:enabled {
    border-color: var(--primary-color);
}

.radio-option input[type="number"]:disabled {
    background: #f5f5f5;
    color: #999;
}

/* 庆祝画面 */
.celebration-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    color: white;
    position: relative;
    overflow: hidden;
    animation: celebrationPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes celebrationPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.celebration-title {
    font-size: 36px;
    font-weight: bold;
    margin-bottom: 20px;
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.celebration-emoji {
    font-size: 48px;
    margin-bottom: 30px;
    animation: pulse-scale 1.5s ease-in-out infinite;
}

@keyframes pulse-scale {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.celebration-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 30px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.2);
    padding: 20px;
    border-radius: 12px;
    min-width: 120px;
}

.stat-label {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: bold;
}

.celebration-message {
    font-size: 20px;
    margin-bottom: 30px;
    opacity: 0.95;
}

.celebration-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.celebration-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.celebration-btn.btn-primary {
    background: white;
    color: #667eea;
}

.celebration-btn.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
}

.celebration-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* 烟花动画 */
.fireworks-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.firework {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    animation: fireworkExplode 1s ease-out forwards;
}

@keyframes fireworkExplode {
    0% {
        transform: translate(0, 0);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty));
        opacity: 0;
    }
}

/* 手机端适配 */
@media (max-width: 480px) {
    .celebration-content {
        padding: 30px 20px;
    }
    
    .celebration-title {
        font-size: 28px;
    }
    
    .celebration-emoji {
        font-size: 36px;
    }
    
    .celebration-stats {
        flex-direction: column;
        gap: 15px;
    }
    
    .stat-item {
        min-width: auto;
    }
    
    .celebration-message {
        font-size: 16px;
    }
    
    .celebration-buttons {
        flex-direction: column;
    }
    
    .celebration-btn {
        width: 100%;
    }
    
    .level-limit-options {
        font-size: 13px;
    }
    
    .radio-option input[type="number"] {
        width: 60px;
    }
}
/* iPad Landscape / Short Screen Optimization for Home Page */
@media screen and (max-height: 850px) {
  .title {
    font-size: 28px;
    margin-bottom: 10px;
  }
  
  .game-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Change to 3 columns */
    gap: 12px; 
    margin-bottom: 15px;
  }
  
  /* Reset last child behavior or adjust for 3 cols */
  .game-buttons .game-button:last-child {
    grid-column: span 3; /* Span full width (3 cols) */
    max-width: 100%; /* Allow full width or keep centered max-width if desired, usually full looks better in compact grid or standard button look */
    /* If we want it to look like others but centered, or just a bar. 
       Let's keep max-width smallish or let it fill?
       The user wants to save height. 
       Row 1: 3
       Row 2: 3
       Row 3: 1 (Random)
       This saves 1 row of height compared to 2-2-2-1.
    */
    max-width: 400px;
  }

  .game-button {
    padding: 12px 5px; /* Further reduce padding */
    gap: 4px;
    height: 100px; /* Force consistent smaller height */
    justify-content: center;
  }
  
  .button-icon {
    font-size: 28px; /* Further reduce icon */
    margin-bottom: 0;
  }
  
  .button-text {
    font-size: 15px;
  }
  
  .container {
    padding: 15px 20px; /* Further compress padding */
    max-width: 700px; /* Allow wider container to fit 3 cols nicely */
  }

  .star-display {
      margin-bottom: 10px;
      padding: 2px 10px;
  }
  
  .settings-btn {
      width: 40px;
      height: 40px;
      font-size: 20px;
      top: 10px;
      right: 10px;
  }
}
