/* Blockyard Studio for phones: big buttons, big text, one thing at a time. Every size is in rem, so the Text size control scales it all. */
:root {
  --m-scale: 1;
  --bg: #f3f6fa; --surface: #ffffff; --surface-2: #e8eef5; --line: #d3dce6; --text: #16212c; --muted: #566676;
  --accent: #1a8cff; --accent-strong: #0b6fd6; --accent-soft: #dcecff; --danger: #d33a30; --ok: #1f8d4c; --warn: #b87500;
  --shadow: 0 -6px 24px rgb(15 30 50 / .18);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --code-bg: #ffffff; --code-text: #16212c;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #12171d; --surface: #1c232b; --surface-2: #28313b; --line: #364351; --text: #e8eef4; --muted: #a2b0bf;
  --accent: #3d9bff; --accent-strong: #7ab8ff; --accent-soft: #1d3550; --danger: #ff7b72; --ok: #56d364; --warn: #e3b341;
  --shadow: 0 -6px 24px rgb(0 0 0 / .5); --code-bg: #161b21; --code-text: #dfe6ed;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { font-size: calc(18px * var(--m-scale)); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; height: 100dvh; overflow: hidden; background: var(--bg); color: var(--text); font: 400 1rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ----- Buttons and bits ----- */
.btn { min-height: 3rem; padding: 0 1.1rem; border: 0; border-radius: .9rem; background: var(--surface-2); color: var(--text); font-weight: 650; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-decoration: none; }
.btn:active { filter: brightness(.92); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.big { min-height: 3.6rem; font-size: 1.15rem; border-radius: 1.1rem; width: 100%; }
.btn:disabled { opacity: .45; }
.icon-btn { width: 3rem; height: 3rem; min-width: 3rem; padding: 0; font-size: 1.3rem; border: 0; border-radius: .9rem; background: transparent; display: inline-grid; place-items: center; }
.icon-btn:disabled { opacity: .35; }
.icon-btn:active { background: var(--surface-2); }
.chip { min-height: 2.6rem; padding: 0 1rem; border-radius: 1.3rem; border: 2px solid var(--line); background: var(--surface); font-weight: 600; font-size: .95rem; white-space: nowrap; }
.chip[aria-pressed="true"], .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.row { display: flex; align-items: center; gap: .6rem; }
.muted { color: var(--muted); }
.toast { position: fixed; left: 50%; top: calc(var(--safe-top) + 4.6rem); transform: translateX(-50%); max-width: min(92vw, 28rem); background: #111b25; color: #fff; padding: .7rem 1.1rem; border-radius: 1rem; font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / .35); z-index: 60; text-align: center; }
.toast.error { background: var(--danger); }

/* ----- Home ----- */
.m-home { height: 100dvh; overflow-y: auto; padding: calc(var(--safe-top) + .8rem) 1rem calc(var(--safe-bottom) + 2rem); max-width: 40rem; margin: 0 auto; display: grid; gap: 1.2rem; align-content: start; }
.m-home-top { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.brand { display: flex; align-items: center; gap: .6rem; font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; }
.brand img { width: 2.2rem; height: 2.2rem; border-radius: .5rem; }
.brand small { font-weight: 600; color: var(--muted); font-size: .9rem; letter-spacing: 0; }
.size-control { display: flex; gap: .3rem; }
.size-control .icon-btn { background: var(--surface); border: 2px solid var(--line); font-weight: 800; }
.m-hero { background: linear-gradient(135deg, var(--accent), #5b6cff); color: #fff; padding: 1.3rem 1.2rem; border-radius: 1.4rem; display: grid; gap: .8rem; }
.m-hero h1 { font-size: 1.6rem; line-height: 1.15; letter-spacing: -.03em; }
.m-hero p { opacity: .92; }
.m-hero .btn { background: #fff; color: #0b4f99; }
.m-section { display: grid; gap: .7rem; }
.m-section h2 { font-size: 1.15rem; }
.m-list { display: grid; gap: .6rem; }
.m-card { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr) auto; align-items: center; gap: .8rem; padding: .8rem; background: var(--surface); border: 2px solid var(--line); border-radius: 1.1rem; text-align: left; width: 100%; }
.m-card .art { width: 3.2rem; height: 3.2rem; border-radius: .8rem; display: grid; place-items: center; font-size: 1.6rem; background: var(--accent-soft); }
.m-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-card small { color: var(--muted); display: block; line-height: 1.25; }
.m-card .go { font-weight: 700; color: var(--accent-strong); white-space: nowrap; }
.m-card.template { grid-template-columns: 3.2rem minmax(0, 1fr); }
.m-card.template small { white-space: normal; }
.m-note { padding: .9rem 1rem; border-radius: 1rem; background: var(--accent-soft); }
.m-foot { color: var(--muted); text-align: center; font-size: .9rem; display: grid; gap: .4rem; }
.m-foot a { color: var(--accent-strong); font-weight: 600; }

/* ----- Editor ----- */
.m-editor { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto auto; }
.m-bar { display: flex; align-items: center; gap: .15rem; padding: calc(var(--safe-top) + .3rem) .4rem .3rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.m-title { flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; font-weight: 750; font-size: 1.05rem; padding: .5rem .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: .7rem; }
.m-title small { display: block; font-weight: 500; font-size: .75rem; color: var(--muted); }
.m-stage { position: relative; min-height: 0; background: #000; }
.m-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.m-gui { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.m-hint { position: absolute; left: .7rem; right: 4.2rem; top: .7rem; padding: .45rem .8rem; border-radius: .9rem; background: rgb(10 20 32 / .72); color: #fff; font-size: .8rem; line-height: 1.3; text-align: center; pointer-events: none; }
.m-float { position: absolute; right: .6rem; top: .6rem; display: grid; gap: .5rem; }
.m-float .icon-btn { background: rgb(10 20 32 / .72); color: #fff; width: 2.8rem; height: 2.8rem; min-width: 2.8rem; border-radius: 50%; }
.m-selbar { display: flex; align-items: center; gap: .4rem; padding: .4rem .6rem; background: var(--surface); border-top: 1px solid var(--line); }
.m-selbar .name { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; font-weight: 700; padding: .5rem .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-selbar .name small { display: block; color: var(--muted); font-weight: 500; font-size: .75rem; }
.m-selbar .btn { min-height: 2.6rem; padding: 0 .9rem; }
.m-panel { background: var(--surface); border-top: 1px solid var(--line); padding: .7rem .9rem; max-height: 40dvh; overflow-y: auto; display: grid; gap: .8rem; box-shadow: var(--shadow); }
.m-panel.tall { max-height: 52dvh; }
.m-panel h3 { font-size: 1rem; display: flex; align-items: center; justify-content: space-between; }
.m-panel h3 .close { font-size: 1.4rem; width: 2.6rem; height: 2.6rem; }
.m-dock { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: .3rem .3rem calc(.3rem + var(--safe-bottom)); gap: .2rem; }
.m-dock button { display: grid; justify-items: center; gap: .1rem; padding: .4rem .1rem; border: 0; border-radius: .9rem; background: transparent; font-size: .78rem; font-weight: 650; color: var(--muted); min-height: 3.6rem; }
.m-dock button span { font-size: 1.45rem; line-height: 1.1; }
.m-dock button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-strong); }
.m-dock button:disabled { opacity: .35; }

/* Panels */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.6rem, 1fr)); gap: .6rem; }
.tile { display: grid; justify-items: center; align-content: center; gap: .25rem; min-height: 5.2rem; padding: .5rem .3rem; border: 2px solid var(--line); border-radius: 1rem; background: var(--surface); font-size: .82rem; font-weight: 650; text-align: center; line-height: 1.15; }
.tile span { font-size: 1.7rem; line-height: 1; }
.tile:active { background: var(--accent-soft); border-color: var(--accent); }
.tabs { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: .4rem; }
.swatch { width: 100%; aspect-ratio: 1; min-width: 2.4rem; border-radius: 50%; border: 3px solid var(--line); padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), inset 0 0 0 3px var(--surface); }
.stepper { display: grid; grid-template-columns: 5.5rem 3.2rem minmax(3rem, 1fr) 3.2rem; align-items: center; gap: .4rem; }
.stepper label { font-weight: 650; }
.stepper .value { text-align: center; font-weight: 750; font-variant-numeric: tabular-nums; }
.stepper .btn { min-height: 3.2rem; padding: 0; font-size: 1.5rem; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.pad .btn { min-height: 3.4rem; font-size: 1.1rem; }
.pad .empty { visibility: hidden; }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }
.field { display: grid; gap: .35rem; }
.field label, .field .label { font-weight: 650; }
.field input[type="text"], .field input[type="search"], .field select { min-height: 3.1rem; padding: 0 .9rem; border: 2px solid var(--line); border-radius: .9rem; background: var(--surface); width: 100%; }
.field input[type="range"] { width: 100%; height: 2.4rem; accent-color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3rem; padding: 0 .2rem; font-weight: 650; }
.switch input { width: 3.2rem; height: 1.8rem; accent-color: var(--accent); }

/* ----- Sheets ----- */
.backdrop { position: fixed; inset: 0; background: rgb(8 14 22 / .55); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88dvh; overflow-y: auto; background: var(--surface); border-radius: 1.4rem 1.4rem 0 0; padding: 1rem 1rem calc(1.2rem + var(--safe-bottom)); box-shadow: var(--shadow); display: grid; gap: .9rem; max-width: 40rem; margin: 0 auto; animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(20%); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet h2 { font-size: 1.25rem; display: flex; justify-content: space-between; align-items: center; }
.menu-list { display: grid; gap: .5rem; }
.menu-list .btn { justify-content: flex-start; width: 100%; font-weight: 650; }
.publish-ok { text-align: center; display: grid; gap: .7rem; justify-items: center; }
.publish-ok .big-icon { font-size: 3.2rem; }
.status { min-height: 1.4rem; font-weight: 600; }
.status.error { color: var(--danger); }

/* ----- Script editor ----- */
.m-script { position: fixed; inset: 0; z-index: 30; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; background: var(--code-bg); padding-top: var(--safe-top); }
.m-script .m-bar { padding-top: .3rem; }
.m-script textarea { width: 100%; height: 100%; border: 0; outline: 0; resize: none; padding: .8rem .9rem; background: var(--code-bg); color: var(--code-text); font: 400 1rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; white-space: pre; overflow: auto; }
.m-keys { display: flex; gap: .4rem; overflow-x: auto; padding: .45rem .5rem; background: var(--surface); border-top: 1px solid var(--line); scrollbar-width: none; }
.m-keys::-webkit-scrollbar { display: none; }
.m-keys button { min-width: 2.7rem; min-height: 2.7rem; padding: 0 .75rem; border: 0; border-radius: .7rem; background: var(--surface-2); font: 650 1.05rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
.m-keys.suggest button { background: var(--accent-soft); color: var(--accent-strong); font-family: inherit; }
.m-script-status { padding: .3rem .9rem calc(.3rem + var(--safe-bottom)); background: var(--surface); font-size: .85rem; color: var(--ok); font-weight: 600; min-height: 1.8rem; }
.m-script-status.bad { color: var(--danger); }

/* Keep the workspace covered until startup and the first editor paint complete. */
.studio-launch{position:fixed;inset:0;z-index:1000;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;padding:24px;background:var(--bg,#17212c);color:var(--text,#fff);text-align:center}.studio-launch h1{max-width:420px;margin:0;font-size:clamp(24px,6vw,34px);line-height:1.2}.studio-launch>img{border-radius:8px}.studio-launch p{max-width:400px;min-height:2em;margin:0;color:var(--muted,#bac7d4);font-size:14px;line-height:1.6}.studio-launch progress{width:min(320px,85vw);height:12px;accent-color:#258ed0}.studio-launch>div{display:flex;flex-wrap:wrap;justify-content:center;gap:10px;margin-top:12px}.studio-launch .btn{min-height:44px}.m-create-return{font-size:12px;padding:.55rem .7rem}.m-home-top .brand{flex:1;min-width:0}.m-home-top .brand small{display:block;font-size:.75rem}.m-home-top .brand img{width:2rem;height:2rem}@media(max-width:380px){.m-home-top{gap:.35rem}.m-home-top .brand{font-size:1.1rem}.m-home-top .size-control button{padding:.45rem}}
