:root {
  --bg: #f7fafc;
  --bg-panel: #ffffff;
  --bg-panel-2: #f1f5f9;
  --accent: #1CB0F6;
  --accent-2: #FF9933;
  --text: #0f172a;
  --text-dim: #64748b;
  --danger: #e11d48;
  --ok: #6FC04A;
  --border: #e2e8f0;
  --mono: "SF Mono", "Fira Code", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- DesiLingo site header — same branding as the rest of lingodesi.com ---------- */
.dl-site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 56px; flex-shrink: 0; padding: 0 16px;
  background: rgba(255,255,255,0.97); border-bottom: 1px solid #e2e8f0;
  position: sticky; top: 0; z-index: 700; overflow-x: auto; white-space: nowrap;
}
.dl-site-header a { text-decoration: none; }
.dl-site-header-brand {
  display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; color: #0f172a;
  flex-shrink: 0;
}
.dl-site-header-brand img { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.dl-site-header-crumbs { display: flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 700; }
.dl-site-header-crumbs a { padding: 6px 10px; border-radius: 8px; color: #334155; flex-shrink: 0; text-decoration: none; }
.dl-site-header-crumbs a:hover { background: rgba(28,176,246,0.08); color: #0369A1; }
.dl-site-header-crumbs .current { padding: 6px 10px; color: #0369A1; font-weight: 800; flex-shrink: 0; }
.dl-site-header-crumbs .crumb-sep { color: #94a3b8; flex-shrink: 0; }

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */
#sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}

.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.brand-glyph { font-size: 28px; }
.brand h1 { font-size: 18px; margin: 0; }
.brand .tag { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }

#chapter-list { flex: 1; min-height: 0; overflow-y: auto; }

.chapter-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  border: 1px solid transparent;
}
.chapter-link .num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #232d45;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}
.chapter-link.done .num { background: var(--ok); color: #0f1420; }
.chapter-link.active { background: var(--bg-panel-2); border-color: var(--border); color: var(--text); }
.chapter-link.locked { opacity: 0.4; cursor: not-allowed; }
.chapter-link:not(.locked):hover { background: var(--bg-panel-2); }

#level-banner {
  margin: 2px 0 12px;
  padding: 8px 10px;
  font-size: 11px;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#level-banner.level-final {
  color: var(--accent-2);
  border-color: var(--accent-2);
  font-weight: 700;
}
#level-banner.level-professional {
  border-color: #ffcb6b;
  box-shadow: inset 0 0 0 1px rgba(255, 203, 107, 0.35);
}

.progress-wrap { margin-top: 16px; }
.progress-label { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.progress-bar { height: 6px; background: #232d45; border-radius: 4px; overflow: hidden; }
#progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }

.ghost-btn {
  margin-top: 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-dim); }

.sidebar-footer-row { display: flex; gap: 8px; align-items: stretch; }
.sidebar-footer-row .ghost-btn { flex: 1; margin-top: 14px; }

.sound-toggle {
  margin-top: 14px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.sound-toggle:hover { border-color: var(--text-dim); color: var(--text); }
#map-header .sound-toggle {
  margin: 8px 0 0 10px;
  height: 30px;
  vertical-align: middle;
}

/* Main content */
#content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}

#narrative-pane, #puzzle-pane {
  padding: 36px 40px;
  overflow-y: auto;
}

#narrative-pane { background: var(--bg); }
#puzzle-pane { background: var(--bg-panel); border-left: 1px solid var(--border); }

.speaker { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-panel-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.avatar .chapter-badge {
  position: absolute;
  bottom: -4px;
  right: -6px;
  font-size: 14px;
  background: var(--bg-panel);
  border-radius: 50%;
  line-height: 1;
  padding: 1px;
}
.brand-glyph { display: flex; align-items: center; }
.speaker-name { font-weight: 600; font-size: 14px; }
.speaker-role { font-size: 11px; color: var(--text-dim); }

#chapter-title { font-size: 26px; margin: 0 0 16px; }
#chapter-body { font-size: 15px; line-height: 1.7; color: #cfd6e8; }
#chapter-body p { margin: 0 0 14px; }
#chapter-body code, .inline-code {
  font-family: var(--mono);
  background: #232d45;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--accent-2);
}
#chapter-body ul { padding-left: 20px; }
#chapter-body pre {
  background: #0b0f18;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  color: #a8f0d8;
}
.callout {
  border-left: 3px solid var(--accent-2);
  background: rgba(255,203,107,0.08);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-dim);
  margin: 8px 0 0;
}
.callout-details { margin: 16px 0; }
.callout-details summary {
  cursor: pointer; list-style: none; font-size: 16px; width: 30px; height: 30px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,203,107,0.12); border: 1px solid var(--accent-2);
}
.callout-details summary::-webkit-details-marker { display: none; }
.callout-details[open] summary { background: var(--accent-2); }

.chapter-scene {
  margin: 4px 0 18px;
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  animation: sceneFadeIn 0.5s ease both;
}
.chapter-scene svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 420 / 230;
  border-radius: 16px;
}
@keyframes sceneFadeIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.puzzle-header { margin-bottom: 18px; }
.puzzle-tag {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
#puzzle-title { margin: 8px 0 0; font-size: 19px; }

#puzzle-body { font-size: 14px; }

.mcq-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.mcq-option:hover { border-color: var(--accent); }
.mcq-option.selected { border-color: var(--accent); background: rgba(125,227,200,0.1); }

.order-list { list-style: none; padding: 0; margin: 0 0 12px; }
.order-item {
  padding: 10px 14px;
  margin-bottom: 6px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: grab;
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.order-item .handle { color: var(--text-dim); }
.order-item.dragging { opacity: 0.4; }
.order-item.selected { border-color: var(--accent); background: rgba(125,227,200,0.12); }

.fill-row { margin-bottom: 12px; }
.fill-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-family: var(--mono); }
.fill-row input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0b0f18;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}
.fill-row input:focus { outline: none; border-color: var(--accent); }

.trace-code {
  background: #0b0f18;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 13px;
  color: #dbe4ff;
  margin-bottom: 14px;
  overflow-x: auto;
  white-space: pre;
}

.feedback {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
}
.feedback.hidden { display: none; }
.feedback.ok { background: rgba(125,227,200,0.12); border: 1px solid var(--ok); color: var(--ok); }
.feedback.bad { background: rgba(255,107,129,0.1); border: 1px solid var(--danger); color: var(--danger); }

.puzzle-actions { margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.puzzle-actions-buttons { display: flex; gap: 10px; }

.puzzle-buddy { display: flex; align-items: center; gap: 10px; position: relative; }
.puzzle-buddy-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.puzzle-buddy-avatar .buddy-badge {
  position: absolute;
  bottom: -4px;
  right: -6px;
  font-size: 18px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}
.puzzle-buddy-avatar.mood-happy { animation: buddyBounce 0.5s ease; }
.puzzle-buddy-avatar.mood-sad { animation: buddyShake 0.4s ease; }
.puzzle-buddy-avatar.mood-thinking { animation: buddyTilt 2.2s ease-in-out infinite; }
.puzzle-buddy-avatar.mood-sleepy { animation: buddyTilt 3s ease-in-out infinite; opacity: 0.85; }
@keyframes buddyBounce { 0%,100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-8px) scale(1.08); } }
@keyframes buddyShake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes buddyTilt { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }

.puzzle-buddy-text {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  max-width: 220px;
  animation: sceneFadeIn 0.3s ease both;
}
.puzzle-buddy-text.hidden { display: none; }
#check-btn, #next-btn {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
#check-btn { background: var(--accent); color: #0b1220; }
#check-btn:hover { filter: brightness(1.1); }
#next-btn { background: var(--accent-2); color: #0b1220; }
#next-btn.hidden { display: none; }

.back-to-map {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 20px;
}
.back-to-map:hover { color: var(--text); border-color: var(--accent); }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: relative; height: auto; max-height: 60vh; }
  #content { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  #sidebar { padding: 16px 14px; max-height: 46vh; }
  .brand h1 { font-size: 16px; }
  #chapter-list { max-height: none; }
  .chapter-link { padding: 9px 10px; font-size: 12.5px; }
  #narrative-pane, #puzzle-pane { padding: 20px 16px; }
  #puzzle-pane { border-left: none; border-top: 1px solid var(--border); }
  #chapter-title { font-size: 21px; }
  #chapter-body { font-size: 14px; }
  .speaker { flex-wrap: wrap; }
  .avatar { width: 38px; height: 38px; font-size: 18px; }
  .mcq-option { padding: 11px 12px; font-size: 13.5px; }
  .order-item { padding: 9px 12px; font-size: 12.5px; }
  .match-game { flex-direction: column; gap: 10px; }
  .sort2-buckets { flex-direction: column; }
  .puzzle-actions { flex-direction: column; align-items: stretch; }
  .puzzle-actions-buttons { justify-content: stretch; }
  .puzzle-actions-buttons button { flex: 1; }
  .puzzle-buddy { flex-wrap: wrap; }
  .puzzle-buddy-text { max-width: 100%; }
  .story-modal-card { padding: 24px 18px; }
  .ghost-btn-lg span, .ghost-btn span { display: none; }
  .ghost-btn-lg, .ghost-btn { padding: 10px; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  #map-footer { display: flex; gap: 10px; justify-content: center; }
  .back-to-map span { display: none; }
}

/* ===================== Animated diagrams ===================== */
.diagram {
  position: relative;
  background: #0b0f18;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 18px 0;
  padding: 20px;
  min-height: 110px;
  overflow: hidden;
}

/* Stack push/pop */
.diagram-stack { display: flex; flex-direction: column-reverse; align-items: center; gap: 6px; min-height: 160px; justify-content: flex-start; }
.stack-box {
  width: 90px; text-align: center; padding: 8px 0;
  border-radius: 6px; font-family: var(--mono); font-weight: 700; color: #0b1220;
  animation: stackPulse 2.4s ease-in-out infinite;
}
.stack-1 { background: var(--accent-2); animation-delay: 0s; }
.stack-2 { background: var(--accent); animation-delay: 0.3s; }
.stack-3 { background: #c792ea; animation-delay: 0.6s; }
.stack-floor { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
@keyframes stackPulse {
  0%, 100% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(-6px); opacity: 0.85; }
}

/* Logic gate */
.diagram-gate { display: flex; align-items: center; justify-content: center; gap: 0; min-height: 100px; }
.gate-input {
  width: 34px; height: 34px; border-radius: 50%;
  background: #232d45; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 12px; margin-right: 14px;
  animation: gateBlink 3s ease-in-out infinite;
}
.in-b { animation-delay: 1.5s; }
.gate-body {
  background: #232d45; border: 1px solid var(--accent);
  padding: 14px 20px; border-radius: 8px; font-family: var(--mono); font-weight: 700; margin-right: 14px;
}
.gate-led {
  width: 22px; height: 22px; border-radius: 50%;
  background: #3a2a2a;
  animation: ledOn 3s ease-in-out infinite;
}
@keyframes gateBlink {
  0%, 40% { background: #232d45; }
  50%, 90% { background: var(--accent); color: #0b1220; }
  100% { background: #232d45; }
}
@keyframes ledOn {
  0%, 45% { background: #3a2a2a; box-shadow: none; }
  55%, 90% { background: #ffcb6b; box-shadow: 0 0 16px 4px rgba(255,203,107,0.7); }
  100% { background: #3a2a2a; box-shadow: none; }
}

/* Network packet */
.diagram-network { display: flex; align-items: center; justify-content: space-between; min-height: 60px; }
.net-node { font-size: 13px; white-space: nowrap; }
.net-wire { flex: 1; height: 2px; background: var(--border); margin: 0 16px; position: relative; }
.net-packet {
  position: absolute; top: -12px; left: 0; font-size: 18px;
  animation: packetMove 2.6s linear infinite;
}
@keyframes packetMove {
  0% { left: 0%; }
  45% { left: 90%; }
  50% { left: 90%; }
  95% { left: 0%; }
  100% { left: 0%; }
}

/* DB join */
.diagram-db { display: flex; align-items: center; justify-content: center; gap: 0; min-height: 110px; }
.db-table { width: 148px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.db-row { padding: 6px 10px; font-size: 11px; font-family: var(--mono); background: #10182a; border-bottom: 1px solid var(--border); white-space: nowrap; }
.db-head { background: #232d45; font-weight: 700; }
.db-row:last-child { border-bottom: none; }
.db-link { width: 50px; height: 2px; background: var(--accent); position: relative; animation: dbPulse 2s ease-in-out infinite; }
@keyframes dbPulse { 0%,100% { opacity: 0.3; } 50% { opacity: 1; } }

/* Brain (AI) */
.diagram-brain { display: flex; align-items: center; justify-content: center; gap: 14px; min-height: 90px; position: relative; }
.brain-emoji { font-size: 40px; animation: brainPulse 2s ease-in-out infinite; }
@keyframes brainPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.brain-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: dotBounce 1.2s ease-in-out infinite; }
.d2 { animation-delay: 0.2s; } .d3 { animation-delay: 0.4s; }
@keyframes dotBounce { 0%, 100% { transform: translateY(0); opacity: 0.4; } 50% { transform: translateY(-8px); opacity: 1; } }

/* ML learning line */
.diagram-ml { min-height: 90px; position: relative; }
.ml-dot { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }
.p1 { left: 10%; top: 70%; } .p2 { left: 35%; top: 40%; } .p3 { left: 60%; top: 55%; } .p4 { left: 85%; top: 20%; }
.ml-line {
  position: absolute; left: 5%; top: 60%; width: 90%; height: 2px;
  background: var(--accent); transform-origin: left center;
  animation: lineSettle 3s ease-in-out infinite;
}
@keyframes lineSettle {
  0% { transform: rotate(10deg); }
  50% { transform: rotate(-14deg) translateY(-10px); }
  100% { transform: rotate(10deg); }
}

/* Web layers */
.diagram-web { min-height: 130px; display: flex; align-items: center; justify-content: center; }
.web-window { width: 100%; max-width: 280px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.web-layer {
  padding: 12px; font-size: 12px; font-family: var(--mono); color: #0b1220; font-weight: 700;
  transform: translateY(-20px); opacity: 0; animation: layerDrop 0.6s ease forwards;
}
.web-html { background: var(--accent-2); animation-delay: 0.1s; }
.web-css { background: var(--accent); animation-delay: 0.5s; }
.web-js { background: #c792ea; animation-delay: 0.9s; }
@keyframes layerDrop { to { transform: translateY(0); opacity: 1; } }

/* ===================== Game-feel polish ===================== */
.pane-enter { animation: paneEnter 0.5s ease; }
@keyframes paneEnter {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.mcq-enter { animation: mcqEnter 0.4s ease backwards; }
@keyframes mcqEnter {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.mcq-option.pop, .match-chip.pop, .gate-toggle.pop { animation: pop 0.25s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.shake-once { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.avatar.celebrate { animation: celebrateBounce 0.6s ease; }
@keyframes celebrateBounce {
  0% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.25) rotate(-8deg); }
  60% { transform: scale(1.1) rotate(6deg); }
  100% { transform: scale(1) rotate(0deg); }
}

#progress-fill {
  position: relative;
  overflow: hidden;
}
#progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
  animation: shimmer 1.8s ease-in-out infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Match game (drag-to-pair) */
.match-game { display: flex; gap: 16px; margin: 14px 0; }
.match-col { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.match-chip {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.match-chip:hover { border-color: var(--accent); }
.match-chip.selected { border-color: var(--accent-2); background: rgba(255,203,107,0.12); }
.match-chip.matched { border-color: var(--ok); background: rgba(125,227,200,0.15); color: var(--ok); cursor: default; opacity: 0.8; }
.match-status { margin-top: 4px; font-size: 12px; color: var(--text-dim); font-weight: 600; }

/* Interactive circuit game */
.diagram-gate-interactive { display: flex; align-items: center; justify-content: center; gap: 0; min-height: 100px; }
.gate-toggle {
  width: 60px; height: 44px; border-radius: 10px;
  border: 1px solid var(--border);
  background: #232d45; color: var(--text);
  font-family: var(--mono); font-weight: 700; font-size: 13px;
  cursor: pointer; margin-right: 16px;
}
.gate-toggle:hover { border-color: var(--accent); }
.gate-toggle.on { background: var(--accent); color: #0b1220; border-color: var(--accent); }
.diagram-gate-interactive .gate-led { animation: none; background: #3a2a2a; box-shadow: none; transition: background 0.2s, box-shadow 0.2s; }
.diagram-gate-interactive .gate-led.lit { background: #ffcb6b; box-shadow: 0 0 18px 5px rgba(255,203,107,0.75); }

/* Sort into two buckets */
.sort2-buckets { display: flex; gap: 14px; margin: 14px 0; }
.sort2-bucket {
  flex: 1; min-height: 110px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  background: rgba(255,255,255,0.02);
}
.sort2-bucket-label { width: 100%; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.sort2-tray {
  min-height: 60px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  background: rgba(255,255,255,0.02);
}
.sort2-tray-label { width: 100%; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.sort2-chip {
  padding: 8px 12px;
  border-radius: 20px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
  cursor: grab;
}
.sort2-chip.dragging { opacity: 0.4; }
.sort2-chip.selected { border-color: var(--accent); background: rgba(125,227,200,0.18); box-shadow: 0 0 0 2px var(--accent); }

/* ===================== Humanified turtle: walk cycle ===================== */
.turtle-inner { transition: transform 0.15s ease; transform-origin: center bottom; }
.turtle-inner.flip { transform: scaleX(-1); }

.player-character:not(.walking) .turtle-inner { animation: idleSway 2.2s ease-in-out infinite; }

@keyframes idleSway {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(1.5deg); }
}
.player-character:not(.walking) .turtle-inner.flip { animation: idleSwayFlip 2.2s ease-in-out infinite; }
@keyframes idleSwayFlip {
  0%, 100% { transform: scaleX(-1) translateY(0) rotate(0deg); }
  50% { transform: scaleX(-1) translateY(-2px) rotate(-1.5deg); }
}

.player-character.walking .tq-leg-left { animation: legSwingA 0.42s linear infinite; }
.player-character.walking .tq-leg-right { animation: legSwingB 0.42s linear infinite; }
.player-character.walking .tq-arm-left { animation: legSwingB 0.42s linear infinite; }
.player-character.walking .tq-arm-back { animation: legSwingA 0.42s linear infinite; }

@keyframes legSwingA {
  0%, 100% { transform: rotate(24deg); }
  50% { transform: rotate(-24deg); }
}
@keyframes legSwingB {
  0%, 100% { transform: rotate(-24deg); }
  50% { transform: rotate(24deg); }
}

/* ===================== World map ===================== */
body.map-body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #eaf7ff 0%, #dff2ff 55%, #f7fafc 100%);
  overflow-x: hidden;
}

#map-header {
  text-align: center;
  padding: 28px 20px 6px;
  color: var(--text);
}
#map-header h1 { margin: 0; font-size: 26px; }
#map-header p { color: var(--text-dim); margin: 6px 0 0; font-size: 13px; }

#map-layout {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: min(1180px, 96vw);
  margin: 20px auto 40px;
}

#level-rail {
  flex-shrink: 0;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 6px;
  border-radius: 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  position: sticky;
  top: 54px;
}
.level-rail-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  margin-bottom: 2px;
}
.level-rail-info {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  flex-shrink: 0;
}
.level-rail-info:hover { border-color: var(--accent); color: var(--text); }

#map-canvas {
  position: relative;
  isolation: isolate;
  flex: 1;
  min-width: 0;
  height: 620px;
  margin: 0;
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.05), transparent 40%),
    linear-gradient(180deg, #2a6f5e 0%, #163f34 60%, #0c231d 100%);
  border: 1px solid #21385a;
  border-top: 3px solid var(--level-accent, var(--accent));
  overflow: hidden;
  transition: border-top-color 0.4s ease, background 0.6s ease;
}

.cloud {
  position: absolute;
  font-size: 34px;
  opacity: 0.5;
  animation: drift 60s linear infinite;
}
.cloud.c1 { top: 6%; left: -10%; animation-duration: 70s; }
.cloud.c2 { top: 18%; left: -20%; animation-duration: 95s; animation-delay: -20s; font-size: 26px; }
.cloud.c3 { top: 3%; left: -30%; animation-duration: 110s; animation-delay: -50s; font-size: 42px; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(140vw); } }

.island {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  animation: bob 4s ease-in-out infinite;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}
.island:nth-of-type(2n) { animation-delay: -1.3s; }
.island:nth-of-type(3n) { animation-delay: -2.6s; }
@keyframes bob { 0%, 100% { transform: translate(-50%, -50%); } 50% { transform: translate(-50%, calc(-50% - 8px)); } }

.island-glow-wrap { position: relative; width: 74px; height: 74px; }
.island-ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  background: conic-gradient(var(--isl-color, var(--accent)) calc(var(--dwell, 0) * 1%), rgba(255,255,255,0.08) 0);
  opacity: 0;
  transition: opacity 0.2s;
}
.island.near-active .island-ring { opacity: 1; }
.island.near-active .island-glow {
  transform: scale(1.12);
  box-shadow: 0 0 34px 10px color-mix(in srgb, var(--isl-color, var(--accent)) 65%, transparent);
}
.island-glow {
  position: relative;
  width: 74px; height: 74px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  border: 2px solid var(--isl-color, var(--accent));
  background: radial-gradient(circle, rgba(255,255,255,0.06), rgba(0,0,0,0.2));
  box-shadow: 0 0 22px 2px color-mix(in srgb, var(--isl-color, var(--accent)) 55%, transparent);
  transition: transform 0.2s, box-shadow 0.2s;
}
.island-name { font-size: 12px; font-weight: 700; color: #f8fafc; text-shadow: 0 1px 3px #000; white-space: nowrap; }
.island-place { font-size: 10px; color: #cbd5e1; text-shadow: 0 1px 2px rgba(0,0,0,0.6); white-space: nowrap; }
.island-progress { font-size: 10px; color: var(--isl-color, var(--accent)); font-weight: 700; }
.island-hint {
  position: absolute;
  top: -22px;
  font-size: 11px;
  font-weight: 700;
  color: var(--isl-color, var(--accent));
  background: rgba(10, 14, 24, 0.85);
  padding: 3px 8px;
  border-radius: 10px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.island.near-active .island-hint { opacity: 1; animation: hintBounce 0.6s ease-in-out infinite alternate; }
@keyframes hintBounce { from { transform: translateY(0); } to { transform: translateY(-4px); } }

.player-character {
  position: absolute;
  width: 64px;
  z-index: 6;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
  will-change: left, top;
}

.map-fade-out { animation: mapFadeOut 0.35s ease forwards; }
@keyframes mapFadeOut {
  to { opacity: 0; transform: scale(0.98); }
}

#map-hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(10, 14, 24, 0.8);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 16px;
  border-radius: 20px;
  z-index: 20;
  white-space: nowrap;
}

#map-footer { text-align: center; padding-bottom: 40px; }
.ghost-btn-lg {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn-lg:hover { color: var(--text); border-color: var(--text-dim); }

@media (max-width: 700px) {
  #map-canvas { height: 780px; }
}

/* ---------- Mobile: island list instead of the walking map ---------- */
.map-list { display: none; }
.map-list-row {
  display: flex; align-items: center; gap: 10px;
  border: 2px solid var(--border); border-radius: 12px;
  background: var(--bg-panel); padding: 10px 12px; margin-bottom: 8px;
  text-align: left; width: 100%; color: var(--text); font-family: inherit;
}
.map-list-row:disabled { opacity: 0.55; }
.map-list-row .mlr-glow {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  border: 2px solid var(--isl-color, var(--accent));
  box-shadow: 0 0 10px 1px color-mix(in srgb, var(--isl-color, var(--accent)) 50%, transparent);
}
.map-list-row .mlr-body { flex: 1; min-width: 0; }
.map-list-row .mlr-name { font-weight: 700; font-size: 13.5px; }
.map-list-row .mlr-place { font-size: 11px; color: var(--text-dim); }
.map-list-row .mlr-progress { font-size: 11px; color: var(--isl-color, var(--accent)); font-weight: 700; margin-top: 2px; }
.map-list-row .mlr-badge { font-size: 18px; flex-shrink: 0; }

@media (max-width: 640px) {
  #map-header { padding: 18px 14px 4px; }
  #map-header h1 { font-size: 20px; }
  #map-header p { font-size: 12px; }
  #map-layout { flex-direction: column; align-items: stretch; width: 96vw; margin: 14px auto 16px; }
  #level-rail {
    width: 100%; flex-direction: row; flex-wrap: wrap; justify-content: center;
    position: static; padding: 10px; gap: 6px;
  }
  .level-rail-label { writing-mode: horizontal-tb; text-orientation: initial; width: 100%; text-align: center; margin: 0 0 4px; }
  .level-rail-pro-divider { width: auto; border-top: none; border-left: 1px dashed rgba(255,203,107,0.4); padding: 0 0 0 6px; margin: 0; }
  #level-rail .level-pill { width: 32px; height: 32px; font-size: 12px; }
  /* The walking map doesn't work well on a phone (no keyboard, tiny targets) —
     show a tappable list of the same islands instead. */
  #map-canvas { display: none; }
  .map-list { display: block; width: 96vw; max-width: 480px; margin: 0 auto 20px; }
  #map-hint { display: none; }
}

/* ===================== Story mode ===================== */
#shard-counter {
  margin-top: 8px;
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-2);
  background: rgba(255, 203, 107, 0.1);
  border: 1px solid rgba(255, 203, 107, 0.3);
  padding: 4px 12px;
  border-radius: 20px;
}

.level-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.level-jump-vertical { flex-direction: column; align-items: center; }
.level-pill {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.level-pill:hover:not(:disabled) { border-color: var(--accent); color: var(--text); transform: scale(1.08); }
.level-pill.active {
  background: var(--pill-accent, var(--accent));
  color: #0b1220;
  border-color: var(--pill-accent, var(--accent));
  box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}
.level-pill.frontier:not(.active) { border-color: var(--pill-accent, var(--accent)); color: var(--pill-accent, var(--accent)); }
.level-pill.completed:not(.active) {
  background: rgba(125, 227, 200, 0.18);
  border-color: var(--ok);
  color: var(--ok);
}
.level-pill.locked { opacity: 0.4; cursor: not-allowed; font-size: 10px; }
/* Levels 10-15 — the professional tier — get a small gold badge + dashed
   double-ring so the difficulty jump reads clearly at a glance. */
.level-pill.professional { border-style: double; border-width: 3px; }
.level-pill-pro {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 9px;
  line-height: 1;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.6));
}

.level-rail-pro-divider {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #ffcb6b;
  margin: 4px 0 2px;
  text-align: center;
  border-top: 1px dashed rgba(255, 203, 107, 0.4);
  padding-top: 4px;
  width: 100%;
}

/* The vertical rail on the world map — bigger pills, clearly visible at a glance */
#level-rail .level-pill {
  width: 40px;
  height: 40px;
  font-size: 15px;
  border-width: 2px;
}
#level-rail .level-pill.frontier:not(.active) {
  box-shadow: 0 0 10px 1px var(--pill-accent, var(--accent));
}


.story-modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 20, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.story-modal.hidden { display: none; }
.story-modal-card {
  position: relative;
  max-width: 520px;
  width: 92vw;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: storyPop 0.35s ease;
}
.story-modal-x {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
}
.story-modal-x:hover { color: var(--text); border-color: var(--text-dim); }
@keyframes storyPop {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.story-modal-glyph { display: flex; justify-content: center; margin-bottom: 12px; }
#story-modal-title { margin: 0 0 16px; font-size: 20px; color: var(--accent-2); }
#story-modal-text { text-align: left; font-size: 14px; line-height: 1.7; color: #cfd6e8; }
#story-modal-text p { margin: 0 0 12px; }
.story-modal-btn {
  margin-top: 12px;
  background: var(--accent-2);
  color: #0b1220;
  border: none;
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.story-modal-btn:hover { filter: brightness(1.08); }

.island.collected .island-glow { border-color: #ffcb6b; box-shadow: 0 0 24px 4px rgba(255, 203, 107, 0.6); }
.shard-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 18px;
  filter: drop-shadow(0 0 4px rgba(255, 203, 107, 0.8));
  animation: shardSpin 3s linear infinite;
}
@keyframes shardSpin {
  0%, 100% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(10deg) scale(1.15); }
}

.island.level-done:not(.collected) .island-glow { border-color: #7de3c8; box-shadow: 0 0 16px 3px rgba(125, 227, 200, 0.5); }
.level-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 15px;
  filter: drop-shadow(0 0 3px rgba(125, 227, 200, 0.8));
}

.island.core-island .island-glow {
  animation: corePulse 1.6s ease-in-out infinite;
  border-width: 3px;
}
@keyframes corePulse {
  0%, 100% { box-shadow: 0 0 22px 2px rgba(255, 203, 107, 0.55); }
  50% { box-shadow: 0 0 40px 12px rgba(255, 203, 107, 0.9); }
}

/* Story callouts + shard banner (course page) */
.story-callout { border-left-color: #6fa8ff; background: rgba(111, 168, 255, 0.08); }
.shard-trial-callout { border-left-color: #ff6b9f; background: rgba(255, 107, 159, 0.08); }
.level-trial-callout { border-left-color: #7de3c8; background: rgba(125, 227, 200, 0.08); }

.shard-banner {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}
.shard-banner.hidden { display: none; }
.shard-banner.shard-won {
  background: rgba(255, 203, 107, 0.12);
  border: 1px solid var(--accent-2);
  color: var(--accent-2);
}
.shard-banner.victory {
  background: linear-gradient(135deg, rgba(255,203,107,0.18), rgba(125,227,200,0.18));
  border: 1px solid var(--accent-2);
  color: #fff;
  font-size: 14px;
  text-align: center;
}
.shard-banner.level-clear {
  background: rgba(125, 227, 200, 0.1);
  border: 1px solid var(--accent);
  color: var(--accent);
}
.shard-banner.level-up {
  background: linear-gradient(135deg, rgba(125,227,200,0.18), rgba(255,203,107,0.18));
  border: 1px solid var(--accent);
  color: #fff;
  text-align: center;
}

.puzzle-icon { flex-shrink: 0; display: flex; align-items: center; }
.puzzle-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.puzzle-header-text { flex: 1; min-width: 0; }
