:root{
  --motion:#22A06B;
  --looks:#FF7043;
  --sound:#CF63CF;
  --events:#FFD700;
  --control:#FFAB19;
  --sensing:#5CB1D6;
  --operators:#40BF4A;
  --variables:#FF5C5C;
  --block-padding:10px 12px;
  --block-radius:14px;
  --script-shadow: 0 6px 0 rgba(0,0,0,0.08);
}

/* Palette block colors like Scratch */
.block{display:flex;align-items:center;padding:var(--block-padding);border-radius:var(--block-radius);margin-bottom:8px;cursor:grab;color:#fff;font-weight:600;box-shadow:var(--script-shadow);border:1px solid rgba(0,0,0,0.06)}
.block.motion{background:var(--motion)}
.block.looks{background:var(--looks)}
.block.control{background:var(--control)}
.block.wait{background:var(--control)}
.block.repeat{background:var(--control)}
.block.change-x{background:var(--motion)}
.block.change-y{background:var(--motion)}
.block.set-x{background:var(--motion)}
.block.set-y{background:var(--motion)}
.block.say{background:var(--looks)}
.block.bounce{background:var(--motion)}

/* Script blocks mimic palette appearance when placed in workspace */
.script-block{display:flex;align-items:center;justify-content:space-between;background:linear-gradient(#fff,#fff);border-radius:12px;padding:8px;margin-bottom:8px;cursor:grab;box-shadow:none;border:0;color:#fff;font-weight:700}
.script-block .label{color:#fff;font-weight:700;margin-right:6px}
.script-block[data-type="move"]{background:var(--motion)}
.script-block[data-type="turn"]{background:var(--motion)}
.script-block[data-type="changeX"]{background:var(--motion)}
.script-block[data-type="changeY"]{background:var(--motion)}
.script-block[data-type="setX"]{background:var(--motion)}
.script-block[data-type="setY"]{background:var(--motion)}
.script-block[data-type="say"]{background:var(--looks)}
.script-block[data-type="repeat"]{background:var(--control)}
.script-block[data-type="wait"]{background:var(--control)}
.script-block[data-type="bounceIfOnEdge"]{background:var(--motion)}
/* Make the 'when key pressed' hat block red in the palette and workspace for clear affordance */
.block.events{background:#E04B4B;color:#fff}
.script-block[data-type="whenKey"]{background:#E04B4B}

/* Params label styling on colored blocks */
.script-block .params{color:rgba(255,255,255,0.9);font-weight:600;margin-right:8px}

/* Make the stack area slightly lighter to contrast colored blocks */
.stackArea{background:#f7f9fb;border:2px dashed rgba(0,0,0,0.05);padding:12px;border-radius:8px;min-height:320px;overflow:auto}

/* Keep other styles intact */
:root{
  --bg:#fff;
  --fg:#111;
  --muted:#666;
  --accent:#222;
  --nav-green: #0FB6A8;
  --block-bg:#f3f3f3;
  --block-border:#ddd;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
*{box-sizing:border-box}
body{margin:0;color:var(--fg);background:var(--bg);height:100vh;display:flex;flex-direction:column}
.topbar{display:flex;justify-content:space-between;align-items:center;padding:10px 16px;border-bottom:1px solid #eee}
/* make the app topbar use the green nav when visible */
.topbar{background:var(--nav-green);color:#fff;border-bottom:0}
.topbar h1{color:#fff}
.topbar h1{font-size:16px;margin:0}
.controls button{margin-left:8px;padding:6px 10px;border:1px solid #ddd;background:#fff;border-radius:4px;cursor:pointer}
/* Home navbar */
.home-nav{position:absolute;top:0;left:0;right:0;background:var(--nav-green);color:#fff;padding:10px 16px;box-shadow:0 4px 12px rgba(0,0,0,0.08);border-bottom:4px solid rgba(0,0,0,0.06)}
.home-nav .nav-inner{max-width:980px;margin:0 auto;display:flex;justify-content:space-between;align-items:center}
/* align search in navbar and make it compact */
.nav-search{display:flex;align-items:center;gap:8px;margin-left:12px}
.nav-search input[type="search"]{padding:8px 10px;border-radius:8px;border:1px solid rgba(255,255,255,0.14);width:260px;background:rgba(255,255,255,0.08);color:#fff}
.nav-search button{padding:8px 10px;border-radius:8px;border:0;background:rgba(255,255,255,0.14);color:#fff;cursor:pointer}
.home-nav .brand{font-weight:700}
.home-nav .nav-link{color:rgba(255,255,255,0.95);margin-left:12px;text-decoration:none;font-weight:600}
/* profile in navbars */
.home-profile, .user-profile{
  display:flex;
  align-items:center;
  gap:8px;
  cursor:pointer;
}
.home-profile img, .user-profile img{
  width:28px;
  height:28px;
  border-radius:50%;
  background:#fff;
  display:inline-block;
  object-fit:cover;
  border:2px solid rgba(255,255,255,0.15);
}
.home-profile span, .user-profile span{
  font-weight:700;
  color:#fff;
  font-size:13px;
}
.user-profile{margin-left:12px}
.layout{display:grid;grid-template-columns:220px 1fr 300px;gap:12px;padding:12px;flex:1}
.palette, .workspace, .stage{background:#fff;border:1px solid #eee;border-radius:6px;padding:12px}
.palette h2,.workspace h2,.stage h2{margin:0 0 8px 0;font-size:14px}
/* Palette should allow scrolling when blocks exceed available vertical space */
.palette{
  /* leave width from grid, but limit height relative to viewport minus top UI chrome */
  max-height: calc(100vh - 160px);
  overflow: auto;
  /* keep inner spacing consistent */
  padding-right: 8px;
}
.block{background:var(--block-bg);border:1px solid var(--block-border);padding:8px;border-radius:6px;margin-bottom:8px;cursor:grab}
.block:active{cursor:grabbing}
.stackArea{min-height:300px;border:2px dashed #f0f0f0;padding:8px;border-radius:6px;overflow:auto;background:#fafafa}
.script-block{display:flex;align-items:center;justify-content:space-between;background:#fff;border:1px solid var(--block-border);padding:8px;border-radius:6px;margin-bottom:8px;cursor:grab}
.script-block .label{font-weight:600;color:var(--accent);margin-right:6px}
.script-block .params{color:var(--muted);margin-right:8px}
.script-block .del{background:transparent;border:0;color:#c33;cursor:pointer}
.hint{display:block;margin-top:6px;color:var(--muted);font-size:12px}
.canvasArea{background:#fff;border:1px solid #eee;margin-top:8px;position:relative;overflow:hidden;aspect-ratio:1/1;height:auto;width:100%;max-width:100%}
.sprite{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);font-size:40px;user-select:none;cursor:grab}
.sprite:active{cursor:grabbing}
.sprite .live-speech{
  position: absolute;
  top: -48px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #111;
  border: 1px solid #ddd;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 12px rgba(18,24,40,0.08);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sprite .live-speech.hidden{ display: none; }
.stage-info{display:flex;justify-content:space-between;margin-top:8px;color:var(--muted);font-size:13px}
.sprite-bar{display:flex;align-items:center;gap:8px;margin-bottom:8px}
.sprite-list{display:flex;gap:6px;align-items:center}
.sprite-list .sprite-item{width:36px;height:36px;border-radius:6px;background:#fafafa;border:1px solid #eee;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:20px}
.sprite-list .sprite-item.selected{outline:2px solid #22A06B}
#addSpriteBtn{padding:6px 8px;border:1px solid #ddd;background:#fff;border-radius:6px;cursor:pointer}
.sprite-item:hover{transform:translateY(-2px);transition:transform 120ms ease}
dialog{border:0;border-radius:8px;padding:12px}
.dialog-row{margin-bottom:8px}
input[type="number"],input[type="text"]{width:100%;padding:6px;border:1px solid #ddd;border-radius:4px}

/* Home / landing styles */
.home{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:linear-gradient(180deg, rgba(250,250,255,0.95), rgba(245,247,255,0.95));
  z-index:50;
}
.home-card{
  width:1100px;
  max-width:96%;
  padding:28px;
  border-radius:16px;
  box-shadow:0 30px 80px rgba(18,24,40,0.12);
  background:linear-gradient(180deg,#fff,#f6fbff);
  text-align:left;
  border:1px solid rgba(0,0,0,0.06);
  display:grid;
  grid-template-columns: 2fr 1fr; /* larger left hero like Scratch */
  gap:22px;
  /* Keep the card visible on small viewports without overflowing the page:
     constrain its height and allow internal scrolling for long content (projects, lists) */
  max-height: calc(100vh - 96px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
/* make hero more prominent */
.home-card .hero {
  display:flex;
  flex-direction:column;
  justify-content:flex-start;
  gap:12px;
  padding-right:8px;
}
.home-card h1{font-size:30px;margin:0;color:var(--accent);line-height:1.08}
.home-card .lead{font-size:15px;color:var(--muted);max-width:760px;margin-bottom:6px}

/* New hero actions: big Create button and search */
.hero-actions{display:flex;align-items:center;gap:14px;margin-top:6px}
.primary.big{background:#22A06B;color:#fff;border:0;padding:14px 22px;border-radius:12px;font-size:16px;box-shadow:0 8px 0 rgba(0,0,0,0.06);cursor:pointer}
.search-wrap{display:flex;align-items:center;gap:8px}
.search-wrap input[type="search"]{padding:10px 12px;border-radius:10px;border:1px solid #e6edf8;width:420px;box-shadow:inset 0 1px 0 rgba(255,255,255,0.6)}
.search-wrap button{padding:10px 12px;border-radius:10px;border:1px solid #ddd;background:#fff;cursor:pointer}

.home-actions.muted-row{display:flex;gap:8px;margin-top:14px;color:var(--muted)}
.home-actions.muted-row button{background:transparent;border:1px solid rgba(0,0,0,0.06);padding:8px 10px;border-radius:8px;cursor:pointer}

/* Featured projects grid larger, Scratch-like cards */
.featured-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:12px}
/* Ensure grid rows can expand so cards aren't squished; favor single-column layout on narrower containers */
.featured-grid{
  grid-auto-rows: minmax(120px, auto);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap:12px;
}
@media(min-width:1100px){ .featured-grid{grid-template-columns:repeat(3,1fr);} }

.feat-card{background:linear-gradient(180deg,#fff,#fcfdff);border:1px solid #eee;padding:10px;border-radius:10px;display:flex;flex-direction:column;align-items:flex-start;gap:10px;min-height:120px}
.feat-card{min-height:140px}
/* make sidebar lists use a single column so items have more width/height */
.sidebar .featured-grid, .user-games .featured-grid {
  grid-template-columns: 1fr;
  grid-auto-rows: minmax(140px, auto);
}
.feat-card .thumb{font-size:36px;width:100%;height:120px;border-radius:6px;background:linear-gradient(180deg,#fbfbff,#fff);display:flex;align-items:center;justify-content:center}
.feat-card .meta{width:100%;display:flex;flex-direction:column;gap:6px}
.feat-card .title{font-weight:700;color:var(--accent);font-size:14px}
.feat-card .by{color:var(--muted);font-size:12px}

/* compact sidebar headings */
.sidebar h3{margin-top:0;margin-bottom:8px;font-size:14px}

/* ensure home overlay content scrolls nicely on small screens */
@media(max-width:900px){
  .home-card{grid-template-columns:1fr; padding:18px}
  .search-wrap input[type="search"]{width:100%}
  .feat-card .thumb{height:90px}
}

/* Studios list */
.studios-list{list-style:none;padding:0;margin:8px 0 0 0;color:var(--muted);font-size:13px}
.studios-list li{margin-bottom:8px}

/* Utility to hide the main app while home is visible */
.app-hidden{display:none}

/* Fullscreen styling for the stage canvas */
.canvasArea:fullscreen,
.canvasArea:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none;
  aspect-ratio: auto;
  border-radius: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  z-index: 10000;
}

/* Slightly larger sprite in fullscreen for visibility */
.canvasArea:fullscreen .sprite,
.canvasArea:-webkit-full-screen .sprite {
  font-size:56px;
}