:root {
  --font-primary: 'Outfit', 'Noto Sans TC', sans-serif;
  
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.85);
  --bg-card-hover: rgba(51, 65, 85, 0.95);
  
  --primary-accent: #6366f1;
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --gold-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  --star-gold: #fbbf24;
  --success-green: #10b981;
  --danger-red: #ef4444;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --glass-border: 1px solid rgba(255, 255, 255, 0.12);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --radius-lg: 16px;
  --radius-md: 12px;
}

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

body {
  font-family: var(--font-primary);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(168, 85, 247, 0.15) 0%, transparent 40%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 1000px;
  min-height: 90vh;
  margin: 20px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: var(--glass-border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top Navigation */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: var(--glass-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.logo-icon {
  font-size: 28px;
}

.brand-title {
  font-size: 22px;
  font-weight: 800;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-tag {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(192, 132, 252, 0.3);
}

.user-stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(30, 41, 59, 0.8);
  border: var(--glass-border);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 14px;
}

.gold-pill { color: #f59e0b; border-color: rgba(245, 158, 11, 0.3); }
.star-pill { color: #fbbf24; border-color: rgba(251, 191, 36, 0.3); }
.food-pill { color: #38bdf8; border-color: rgba(56, 189, 248, 0.3); }

.btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: var(--glass-border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Content Area Panels */
.content-area {
  flex: 1;
  padding: 28px;
  position: relative;
}

.view-panel {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.view-panel.active {
  display: block;
}

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

/* Home Hero Banner */
.hero-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(168, 85, 247, 0.2) 100%);
  border: var(--glass-border);
  padding: 32px;
  border-radius: var(--radius-lg);
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}

.hero-text h1 {
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 8px;
}

.hero-text p {
  color: var(--text-muted);
  font-size: 16px;
}

.hero-decor {
  display: flex;
  gap: 16px;
}

.floating-emoji {
  font-size: 48px;
  animation: float 3s ease-in-out infinite alternate;
}

.e2 { animation-delay: 0.6s; }
.e3 { animation-delay: 1.2s; }

@keyframes float {
  from { transform: translateY(0); }
  to { transform: translateY(-12px); }
}

/* Mode Cards Grid */
.mode-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.mode-card {
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.mode-card:hover {
  transform: translateY(-6px);
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 12px 20px -5px rgba(99, 102, 241, 0.3);
}

.card-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.card-info h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}

.card-info p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.btn-action {
  background: var(--primary-gradient);
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
  align-self: flex-start;
}

.mode-card:hover .btn-action {
  opacity: 0.9;
}

/* Map Level Select View */
.section-header {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.btn-back {
  background: rgba(255, 255, 255, 0.08);
  border: var(--glass-border);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  width: fit-content;
}

.grade-tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.grade-tab {
  background: rgba(255, 255, 255, 0.05);
  border: var(--glass-border);
  color: var(--text-muted);
  padding: 8px 20px;
  border-radius: 20px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.grade-tab.active {
  background: var(--primary-gradient);
  color: white;
  border-color: transparent;
}

.level-nodes-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px;
}

.level-node-card {
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.level-node-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.level-node-card:not(.locked):hover {
  transform: scale(1.05);
  border-color: var(--star-gold);
}

.level-number {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 6px;
}

.level-stars {
  font-size: 14px;
  color: var(--star-gold);
}

/* Battle Game View */
.game-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.game-progress-track {
  flex: 1;
  max-width: 300px;
  height: 14px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  margin: 0 20px;
}

.progress-bar-fill {
  height: 100%;
  width: 10%;
  background: var(--primary-gradient);
  transition: width 0.3s ease;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  font-weight: 800;

}

.timer-badge {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 800;
}

.combo-badge {
  background: rgba(245, 158, 11, 0.2);
  color: #fde047;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 800;
}

.question-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.question-type-tag {
  background: var(--primary-accent);
  color: white;
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
}

.question-display-box {
  width: 100%;
  max-width: 450px;
  height: 240px;
  background: rgba(0, 0, 0, 0.3);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin-bottom: 24px;
}

.question-display-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.question-text-box {
  padding: 20px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 600px;
}

.option-btn {
  background: var(--bg-card);
  border: var(--glass-border);
  color: var(--text-main);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 70px;
}

.option-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary-accent);
  transform: translateY(-2px);
}

.option-btn.correct {
  background: rgba(16, 185, 129, 0.8) !important;
  border-color: #34d399 !important;
}

.option-btn.wrong {
  background: rgba(239, 68, 68, 0.8) !important;
  border-color: #fca5a5 !important;
}

.option-btn img {
  max-height: 90px;
  object-fit: contain;
}

/* Foods Gallery View */
.foods-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
}

.food-card {
  background: var(--bg-card);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  position: relative;
  transition: all 0.25s;
}

.food-card.rarity-common { border-color: #10b981; }
.food-card.rarity-rare { border-color: #3b82f6; }
.food-card.rarity-epic { border-color: #a855f7; }
.food-card.rarity-legendary { border-color: #f59e0b; box-shadow: 0 0 15px rgba(245, 158, 11, 0.3); }

.food-card.locked {
  filter: grayscale(1);
  opacity: 0.6;
}

.food-icon {
  font-size: 56px;
  margin-bottom: 8px;
}

.food-name {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 4px;
}

.food-buff {
  font-size: 12px;
  color: #38bdf8;
  font-weight: 700;
}

/* Dictionary Grid */
.search-bar-box {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

#dict-search-input {
  flex: 1;
  min-width: 200px;
  background: rgba(0, 0, 0, 0.4);
  border: var(--glass-border);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  color: white;
  font-size: 15px;
}

.filter-btn {
  background: rgba(255, 255, 255, 0.08);
  border: var(--glass-border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 700;
}

.filter-btn.active {
  background: var(--primary-accent);
  color: white;
}

.dict-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 6px;
}

.word-card {
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
}

.word-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary-accent);
}

.word-thumb {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
}

.word-info h3 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 2px;
}

.word-tag {
  font-size: 11px;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #1e293b;
  border: var(--glass-border);
  border-radius: 24px;
  padding: 32px;
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.stars-display {
  font-size: 40px;
  margin: 16px 0;
}

.chest-reward-box {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 16px;
  padding: 20px;
  margin: 20px 0;
}

.chest-icon-anim {
  font-size: 64px;
  cursor: pointer;
  animation: bounce 1.5s infinite;
}

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

.modal-footer {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: var(--glass-border);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
}

.detail-img-box {
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  margin-bottom: 12px;
  border-radius: 12px;
}

.btn-tts {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 700;
  cursor: pointer;
  margin: 12px 0;
}
