/* Modern Mobile-First CSS for Ragam Geometris Nusantara */
:root {
  --primary: #9a3412;        /* Terracotta Warmth */
  --primary-light: #c2410c;
  --primary-dark: #7c2d12;
  --accent: #d97706;         /* Golden Amber */
  --accent-light: #f59e0b;
  --bg-page: #fbf9f5;        /* Warm cream background */
  --bg-card: #ffffff;
  --bg-muted: #f4ede4;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border: #e7ded4;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(154, 52, 18, 0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(154, 52, 18, 0.12), 0 8px 10px -6px rgba(0,0,0,0.05);
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  padding-bottom: 40px;
  overflow-x: hidden;
}

/* Header Styles */
.app-header {
  background: linear-gradient(135deg, #7c2d12 0%, #9a3412 60%, #b45309 100%);
  color: #fff;
  padding: 14px 16px 8px;
  box-shadow: 0 4px 20px rgba(124, 45, 18, 0.25);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

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

.brand-icon {
  font-size: 1.8rem;
  background: rgba(255, 255, 255, 0.18);
  padding: 6px;
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

.brand-text h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.brand-text .subtitle {
  font-size: 0.72rem;
  opacity: 0.9;
  letter-spacing: 0.02em;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.05);
}

/* Gamification Progress Bar in Header */
.gamify-bar {
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.level-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  padding-right: 8px;
}

.badge-icon {
  font-size: 1.4rem;
}

.badge-info {
  display: flex;
  flex-direction: column;
}

.level-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
}

.level-num {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fef08a;
}

.progress-wrap {
  flex: 1;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.star-text {
  color: #fef08a;
}

.xp-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 99px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #facc15 0%, #fb923c 100%);
  border-radius: 99px;
  transition: width 0.4s ease-out;
}

/* Nav Tabs */
.nav-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: rgba(0, 0, 0, 0.18);
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav-tab {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.82);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.nav-tab .tab-emoji {
  font-size: 1.1rem;
}

.nav-tab.active {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-weight: 700;
}

/* Main Container */
.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 14px;
}

.tab-content {
  display: none;
}

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

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

.section-hero {
  margin-bottom: 16px;
  text-align: center;
}

.section-hero h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: var(--primary-dark);
  font-weight: 700;
  margin-bottom: 4px;
}

.section-hero p {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

/* Motif Chips */
.motif-chips {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (min-width: 600px) {
  .motif-chips {
    grid-template-columns: repeat(4, 1fr);
  }
}

.motif-chip {
  background: var(--bg-muted);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  font-family: var(--font-sans);
}

.motif-chip .chip-icon {
  font-size: 1.4rem;
}

.motif-chip strong {
  display: block;
  font-size: 0.82rem;
  color: var(--text-main);
}

.motif-chip small {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.motif-chip.active {
  background: #fff7ed;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(154, 52, 18, 0.15);
}

.motif-chip.active strong {
  color: var(--primary-dark);
}

/* Palette Card */
.palette-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.harmony-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  border: 1px solid #fde68a;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  width: 42px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  border-radius: 34px;
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Palette Preset Buttons */
.palette-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

@media (min-width: 600px) {
  .palette-presets {
    grid-template-columns: repeat(4, 1fr);
  }
}

.palette-btn {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.palette-swatches {
  display: flex;
  gap: 3px;
  width: 100%;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
}

.palette-swatches span {
  flex: 1;
  height: 100%;
}

.palette-btn .p-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-main);
}

.palette-btn.active {
  border-color: var(--primary);
  background: #fff7ed;
  box-shadow: 0 0 0 2px rgba(154, 52, 18, 0.15);
}

.palette-btn.active .p-name {
  color: var(--primary-dark);
}

/* Active Swatches & Custom Picker */
.color-picker-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.sub-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
}

.swatch-list {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.swatch-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1.5px #cbd5e1;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.swatch-dot:hover {
  transform: scale(1.15);
}

.swatch-dot.active {
  transform: scale(1.18);
  box-shadow: 0 0 0 2.5px var(--primary), 0 2px 6px rgba(0,0,0,0.2);
}

.custom-color-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.custom-color-btn input[type="color"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  top: 0; left: 0;
}

/* Canvas Area */
.canvas-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #fdfaf6;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}

.canvas-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.dot.live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.canvas-buttons {
  display: flex;
  gap: 6px;
}

.btn-sm {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-sans);
}

.btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text-main);
}

.btn-ghost:hover {
  background: #f1f5f9;
}

.btn-accent {
  background: var(--primary);
  color: #fff;
}

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

/* Canvas Viewport */
.canvas-viewport {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, #ffffff 0%, #faf6f0 100%);
  min-height: 320px;
  user-select: none;
}

.svg-stage {
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.svg-stage svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 6px 12px rgba(154, 52, 18, 0.08));
}

/* SVG Interactive elements */
.svg-stage path, 
.svg-stage polygon, 
.svg-stage circle, 
.svg-stage rect, 
.svg-stage ellipse {
  cursor: pointer;
  transition: fill 0.2s ease, stroke-width 0.2s ease, opacity 0.2s ease;
}

.svg-stage path:hover, 
.svg-stage polygon:hover, 
.svg-stage circle:hover, 
.svg-stage rect:hover, 
.svg-stage ellipse:hover {
  opacity: 0.82;
  filter: brightness(1.1);
}

.canvas-feedback {
  background: #fefce8;
  border-top: 1px solid #fef08a;
  padding: 10px 14px;
  display: flex;
  gap: 10px;
  font-size: 0.78rem;
  color: #854d0e;
}

.feedback-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.feedback-content strong {
  display: block;
  margin-bottom: 2px;
}

/* ==================== TAB 2: QUIZ / MISSION ==================== */
.quiz-card {
  position: relative;
  overflow: hidden;
}

.quiz-top-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.quiz-level-tag {
  background: #ede9fe;
  color: #5b21b6;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  text-transform: uppercase;
}

.quiz-reward-tag {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
}

.quiz-progress-track {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  margin-bottom: 16px;
  overflow: hidden;
}

.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b5cf6, #3b82f6);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.quiz-question-box h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 12px;
}

.quiz-visual-hint {
  display: flex;
  justify-content: center;
  margin: 10px 0 16px;
  background: #f8fafc;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.quiz-options-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-opt-btn {
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
}

.quiz-opt-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #fff7ed;
  transform: translateY(-1px);
}

.quiz-opt-btn .opt-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.quiz-opt-btn.correct {
  border-color: #10b981;
  background: #ecfdf5;
  color: #065f46;
}

.quiz-opt-btn.correct .opt-badge {
  background: #10b981;
  color: #ffffff;
}

.quiz-opt-btn.wrong {
  border-color: #ef4444;
  background: #fef2f2;
  color: #991b1b;
}

.quiz-opt-btn.wrong .opt-badge {
  background: #ef4444;
  color: #ffffff;
}

.quiz-feedback-box {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: var(--radius-md);
  padding: 14px;
  animation: slideUp 0.3s ease;
}

.quiz-feedback-box.incorrect {
  background: #fff1f2;
  border-color: #fecdd3;
}

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

.feedback-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
  color: #166534;
}

.quiz-feedback-box.incorrect .feedback-title {
  color: #9f1239;
}

.quiz-feedback-box p {
  font-size: 0.8rem;
  color: var(--text-main);
  margin-bottom: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(154, 52, 18, 0.2);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(154, 52, 18, 0.25);
}

.quest-summary-card h3 {
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: var(--text-main);
}

.quest-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
}

.q-stat {
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
}

.qs-val {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.qs-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ==================== TAB 3: ENCYCLOPEDIA ==================== */
.encyclopedia-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.motif-info-card {
  padding: 16px;
}

.motif-card-header {
  margin-bottom: 10px;
}

.motif-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.motif-card-header h3 {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--text-main);
}

.motif-preview-svg {
  width: 100%;
  max-width: 220px;
  margin: 8px auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.motif-details p {
  font-size: 0.82rem;
  color: var(--text-main);
  margin-bottom: 8px;
  line-height: 1.5;
}

.color-tip {
  background: #fff7ed;
  border-left: 3px solid var(--primary);
  padding: 8px 10px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.78rem;
  color: #7c2d12;
  margin-top: 10px;
}

.color-tip strong {
  display: block;
  margin-bottom: 2px;
}

/* ==================== TAB 4: PROFILE & BADGES ==================== */
.student-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border-color: #fed7aa;
}

.student-avatar {
  font-size: 2.8rem;
  background: #ffffff;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.student-details h3 {
  font-size: 1.05rem;
  color: var(--primary-dark);
  font-weight: 700;
}

.student-details p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.student-badges-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: #b45309;
}

/* Badge Grid */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.badge-item {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  transition: all 0.2s ease;
}

.badge-item.unlocked {
  background: #ffffff;
  border-color: #f59e0b;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.15);
}

.badge-item.locked {
  background: #f1f5f9;
  border-color: #cbd5e1;
  opacity: 0.55;
  filter: grayscale(1);
}

.badge-ico {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.badge-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.badge-desc {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.25;
}

/* Share / Report Area */
.share-box {
  margin-top: 10px;
}

.report-textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: monospace;
  font-size: 0.76rem;
  background: #f8fafc;
  color: var(--text-main);
  resize: none;
  margin-bottom: 10px;
}

.share-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-ghost {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 999;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast.hidden {
  opacity: 0;
  transform: translate(-50%, 20px);
}

/* Canvas Confetti */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1000;
}

.hidden {
  display: none !important;
}
