:root {
  --ink: #17202a;
  --muted: #667085;
  --panel: #ffffff;
  --line: #d7dee8;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #f7c948;
  --canvas: #f6f9fc;
  --glow: rgba(37, 99, 235, 0.22);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(56, 189, 248, 0.18), transparent 32%),
    radial-gradient(circle at 90% 10%, rgba(250, 204, 21, 0.18), transparent 28%),
    #eaf0f6;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a.command {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

a.command[hidden] {
  display: none !important;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  min-height: 72px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #111827, #2563eb);
  color: #fff;
  border-radius: 8px;
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.1;
}

.brand p,
.buddy-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.command,
.inspector-actions button,
.buddy-inputs button {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 8px;
  background: #eef2f7;
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(15, 23, 42, 0.08);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.command:hover,
.tool:hover,
.palette-item:hover,
.mode-card:hover,
.inspector-actions button:hover,
.buddy-inputs button:hover,
.quick-ideas button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.command.primary { background: var(--green); color: #fff; }
.command.danger { background: #fee2e2; color: #991b1b; }
.command.surprise { background: var(--yellow); color: #3a2a00; }
.command.save-link { background: #dcfce7; color: #166534; }

.mode-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 8px;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.mode-card {
  min-height: 58px;
  padding: 9px 10px;
  display: grid;
  align-content: center;
  gap: 2px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.05);
}

.mode-card span {
  font-weight: 900;
  color: var(--ink);
}

.mode-card small {
  color: var(--muted);
  font-weight: 750;
}

.mode-card.active {
  border-color: #2563eb;
  background: #dbeafe;
  box-shadow: 0 10px 24px var(--glow);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(360px, 1fr) 300px;
}

.side-panel {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.inspector-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

h2 {
  margin: 8px 0 10px;
  font-size: 15px;
}

.tool-grid,
.palette {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.tool,
.palette-item {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #f2f5f9;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
}

.tool.active,
.palette-item.active {
  border-color: var(--blue);
  background: #dbeafe;
  box-shadow: 0 8px 18px var(--glow);
}

.tool-icon,
.sample {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  display: inline-block;
  position: relative;
}

.pointer { border-left: 15px solid #111827; border-top: 22px solid transparent; transform: rotate(-18deg); }
.move::before { content: ""; position: absolute; inset: 5px; border: 3px solid #111827; transform: rotate(45deg); }
.rotate { border: 4px solid #111827; border-left-color: transparent; border-radius: 50%; }
.delete::before, .delete::after { content: ""; position: absolute; left: 12px; top: 2px; width: 4px; height: 24px; background: #111827; }
.delete::before { transform: rotate(45deg); }
.delete::after { transform: rotate(-45deg); }
.draw { border: 3px solid #111827; border-radius: 50% 40% 45% 30%; }
.paint::before { content: ""; position: absolute; left: 4px; top: 4px; width: 20px; height: 20px; border-radius: 50%; background: conic-gradient(#ef4444, #facc15, #22c55e, #38bdf8, #8b5cf6, #ef4444); }
.terrain::before { content: ""; position: absolute; left: 1px; right: 1px; bottom: 4px; height: 16px; background: #22c55e; clip-path: polygon(0 85%, 18% 55%, 34% 72%, 53% 28%, 72% 62%, 100% 40%, 100% 100%, 0 100%); }

.ball,
.wheel {
  border-radius: 50%;
  background: #ef4444;
}

.wheel {
  background: radial-gradient(circle, #fff 18%, #374151 20%, #374151 30%, #f59e0b 31%);
}

.box { background: #3b82f6; border-radius: 5px; }
.block { background: repeating-linear-gradient(90deg, #60a5fa 0 12px, #2563eb 12px 14px); border-radius: 5px; }
.plank { height: 10px; margin-top: 9px; background: #c18446; border-radius: 5px; box-shadow: inset 0 2px #e7b06b; }
.triangle { width: 0; height: 0; border-left: 15px solid transparent; border-right: 15px solid transparent; border-bottom: 27px solid #22c55e; }
.ramp { width: 0; height: 0; border-left: 30px solid transparent; border-bottom: 25px solid #8b5cf6; }
.platform { height: 10px; margin-top: 9px; background: #64748b; border-radius: 5px; }
.spring::before { content: "~~~~"; position: absolute; top: 2px; left: 0; color: #0891b2; font-weight: 900; font-size: 20px; }
.rocket { background: #f97316; clip-path: polygon(50% 0, 85% 28%, 70% 100%, 30% 100%, 15% 28%); }
.target { border-radius: 50%; background: repeating-radial-gradient(circle, #22c55e 0 4px, #111827 4px 7px); }

.stage-wrap {
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: linear-gradient(#f8fbff, var(--canvas));
}

.mission-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(215, 222, 232, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  pointer-events: auto;
}

.mission-panel strong {
  display: block;
  margin-bottom: 2px;
  font-size: 15px;
}

.mission-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

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

.mission-actions button,
.quick-ideas button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 900;
}

#worldCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage-hud {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.status-pill,
.hint {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  font-size: 13px;
  font-weight: 800;
}

.hint {
  max-width: 520px;
  color: var(--muted);
  font-weight: 700;
}

.inspector,
.buddy {
  margin-bottom: 16px;
}

.inspector label,
.parent-settings label {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

select,
input[type="text"],
input[type="color"] {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

input[type="color"] {
  padding: 3px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin: 8px 0 12px;
}

.swatches button {
  aspect-ratio: 1;
  min-height: 30px;
  border: 2px solid #ffffff;
  border-radius: 8px;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--line);
}

.check-row,
.parent-settings label:has(input[type="checkbox"]) {
  display: flex !important;
  align-items: center;
  gap: 8px !important;
}

.inspector-actions,
.buddy-inputs {
  display: grid;
  gap: 8px;
}

.inspector-actions {
  grid-template-columns: 1fr 1fr;
}

.buddy-inputs {
  grid-template-columns: 0.7fr 1.5fr 0.8fr;
}

.quick-ideas {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.buddy-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
}

.buddy-head .switch {
  margin-left: auto;
}

.mascot {
  width: 46px;
  height: 44px;
  flex: 0 0 46px;
  position: relative;
  border: 3px solid #111827;
  border-radius: 8px;
  background: linear-gradient(#a7f3d0, #67e8f9);
  box-shadow: inset 0 -7px 0 rgba(255,255,255,0.35);
}

.mascot::before,
.mascot::after {
  content: "";
  position: absolute;
  top: -10px;
  width: 3px;
  height: 10px;
  background: #111827;
}

.mascot::before { left: 12px; transform: rotate(-18deg); }
.mascot::after { right: 12px; transform: rotate(18deg); }

.mascot-eye {
  position: absolute;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #111827;
}

.mascot-eye.left { left: 11px; }
.mascot-eye.right { right: 11px; }

.mascot-mouth {
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 10px;
  height: 4px;
  border-radius: 99px;
  background: #111827;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 46px;
  height: 26px;
  display: block;
  position: relative;
  border-radius: 99px;
  background: #d0d5dd;
}

.switch span::after {
  content: "";
  width: 20px;
  height: 20px;
  position: absolute;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.switch input:checked + span { background: #111827; }
.switch input:checked + span::after { transform: translateX(20px); }

.buddy-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

#buddyPrompt {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 900;
}

.buddy-log {
  max-height: 112px;
  overflow: auto;
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.buddy-message {
  padding: 7px 8px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: #344054;
  font-size: 13px;
  line-height: 1.3;
}

.buddy-message.user {
  background: #eef2ff;
  color: #3730a3;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.choice-grid button {
  min-height: 42px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #075985;
  font-weight: 900;
}

.privacy-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.parent-settings {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.parent-settings summary {
  cursor: pointer;
  font-weight: 900;
}

@media (max-width: 1000px) {
  .mode-strip {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

  .workspace {
    grid-template-columns: 180px minmax(300px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    max-height: 300px;
  }
}

@media (max-width: 720px) {
  .topbar,
  .inspector-panel {
    display: block;
  }

  .mode-strip {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .stage-wrap {
    order: 1;
  }

  .tools-panel {
    order: 2;
  }

  .inspector-panel {
    order: 3;
  }

  .mode-card {
    margin-bottom: 8px;
  }

  .mission-panel {
    position: static;
    margin: 8px;
    display: grid;
  }

  .topbar {
    min-height: auto;
  }

  .side-panel {
    max-height: none;
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage-wrap {
    height: 60vh;
    min-height: 360px;
  }
}
