﻿:root {
  --primary: #4f46e5;
  --primary-light: #e0e7ff;
  --primary-dark: #3730a3;
  --accent: #06b6d4;
  --accent-light: #cffafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 25px -5px rgba(79, 70, 229, 0.1), 0 8px 10px -6px rgba(79, 70, 229, 0.1);
}

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

body {
  font-family: 'Fredoka', 'Noto Sans TC', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: white;
  border-bottom: 2px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2.2rem;
}

.logo-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.logo-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Status Bar */
.user-status-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-box {
  background: var(--bg-main);
  padding: 0.4rem 0.8rem;
  border-radius: 50px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.offline {
  background: var(--text-muted);
}

/* Navigation Steps */
.step-nav {
  display: flex;
  background: white;
  padding: 0.5rem 2rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  overflow-x: auto;
}

.step-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  background: transparent;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  transition: all 0.2s;
  white-space: nowrap;
}

.step-btn .step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.step-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

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

.step-btn.active .step-num {
  background: white;
  color: var(--primary);
}

/* Main Container */
.main-container {
  max-width: 1160px;
  margin: 1.5rem auto;
  padding: 0 1rem;
  flex: 1;
  width: 100%;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* Section Hero */
.section-hero {
  text-align: center;
  margin-bottom: 2rem;
}

.section-hero h2 {
  font-size: 1.8rem;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.section-hero p {
  color: var(--text-muted);
  font-size: 1rem;
}

/* Units Grid */
.units-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.5rem;
}

.unit-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s;
}

.unit-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.unit-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.unit-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
}

.unit-emoji {
  font-size: 1.5rem;
}

.unit-header h3 {
  font-size: 1.15rem;
  color: var(--text-main);
}

/* Pattern Box */
.pattern-box {
  background: #f1f5f9;
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.pattern-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.pattern-item:last-child {
  margin-bottom: 0;
}

.pattern-item .tag {
  background: white;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.highlight {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 700;
}

.audio-btn {
  background: white;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  margin-left: auto;
  transition: transform 0.1s;
}

.audio-btn:hover {
  transform: scale(1.15);
  background: var(--primary-light);
}

/* Interactive Area */
.interactive-area {
  background: white;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-top: auto;
}

.input-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.live-sentence {
  margin-top: 0.8rem;
  padding: 0.6rem;
  background: #f0fdf4;
  border-left: 4px solid var(--success);
  border-radius: 4px;
  font-size: 0.9rem;
  color: #166534;
  font-weight: 600;
}

/* Slider Component */
.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
  height: 8px;
  border-radius: 4px;
  cursor: pointer;
}

.slider-min, .slider-max {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.slider-feedback {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.4rem 0;
}

.cake-display {
  font-size: 1.1rem;
}

.age-word-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Dropdown row */
.dropdown-row {
  display: flex;
  gap: 0.5rem;
}

/* Chips */
.pill-chips, .pill-chips-small {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  background: #f1f5f9;
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: 50px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}

.chip:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Drag and Drop Styling */
.dnd-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.draggable-source {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.drag-tag {
  background: white;
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  cursor: grab;
  font-size: 0.85rem;
  font-weight: 500;
  user-select: none;
  transition: transform 0.15s, background-color 0.15s;
}

.drag-tag:active {
  cursor: grabbing;
}

.drag-tag:hover {
  background: #f8fafc;
  transform: translateY(-2px);
}

.drop-target-box {
  min-height: 60px;
  border: 2px dashed #94a3b8;
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: #f8fafc;
  transition: background 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.drop-target-box.drag-over {
  background: var(--accent-light);
  border-color: var(--accent);
}

.drop-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.7rem;
}

.selected-hobbies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.selected-chip {
  background: var(--accent-light);
  color: #0e7490;
  border: 1px solid #67e8f9;
  padding: 0.25rem 0.6rem;
  border-radius: 50px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 600;
}

.remove-chip-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #0e7490;
  font-weight: bold;
}

/* Favorites selector */
.fav-selector-group {
  margin-bottom: 0.5rem;
}

.fav-label {
  font-size: 0.85rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

/* TAB 2: Builder & Student ID Card */
.builder-layout {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
}

.id-card-wrap {
  width: 100%;
  max-width: 650px;
}

.student-id-card {
  background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
  border: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 15px 35px -5px rgba(79, 70, 229, 0.15);
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.student-id-card::before {
  content: "A1 PASSPORT";
  position: absolute;
  top: 15px;
  right: -30px;
  background: var(--warning);
  color: white;
  padding: 4px 35px;
  transform: rotate(45deg);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.card-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px dashed #cbd5e1;
  padding-bottom: 0.8rem;
  margin-bottom: 1.2rem;
}

.badge-school {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.95rem;
}

.badge-class {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 700;
}

.card-avatar-area {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  margin-bottom: 1.5rem;
}

.avatar-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fef08a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  border: 3px solid white;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.avatar-info h3 {
  font-size: 1.5rem;
  color: var(--text-main);
}

.avatar-info p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card-intro-content {
  background: white;
  border-radius: var(--radius-sm);
  padding: 1.2rem;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  margin-bottom: 1.2rem;
}

.card-intro-content h4 {
  font-size: 0.9rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.intro-paragraph {
  font-size: 1.05rem;
  line-height: 1.8;
  color: #334155;
}

.card-footer-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag-chip {
  background: white;
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1.5rem;
  justify-content: center;
}

/* TAB 3: Quizzes */
.quiz-container {
  max-width: 750px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.quiz-box {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.quiz-badge {
  display: inline-block;
  background: var(--accent-light);
  color: #0891b2;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  margin-bottom: 0.8rem;
}

.quiz-title {
  font-size: 1.15rem;
  margin-bottom: 1rem;
}

.quiz-audio-trigger {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: #f8fafc;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.option-btn {
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.option-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.option-btn.correct {
  background: var(--success-light);
  border-color: var(--success);
  color: #065f46;
}

.option-btn.wrong {
  background: #fee2e2;
  border-color: var(--danger);
  color: #991b1b;
}

.quiz-feedback {
  margin-top: 0.8rem;
  font-weight: 600;
  font-size: 0.95rem;
}

/* Scramble styling */
.scramble-slot {
  min-height: 50px;
  background: #f1f5f9;
  border: 2px dashed #94a3b8;
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.slot-placeholder {
  color: #94a3b8;
  font-size: 0.9rem;
}

.scramble-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.word-chip {
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 0.4rem 0.8rem;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  transition: transform 0.15s;
}

.word-chip:hover {
  transform: scale(1.08);
  background: var(--primary-light);
}

.word-chip.used {
  opacity: 0.3;
  pointer-events: none;
}

.scramble-controls {
  display: flex;
  gap: 0.5rem;
}

.quiz-submit-card {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  padding: 1.5rem;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.quiz-submit-card h3 {
  font-size: 1.4rem;
  margin-bottom: 0.3rem;
}

.quiz-submit-card p {
  opacity: 0.9;
  margin-bottom: 1rem;
}

/* TAB 4: Dashboard Table */
.class-filter-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  background: white;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.table-responsive {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.dashboard-table th, .dashboard-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.dashboard-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
}

.dashboard-table tr:hover {
  background: #f8fafc;
}

.text-center {
  text-align: center;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1.05rem;
  border-radius: 50px;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

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

.btn-accent:hover {
  background: #0891b2;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

.btn-outline {
  background: white;
  border: 1px solid var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-main);
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--danger);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-card.modal-lg {
  max-width: 700px;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.5rem;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.2rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* History List */
.history-list {
  list-style: none;
  margin-bottom: 1.5rem;
}

.history-list li {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #1e293b;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.3s;
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.save-status-msg {
  margin-top: 0.8rem;
  font-weight: 600;
  font-size: 0.9rem;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  background: white;
  margin-top: auto;
}

@media (max-width: 640px) {
  .app-header {
    padding: 0.8rem 1rem;
  }
  .units-grid {
    grid-template-columns: 1fr;
  }
  .quiz-options {
    grid-template-columns: 1fr;
  }
  .card-avatar-area {
    flex-direction: column;
    text-align: center;
  }
}
