:root {
  --studio-ink: #2c3e50;
  --studio-blue: #2d96ee;
  --studio-line: #bfdcf6;
  --studio-shelf: #ffffffdb;
  --studio-paper: #fff;
  --studio-stage: #f5f2f7;
  --studio-orange: #ffa62b;
  --studio-ochre: #e0850e;
  --studio-palette-motion: #4785b2;
  --studio-panel-shadow: #cadff2 0 6px 0, #234b7d14 0 8px 20px;
  --studio-radius: 26px;
  --studio-pill: 999px;
  --studio-card-radius: 20px;
  --studio-small-radius: 3px;
  --studio-stage-width: 518px;
  --studio-side: 16px;
  --studio-top-height: 486px;
  --studio-palette-height: 86px;
}

html, body { margin: 0; width: 100%; min-width: 0; overflow: hidden; }
body { color: var(--studio-ink); font: 14px Roboto, Arial, sans-serif; background: #f8fbfc; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [role=button]:focus-visible { outline: 3px solid var(--studio-blue); outline-offset: -3px; }
input, textarea { user-select: text; }
#web-editor { position: relative; height: 100dvh; width: 100%; overflow: hidden; }
#web-editor .frame { min-height: 0; min-width: 0; }
#frame .topsection { position: relative; height: var(--studio-top-height); background: linear-gradient(#cae8f8, #eef5fc); }
#frame, #paintframe, #palette { touch-action: none; }
#frame input { touch-action: auto; }
#frame .flipme, #frame #projectinfo { display: none; }
#load-status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px; border-radius: 16px; background: white; z-index: 5000; }

.junior-project-tools { position: absolute; z-index: 12; top: 14px; left: var(--studio-side); display: flex; align-items: center; gap: 10px; }
.junior-project-tools button, #junior-info { box-sizing: border-box; font-weight: 700; }
#project-home { width: 56px; height: 46px; border: 2px solid white; border-radius: 16px; background: var(--studio-orange) url(junior.svg) center / 38px no-repeat; box-shadow: var(--studio-ochre) 0 4px 0; }
#project-title, #junior-info { height: 44px; min-width: 46px; padding: 0 14px; border: 2px solid var(--studio-line); border-radius: var(--studio-pill); background: var(--studio-shelf); box-shadow: #cadff2 0 3px 0, #234b7d14 0 4px 14px; }
#project-title { max-width: clamp(80px, calc(50vw - var(--studio-stage-width)/2 - 82px), 178px); min-width: 80px; padding-inline: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 800; }
#junior-info { position: absolute; top: 14px; right: var(--studio-side); z-index: 12; padding: 0; color: var(--studio-blue); font-size: 24px; }

#frame .centerpanel { width: 100%; height: 100%; pointer-events: none; }
#frame #stageframe { position: absolute; left: 50%; top: 80px; margin: 0; transform: translateX(-50%); width: var(--studio-stage-width); height: calc(var(--studio-stage-width) * .75); box-sizing: border-box; border: 4px solid white; border-radius: var(--studio-radius); background: var(--studio-stage); box-shadow: var(--studio-panel-shadow); pointer-events: auto; }
#frame #stageframe .stage { top: 0; left: 0; border: 0; margin: 0; border-radius: 21px; box-shadow: none; }
.junior-stage-controls { position: absolute; left: -4px; right: -4px; top: -74px; height: 58px; padding: 0 3px 0 12px; display: grid; grid-template-columns: 52px 52px 1fr 52px 52px 1fr 52px 52px; align-items: center; gap: 9px; border: 3px solid #b3d5f0; border-radius: var(--studio-pill); background: #fff; box-shadow: #234b7d14 0 4px 10px; box-sizing: border-box; }
#stageframe .junior-stage-controls > div { position: static; width: 52px; height: 52px; cursor: pointer; background-size: contain; background-repeat: no-repeat; background-position: center; }
.junior-stage-controls #setbkg { grid-column: 4; }
.junior-stage-controls #resetall { grid-column: 7; }
.junior-stage-controls #go { grid-column: 8; }
#frame > #stage.fullscreen { z-index: 100; border-radius: 8px; }
#frame > #go.presentationmode, #frame > #full.presentationmode { z-index: 101; }
#frame:has(> #stage.fullscreen) .topsection { visibility: hidden; }

#frame .leftpanel, #frame .rightpanel { position: absolute; top: 74px; bottom: 18px; height: auto; margin: 0; box-sizing: border-box; background: var(--studio-shelf); border: 3px solid var(--studio-line); border-radius: var(--studio-radius); box-shadow: var(--studio-panel-shadow); z-index: 3; }
#frame .leftpanel { left: var(--studio-side); width: 244px; }
#frame .rightpanel { right: var(--studio-side); width: 196px; }
#frame #library, #frame #pages { position: absolute; inset: 0; width: auto; height: auto; margin: 0; }
#frame #library { padding: 10px; box-sizing: border-box; }
#frame #library .spritethumbs { width: 100%; max-height: calc(100% - 80px); overflow: hidden; scrollbar-width: none; }
#frame #library .spritecc { margin: 4px; padding-top: 4px; width: calc(100% - 8px); }
#frame .spritethumb { display: block; box-sizing: border-box; width: 100%; height: 68px; border: 3px solid var(--studio-line); border-radius: var(--studio-card-radius); background: var(--studio-paper); text-align: left; margin: 0 0 10px; cursor: pointer; }
#frame .spritethumb.on { border-color: var(--studio-orange); box-shadow: var(--studio-ochre) 0 4px 0, #ffa62b47 0 0 0 4px; }
#frame .spritethumb .thumbcanvas { inset: 0 auto auto 6px; width: 62px; height: 62px; margin: 0; }
#frame .spritethumb .sname { top: 0; bottom: 0; left: 64px; right: 46px; width: auto; display: flex; align-items: center; font-size: 14px; font-weight: 900; color: var(--studio-ink); text-align: left; }
#frame .spritethumb.on .sname { color: var(--studio-ochre); }
#frame .spritethumb.on .brush { display: block; top: 9px; right: 10px; left: auto; width: 41px; height: 41px; border: 0; padding: 0; background-size: contain; }
#frame .spritethumb .brush:disabled { opacity: .45; cursor: default; }
#frame .spritethumb .deletespritethumb { z-index: 7; width: 34px; height: 34px; }
#frame #library .scrollbar { z-index: 8; top: 10px; right: 1px; left: auto; height: calc(100% - 100px); width: 8px; }
#frame .scrollbar .sbthumb { width: 8px; }
#frame #library .addsprite, #frame #emptypage { display: grid; place-items: center; box-sizing: border-box; position: relative; background: var(--studio-paper); border: 3px dashed var(--studio-blue); border-radius: var(--studio-card-radius); box-shadow: #cadff2 0 4px 0, #234b7d14 0 4px 14px; color: var(--studio-blue); cursor: pointer; }
#frame #library .addsprite { width: 100%; height: 58px; margin: 4px 0 0; }
#frame #library .addsprite::before, #frame #emptypage::before { content: '+'; font-size: 36px; line-height: 1; font-weight: 700; pointer-events: none; }
#frame #pagecc { inset: 8px 6px 4px; width: auto; height: auto; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; gap: 10px; overflow: auto; scrollbar-width: none; padding: 2px 5px 8px; }
#frame #pagecc .pagethumb, #frame > .pagethumb { width: 140px; height: 106px; flex: none; position: relative; box-sizing: border-box; border-radius: var(--studio-card-radius); border: 3px solid var(--studio-line); background: white; cursor: pointer; margin: 0; }
#frame #pagecc .pagethumb.on { border-color: var(--studio-orange); box-shadow: var(--studio-ochre) 0 4px 0, #ffa62b47 0 0 0 4px; }
#frame #pagecc .pc-container { position: absolute; inset: 4px; margin: 0; border-radius: 12px; overflow: hidden; }
#frame #pagecc .pc { width: 100%; height: 100%; zoom: 1 !important; }
#frame #pagecc .pagenum { display: grid; place-items: center; box-sizing: border-box; position: absolute; right: 6px; top: 6px; margin: 0; padding: 0; width: 26px; height: 26px; border-radius: var(--studio-pill); font-size: 13px; background: #8098b3; text-shadow: none; }
#frame #pagecc .on .pagenum { background: var(--studio-orange); box-shadow: var(--studio-ochre) 0 2px 0; }
#frame #pagecc .deletethumb { position: absolute; left: -4px; top: -4px; margin: 0; width: 34px; height: 34px; }
#frame #pagecc #emptypage { height: 48px; aspect-ratio: auto; margin: 0; border: 3px dashed var(--studio-blue); }
#frame #emptypage .empty { display: none; }
#frame #emptypage::before { font-size: 30px; }

#frame #blockspalette { position: relative; height: var(--studio-palette-height); display: flex; align-items: center; gap: 6px; padding: 0 12px 0 6px; box-sizing: border-box; border-block: 3px solid var(--studio-line); background: #fff !important; }
#frame #blockspalette .categoryselector { flex: 0 0 354px; width: 354px; height: 64px; overflow: visible; }
#frame #blockspalette .catbkg, #frame #blockspalette .papercut { visibility: hidden; }
#frame #selectors > button { margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer; }
#frame #selectors > button img { inset: 0; }
#junior-palette-scroll { flex: 1 1 auto; min-width: 0; height: 68px; box-sizing: content-box; border: 2px solid #accce6; border-radius: 18px; background: var(--palette-color, var(--studio-palette-motion)); box-shadow: inset 0 2px 4px #234b7d26; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; display: flex; position: relative; }
#frame #palette { flex: 0 0 auto; height: 68px; margin: 0; }
.sound-choices { display: flex; flex: 0 0 auto; align-items: center; gap: 6px; padding: 0 22px 0 4px; }
.sound-choices[hidden] { display: none; }
.sound-choices button { flex: none; min-height: 36px; padding: 4px 8px; border: 1px solid #ffffff80; border-radius: 16px; background: #ffffff40; color: #437515; font-size: 13px; font-weight: 900; }
.sound-choices button:disabled { opacity: .7; cursor: default; }
button.palette-step { display: none; }
.overflowing button.palette-step { display: block; position: sticky; z-index: 8; align-self: center; flex: 0 0 22px; width: 22px; height: 34px; padding: 0; font: 700 24px Roboto, sans-serif; color: white; border: 0; border-radius: 12px; background: #24465cd9; }
.overflowing button.palette-step:disabled { visibility: hidden; }
.palette-step.previous { order: -1; left: 0; margin-right: -22px; }
.palette-step.next { right: 0; margin-left: -22px; }
#frame #undocontrols { position: relative; inset: auto; margin: 0 0 0 6px; width: 108px; height: 50px; flex: 0 0 108px; display: flex; justify-content: space-around; align-items: center; }
#frame #undocontrols div { position: static; width: 50px; height: 50px; margin: 0; cursor: pointer; }
#frame #scripts { inset: calc(var(--studio-top-height) + var(--studio-palette-height)) 0 0; width: 100% !important; height: auto !important; background: #fafdff radial-gradient(circle, #cde5fa 1.7px, transparent 2px) 0 0 / 24px 24px; }
#frame .watermark { top: 23px; left: 29px; opacity: .23; pointer-events: none; }

#libframe, #paintframe { inset: 0; min-width: 0; min-height: 0; overflow: hidden; }
#libframe .topbar { position: absolute; height: 68px; }
#libframe .bkgbuttons { display: flex; align-items: center; justify-content: flex-end; width: auto; height: 56px; padding-right: 10px; gap: 8px; }
#libframe .bkgbuttons > div { display: block; flex: 0 0 48px; width: 48px; height: 48px; margin: 0; cursor: pointer; }
#libframe #asssetsview { position: absolute; inset: 68px 0 0; overflow: hidden; touch-action: pan-y; padding: 0; }
#libframe #scrollarea { width: 100% !important; height: 100% !important; box-sizing: border-box; overscroll-behavior: contain; padding: 8px; }

dialog { width: min(540px, calc(100% - 28px)); max-width: none; max-height: min(720px, 85dvh); overflow: auto; box-sizing: border-box; border: 3px solid var(--studio-line); border-radius: var(--studio-radius); padding: 20px; color: var(--studio-ink); background: white; box-shadow: 0 12px 36px #234b7d44; }
dialog::backdrop { background: #203a5570; }
.dialog-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.dialog-title h1 { color: inherit; margin: 0; font-size: 22px; }
dialog button { min-height: 40px; border: 2px solid var(--studio-line); border-radius: 12px; background: #f6fbff; padding: 5px 10px; font-weight: 700; }
dialog button:hover { background: #e5f4ff; }
dialog a { color: #1b61a5; }
dialog p + p { margin-top: 12px; }
.project-name { display: grid; gap: 4px; font-weight: 700; }
.project-name input { min-width: 0; border: 2px solid var(--studio-line); border-radius: 12px; padding: 9px; font: inherit; color: var(--studio-ink); }
.project-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
#project-list { display: grid; gap: 6px; padding: 0; margin: 0; list-style: none; }
#project-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
#project-list li button:first-child { text-align: left; overflow-wrap: anywhere; }
#project-list button[aria-current=true] { border-color: var(--studio-orange); }
#project-status:not(:empty) { margin-top: 12px; }

@media (max-width: 1040px) {
  :root { --studio-stage-width: clamp(420px, 62.5vw, 480px); --studio-top-height: 450px; }
  #project-title { padding-inline: 8px; text-align: left; }
  #frame #stageframe { top: 74px; }
  .junior-stage-controls { top: -70px; height: 56px; }
  #stageframe .junior-stage-controls > div { width: 48px; height: 48px; }
  #frame .leftpanel { width: clamp(188px, 31.8vw, 244px); }
  #frame .rightpanel { width: clamp(160px, 25.5vw, 196px); }
  #frame #pagecc .pagethumb { max-width: 100%; }
}

@media (max-width: 680px) {
  :root { --studio-stage-width: clamp(146px, (100dvh - 555px) * 4 / 3, 242px); --studio-top-height: calc(248px + var(--studio-stage-width) * .75); --studio-palette-height: 106px; }
  .junior-project-tools { top: 10px; gap: 7px; }
  #project-home { width: 44px; height: 44px; background-size: 33px; }
  #project-title { max-width: 80px; padding-inline: 5px; }
  #junior-info { top: 10px; min-width: 40px; }
  #frame #stageframe { top: 237px; border-radius: var(--studio-card-radius); }
  .junior-stage-controls { position: fixed; top: 10px; left: 154px; right: 62px; height: 44px; padding: 0 4px; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; justify-items: center; }
  #stageframe .junior-stage-controls > div { grid-column: auto; width: 100%; height: 40px; }
  #frame #stageframe { transform: none; left: calc(50% - var(--studio-stage-width) / 2); }
  #frame .leftpanel, #frame .rightpanel { top: 74px; bottom: auto; height: 152px; }
  #frame .leftpanel { width: calc(56% - 21px); }
  #frame .rightpanel { width: calc(44% - 21px); }
  #frame #library { padding: 6px; }
  #frame #library .spritethumbs { max-height: 78px; }
  #frame #library .addsprite { height: 40px; }
  #frame .spritethumb .thumbcanvas { left: 0; width: 55px; }
  #frame .spritethumb .sname { left: 55px; right: 38px; }
  #frame .spritethumb.on .brush { right: 3px; width: 35px; }
  #frame #pagecc .pagethumb { height: 78px; }
  #frame #pagecc #emptypage { height: 40px; }
  #frame #pagecc:has(.pagethumb:nth-child(3)) { gap: 5px; }
  #frame #pagecc:has(.pagethumb:nth-child(3)) .pagethumb { height: 27px; border-radius: 11px; }
  #frame #pagecc:has(.pagethumb:nth-child(3)) .pagenum { top: 1px; width: 18px; height: 18px; }
  #frame #pagecc:has(.pagethumb:nth-child(3)) #emptypage { height: 27px; }
  #frame #pagecc:has(.pagethumb:nth-child(3)) #emptypage::before { font-size: 21px; }
  #frame #blockspalette { display: grid; grid-template-columns: minmax(0, 1fr) 70px; grid-template-rows: 51px 48px; gap: 0 5px; padding: 0 8px; }
  #frame #blockspalette .categoryselector { grid-column: 1 / -1; width: min(100%, 354px); height: 50px; align-self: start; }
  #frame #selectors > button { left: calc((var(--category-index) + .5) * 100% / 6 - 23px) !important; width: 46px !important; }
  #frame #selectors > button, #frame #selectors > button img { height: 50px !important; }
  #frame #selectors > button img { width: 46px; }
  #junior-palette-scroll { height: 44px; }
  #frame #palette { height: 44px; }
  #frame #undocontrols { width: 70px; height: 44px; margin: 0; }
  #frame #undocontrols div { width: 34px; height: 34px; }
  #libframe .assetname-container { display: none; }
  #paintframe .side { width: 48px; right: 4px; top: 0; padding: 0; }
  #paintframe .side.up { left: 4px; right: auto; }
  #paintframe .paintpalette { width: 48px; }
  #paintframe .paintpalette .element { margin: 0 0 4px; width: 46px; height: 46px; }
  #paintframe .paintpalette .tool { width: 46px; height: 46px; }
  #paintframe .paintpalette .section.space { top: 200px; margin: 0; }
  #paintframe .workspacebkg { width: calc(100% - 108px); height: min(55vh, 480px); }
  #paintframe .swatchpalette-container { top: auto; bottom: 5px; }
  #paintframe .swatchpalette { width: min(100%, 380px); height: auto; text-align: center; }
  #paintframe .swatchbucket, #paintframe .splasharea, #paintframe .splasharea img { width: 32px; height: 32px; }
  #paintframe .swatchframe { margin: 3px; width: 25px; height: 25px; }
  #paintframe .swatchcolor { width: 21px; height: 21px; }
}

@media (max-width: 475px) {
  :root {
    --studio-stage-width: clamp(146px, (100dvh - 555px) * 4 / 3, 242px);
    --studio-top-height: calc(268.5px + var(--studio-stage-width) * .75);
    --studio-palette-height: 86px;
  }
  #project-title { display: none; }
  .junior-stage-controls { left: 64px; right: 62px; top: 9px; height: 48px; }
  #frame .leftpanel, #frame .rightpanel { bottom: 18px; height: auto; pointer-events: none; }
  #frame .leftpanel { width: calc(56% - 10px); }
  #frame .rightpanel { width: calc(44% - 10px); }
  #frame #library, #frame #pages { bottom: auto; height: 180px; pointer-events: auto; }
  #frame #pagecc { gap: 14px; padding-inline: 2px; }
  #frame #library { padding: 10px; }
  #frame #library .spritethumbs { max-height: 92px; }
  #frame .spritethumb.on .brush { height: 35px; }
  #frame #library .addsprite { height: 48px; }
  #frame #pagecc #emptypage { height: 42px; }
  #frame #pagecc .pagethumb { height: 106px; }
  #frame #stageframe { top: 253px; border-radius: 16px; box-shadow: none; z-index: 4; }
  #frame #blockspalette { grid-template-rows: 40px 40px; }
  #frame #blockspalette .categoryselector { width: min(100%, 324px); margin-left: 5px; height: 40px; }
  #frame #selectors > button, #frame #selectors > button img { height: 44px !important; }
  #junior-palette-scroll { height: 38px; background: #fff; border-radius: 11px; box-shadow: none; }
  #junior-palette-scroll:has(.sound-choices:not([hidden])) { background: var(--palette-color); }
  .sound-choices { gap: 4px; padding-inline: 2px 4px; }
  .sound-choices button { padding-inline: 6px; }
  #frame #palette { height: 40px; top: -2px; }
  #frame #undocontrols { height: 40px; }
}

@media (max-height: 620px) and (min-width: 681px) {
  :root { --studio-stage-width: min(430px, (100dvh - 190px) * 4 / 3); --studio-top-height: calc(var(--studio-stage-width) * .75 + 88px); }
}
