@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@600;700;800&display=swap');

:root {
  --bg: #fff9e6;
  --sky: #a5d8ff;
  --gold: #ffd43b;
  --gold-d: #fab005;
  --green: #51cf66;
  --green-d: #37b24d;
  --red: #ff6b6b;
  --purple: #9775fa;
  --brown: #5c4033;
  --wall: #868e96;
  --tile: #f1f3f5;
  --shadow: rgba(92, 64, 51, 0.18);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(165deg, #fff4e6 0%, var(--sky) 45%, #d0ebff 100%);
  min-height: 100vh;
  color: var(--brown);
}

.app { max-width: 800px; margin: 0 auto; padding: 0.5rem; }

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 8px;
}

.logo {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1rem, 4vw, 1.4rem);
  color: var(--gold-d);
  text-shadow: 2px 2px 0 #fff;
}

.tagline { font-size: 0.72rem; font-weight: 700; color: var(--purple); }

.lang-switch { display: flex; gap: 4px; }
.lang-btn {
  padding: 6px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  border: 2px solid var(--brown);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.lang-btn.active { background: var(--gold); }

.screen { display: none; animation: fadeIn 0.25s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--bg);
  border: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 10px 28px var(--shadow);
}

.menu-card { text-align: center; max-width: 380px; margin: 0 auto; }
.hero-float {
  font-size: 3rem;
  animation: float 2s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.menu-card h2 { font-family: 'Fredoka', sans-serif; color: var(--gold-d); }
.v2 { font-size: 0.65em; background: var(--purple); color: #fff; padding: 2px 8px; border-radius: 8px; }
.subtitle { font-weight: 700; color: var(--purple); margin-bottom: 0.75rem; }
.progress-text { margin-top: 1rem; font-size: 0.8rem; font-weight: 700; }

.btn {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0.3rem auto;
  padding: 0.7rem 1rem;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.95rem;
  border: 3px solid var(--brown);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px var(--shadow); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, var(--green), var(--green-d)); color: #fff; }
.btn.secondary { background: #fff; color: var(--brown); }
.btn.accent { background: linear-gradient(180deg, #da77f2, var(--purple)); color: #fff; }
.btn.tiny { font-size: 0.78rem; padding: 0.4rem 0.75rem; width: auto; display: inline-block; margin: 0; }
.sound-check { display: block; margin-top: 0.5rem; font-size: 0.85rem; }

.scroll-card { max-height: 82vh; overflow-y: auto; }

/* Level map */
.map-card { max-width: 520px; margin: 0 auto; text-align: center; }
.map-sub { font-size: 0.85rem; margin-bottom: 1rem; }
.level-map {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 1rem 0;
  min-height: 200px;
}
.map-node {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--brown);
  background: #fff;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-node.done { background: #d3f9d8; border-color: var(--green-d); }
.map-node.locked { opacity: 0.4; pointer-events: none; background: #eee; }
.map-node.current { box-shadow: 0 0 0 4px var(--gold); transform: scale(1.08); }
.map-node .node-stars { position: absolute; bottom: -14px; font-size: 0.55rem; left: 0; right: 0; }

/* Tutorial */
.tutorial-card { max-width: 400px; margin: 0 auto; text-align: center; }
.tut-step-label { font-weight: 700; color: var(--purple); margin-bottom: 0.5rem; }
.tut-text { line-height: 1.55; margin: 1rem 0; font-size: 0.95rem; }
.tut-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.tut-actions .btn { margin: 0; flex: 1; min-width: 120px; }

/* Report */
.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 1rem 0;
  text-align: center;
}
.report-stat {
  background: #fff;
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 10px;
}
.report-stat strong { display: block; font-size: 1.4rem; color: var(--gold-d); }
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  margin: 1rem 0;
}
.report-table th, .report-table td {
  border: 2px solid var(--gold);
  padding: 8px 6px;
  text-align: left;
}
.report-table th { background: var(--gold); }

.help-list { text-align: left; padding-left: 1.2rem; margin: 1rem 0; line-height: 1.6; font-size: 0.88rem; }

/* Game */
.game-layout { display: flex; flex-direction: column; gap: 8px; }
.game-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.level-info { flex: 1; }
.level-info h2 { font-family: 'Fredoka', sans-serif; font-size: 1.05rem; color: var(--gold-d); }
.objective { font-size: 0.76rem; line-height: 1.35; }
.stars-display { font-weight: 800; }

.board-wrap {
  background: rgba(255,255,255,0.7);
  border: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}

.board-note {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brown);
  opacity: 0.85;
  margin-bottom: 8px;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  width: min(94vw, 360px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.cell {
  border-radius: 10px;
  border: 2px solid rgba(92,64,51,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 4vw, 1.4rem);
  position: relative;
  min-height: 0;
  cursor: default;
  user-select: none;
}
.cell.path { background: var(--tile); }
.cell.wall { background: var(--wall); }
.cell.start { background: #b2f2bb; }
.cell.goal { background: #ffec99; animation: goalPulse 1.5s ease infinite; }
@keyframes goalPulse { 0%, 100% { box-shadow: inset 0 0 0 0 transparent; } 50% { box-shadow: inset 0 0 0 3px var(--gold); } }
.cell.pusaka { background: #fff3bf; }
.cell.buto { background: #ffc9c9; }
.cell.obstacle { background: #dee2e6; }

.entity {
  position: absolute;
  font-size: 1.6rem;
  z-index: 3;
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
  filter: drop-shadow(2px 3px 4px rgba(0,0,0,0.2));
}
.entity.hop { animation: hop 0.35s ease; }
@keyframes hop {
  0% { transform: scale(1) translateY(0); }
  40% { transform: scale(1.15) translateY(-6px); }
  100% { transform: scale(1) translateY(0); }
}
.entity.turn-anim { animation: turnPop 0.3s ease; }
@keyframes turnPop { 50% { transform: scale(1.2) rotate(15deg); } }

.cell.flash-ok { animation: flashOk 0.4s; }
@keyframes flashOk { 50% { background: #d3f9d8; } }
.cell.flash-bad { animation: flashBad 0.4s; }
@keyframes flashBad { 50% { background: #ffe3e3; } }

.feedback {
  text-align: center;
  font-weight: 800;
  font-size: 0.9rem;
  min-height: 2rem;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.8);
}
.feedback.ok { color: var(--green-d); }
.feedback.warn { color: #e67700; }
.feedback.err { color: #c92a2a; }

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 640px) {
  .workspace { grid-template-columns: 1fr 1fr; }
}

.panel-label { font-size: 0.75rem; font-weight: 800; color: var(--purple); }
.drag-hint { font-size: 0.68rem; opacity: 0.75; margin-bottom: 6px; }

.blocks-panel {
  border: 3px solid var(--purple);
  border-radius: 14px;
  padding: 10px;
  background: rgba(243, 240, 255, 0.85);
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 10px;
  background: #fff;
  border-radius: 12px;
  min-height: 88px;
}

.block-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  min-height: 52px;
  min-width: 100px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  border: 3px solid var(--brown);
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  text-align: left;
  transition: box-shadow 0.15s, transform 0.12s;
  -webkit-appearance: none;
  appearance: none;
  background: #fff;
}
.block-chip:hover { box-shadow: 0 4px 12px var(--shadow); transform: translateY(-2px); }
.block-chip:active { transform: scale(0.97); }
.block-chip.dragging { opacity: 0.55; cursor: grabbing; }

.chip-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}
.block-chip.move { background: #e7f5ff; border-color: #339af0; }
.block-chip.turn { background: #f3f0ff; border-color: var(--purple); }
.block-chip.action { background: #fff5f5; border-color: var(--red); }
.block-chip.loop { background: #ebfbee; border-color: var(--green-d); }
.block-chip.if { background: #fff9db; border-color: var(--gold-d); }

.queue {
  min-height: 72px;
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  padding: 10px;
  background: #fff;
  border: 3px dashed var(--gold-d);
  border-radius: 14px;
  transition: background 0.2s, border-color 0.2s;
}
.queue.drag-over { background: #e7f5ff; border-color: #339af0; border-style: solid; }
.queue-empty { width: 100%; text-align: center; font-size: 0.8rem; opacity: 0.55; pointer-events: none; }

.queue-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid #339af0;
  background: #e7f5ff;
  cursor: grab;
}
.queue-item.drag-over-item { border-top: 3px solid var(--purple); }
.queue-item .rm {
  width: 22px; height: 22px;
  border: none; border-radius: 50%;
  background: var(--red); color: #fff;
  font-size: 0.75rem; cursor: pointer;
  line-height: 1;
}

.run-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.run-row .btn { margin: 0; flex: 1; min-width: 90px; max-width: 140px; }

.educator-panel {
  font-size: 0.8rem;
  background: rgba(255,255,255,0.85);
  border: 2px solid var(--purple);
  border-radius: 12px;
  padding: 8px 12px;
}
.educator-panel summary { font-weight: 800; cursor: pointer; color: var(--purple); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(91, 163, 217, 0.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.overlay.hidden { display: none; }
.win-card { text-align: center; max-width: 340px; animation: popIn 0.35s ease; }
@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.win-stars { font-size: 1.3rem; font-weight: 800; margin: 0.5rem 0; }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 1rem 0; }
.badge-pill { padding: 6px 12px; background: var(--gold); border: 2px solid var(--brown); border-radius: 20px; font-size: 0.75rem; font-weight: 700; }
