.scratch-editor {
  display: grid;
  grid-template-columns: 230px minmax(310px, 1fr) 230px;
  border: 1px solid #3b4544;
  border-radius: 16px;
  overflow: hidden;
  background: #1b2123;
}
.screen-game .screen-heading h1 {
  font-size: clamp(28px, 3.5vw, 48px);
}
.screen-game .screen-heading p {
  font-size: 14px;
}
.scratch-section-title {
  font-size: 10px;
  letter-spacing: 1.3px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #bdc9c7;
  margin-bottom: 18px;
}
.scratch-section-title > span {
  font-size: 8px;
  color: #80918b;
}
.scratch-palette {
  padding: 22px 18px;
  background: #20272a;
  border-right: 1px solid #3b4544;
}
.scratch-palette > p {
  font-size: 11px;
  margin: 0 0 20px;
}
.palette-blocks {
  display: grid;
  gap: 17px;
}
.palette-item > small {
  font-size: 8px;
  letter-spacing: 1px;
  color: #98a9a9;
  display: block;
  margin-bottom: 7px;
}
.scratch-block {
  --block: #4c97ff;
  --edge: #3373cc;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: var(--block);
  color: white;
  text-shadow: 0 1px 1px #0005;
  padding: 15px 13px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  min-height: 46px;
  text-align: left;
  width: max-content;
  max-width: 100%;
  border-radius: 5px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: inset 0 0 0 1px var(--edge);
  z-index: 1;
  margin: 0 0 1px;
}
.scratch-block:not(.boolean):not(.event):before {
  content: '';
  position: absolute;
  top: 0;
  left: 24px;
  width: 30px;
  height: 7px;
  background: var(--socket-bg, #20272a);
  clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
}
.scratch-block:not(.boolean):after,
.if-foot:after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 24px;
  width: 30px;
  height: 7px;
  background: var(--block);
  clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
  z-index: 3;
}
.scratch-block.event {
  --block: #ffbf00;
  --edge: #c89100;
  color: #493707;
  text-shadow: none;
  border-radius: 36px 36px 5px 5px;
  padding-top: 22px;
  margin-top: 5px;
}
.event-icon {
  font-size: 22px;
  color: #fff;
  line-height: 1;
}
.scratch-block.sensing {
  --block: #5cb1d6;
  --edge: #308cad;
}
.scratch-block.control {
  --block: #ffab19;
  --edge: #cf850b;
  color: #4e3207;
  text-shadow: none;
}
.scratch-block.sound {
  --block: #cf63cf;
  --edge: #a63ca6;
}
.scratch-block.looks {
  --block: #9966ff;
  --edge: #774cce;
}
.scratch-block.boolean {
  --block: #59c059;
  --edge: #389438;
  clip-path: polygon(
    12px 0,
    calc(100% - 12px) 0,
    100% 50%,
    calc(100% - 12px) 100%,
    12px 100%,
    0 50%
  );
  border-radius: 0;
  padding: 11px 20px;
  min-height: 38px;
  font-size: 11px;
}
.scratch-block.is-selected {
  filter: brightness(1.15);
  outline: 3px solid #edfaae;
  outline-offset: 3px;
}
.scratch-block.boolean.is-selected {
  filter: drop-shadow(0 0 5px #e5ff64) brightness(1.2);
}
.palette-piece.control {
  display: block;
  padding-bottom: 11px;
  width: 100%;
}
.mini-cavity {
  display: block;
  height: 18px;
  background: #20272a;
  margin: 12px -13px 8px 3px;
  border-radius: 4px 0 0 4px;
}
.scratch-canvas {
  --socket-bg: #182025;
  background-color: #182025;
  background-image: radial-gradient(#45515680 1px, transparent 1px);
  background-size: 20px 20px;
  padding: 22px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.scratch-program {
  flex: 1;
  min-height: 380px;
  padding-top: 8px;
}
.scratch-stack {
  position: relative;
  min-width: 0;
  padding-bottom: 5px;
}
.scratch-stack > .scratch-block {
  min-width: 190px;
}
.snap-slot {
  display: block;
  position: relative;
  height: 0;
  width: 100%;
  max-width: 340px;
  border: 0;
  background: transparent;
  padding: 0;
  z-index: 4;
  text-align: left;
  border-radius: 4px;
  color: #a9babc;
}
.snap-slot > span {
  display: none;
  font-size: 10px;
  font-weight: 400;
  line-height: 1.4;
}
.snap-slot:last-child {
  height: 37px;
  margin-top: 10px;
  border: 1px dashed #617178;
  padding: 8px 12px;
}
.snap-slot:last-child > span {
  display: block;
}
.scratch-stack:not(:has(.scratch-block)):not(:has(.scratch-if)) > .snap-slot {
  height: 62px;
}
.snap-slot:focus-visible,
.snap-slot:hover,
.scratch-dragging .snap-slot {
  background: #d0f87812;
  outline: 1px dashed #a7cb6e;
}
.snap-slot.snap-hover {
  background: #d0f87866;
  outline: 3px solid #d0f878;
  box-shadow: 0 0 14px #c3ee7333;
}
.scratch-help {
  font-size: 10px;
  line-height: 1.8;
  color: #97a9af;
  margin-top: 30px;
}
.scratch-if {
  position: relative;
  background: #ffab19;
  --block: #ffab19;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px #cc840c;
  max-width: 100%;
  color: #4e3207;
}
.scratch-if > .if-head {
  width: 100%;
  height: 59px;
  align-items: center;
  padding-left: 12px;
  box-shadow: none;
  padding-right: 0;
}
.if-head:after {
  display: none;
}
.if-head:before {
  background: #182025 !important;
}
.if-condition {
  position: absolute;
  top: 10px;
  left: 56px;
  right: 8px;
  display: flex;
  gap: 7px;
  align-items: center;
  z-index: 3;
  font-size: 12px;
}
.if-condition .scratch-block {
  font-size: 10px;
  padding: 10px 15px;
  white-space: nowrap;
}
.boolean-socket {
  border: 0;
  clip-path: polygon(
    12px 0,
    calc(100% - 12px) 0,
    100% 50%,
    calc(100% - 12px) 100%,
    12px 100%,
    0 50%
  );
  background: #b16b09;
  color: #ffe0a5;
  font-size: 11px;
  min-height: 36px;
  padding: 8px 22px;
}
.boolean-socket.snap-hover {
  background: #80c650;
  color: #163b1a;
}
.if-mouth {
  --socket-bg: #182025;
  background: #182025;
  margin-left: 17px;
  padding: 8px 9px 8px 15px;
  border-radius: 4px 0 0 4px;
  min-height: 65px;
  box-shadow: inset 1px 1px 0 #bb790c;
}
.if-mouth > small {
  display: block;
  color: #9baeb2;
  font-size: 8px;
  letter-spacing: 1px;
  margin: 2px 0 9px;
}
.if-mouth .scratch-block {
  min-width: 0;
}
.if-mouth .snap-slot {
  max-width: 100%;
}
.if-else {
  height: 33px;
  font-weight: 700;
  font-size: 12px;
  padding: 9px 14px;
}
.if-foot {
  height: 20px;
  position: relative;
}
.scratch-preview {
  padding: 22px 17px;
  border-left: 1px solid #3b4544;
  background: #222a2a;
}
.scratch-preview .door-scene {
  min-height: 225px;
}
.scratch-preview .door-frame {
  width: 105px;
  height: 170px;
  border-width: 6px;
}
.scratch-preview .door-panel {
  inset: 50px 13px 20px;
}
.scratch-preview .door-number {
  font-size: 10px;
  top: 20px;
}
.scratch-preview .door-caption {
  font-size: 7px;
  bottom: 9px;
}
.scratch-key {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin: 20px 0;
  cursor: pointer;
}
.scratch-key input {
  accent-color: var(--lime);
  width: 17px;
  height: 17px;
}
.scratch-preview .primary {
  width: 100%;
  font-size: 10px;
  padding: 14px 8px;
}
.scratch-output {
  font-size: 11px;
  color: #bac9c2;
  line-height: 1.7;
  margin-top: 18px;
  min-height: 65px;
}
.scratch-return {
  background: transparent;
  border: 1px dashed #728084;
  border-radius: 6px;
  font-size: 10px;
  color: #bac8c9;
  padding: 12px;
  width: 100%;
  margin-top: 25px;
}
.scratch-return.snap-hover {
  background: #d0f87830;
  border-color: var(--lime);
}
.scratch-drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  padding: 15px 20px;
  background: #77a5ef;
  color: white;
  font-size: 13px;
  font-weight: bold;
  border: 2px solid #d0f878;
  border-radius: 8px;
  box-shadow: 0 12px 30px #0008;
  max-width: 260px;
  transform: rotate(-3deg);
}
.scratch-dragging {
  user-select: none;
  cursor: grabbing;
}
.scratch-editor:has(.is-selected) .snap-slot,
.scratch-dragging .snap-slot {
  background: #d0f87812;
}
.scratch-editor:has(.is-selected) .snap-slot:not(:last-child),
.scratch-dragging .snap-slot:not(:last-child) {
  height: 14px;
  outline: 1px dashed #788c59;
}
.scratch-editor:has(.is-selected) .boolean-socket {
  filter: brightness(1.3);
}
.screen-game:has(.correct) .scratch-canvas {
  box-shadow: inset 0 0 0 2px #b2d577;
}
.screen-game:has(.incorrect) .scratch-canvas {
  box-shadow: inset 0 0 0 1px #cb7661;
}
@media (max-width: 1100px) {
  .scratch-editor {
    grid-template-columns: 210px minmax(280px, 1fr);
  }
  .scratch-preview {
    grid-column: 1/-1;
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 12px 22px;
    border-left: 0;
    border-top: 1px solid #3b4544;
  }
  .scratch-preview .scratch-section-title {
    grid-column: 1/-1;
    margin: 0;
  }
  .scratch-preview .door-scene {
    grid-row: 2/6;
    min-height: 210px;
  }
  .scratch-key {
    margin: 8px 0;
  }
  .scratch-preview .text-button {
    margin: 0;
  }
  .scratch-output {
    min-height: 0;
    margin: 0;
  }
  .scratch-canvas {
    padding: 18px;
  }
  .scratch-block {
    font-size: 11px;
  }
}
@media (max-width: 620px) {
  .scratch-editor {
    grid-template-columns: 1fr;
  }
  .scratch-palette {
    border-right: 0;
    border-bottom: 1px solid #3b4544;
    padding: 18px;
  }
  .palette-blocks {
    grid-template-columns: 1fr 1fr;
    gap: 18px 10px;
  }
  .palette-item .scratch-block {
    font-size: 10px;
    max-width: 100%;
    padding-left: 10px;
    padding-right: 10px;
  }
  .palette-item .boolean {
    padding-left: 16px;
    padding-right: 16px;
  }
  .palette-item .event {
    min-height: 62px;
  }
  .scratch-palette > p {
    margin-bottom: 15px;
  }
  .scratch-return {
    margin-top: 20px;
  }
  .scratch-program {
    min-height: 230px;
  }
  .scratch-canvas {
    padding: 20px 16px;
  }
  .scratch-preview {
    grid-template-columns: 125px 1fr;
    gap: 12px;
  }
  .scratch-preview .primary {
    font-size: 9px;
  }
  .scratch-key {
    font-size: 10px;
  }
  .scratch-help {
    margin-top: 20px;
  }
  .if-condition .scratch-block {
    font-size: 9px;
  }
  .if-condition {
    gap: 5px;
  }
  .scratch-stack > .scratch-block {
    max-width: 100%;
  }
}
.if-condition {
  pointer-events: none;
}
.if-condition > button {
  pointer-events: auto;
}
.scratch-if {
  max-width: 380px;
}
.scratch-palette {
  max-height: 590px;
  overflow-y: auto;
  scrollbar-color: #637277 #20272a;
  scrollbar-width: thin;
}
.scratch-canvas {
  max-height: 590px;
  overflow-y: auto;
  scrollbar-color: #637277 #182025;
  scrollbar-width: thin;
}
.scratch-stack > .scratch-block {
  min-width: 190px;
}
.scratch-block {
  min-height: 40px;
  padding-top: 12px;
  padding-bottom: 12px;
}
.if-mouth {
  padding-top: 5px;
  padding-bottom: 5px;
}
.if-mouth > small {
  margin-bottom: 5px;
}
.if-else {
  height: 28px;
  padding-top: 7px;
}
.scratch-help {
  margin-top: 20px;
}
.scratch-program {
  min-height: 280px;
}
.scratch-section-title {
  flex-shrink: 0;
}
.scratch-editor .snap-slot:not(:last-child):focus-visible {
  height: 14px;
  outline: 2px solid var(--lime);
}
@media (max-width: 620px) {
  .scratch-palette {
    max-height: 350px;
  }
  .scratch-canvas {
    max-height: none;
    overflow: visible;
  }
  .scratch-if {
    max-width: 100%;
  }
}
