/* English Learning Zone - Common Styles */
/* 多主题系统，移动优先，触摸友好，适合人类使用 */

/* Base Variables */
:root {
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --font-main: 'Nunito', 'Quicksand', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: var(--font-main);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.22s ease;
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
}

/* Theme: Playful (Default) */
:root[data-theme="playful"] {
  --bg-primary: #fdf8f5;
  --bg-primary-subtle: #fbeee6;
  --bg-card: #ffffff;
  --bg-card-hover: #fcfcfc;
  --bg-input: #f0f0f5;
  --text-primary: #2d3748;
  --text-secondary: #718096;
  --text-muted: #a0aec0;
  --accent: var(--game-color, #ff6b6b);
  --accent-soft: rgba(255, 107, 107, 0.15);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.1);
  --border-color: rgba(0, 0, 0, 0.05);
  --btn-shadow: 0 4px 0 var(--accent-soft);
  --bg-glass: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.5);
  --icon-bg: #fff0f0;
}

/* Theme: Sleek Dark */
:root[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-primary-subtle: #16162a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #22223a;
  --bg-input: #0f3460;
  --text-primary: #f0f0f5;
  --text-secondary: #a8a8b8;
  --text-muted: #6e6e82;
  --accent: var(--game-color, #5b9cf5);
  --accent-soft: rgba(91, 156, 245, 0.15);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.3);
  --border-color: rgba(255, 255, 255, 0.06);
  --btn-shadow: 0 4px 12px var(--accent-soft);
  --bg-glass: rgba(26, 26, 46, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --icon-bg: rgba(91, 156, 245, 0.1);
}

/* Theme: Clean Light */
:root[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-primary-subtle: #eaeaea;
  --bg-card: #ffffff;
  --bg-card-hover: #f9f9f9;
  --bg-input: #efefef;
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --text-muted: #a1a1a6;
  --accent: var(--game-color, #0066cc);
  --accent-soft: rgba(0, 102, 204, 0.15);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06);
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.08);
  --border-color: rgba(0, 0, 0, 0.06);
  --btn-shadow: 0 2px 8px var(--accent-soft);
  --bg-glass: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(0, 0, 0, 0.05);
  --icon-bg: rgba(0, 102, 204, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ---- Game Header ---- */
.game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.game-nav {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.game-header .back-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text-primary);
  font-size: 20px; cursor: pointer; border-radius: 50%;
}
.game-header .back-btn:active { background: rgba(255,255,255,0.1); }

.game-header h1 {
  font-size: 18px; font-weight: 600;
  flex: 1;
}

.game-header .level-badge {
  font-size: 12px; padding: 2px 8px;
  background: var(--accent); color: #fff;
  border-radius: 10px; font-weight: 600;
}

.game-nav-tail {
  width: 36px;
  height: 36px;
  display: inline-flex;
  flex-shrink: 0;
}

.game-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.game-username {
  font-size: 13px;
  opacity: .8;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary, #aaa);
}

#game-logout-btn {
  font-size: 16px;
}

/* ---- Container ---- */
.game-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  min-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 12px 24px;
  border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all var(--transition-fast);
  color: #fff; background: var(--accent);
  -webkit-user-select: none; user-select: none;
  box-shadow: var(--btn-shadow);
}
.btn:hover { transform: translateY(-2px) scale(1.02); filter: brightness(1.05); box-shadow: 0 8px 20px var(--accent-soft); }
.btn:active { transform: translateY(1px); filter: brightness(0.9); box-shadow: none; }
.btn:disabled { opacity: 0.5; pointer-events: none; filter: grayscale(1); box-shadow: none; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
  box-shadow: none;
}
.btn-outline:hover { background: var(--accent-soft); }

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  box-shadow: none;
  transition: all var(--transition-fast);
}
.btn-ghost:hover { background: var(--bg-input); color: var(--text-primary); border-color: var(--border-color); transform: translateY(-1px) scale(1.03); }

.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 14px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
.btn-success { background: var(--success); box-shadow: 0 4px 12px rgba(52, 211, 153, 0.2); }
.btn-error { background: var(--error); box-shadow: 0 4px 12px rgba(248, 113, 113, 0.2); }

/* ---- Cards ---- */
.card {
  background: var(--bg-glass);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background-color var(--transition-normal), border-color var(--transition-normal), box-shadow var(--transition-normal);
}

/* ---- Score Bar ---- */
.score-bar {
  display: flex; justify-content: space-around;
  padding: 12px; background: var(--bg-card);
  border-radius: var(--radius); margin-bottom: 16px;
}
.score-bar .stat { text-align: center; }
.score-bar .stat-value { font-size: 24px; font-weight: 700; color: var(--accent); }
.score-bar .stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px; max-width: 400px; width: 100%;
  text-align: center;
}
.modal h2 { font-size: 22px; margin-bottom: 12px; }
.modal p { color: var(--text-secondary); margin-bottom: 20px; }

/* ---- Timer ---- */
.timer {
  font-size: 14px; color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.timer.urgent { color: var(--error); font-weight: 600; }

/* ---- TTS Button ---- */
.tts-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-input); border: none;
  border-radius: 50%; cursor: pointer; color: var(--text-secondary);
  font-size: 16px; flex-shrink: 0;
}
.tts-btn:active { background: var(--border-color); }

/* ---- Progress Bar ---- */
.progress-bar {
  height: 4px; background: var(--bg-input);
  border-radius: 2px; overflow: hidden;
}
.progress-bar .fill {
  height: 100%; background: var(--accent);
  transition: width 0.3s ease;
}

/* ---- Utilities ---- */
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }

/* ---- Hub Game Grid ---- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.game-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-decoration: none; color: inherit;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), border-color var(--transition-normal), box-shadow var(--transition-normal), background-color var(--transition-normal);
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 12px;
  position: relative;
  overflow: hidden;
  animation: elz-fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
@keyframes elz-fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.game-card:hover { 
  transform: translateY(-6px) scale(1.01); 
  border-color: var(--accent); 
  box-shadow: var(--shadow-card);
  background: var(--bg-card-hover);
}
.game-card:hover::before { opacity: 1; }
.game-card:active { transform: translateY(0) scale(0.98); box-shadow: var(--shadow-sm); }
.game-card .game-icon { 
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--icon-bg);
  color: var(--accent);
  transition: transform var(--transition-normal), background-color var(--transition-normal);
}
.game-card .game-icon svg {
  width: 32px;
  height: 32px;
}
.game-card:hover .game-icon { transform: scale(1.1) rotate(2deg); }
.game-card .game-name { font-size: 16px; font-weight: 700; letter-spacing: 0.3px; z-index: 1; }
.game-card .game-desc { font-size: 13px; color: var(--text-secondary); z-index: 1; font-weight: 500; }
.game-card .game-tags {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; z-index: 1;
}
.game-card .tag {
  font-size: 11px; font-weight: 600; padding: 4px 10px;
  border-radius: var(--radius-pill); background: var(--bg-input);
  color: var(--text-secondary); border: 1px solid var(--border-color);
  transition: background-color var(--transition-normal), color var(--transition-normal);
}
.game-card:hover .tag {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Responsive ---- */
@media (min-width: 768px) {
  .game-grid { grid-template-columns: repeat(3, 1fr); }
  .game-container { max-width: 700px; padding: 24px; }
}

/* ---- Hub Specific Layout ---- */
.hub-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px; padding: 0 8px; flex-wrap: wrap; gap: 16px;
}
.hub-title-area { flex: 1; min-width: 260px; }
.hub-actions {
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.user-greeting {
  font-size: 15px; color: var(--text-secondary);
}
.user-greeting .user-name {
  color: var(--text-primary); font-weight: 600;
}
.action-buttons {
  display: flex; gap: 8px;
}
.action-buttons .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 12px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600; text-decoration: none;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-primary); cursor: pointer; transition: var(--transition-fast);
}
.action-buttons .btn-ghost:hover {
  background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.15);
  transform: translateY(-1px);
}
.action-buttons .btn-ghost.icon-only { padding: 6px 10px; font-size: 15px; }

.dashboard-card {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px; padding: 24px 28px; flex-wrap: wrap; gap: 16px;
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-primary-subtle) 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}
.dashboard-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.dashboard-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 100%);
  pointer-events: none;
}
.level-info { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.level-info .muted { font-size: 14px; font-weight: 500; letter-spacing: 0.2px; }

@media (max-width: 600px) {
  .dashboard-card { flex-direction: column; align-items: flex-start; }
}
.page { max-width: 980px; margin: 0 auto; padding: 24px 16px 40px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 15px; font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px var(--accent-soft);
}
.title { font-size: 32px; font-weight: 800; letter-spacing: -0.8px; margin: 0 0 8px; line-height: 1.2; }
.subtitle { font-size: 16px; margin: 0; color: var(--text-secondary); line-height: 1.5; font-weight: 500; }

/* Custom Checkbox Toggle (iOS Style) */
.toggle-switch {
  display: inline-flex; align-items: center; gap: 12px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: relative; width: 52px; height: 32px;
  background: var(--bg-input); border-radius: var(--radius-pill);
  transition: all var(--transition-normal);
  border: 2px solid transparent;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
}
.toggle-slider::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: transform var(--transition-normal), width var(--transition-fast);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.toggle-switch input:active + .toggle-slider::after { width: 30px; }
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::after { transform: translateX(20px); }
.toggle-switch input:checked:active + .toggle-slider::after { transform: translateX(14px); width: 30px; }
.toggle-label { font-size: 15px; font-weight: 700; color: var(--text-primary); user-select: none; }

.button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
  padding: 10px 16px; font-weight: 600; font-size: 15px;
  cursor: pointer; transition: all var(--transition-fast);
  box-shadow: 0 2px 8px var(--accent-soft);
}
.button:hover { transform: translateY(-1px); filter: brightness(1.1); box-shadow: 0 4px 12px var(--accent-soft); }
.button:active { transform: translateY(1px); filter: brightness(0.9); }
.button.ghost {
  background: transparent; box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}
.button.ghost:hover { background: rgba(255, 255, 255, 0.05); }

/* ---- Help Button & Modal ---- */
.help-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.1); border: none;
  border-radius: 50%; cursor: pointer;
  color: var(--text-primary); font-size: 18px; font-weight: 700;
  flex-shrink: 0; transition: background 0.15s;
}
.help-btn:active { background: rgba(255,255,255,0.2); }
.help-modal-body { text-align: left; }
.help-modal-body h3 {
  font-size: 15px; color: var(--accent);
  margin: 14px 0 6px; font-weight: 600;
}
.help-modal-body h3:first-child { margin-top: 0; }
.help-modal-body p,
.help-modal-body li {
  font-size: 14px; color: var(--text-secondary);
  line-height: 1.6; margin: 0;
}
.help-modal-body ul {
  padding-left: 18px; margin: 4px 0 8px;
  list-style: disc;
}
.help-modal-body .help-keys {
  display: inline-block; padding: 2px 8px;
  background: rgba(255,255,255,0.1); border-radius: 4px;
  font-size: 12px; font-family: monospace; color: var(--text-primary);
}

/* =====================================================
   Celebration Animations (game-kit.js celebrate.*)
   ===================================================== */

/* ----- confetti ----- */
.elz-confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.elz-confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0;
  animation: elz-confetti-fall 1.5s ease-out forwards;
}
.elz-confetti.circle  { border-radius: 50%; }
.elz-confetti.square  { border-radius: 2px; }
.elz-confetti.ribbon  { width: 4px; height: 16px; border-radius: 2px; }

@keyframes elz-confetti-fall {
  0%   { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg) scale(0.5); }
}

/* ----- particle burst ----- */
.elz-particle {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  animation: elz-particle-burst 0.55s ease-out forwards;
}

@keyframes elz-particle-burst {
  from { opacity: 1; transform: translate(-50%, -50%) translate3d(0,0,0) scale(1); }
  to   { opacity: 0; transform: translate(-50%, -50%) translate3d(var(--dx), var(--dy), 0) scale(0.2); }
}

/* ----- star burst (inside container) ----- */
.elz-star {
  position: absolute;
  width: 12px;
  height: 12px;
  pointer-events: none;
  background: radial-gradient(circle, #fff0ad, #ffd057 60%, #ff9f43 100%);
  clip-path: polygon(50% 0%,63% 35%,100% 35%,71% 57%,82% 100%,50% 74%,18% 100%,29% 57%,0% 35%,37% 35%);
  animation: elz-star-burst 0.95s ease-out forwards;
}

@keyframes elz-star-burst {
  0%   { transform: translate(0,0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(0.9); opacity: 0; }
}

/* ----- emoji rain ----- */
.elz-emoji-particle {
  position: fixed;
  top: -40px;
  pointer-events: none;
  z-index: 9999;
  user-select: none;
  animation: elz-emoji-fall 1.6s ease-in forwards;
}

@keyframes elz-emoji-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: 0; }
}

/* ----- screen fx (game-kit screenFx) ----- */
body.flash-correct {
  animation: elz-flash-correct 0.3s ease-out;
}
@keyframes elz-flash-correct {
  0%,100% { background-color: inherit; }
  40%     { background-color: rgba(34,197,94,0.2); }
}

body.screen-shake {
  animation: elz-screen-shake 0.4s ease-out;
}
@keyframes elz-screen-shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-8px); }
  40%     { transform: translateX(8px); }
  60%     { transform: translateX(-5px); }
  80%     { transform: translateX(5px); }
}
