/* AI EcoPet Creator
   Layout: Scratch-style workbench. Blocks on the left, the pet & dashboard designer in the middle (can fold away),
   the live stage with its AI input on the right. One deliberate light look, so it matches the Blockly workspace. */
:root {
  --bg: #eaf3ed;
  --surface: #ffffff;
  --surface2: #f4f8f5;
  --ink: #1f2a33;
  --muted: #586872;
  --line: #d3e0d7;
  --leaf: #2b8a3e;
  --leaf-soft: #d3f9d8;
  --leaf-ink: #ffffff;
  --sky: #1c6dd0;
  --sky-soft: #dbeafe;
  --sun: #ffbf00;
  --sim: #d9480f;
  --sim-soft: #fff0e6;
  --danger: #c92a2a;
  --display: "Baloo 2", "Nunito", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --body: "Nunito", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 51, .06), 0 4px 14px rgba(31, 42, 51, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.15; text-wrap: balance; }
p { margin: 0; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-weight: 800; white-space: nowrap; transition: transform .08s, border-color .15s, background .15s; }
.btn:hover { border-color: #9fb5a7; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--leaf); border-color: var(--leaf); color: var(--leaf-ink); }
.btn.primary:hover { background: #237032; }
.btn.run { background: #37b24d; border-color: #2b8a3e; color: #fff; font-size: 16px; padding: 7px 18px; }
.btn.stop { background: #fff; border-color: #f1a7a7; color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 6px 10px; }
.btn.sim { border-color: #ffc9a8; background: var(--sim-soft); color: #8a2c06; }
.btn.sim:hover { border-color: var(--sim); }
.btn.big { padding: 10px 14px; border-radius: 12px; font-size: 15px; justify-content: center; }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- top bar ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); background: var(--surface); border-bottom: 2px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 42px; height: 42px; flex: none; }
.brand h1 { font-size: 21px; color: var(--leaf); }
.brand small { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.proj-name { border: 2px solid var(--line); border-radius: 10px; padding: 5px 10px; font-weight: 800; width: 210px; max-width: 100%; background: var(--surface2); }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.mode-switch { display: flex; background: var(--surface2); border: 2px solid var(--line); border-radius: 999px; padding: 3px; }
.mode-switch button { border: 0; background: transparent; border-radius: 999px; padding: 6px 16px; font-weight: 800; }
.mode-switch button[aria-pressed="true"] { background: var(--leaf); color: #fff; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.15); padding: 6px; width: 340px; max-width: calc(100vw - 32px); }
.menu-pop button { display: flex; gap: 10px; align-items: flex-start; text-align: left; width: 100%; border: 0; background: transparent; border-radius: 10px; padding: 8px 10px; }
.menu-pop button:hover { background: var(--surface2); }
.menu-pop .ex-emoji { font-size: 26px; line-height: 1; }
.menu-pop b { display: block; }
.menu-pop span { font-size: 13px; color: var(--muted); }

/* ---------- work area ---------- */
.work { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(380px, 1fr) 320px minmax(400px, 480px); gap: 0; }
.work.no-design { grid-template-columns: minmax(380px, 1fr) minmax(400px, 500px); }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 2px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.pane-head h2 { font-size: 18px; }
.rule-status { font-size: 13px; font-weight: 700; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.rule-status .dot { width: 10px; height: 10px; border-radius: 50%; background: #adb5bd; }
.rule-status.on .dot { background: #37b24d; box-shadow: 0 0 0 4px rgba(55, 178, 77, .2); }
.pane-head .spacer { flex: 1; }
.code-pane { position: relative; background: var(--surface); border-right: 2px solid var(--line); }
#blocklyDiv { flex: 1; min-height: 300px; position: relative; }
.error-bar { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 30; background: #fff5f5; border: 2px solid #ffa8a8; color: #8b1a1a; border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); font-weight: 700; }
.error-bar p { flex: 1; min-width: 0; }

.design-pane { background: var(--surface2); border-right: 2px solid var(--line); }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; background: var(--surface); border-bottom: 2px solid var(--line); }
.tabs button { border: 2px solid transparent; border-bottom: 0; background: transparent; border-radius: 10px 10px 0 0; padding: 7px 12px; font-weight: 800; color: var(--muted); margin-bottom: -2px; }
.tabs button[aria-selected="true"] { background: var(--surface2); border-color: var(--line); color: var(--ink); }
.tab-body { overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; }
.field-group { display: flex; flex-direction: column; gap: 8px; }
.field-group > h3 { font-size: 15px; }
.hint { font-size: 12.5px; color: var(--muted); }
.text-in { border: 2px solid var(--line); border-radius: 10px; padding: 6px 10px; background: #fff; width: 100%; font-weight: 700; }
.num-in { border: 2px solid var(--line); border-radius: 10px; padding: 5px 8px; background: #fff; width: 90px; font-weight: 700; }
select.sel { border: 2px solid var(--line); border-radius: 10px; padding: 5px 8px; background: #fff; font-weight: 700; max-width: 100%; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.pick { border: 3px solid transparent; background: #fff; border-radius: 12px; padding: 4px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12.5px; font-weight: 800; box-shadow: var(--shadow); }
.pick svg { width: 100%; height: auto; display: block; }
.pick[aria-pressed="true"] { border-color: var(--leaf); background: var(--leaf-soft); }
.pick.bg { padding: 0 0 6px; overflow: hidden; }
.pick.bg .thumb { width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 9px 9px 0 0; }
.pick.bg .thumb svg { width: 100%; height: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-weight: 800; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--leaf-soft); border-color: var(--leaf); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 700; font-size: 14px; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--leaf); }
.add-row { display: flex; flex-wrap: wrap; gap: 6px; }
.w-list { display: flex; flex-direction: column; gap: 8px; }
.w-item { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px; display: grid; gap: 6px; }
.w-item header { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.w-item header .grow { flex: 1; }
.w-item label { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.w-item.selected { border-color: var(--sky); }
.w-colours { display: flex; gap: 4px; flex-wrap: wrap; }
.w-colours button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.w-colours button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- preview ---------- */
.preview-pane { background: var(--bg); overflow: auto; }
.preview-inner { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.stage-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stage-bar .spacer { flex: 1; }
.stage { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden; background: #cfe8ff; box-shadow: 0 0 0 3px #fff, 0 6px 24px rgba(31, 42, 51, .18); container-type: inline-size; user-select: none; -webkit-user-select: none; touch-action: none; }
.stage-bg, .stage-bg svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-title { position: absolute; left: 0; right: 0; top: 3cqw; text-align: center; font-family: var(--display); font-weight: 800; font-size: 5.4cqw; color: #fff; text-shadow: 0 .35cqw 0 rgba(0,0,0,.25), 0 0 1.2cqw rgba(0,0,0,.25); pointer-events: none; padding: 0 4cqw; line-height: 1.1; }
.pet-wrap { position: absolute; width: 36cqw; transform: translate(-50%, -100%); cursor: pointer; }
.pet-wrap.dragging, .widget.dragging { cursor: grabbing; }
.pet-anim, .pet-move { transform-origin: 50% 95%; }
.pet-svg { width: 100%; height: auto; display: block; overflow: visible; }
.pet-name { position: absolute; left: 50%; bottom: -3.4cqw; transform: translateX(-50%); background: rgba(255,255,255,.92); border-radius: 999px; padding: .2cqw 1.8cqw; font-weight: 800; font-size: 2.6cqw; white-space: nowrap; box-shadow: 0 .3cqw 1cqw rgba(0,0,0,.12); }
.bubble { position: absolute; left: 62%; bottom: 86%; width: max-content; max-width: 40cqw; background: #fff; border: .5cqw solid #2b3340; border-radius: 3cqw; padding: 1.2cqw 2cqw; font-weight: 800; font-size: 3.2cqw; line-height: 1.25; color: #1f2a33; box-shadow: 0 .6cqw 0 rgba(0,0,0,.12); animation: pop .25s ease-out; word-wrap: break-word; }
.bubble.left { left: auto; right: 62%; }
.bubble.left::after { left: auto; right: 3cqw; border-left-width: 1.3cqw; border-right-width: .6cqw; }
.bubble::after { content: ""; position: absolute; left: 3cqw; bottom: -2.6cqw; border: 1.3cqw solid transparent; border-top: 1.6cqw solid #2b3340; border-left-width: .6cqw; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.widgets { position: absolute; inset: 0; pointer-events: none; }
.widget { position: absolute; pointer-events: auto; font-size: 2.6cqw; line-height: 1.15; font-weight: 800; --wc: #2f9e44; }
.mode-edit .widget { cursor: grab; }
.mode-edit .widget:hover { outline: .4cqw dashed rgba(28, 109, 208, .7); outline-offset: .4cqw; }
.mode-edit .widget.selected { outline: .5cqw solid #1c6dd0; outline-offset: .4cqw; }
.w-card { background: rgba(255,255,255,.93); border-radius: 2cqw; padding: .9cqw 1.6cqw; box-shadow: 0 .4cqw 1.4cqw rgba(0,0,0,.14); border-left: 1.1cqw solid var(--wc); min-width: 15cqw; }
.w-card .cap { font-size: 2.3cqw; color: #4a5560; font-weight: 800; white-space: nowrap; }
.w-card .val { font-family: var(--display); font-size: 4.6cqw; line-height: 1; color: var(--wc); font-variant-numeric: tabular-nums; white-space: nowrap; }
.w-card .val small { font-size: 2.4cqw; color: #4a5560; margin-left: .4cqw; }
.w-bar { min-width: 26cqw; }
.w-bar .track { height: 2.4cqw; border-radius: 9cqw; background: #e9ecef; overflow: hidden; margin-top: .6cqw; }
.w-bar .fill { height: 100%; border-radius: 9cqw; background: var(--wc); transition: width .4s ease; }
.w-bar .row { display: flex; justify-content: space-between; gap: 1.4cqw; align-items: baseline; }
.w-bar .num { font-size: 2.2cqw; color: #4a5560; font-variant-numeric: tabular-nums; white-space: nowrap; }
.w-bar.done .cap::after { content: " ✓"; color: var(--wc); }
.w-label { background: var(--wc); color: #fff; border-radius: 2cqw; padding: 1cqw 2cqw; font-size: 3cqw; box-shadow: 0 .4cqw 1.2cqw rgba(0,0,0,.18); max-width: 60cqw; }
.w-button { border: 0; background: var(--wc); color: #fff; border-radius: 99cqw; padding: 1.4cqw 3cqw; font-weight: 800; font-size: 3.1cqw; box-shadow: 0 .7cqw 0 rgba(0,0,0,.25); font-family: inherit; }
.w-button:active { transform: translateY(.5cqw); box-shadow: 0 .2cqw 0 rgba(0,0,0,.25); }
.w-badges .shelf { display: flex; gap: .8cqw; font-size: 4.2cqw; min-height: 5cqw; align-items: center; }
.w-badges .empty { font-size: 2.2cqw; color: #868e96; }
.w-activity .val { font-size: 3.8cqw; }
.src-chip { display: inline-block; font-size: 1.8cqw; padding: .2cqw 1cqw; border-radius: 9cqw; background: #e9ecef; color: #495057; vertical-align: middle; margin-left: .6cqw; font-family: var(--body); }
.src-chip.sim { background: var(--sim); color: #fff; }
.src-chip.mb { background: var(--sky); color: #fff; }

.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.banner { position: absolute; left: 6cqw; right: 6cqw; top: 36%; text-align: center; background: linear-gradient(135deg, #ffd43b, #ff922b); color: #3b1f00; font-family: var(--display); font-weight: 800; font-size: 6cqw; line-height: 1.1; border-radius: 3cqw; padding: 2.4cqw; box-shadow: 0 1cqw 0 rgba(0,0,0,.2); animation: banner 2.6s ease forwards; pointer-events: none; }
@keyframes banner { 0% { transform: scale(.4) rotate(-6deg); opacity: 0; } 12% { transform: scale(1.06) rotate(1deg); opacity: 1; } 20% { transform: scale(1) rotate(0); } 85% { opacity: 1; } 100% { opacity: 0; transform: translateY(-4cqw); } }
.toasts { position: absolute; left: 50%; transform: translateX(-50%); top: 12cqw; display: flex; flex-direction: column; gap: 1cqw; align-items: center; pointer-events: none; width: 90%; }
.toast { background: #2b3340; color: #fff; border-radius: 99cqw; padding: .9cqw 2.2cqw; font-weight: 800; font-size: 2.8cqw; animation: toast 2.8s ease forwards; }
@keyframes toast { 0% { transform: translateY(3cqw); opacity: 0; } 10% { transform: none; opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }
.sim-ribbon { position: absolute; left: 0; right: 0; bottom: 0; background: repeating-linear-gradient(-45deg, #d9480f 0 2cqw, #e8590c 2cqw 4cqw); color: #fff; font-weight: 800; font-size: 2.2cqw; text-align: center; padding: .4cqw; letter-spacing: .08em; pointer-events: none; }

/* pet motion */
.pet-move.idle { animation: bob 2.4s ease-in-out infinite; }
.pet-move.walk { animation: walk .55s ease-in-out infinite; }
.pet-move.jog { animation: jog .32s ease-in-out infinite; }
.pet-move.sleepy { animation: breathe 3.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.5%); } }
@keyframes walk { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-5%) rotate(3deg); } }
@keyframes jog { 0%, 100% { transform: translateY(0) rotate(-5deg) scaleY(.97); } 50% { transform: translateY(-10%) rotate(5deg) scaleY(1.02); } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.03, .97); } }
.anim-jump { animation: a-jump .7s cubic-bezier(.3, 1.6, .5, 1); }
.anim-spin { animation: a-spin .8s ease-in-out; }
.anim-dance { animation: a-dance 1.2s ease-in-out; }
.anim-shake { animation: a-shake .6s ease-in-out; }
.anim-grow { animation: a-grow .9s ease-in-out; }
.anim-nod { animation: a-nod .8s ease-in-out; }
.anim-flip { animation: a-flip .8s ease-in-out; }
@keyframes a-jump { 0% { transform: translateY(0); } 40% { transform: translateY(-35%) scale(1.05, .95); } 70% { transform: translateY(0) scale(1.08, .92); } 100% { transform: none; } }
@keyframes a-spin { to { transform: rotate(360deg); } }
@keyframes a-dance { 0%, 100% { transform: none; } 20% { transform: rotate(-12deg) translateX(-6%); } 40% { transform: rotate(12deg) translateX(6%); } 60% { transform: rotate(-12deg) translateX(-6%); } 80% { transform: rotate(12deg) translateX(6%); } }
@keyframes a-shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-5%); } 40%, 80% { transform: translateX(5%); } }
@keyframes a-grow { 0%, 100% { transform: none; } 50% { transform: scale(1.25); } }
@keyframes a-nod { 0%, 100% { transform: none; } 30% { transform: rotate(8deg); } 60% { transform: rotate(-4deg); } }
@keyframes a-flip { 0% { transform: none; } 50% { transform: translateY(-25%) scaleX(-1); } 100% { transform: none; } }
.pet-svg .zzz text { animation: zzz 2s ease-in-out infinite; }
.pet-svg .zzz text + text { animation-delay: .5s; }
@keyframes zzz { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
.pet-svg .sparkles { animation: twinkle 1.6s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }
.pet-svg .glow { animation: twinkle 1s ease-in-out infinite; }
.bg-svg .firefly { animation: twinkle 2.2s ease-in-out infinite; }

/* readouts under the stage */
.readout { display: flex; flex-wrap: wrap; gap: 6px; }
.readout .r { background: var(--surface); border: 2px solid var(--line); border-radius: 10px; padding: 3px 8px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.readout .r b { color: var(--ink); font-variant-numeric: tabular-nums; }
.readout .r.var { border-color: #ffc078; }

/* cards under the stage */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 2px solid var(--line); }
.card > header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.card > header h3 { font-size: 16px; }
.card .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.seg { display: inline-flex; background: var(--surface2); border: 2px solid var(--line); border-radius: 999px; padding: 2px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 4px 12px; font-weight: 800; font-size: 14px; }
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.sim-tag { margin-left: auto; font-size: 11px; font-weight: 800; letter-spacing: .06em; color: #fff; background: var(--sim); border-radius: 6px; padding: 2px 7px; }
.sim-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.sim-grid .wide { grid-column: span 2; }
.sim-live { font-weight: 800; color: var(--sim); font-variant-numeric: tabular-nums; min-height: 1.4em; }
.conn-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.conn-dot { width: 12px; height: 12px; border-radius: 50%; background: #adb5bd; flex: none; }
.conn-dot.connected, .conn-dot.connecting { background: var(--sun); }
.conn-dot.receiving { background: #37b24d; box-shadow: 0 0 0 4px rgba(55, 178, 77, .25); }
.conn-dot.lost, .conn-dot.error { background: var(--danger); }
.conn-msg { font-weight: 700; font-size: 14px; flex: 1; min-width: 160px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; background: var(--surface2); border-radius: 6px; padding: 2px 6px; overflow-wrap: anywhere; }
.link { background: none; border: 0; color: var(--sky); font-weight: 800; text-decoration: underline; padding: 0; text-align: left; }
.log { list-style: none; margin: 0; padding: 0; max-height: 170px; overflow: auto; font-size: 13px; display: flex; flex-direction: column; }
.log li { display: grid; grid-template-columns: 44px auto 1fr; gap: 8px; align-items: center; padding: 3px 0; border-bottom: 1px solid var(--surface2); }
.log li.dup { opacity: .5; }
.log li.mistake .txt { color: var(--sim); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .src { font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 6px; color: #fff; background: var(--sky); }
.log .src.sim { background: var(--sim); }
.log .empty { color: var(--muted); display: block; padding: 6px 0; }
.carbon-grid { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; font-size: 14px; font-weight: 700; }
.formula { background: var(--leaf-soft); border-radius: 10px; padding: 8px 10px; font-weight: 700; font-size: 13.5px; color: #1b5e2a; }

/* ---------- play mode ---------- */
.app.mode-play .code-pane, .app.mode-play .design-pane, .app.mode-play .edit-only { display: none !important; }
.app.mode-play .work { grid-template-columns: 1fr; }
.app.mode-play #simPanel > .hint { display: none; }
.app.mode-play .preview-inner { max-width: min(1100px, calc((100vh - 300px) * 4 / 3 + 24px)); min-width: min(100%, 360px); margin: 0 auto; width: 100%; }
.app.mode-play .preview-pane { background: radial-gradient(circle at 50% 0, #d3f9d8, var(--bg) 60%); }
.app.mode-play .widget { cursor: default; outline: none !important; }
.app.mode-play .sim-grid { grid-template-columns: repeat(4, 1fr); }
.app.mode-play .sim-grid .wide { grid-column: span 2; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.3); max-width: min(720px, calc(100vw - 32px)); width: 100%; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgba(20, 30, 25, .45); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 2px solid var(--line); }
.dlg-head h2 { font-size: 20px; flex: 1; }
.dlg-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow: auto; }
.dlg-body ol, .dlg-body ul { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.dlg-body pre { background: #1f2a33; color: #e9f5ec; border-radius: 10px; padding: 12px; overflow-x: auto; font-size: 13px; margin: 0; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 2px solid var(--line); }

/* Blockly tweaks */
.blocklyToolboxDiv { padding-top: 6px; }
.blocklyToolboxCategory { margin-bottom: 4px; border-radius: 0 10px 10px 0; height: 34px; line-height: 34px; padding-right: 10px; }
.blocklyToolboxCategoryLabel { font-family: var(--body) !important; font-weight: 800; font-size: 14px !important; }
.blocklyFlyoutLabelText { font-family: var(--body) !important; font-weight: 800; fill: #586872 !important; }
.ep-fired > .blocklyPath { filter: drop-shadow(0 0 5px #ffd400) drop-shadow(0 0 9px #ffd400); }

/* ---------- smaller screens ---------- */
@media (max-width: 1280px) {
  .work { grid-template-columns: minmax(340px, 1fr) 290px 400px; }
  .work.no-design { grid-template-columns: minmax(340px, 1fr) 420px; }
}
@media (max-width: 980px) {
  .work, .work.no-design { display: flex; flex-direction: column; overflow: auto; }
  .code-pane { height: 72vh; flex: none; border-right: 0; border-bottom: 2px solid var(--line); }
  .design-pane { flex: none; border-right: 0; max-height: none; }
  .preview-pane { overflow: visible; flex: none; }
  .proj-name { width: 160px; }
  .app.mode-play .preview-inner { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .pet-move, .anim-jump, .anim-spin, .anim-dance, .anim-shake, .anim-grow, .anim-nod, .anim-flip { animation-duration: .01s !important; animation-iteration-count: 1 !important; }
}
