:root {
  --brand-primary: #d85626;
  --brand-primary-dark: #b8451d;
  --brand-accent: #ec4f4f;
  --brand-dark: #111111;
  --brand-light: #fff6f1;
  --brand-surface: #ffffff;
  --brand-muted: #f3f4f6;
  --brand-text: #1f2937;
  --toolbox-width: 260px;
  --radius-large: 20px;
  --radius-medium: 14px;
  --shadow: 0 16px 40px rgba(17, 17, 17, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--brand-text);
  background: linear-gradient(180deg, #fff9f5, #f6f8ff);
  overflow: hidden;
}

h1,
h2,
h3 {
  font-family: "Fredoka", system-ui, sans-serif;
  margin: 0;
}

p {
  margin: 0;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 15px 20px 15px;
  overflow: hidden;
}

.screen {
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none;
}

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti {
  position: absolute;
  top: -10px;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  transform: rotate(0deg);
  animation-name: confetti-fall;
  animation-timing-function: ease-in-out;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 10px 10px;
  background: var(--brand-surface);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow);
  position: relative;
}

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

.brand-avatar {
  width: 54px;
  height: 54px;
}

.brand h1 {
  font-size: 1.6rem;
}

.brand p {
  color: #6b7280;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.select-label {
  font-weight: 600;
}

.select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  font-family: inherit;
}

.progress {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--brand-light);
  color: var(--brand-primary-dark);
  font-weight: 700;
}

.progress-dots {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 520px;
}

.progress-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  background: #fff;
  cursor: pointer;
}

.progress-dot.completed {
  background: #16a34a;
  border-color: #16a34a;
}

.progress-dot.current {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(216, 86, 38, 0.25);
}

.progress-dot.locked {
  cursor: not-allowed;
  opacity: 0.5;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 18px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--brand-surface);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.simulator canvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius-medium);
  border: 2px solid var(--brand-muted);
  background: #fffdf9;
}

.simulator canvas.shake {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(5px);
  }
  100% {
    transform: translateX(0);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.button-row {
  display: flex;
  gap: 8px;
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.story {
  color: #4b5563;
}

.goal-box {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--brand-light);
  border: 1px solid rgba(216, 86, 38, 0.2);
}

.status {
  min-height: 28px;
  font-weight: 700;
  color: var(--brand-accent);
  text-align: center;
}

.status--topbar {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--brand-light);
  border: 1px solid rgba(216, 86, 38, 0.25);
  max-width: min(600px, 60vw);
  white-space: normal;
  overflow: visible;
  text-overflow: initial;
  line-height: 1.2;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.status--topbar:empty {
  display: none;
}

.nav-buttons {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

.button {
  border: none;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-family: "Nunito", system-ui, sans-serif;
  cursor: pointer;
  background: #e5e7eb;
  color: #111827;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(17, 17, 17, 0.12);
}

.button.primary {
  background: var(--brand-primary);
  color: #fff;
}

.button.ghost {
  background: #f3f4f6;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.blockly-panel {
  padding: 12px 12px 16px;
}

.blockly-header {
  display: grid;
  grid-template-columns: var(--toolbox-width) 1fr;
  align-items: center;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
  color: #6b7280;
  gap: 10px;
  margin: 4px 8px 8px;
}

.blockly-label {
  padding: 6px 10px;
}

#blockly-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-medium);
  overflow: hidden;
  border: 2px solid var(--brand-muted);
  background: #fff;
}

#blocklyDiv {
  width: 100%;
  height: 100%;
}

.blocklyToolboxDiv {
  width: var(--toolbox-width) !important;
  background: #fff7f0;
  border-right: 2px solid rgba(216, 86, 38, 0.15);
}

.blocklyToolboxCategory
{
	height: 30px;
    line-height: 28px;
    margin-bottom: 5px;
    padding-right: 8px;
    white-space: nowrap;
    font-size: xx-large;
}

.blocklyToolboxCategoryLabel
{
	    font-weight: bolder;
}

.blocklyTreeRow {
  margin-bottom: 8px;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-weight: 800;
  border: 2px solid transparent;
  background: linear-gradient(180deg, #fff7f0, #fff);
  box-shadow: 0 6px 14px rgba(216, 86, 38, 0.12);
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.blocklyTreeLabel {
  font-weight: 800;
  letter-spacing: 0.01em;
}

.blocklyTreeSelected,
.blocklyTreeRow:hover {
  background: rgba(216, 86, 38, 0.2) !important;
  border-color: rgba(216, 86, 38, 0.35);
  box-shadow: 0 10px 18px rgba(216, 86, 38, 0.18);
  transform: translateY(-1px);
}

.blocklyTreeSelected {
  background: linear-gradient(180deg, #e86a3c, #cf4f21) !important;
  border-color: var(--brand-primary-dark);
  color: #fff;
  box-shadow: 0 12px 22px rgba(216, 86, 38, 0.28);
}

.blocklyTreeSelected .blocklyTreeLabel {
  color: #fff;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10000;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  max-width: 720px;
  width: 100%;
  background: #fff;
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
  max-height: calc(100vh - 80px);
  overflow: auto;
}

.intro-block-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 14px;
  background: #facc15;
  color: #111827;
  font-weight: 800;
  box-shadow: 0 8px 16px rgba(250, 204, 21, 0.3);
  margin: 10px auto 14px;
  border: 2px solid #d97706;
}

.intro-block-preview--move {
  background: #c68a5f;
  border-color: #a86a3b;
  color: #fff;
  box-shadow: 0 8px 16px rgba(198, 138, 95, 0.35);
}

.intro-block-preview--repeat {
  background: #8fd36a;
  border-color: #4b9f3a;
  color: #0f172a;
  box-shadow: 0 8px 16px rgba(118, 200, 96, 0.35);
}

.intro-blocks {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 10px 0 6px;
}

.intro-block-chip {
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.95rem;
  border: 2px solid transparent;
}

.intro-block-chip--move {
  background: #c68a5f;
  border-color: #a86a3b;
  color: #fff;
  box-shadow: 0 6px 12px rgba(198, 138, 95, 0.3);
}

.move-demo {
  display: flex;
  justify-content: center;
  margin: 14px 0 4px;
}

.move-grid {
  position: relative;
  width: 140px;
  height: 140px;
  border-radius: 14px;
  background: repeating-linear-gradient(
      90deg,
      rgba(15, 23, 42, 0.08),
      rgba(15, 23, 42, 0.08) 1px,
      transparent 1px,
      transparent 46px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(15, 23, 42, 0.08),
      rgba(15, 23, 42, 0.08) 1px,
      transparent 1px,
      transparent 46px
    );
  background-color: #f8fafc;
  border: 2px solid #e2e8f0;
}

.move-grid--wide {
  width: 170px;
}

.move-robot {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #22c55e;
  left: 61px;
  top: 61px;
  box-shadow: 0 6px 12px rgba(34, 197, 94, 0.35);
  animation: move-path 3.2s infinite ease-in-out;
}

.move-robot--double {
  left: 16px;
  top: 61px;
  animation: move-path-double 2.8s infinite ease-in-out;
}

@keyframes move-path {
  0% {
    transform: translate(0, 0);
  }
  30% {
    transform: translate(0, -46px);
  }
  60% {
    transform: translate(-46px, -46px);
  }
  100% {
    transform: translate(46px, -46px);
  }
}

@keyframes move-path-double {
  0% {
    transform: translate(0, 0);
  }
  60% {
    transform: translate(92px, 0);
  }
  100% {
    transform: translate(92px, 0);
  }
}

.repeat-demo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 12px 0 4px;
}

.repeat-loop {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 4px solid #4b9f3a;
  border-right-color: transparent;
  position: relative;
  animation: spin-loop 1.6s infinite linear;
}

.repeat-loop::after {
  content: "";
  position: absolute;
  right: -4px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: #4b9f3a;
  transform: rotate(20deg);
}

.repeat-count {
  font-weight: 800;
  color: #4b9f3a;
  font-size: 1.1rem;
}

@keyframes spin-loop {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.turn-demo {
  display: flex;
  justify-content: center;
  margin: 12px 0 4px;
}

.turn-arrow {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 4px solid #c68a5f;
  position: relative;
  animation: turn-spin 2s infinite ease-in-out;
}

.turn-arrow::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: #c68a5f;
  transform: translateX(-50%) rotate(45deg);
}

@keyframes turn-spin {
  0%,
  40% {
    transform: rotate(0deg);
  }
  70%,
  100% {
    transform: rotate(180deg);
  }
}

.tree-intro-animation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 18px auto 22px;
}

.tree-cell {
  width: 74px;
  height: 74px;
  border-radius: 14px;
  background: #e9f8e6;
  border: 2px solid #c6e6bf;
  position: relative;
  overflow: hidden;
}

.tree-cell.grass {
  background: #f0faf0;
  border-color: #bfe6b9;
  opacity: 0;
  animation: grass-appear 2.6s infinite;
}

.tree-cell.grass::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 10px;
  background: radial-gradient(circle at 30% 40%, #7bd38c, transparent 60%),
    radial-gradient(circle at 70% 60%, #5bbf77, transparent 60%);
  opacity: 0.9;
}

.tree-top {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2fa64a;
  position: absolute;
  top: 12px;
  left: 18px;
  animation: tree-fade 2.6s infinite;
}

.tree-trunk {
  width: 10px;
  height: 18px;
  background: #8b5a2b;
  position: absolute;
  bottom: 12px;
  left: 31px;
  border-radius: 4px;
  animation: tree-fade 2.6s infinite;
}

.tree-remove-x {
  position: absolute;
  top: 6px;
  right: 8px;
  font-weight: 800;
  font-size: 18px;
  color: #dc2626;
  opacity: 0;
  animation: x-pop 2.6s infinite;
}

.tree-arrow {
  font-size: 26px;
  color: #94a3b8;
}

@keyframes tree-fade {
  0%,
  45% {
    opacity: 1;
    transform: scale(1);
  }
  60%,
  100% {
    opacity: 0;
    transform: scale(0.9);
  }
}

@keyframes x-pop {
  0%,
  40% {
    opacity: 0;
    transform: scale(0.8);
  }
  50%,
  65% {
    opacity: 1;
    transform: scale(1);
  }
  80%,
  100% {
    opacity: 0;
    transform: scale(0.9);
  }
}

@keyframes grass-appear {
  0%,
  55% {
    opacity: 0;
    transform: scale(0.9);
  }
  70%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  padding: 16px;
  border-radius: var(--radius-large);
  background: #fff;
  border: 1px solid #f0e6de;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}

.world-card {
  padding: 18px;
  border-radius: 18px;
  background: #fffdf9;
  border: 2px solid rgba(216, 86, 38, 0.18);
  box-shadow: 0 10px 22px rgba(17, 17, 17, 0.08);
  cursor: pointer;
  transition: transform 0.15s ease, border 0.2s ease, box-shadow 0.2s ease;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.world-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand-primary);
  box-shadow: 0 14px 28px rgba(17, 17, 17, 0.12);
}

.world-card.locked {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.world-card.locked:hover {
  transform: none;
  border-color: transparent;
}

.world-card h3 {
  margin-bottom: 6px;
  font-size: 1.15rem;
}

.world-card-image {
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: 14px;
  border: 2px solid rgba(216, 86, 38, 0.15);
  background: #fff;
}

.world-card.locked .world-card-image {
  filter: grayscale(0.7);
}

.world-lock {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid rgba(148, 163, 184, 0.75);
  display: grid;
  place-items: center;
  font-size: 28px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.25);
  transform: translate(-50%, -50%);
  z-index: 2;
}

.world-card p {
  color: #4b5563;
}

.landing {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 15px 20px;
}

.landing-header {
  background: var(--brand-surface);
  border-radius: var(--radius-large);
  padding: 10px 10px;
  box-shadow: var(--shadow);
}

.landing-content {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 2fr;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.landing-info {
  background: #fff;
  border-radius: var(--radius-large);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.landing-robot {
  width: 100%;
  max-width: 260px;
  align-self: center;
  height: auto;
}

.landing-list {
  margin: 0;
  padding-left: 18px;
  color: #4b5563;
}

@media (max-width: 1100px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }

  .blockly-header {
    grid-template-columns: 1fr;
  }

  .landing-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1366px) and (max-height: 800px) {
  :root {
    --toolbox-width: 220px;
  }

  .app,
  .landing {
    padding: 10px 14px;
    gap: 12px;
  }

  .topbar,
  .landing-header {
    padding: 8px 10px;
  }

  .brand-avatar {
    width: 44px;
    height: 44px;
  }

  .brand h1 {
    font-size: 1.35rem;
  }

  .progress-dots {
    gap: 6px;
  }

  .progress-dot {
    width: 14px;
    height: 14px;
  }

  .main-grid {
    gap: 12px;
  }

  .panel {
    padding: 12px;
    gap: 10px;
  }

  .panel-header h2 {
    font-size: 1.1rem;
  }

  .simulator canvas {
    max-height: 360px;
  }

  .blockly-header {
    font-size: 0.68rem;
  }

  .landing-content {
    gap: 16px;
  }

  .landing-info {
    padding: 16px;
    gap: 10px;
  }

  .landing-robot {
    max-width: 200px;
  }

  .world-card {
    padding: 14px;
  }

  .world-card-image {
    height: 160px;
  }
}
