:root {
  --primary: #4F46E5;
  --gold: #F59E0B;
  --gold-light: #FDE68A;
  --bg-sky: #ECFDF5;
  --text-dark: #1E293B;
  --radius-xl: 24px;
  --shadow-node: 0 12px 24px -6px rgba(0,0,0,0.15), 0 4px 8px rgba(0,0,0,0.06);
}

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

body {
  font-family: "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-dark);
  background: #F0F9FF;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.4s ease;
}

/* Biome Themes */
body.theme-1 { background: linear-gradient(180deg, #E0F2FE 0%, #BAE6FD 40%, #FEF3C7 100%); }
body.theme-2 { background: linear-gradient(180deg, #D1FAE5 0%, #A7F3D0 50%, #E0F2FE 100%); }
body.theme-3 { background: linear-gradient(180deg, #EDE9FE 0%, #DDD6FE 50%, #F5D0FE 100%); }
body.theme-4 { background: linear-gradient(180deg, #FEF3C7 0%, #FDE68A 50%, #FED7AA 100%); }
body.theme-5 { background: linear-gradient(180deg, #DBEAFE 0%, #BFDBFE 50%, #C7D2FE 100%); }
body.theme-6 { background: linear-gradient(180deg, #1E1B4B 0%, #312E81 50%, #4C1D95 100%); color: #F8FAFC; }

/* Top Header Bar */
.map-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 2px solid rgba(0, 0, 0, 0.06);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
body.theme-6 .map-header {
  background: rgba(15, 23, 42, 0.88);
  border-bottom-color: rgba(255, 255, 255, 0.1);
  color: white;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  font-size: 28px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.15));
  animation: floatIcon 3s ease-in-out infinite alternate;
}
@keyframes floatIcon {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-3px) rotate(6deg); }
}

.brand-title {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.5px;
}
.brand-sub {
  font-size: 11px;
  font-weight: 700;
  color: #64748B;
  display: block;
}
body.theme-6 .brand-sub { color: #94A3B8; }

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

.stat-pill {
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 20px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.stat-pill:active { transform: scale(0.95); }
body.theme-6 .stat-pill {
  background: #1E293B;
  border-color: #334155;
  color: white;
}

.icon-btn {
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
body.theme-6 .icon-btn {
  background: #1E293B;
  border-color: #334155;
}

/* Stage Selector Tabs */
.stage-tabs-wrapper {
  overflow-x: auto;
  scrollbar-width: none;
  padding: 12px 16px 6px;
  display: flex;
  justify-content: flex-start;
  position: relative;
  z-index: 20;
}
.stage-tabs-wrapper::-webkit-scrollbar { display: none; }

.stage-tabs {
  display: flex;
  gap: 8px;
  margin: 0 auto;
}

.stage-tab {
  border: none;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  border-radius: 18px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  color: #475569;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  white-space: nowrap;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
body.theme-6 .stage-tab {
  background: rgba(30, 41, 59, 0.7);
  color: #CBD5E1;
}

.stage-tab.active {
  background: #FFFFFF;
  color: #1E293B;
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
  border: 2px solid var(--tab-color, #4F46E5);
}
body.theme-6 .stage-tab.active {
  background: #0F172A;
  color: #FFFFFF;
}

/* Adventure Map Canvas */
.map-viewport {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 20px 100px;
  min-height: 80vh;
}

.trail-container {
  position: relative;
  width: 100%;
}

/* SVG Winding Path */
.trail-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}
.trail-path-bg {
  stroke: rgba(255, 255, 255, 0.6);
  stroke-width: 16;
  stroke-linecap: round;
  fill: none;
}
.trail-path-line {
  stroke: var(--gold);
  stroke-width: 6;
  stroke-dasharray: 10 12;
  stroke-linecap: round;
  fill: none;
  animation: dashMove 20s linear infinite;
}
@keyframes dashMove {
  to { stroke-dashoffset: -1000; }
}

/* Level Nodes */
.level-nodes {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.level-row {
  display: flex;
  align-items: center;
  position: relative;
}
.level-row.left { justify-content: flex-start; padding-left: 20px; }
.level-row.center { justify-content: center; }
.level-row.right { justify-content: flex-end; padding-right: 20px; }

.level-node-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.level-node-card:active {
  transform: scale(0.92);
}

.node-bubble {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 4px solid #FFFFFF;
  box-shadow: var(--shadow-node);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: all 0.25s ease;
}
.level-node-card:hover .node-bubble {
  transform: scale(1.08);
  box-shadow: 0 16px 32px rgba(245, 158, 11, 0.4);
}

.node-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.level-badge-num {
  position: absolute;
  top: -4px;
  left: -4px;
  background: var(--gold);
  color: white;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.level-stars {
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 2px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.node-title-label {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  max-width: 100px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 8px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
body.theme-6 .node-title-label {
  background: rgba(15, 23, 42, 0.85);
  color: white;
}

/* Current active level marker */
.current-avatar {
  position: absolute;
  top: -24px;
  font-size: 26px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.25));
  animation: jumpAvatar 1.2s ease-in-out infinite alternate;
}
@keyframes jumpAvatar {
  0% { transform: translateY(0); }
  100% { transform: translateY(-10px); }
}

/* Modal Popup: Mission Briefing Card */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.mission-card {
  background: #FFFFFF;
  border-radius: var(--radius-xl);
  max-width: 360px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 24px 48px -12px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.show .mission-card {
  transform: translateY(0) scale(1);
}

.card-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: #F1F5F9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.mission-cover {
  width: 160px;
  height: 190px;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: 0 12px 24px -6px rgba(0,0,0,0.25);
  border: 4px solid #FFFFFF;
  margin-bottom: 16px;
}

.mission-stage-badge {
  background: #EEF2FF;
  color: #4F46E5;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
}

.mission-title {
  font-size: 20px;
  font-weight: 900;
  color: #0F172A;
  text-align: center;
  margin-bottom: 6px;
}

.mission-meta {
  font-size: 13px;
  color: #64748B;
  margin-bottom: 18px;
}

.btn-start-reading {
  width: 100%;
  background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
  color: white;
  border: none;
  border-radius: 18px;
  padding: 14px 20px;
  font-size: 17px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(217, 119, 6, 0.4);
  transition: transform 0.15s ease;
}
.btn-start-reading:active {
  transform: scale(0.96);
}

/* Embedded Picture Book Reader View */
.reader-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #FDFBF7;
  z-index: 200;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.reader-modal.show {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.reader-header {
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-back-map {
  background: #F1F5F9;
  border: none;
  padding: 8px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 800;
  color: #334155;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.reader-book-title {
  font-size: 16px;
  font-weight: 900;
}

.reader-controls-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reader-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
}

.reader-book-stage {
  max-width: 540px;
  width: 100%;
  aspect-ratio: 1000 / 1140;
  background: white;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.15);
  overflow: hidden;
  position: relative;
}

.reader-page-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.reader-dock {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 580px;
  margin: 0 auto;
  width: 100%;
  border-radius: 24px 24px 0 0;
}

.reader-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 12px;
}
.reader-btn:disabled { opacity: 0.3; }

.reader-play-main {
  background: #4F46E5;
  color: white;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
  margin-top: -18px;
}
.reader-play-main:active { transform: scale(0.92); }

/* Confetti Celebration */
.celebration-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 300;
  pointer-events: none;
  display: none;
  align-items: center;
  justify-content: center;
}
.celebration-overlay.show {
  display: flex;
  pointer-events: auto;
}
.celebration-box {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 28px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 32px 64px rgba(0,0,0,0.3);
  max-width: 340px;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
