:root {
  --bg: #f3f6fd;
  --line: #d4dcf2;
  --text: #1d2a44;
  --muted: #5a6c93;
  --scratch-blue: #4c97ff;
  --scratch-orange: #ffab19;
  --scratch-purple: #9966ff;
  --scratch-yellow: #ffd500;
  --scratch-cyan: #2dc2d6;
  --scratch-green: #5cbf2a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand h1 {
  margin: 0.2rem 0 0;
  font-size: clamp(1.25rem, 2.4vw, 1.6rem);
}

.tag {
  margin: 0;
  color: #ff8c1a;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.toolbar-btn,
.new-btn,
.reset-btn {
  border: none;
  border-radius: 999px;
  padding: 0.58rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.toolbar-btn {
  background: var(--scratch-blue);
  color: #fff;
}

.workspace {
  width: min(1100px, 96%);
  margin: 1rem auto;
}

.project-shell {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(34, 66, 124, 0.1);
  padding: 1rem;
  min-height: 520px;
}

.project-shell::before {
  content: "Open Folder to show New";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  border: 2px dashed var(--line);
  border-radius: 14px;
  margin: 1rem;
}

.project-shell.is-open::before {
  display: none;
}

.project-toolbar {
  display: none;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.35rem;
}

.project-shell.is-open .project-toolbar {
  display: flex;
}

.category-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: min(720px, 100%);
}

.cat-tab {
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 0.38rem 0.75rem;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  color: #fff;
}

.cat-tab.motion {
  background: var(--scratch-blue);
}

.cat-tab.looks {
  background: #8a55d7;
}

.cat-tab.sound {
  background: #cf63cf;
}

.cat-tab.events {
  background: var(--scratch-yellow);
  color: #524100;
}

.cat-tab.control {
  background: var(--scratch-orange);
  color: #402900;
}

.cat-tab.sensing {
  background: var(--scratch-cyan);
}

.cat-tab.operators {
  background: var(--scratch-green);
}

.cat-tab.active {
  box-shadow: 0 0 0 2px #1d2a44;
}

.toolbar-right {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

.share-btn {
  border: none;
  border-radius: 999px;
  padding: 0.58rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
  background: #5865f2;
  color: #fff;
}

.share-status {
  margin: 0 0 0.5rem;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  background: #e8f5e9;
  color: #1b5e20;
  font-size: 0.88rem;
  font-weight: 700;
}

.new-btn {
  background: #43b581;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.58rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.command-menu {
  position: absolute;
  top: 2.8rem;
  right: 0;
  width: 260px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  box-shadow: 0 10px 24px rgba(41, 67, 116, 0.14);
  display: grid;
  gap: 0.45rem;
  z-index: 2;
}

.menu-title {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.columns {
  display: none;
  grid-template-columns: minmax(230px, 290px) 1fr;
  gap: 1rem;
  margin-top: 0.6rem;
}

.project-shell.is-open .columns {
  display: grid;
}

.stage-panel {
  display: none;
  margin-bottom: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, #e8f4ff 0%, #dcecff 45%, #cfe3ff 100%);
}

.project-shell.is-open .stage-panel {
  display: block;
}

.stage-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.75rem;
  background: rgba(255, 255, 255, 0.75);
  border-bottom: 1px solid var(--line);
  font-size: 0.82rem;
  font-weight: 700;
}

.stage-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.flag-btn,
.stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 2px solid #ffffff;
  background: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(30, 50, 90, 0.18);
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.flag-btn:hover,
.stop-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(30, 50, 90, 0.24);
}

.flag-btn.is-active {
  background: #e7f7df;
  box-shadow: 0 0 0 3px #4cbb17;
}

.stop-btn.is-active {
  background: #fde4e4;
  box-shadow: 0 0 0 3px #e23434;
}

.stage-title {
  margin-left: 0.25rem;
}

.stage-sprite-name {
  margin-left: auto;
}

.stage-title {
  color: var(--text);
}

.stage-sprite-name {
  color: var(--muted);
}

.stage-canvas {
  position: relative;
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #ffffff;
}

.fox-sprite {
  display: block;
  filter: drop-shadow(0 6px 10px rgba(30, 50, 90, 0.18));
  transform-origin: center center;
  will-change: transform;
}

.speech-bubble {
  position: absolute;
  max-width: 200px;
  padding: 0.45rem 0.7rem;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  border: 2px solid #1d2a44;
  border-radius: 14px;
  box-shadow: 0 4px 10px rgba(30, 50, 90, 0.18);
  z-index: 5;
  pointer-events: none;
  word-wrap: break-word;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: -10px;
  bottom: 8px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-left: 2px solid #1d2a44;
  border-bottom: 2px solid #1d2a44;
  transform: rotate(45deg);
}

.speech-bubble.think {
  border-style: dashed;
}

.speech-bubble.think::after {
  border-radius: 50%;
  width: 8px;
  height: 8px;
  left: -6px;
  bottom: 4px;
  background: #ffffff;
  border: 2px solid #1d2a44;
  transform: none;
}

.costumes-btn {
  position: absolute;
  left: 12px;
  bottom: 12px;
  border: 2px solid #ffffff;
  background: #8a55d7;
  color: #fff;
  font-weight: 700;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(30, 50, 90, 0.22);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.costumes-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(30, 50, 90, 0.28);
}

.costumes-btn[hidden] {
  display: none;
}

.sprite-pick-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 3px solid #ffffff;
  background: #ffb84d;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(30, 50, 90, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.sprite-pick-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(30, 50, 90, 0.28);
}

.sprite-pick-btn:active {
  transform: translateY(0);
}

.sprite-pick-btn img {
  display: block;
  pointer-events: none;
}

.sprite-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 60, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}

.sprite-modal[hidden] {
  display: none;
}

.sprite-modal-card {
  width: min(720px, 100%);
  max-height: 86vh;
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(20, 32, 60, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sprite-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.sprite-modal-head h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  border: none;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  background: #e7edf9;
  color: #244376;
}

.sprite-search {
  margin: 0.85rem 1rem 0;
  padding: 0.6rem 0.85rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
}

.sprite-search:focus {
  border-color: var(--scratch-blue);
}

.sprite-grid {
  list-style: none;
  margin: 0;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.6rem;
  overflow-y: auto;
}

.sprite-grid li {
  display: block;
}

.sprite-tile {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fafbff;
  padding: 0.55rem 0.4rem;
  cursor: pointer;
  display: grid;
  gap: 0.3rem;
  justify-items: center;
  transition: border-color 0.12s ease, transform 0.12s ease, background 0.12s ease;
  font-family: inherit;
}

.sprite-tile:hover {
  border-color: var(--scratch-blue);
  background: #f1f6ff;
  transform: translateY(-2px);
}

.sprite-tile img {
  display: block;
  width: 64px;
  height: 64px;
}

.sprite-tile span {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.sprite-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  padding: 1rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem;
}

.panel h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

#paletteHint {
  margin-top: 0;
  color: var(--muted);
}

.palette-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.palette-note {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.command-type,
.palette-block {
  border: none;
  border-radius: 10px;
  color: #fff;
  text-align: left;
  font-weight: 700;
  padding: 0.56rem 0.75rem;
  cursor: pointer;
}

.motion {
  background: var(--scratch-blue);
}

.looks {
  background: #8a55d7;
}

.sound {
  background: #cf63cf;
}

.events {
  background: var(--scratch-yellow);
  color: #524100;
}

.control {
  background: var(--scratch-orange);
  color: #402900;
}

.sensing {
  background: var(--scratch-cyan);
}

.operators {
  background: var(--scratch-green);
}

.variables {
  background: #ff8c1a;
}

.myblocks {
  background: #ff6ca8;
}

.script-help {
  margin-top: 0;
  color: var(--muted);
}

.script-area {
  min-height: 220px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  color: #64769d;
}

.script-block {
  display: inline-block;
  margin: 0.35rem 0.3rem 0 0;
  border-radius: 999px;
  padding: 0.35rem 0.72rem;
  font-weight: 700;
  color: #fff;
}

.script-block.dark-text {
  color: #3f2d00;
}

.script-actions {
  margin-top: 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.reset-btn {
  background: #e7edf9;
  color: #244376;
}

.costumes-card {
  width: min(540px, 100%);
}

.costumes-body {
  padding: 0.85rem 1rem 1rem;
  overflow-y: auto;
  display: grid;
  gap: 0.8rem;
}

.costumes-help {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.costumes-speed {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.costumes-speed input[type="range"] {
  width: 100%;
}

.costume-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.costume-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.45rem 0.6rem;
  background: #fafbff;
}

.costume-row.is-current {
  border-color: var(--scratch-blue);
  background: #eef5ff;
}

.costume-thumb {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  flex-shrink: 0;
}

.costume-thumb img {
  width: 36px;
  height: 36px;
  display: block;
}

.costume-meta {
  display: grid;
  flex: 1;
  min-width: 0;
}

.costume-index {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.costume-name {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.costume-actions {
  display: flex;
  gap: 0.35rem;
}

.costume-actions button {
  border: none;
  border-radius: 8px;
  background: #e7edf9;
  color: #244376;
  font-weight: 700;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
}

.costume-actions button.delete {
  background: #fde4e4;
  color: #9b1818;
}

.costume-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.add-costume-btn {
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--scratch-green);
  color: #fff;
  font-family: inherit;
  justify-self: start;
}

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