/* Emberglade — design tokens and layout. One product, three form factors.
   Hierarchy of attention: WORLD > WICK > the next lantern > the child's actions > the code > RUN.
   The tray is an instrument made of the same material as the Workshop Nook; it never becomes the protagonist. */

@font-face{ font-family:'Poppins'; src:url('../fonts/Poppins-Bold.woff') format('woff'); font-weight:600 800; font-display:swap; }
@font-face{ font-family:'Inter'; src:url('../fonts/Inter-Regular.woff') format('woff'); font-weight:400; font-display:swap; }
@font-face{ font-family:'Inter'; src:url('../fonts/Inter-SemiBold.woff') format('woff'); font-weight:600; font-display:swap; }

:root{
  --dusk:#1B2E35; --dusk-deep:#0A1418;
  --ember:#FF8C42; --gold:#FFD166; --spirit:#9FEFE0; --moss:#7FD858;
  --shell-cream:#F1E9D6; --shell-teal:#2F4C56; --shell-teal-dark:#1C333B;
  --leaf:#3D6B5C; --leaf-glow:#8FE0B8;
  --bark:#151F1C; --bark-mid:#20302C;
  --wood:#3B2E22; --wood-dark:#241B14; --brass:#C9A24A;
  --parchment:#F5EFE0; --parchment-dim:#E7DFCB;

  --font-display:'Bricolage Grotesque','Poppins',system-ui,sans-serif;
  --font-ui:'Manrope','Inter',system-ui,-apple-system,sans-serif;
  --font-mono:'JetBrains Mono',ui-monospace,'DejaVu Sans Mono',Menlo,monospace;

  --r-lg:20px; --r-md:13px; --r-sm:9px;
  --gap:16px; --pad:18px;
  --slot:38px; --cmd-min:0px; --icon:23px;
}
@media (pointer:coarse){ :root{ --slot:48px; --cmd-min:74px; --icon:28px; } }

*{ box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
html,body{ height:100%; }
body{
  background:#060D0F; color:var(--parchment); font-family:var(--font-ui);
  overflow:hidden; overscroll-behavior:none; touch-action:manipulation;
  -webkit-user-select:none; user-select:none; -webkit-touch-callout:none;
}
button{ font:inherit; color:inherit; border:0; background:none; cursor:pointer; }
button:focus-visible{ outline:2px solid var(--spirit); outline-offset:3px; }
[hidden]{ display:none !important; }

/* ---------------------------------------------------------------- frame */
.app{
  height:100vh; height:100dvh; width:100%;
  display:grid; grid-template-columns:minmax(0,1fr) clamp(300px,27vw,400px);
  gap:var(--gap); padding:var(--pad);
  background:radial-gradient(120% 90% at 30% 0%, #1E353D 0%, #0E1D22 55%, #081013 100%);
}
.stage{ position:relative; min-width:0; min-height:0; border-radius:var(--r-lg); overflow:hidden;
  box-shadow:0 40px 90px -30px rgba(0,0,0,.75), inset 0 0 0 1px rgba(255,255,255,.06), 0 0 60px -22px rgba(255,140,66,.1); }
.world-pane{ position:absolute; inset:0; }
.world-svg{ width:100%; height:100%; display:block; touch-action:manipulation; }

.brand{ position:absolute; top:16px; left:20px; display:flex; align-items:center; gap:8px; opacity:.5; pointer-events:none; }
.brand-mark{ width:16px; height:16px; border-radius:50%; background:radial-gradient(circle at 35% 30%, var(--spirit), var(--ember) 75%); box-shadow:0 0 10px rgba(255,140,66,.4); }
.brand-name{ font-family:var(--font-display); font-weight:700; font-size:12px; letter-spacing:.3px; }

.corner-btn{
  position:absolute; width:48px; height:48px; border-radius:50%; display:grid; place-items:center;
  background:rgba(10,20,24,.55); box-shadow:inset 0 0 0 1px rgba(255,255,255,.08); backdrop-filter:blur(6px);
  transition:background .2s, transform .15s;
}
.corner-btn:active{ transform:scale(.94); }
.corner-btn svg{ width:22px; height:22px; }
.sound-btn{ top:12px; right:12px; }
.tutor-fab{ left:14px; bottom:14px; width:58px; height:58px; background:linear-gradient(160deg,#3a2f22,#241B14); box-shadow:inset 0 0 0 1px rgba(255,209,102,.28), 0 10px 24px -10px rgba(0,0,0,.7); }
.tutor-fab svg{ width:36px; height:36px; }
.tutor-fab.on{ box-shadow:inset 0 0 0 2px var(--gold), 0 10px 24px -10px rgba(0,0,0,.7); }

/* ---------------------------------------------------------------- tray (the workshop instrument) */
.tray{
  position:relative; border-radius:var(--r-lg); padding:26px 18px 22px; min-height:0;
  background:linear-gradient(160deg,#322820 0%,#1E1912 100%);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.03), inset 0 0 0 1px rgba(0,0,0,.25), 0 30px 60px -30px rgba(0,0,0,.8);
  display:flex; flex-direction:column; justify-content:center; gap:24px; overflow:hidden;
}
.commands{ display:flex; gap:10px; }
.cmd{
  flex:1 1 0; max-width:92px; min-height:var(--cmd-min); aspect-ratio:1; max-height:96px; border-radius:var(--r-md);
  background:linear-gradient(160deg,#3b2d1c,#221A11); border:1px solid rgba(0,0,0,.3);
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px;
  box-shadow:0 3px 0 #130e08, 0 6px 12px -6px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.05);
  transition:transform .08s, box-shadow .08s, filter .2s;
}
.cmd:active, .cmd.pressed{ transform:translateY(2px); box-shadow:0 1px 0 #130e08, inset 0 2px 4px rgba(0,0,0,.4); }
.cmd svg{ width:var(--icon); height:var(--icon); }
.cmd-lb{ font-family:var(--font-display); font-weight:700; font-size:10px; color:rgba(255,209,102,.88); letter-spacing:.7px; }
.cmd[disabled]{ filter:saturate(.4) brightness(.7); cursor:default; }
.cmd.new{ animation:cmdIn .7s ease-out both; }
@keyframes cmdNudge{ 0%,100%{ transform:none; box-shadow:0 0 0 0 rgba(255,209,102,0);} 50%{ transform:translateY(-3px); box-shadow:0 0 0 4px rgba(255,209,102,.35), 0 0 22px rgba(255,209,102,.4);} }
.cmd.nudge{ animation:cmdNudge 1.8s ease-in-out 3; }
@keyframes cmdIn{ from{ opacity:0; transform:translateY(10px) scale(.92);} to{ opacity:1; transform:none; } }

.record{ background:rgba(0,0,0,.17); border-radius:16px; padding:14px; box-shadow:inset 0 2px 6px rgba(0,0,0,.32); display:flex; flex-direction:column; gap:12px; }
.seq-row{ display:flex; align-items:flex-start; gap:8px; }
.sequence{ flex:1; display:flex; flex-wrap:wrap; gap:7px; min-height:var(--slot); align-items:center; }
.slot{
  width:var(--slot); height:var(--slot); border-radius:var(--r-sm); border:1.5px dashed rgba(201,162,74,.26);
  display:grid; place-items:center; transition:border-color .2s, background .2s, box-shadow .2s;
}
.slot.filled{ border-style:solid; border-color:rgba(255,209,102,.42); background:linear-gradient(160deg,#3E3020,#241C11); box-shadow:0 2px 0 #120d07; }
.slot svg{ width:calc(var(--slot) * .42); height:calc(var(--slot) * .42); }
.slot.live{ border-color:var(--gold); box-shadow:0 0 0 2px rgba(255,209,102,.35), 0 0 16px rgba(255,209,102,.35); }
.slot.where{ animation:slotWhere 1.1s ease-in-out 2; border-color:var(--gold); }
.slot.fresh{ animation:fresh .5s ease-out; }
@keyframes slotWhere{ 0%,100%{ box-shadow:0 0 0 0 rgba(255,209,102,0);} 50%{ box-shadow:0 0 0 4px rgba(255,209,102,.4), 0 0 18px rgba(255,209,102,.45);} }
@keyframes fresh{ 0%{ transform:scale(.7); opacity:.2;} 60%{ transform:scale(1.08);} 100%{ transform:scale(1); opacity:1;} }

.group{ display:flex; align-items:center; gap:6px; padding:5px; border-radius:11px; border:1.5px solid rgba(143,224,184,.35); background:rgba(61,107,92,.16); }
.group.open{ border-color:var(--leaf-glow); box-shadow:0 0 0 2px rgba(143,224,184,.2); }
.gcount{ min-width:var(--slot); height:var(--slot); border-radius:var(--r-sm); display:flex; align-items:center; justify-content:center; gap:3px; background:linear-gradient(160deg,#27403a,#1a2c27); color:var(--leaf-glow); font-family:var(--font-display); font-weight:800; font-size:14px; padding:0 8px; box-shadow:0 2px 0 #0e1a17; }
.gcount svg{ width:15px; height:15px; }
.gbody{ display:flex; gap:5px; align-items:center; }
.gdone{ width:30px; height:var(--slot); display:grid; place-items:center; border-radius:8px; color:var(--leaf-glow); }
.gdone svg{ width:16px; height:16px; }

.seq-actions{ display:flex; flex-direction:column; gap:6px; }
.mini{ width:34px; height:34px; border-radius:10px; display:grid; place-items:center; background:rgba(255,255,255,.04); box-shadow:inset 0 0 0 1px rgba(255,255,255,.06); color:rgba(245,239,224,.7); }
.mini:active{ transform:scale(.92); }
.mini svg{ width:16px; height:16px; }
.mini[disabled]{ opacity:.3; cursor:default; }
@media (pointer:coarse){ .mini{ width:44px; height:44px; } .mini svg{ width:20px; height:20px; } }

.code-panel{
  border-radius:12px; padding:14px 16px; min-height:112px;
  background:linear-gradient(160deg,var(--parchment),var(--parchment-dim));
  box-shadow:inset 0 1px 0 rgba(255,255,255,.4), 0 8px 20px -10px rgba(0,0,0,.45);
  display:flex; flex-direction:column;
}
.code-marker{ font-size:12px; opacity:.5; margin-bottom:6px; color:#3B4A2E; }
.code-lines{ display:flex; flex-direction:column; }
.code-line{ font-family:var(--font-mono); font-size:13.5px; color:#3B4A2E; line-height:1.85; border-radius:5px; padding:0 6px; margin:0 -6px; transition:background .2s; white-space:pre; }
.code-line .kw{ color:#B85C1F; font-weight:500; }
.code-line .num{ color:#7a5a12; font-weight:600; }
.code-line.live{ background:rgba(255,209,102,.5); }
.code-line.where{ animation:lineWhere 1.1s ease-in-out 2; }
.code-line.fresh{ animation:lineFresh .6s ease-out; }
.code-empty{ font-family:var(--font-mono); font-size:13.5px; color:#3B4A2E; opacity:.3; line-height:1.85; }
@keyframes lineFresh{ 0%{ background:rgba(255,209,102,.8); transform:translateX(-6px); opacity:.3;} 100%{ background:rgba(255,209,102,0); transform:none; opacity:1;} }
@keyframes lineWhere{ 0%,100%{ background:rgba(255,209,102,0);} 50%{ background:rgba(255,209,102,.55);} }

.run-btn{
  width:100%; display:flex; align-items:center; justify-content:center; gap:10px; padding:15px; min-height:54px; border-radius:var(--r-md);
  background:radial-gradient(circle at 30% 25%,#F0A363,var(--ember) 75%);
  box-shadow:0 5px 0 #9a4a14, 0 14px 22px -10px rgba(255,140,66,.5), inset 0 1px 0 rgba(255,255,255,.3);
  font-family:var(--font-display); font-weight:800; font-size:15px; letter-spacing:.9px; color:#2B1404;
  animation:runBreathe 3.6s ease-in-out infinite; transition:transform .08s, box-shadow .08s;
}
.run-btn svg{ width:18px; height:18px; }
.run-btn:active{ transform:translateY(4px); box-shadow:0 1px 0 #9a4a14, 0 6px 12px -8px rgba(255,140,66,.5), inset 0 1px 0 rgba(255,255,255,.3); animation:none; }
.run-btn[disabled]{ animation:none; filter:saturate(.55) brightness(.8); cursor:default; }
.run-btn.go{ background:radial-gradient(circle at 30% 25%,#FFE29A,var(--gold) 75%); box-shadow:0 5px 0 #a8801f, 0 14px 22px -10px rgba(255,209,102,.5), inset 0 1px 0 rgba(255,255,255,.4); }
@keyframes runBreathe{ 0%,100%{ filter:brightness(1);} 50%{ filter:brightness(1.1);} }

.code-toggle{ display:none; }

/* ---------------------------------------------------------------- tutor */
.tutor{
  position:absolute; left:14px; bottom:84px; width:min(360px, calc(100% - 28px)); max-height:min(460px, calc(100% - 110px));
  display:flex; flex-direction:column; border-radius:18px; overflow:hidden;
  background:linear-gradient(160deg,rgba(44,34,24,.97),rgba(26,21,14,.97)); backdrop-filter:blur(10px);
  box-shadow:0 30px 60px -20px rgba(0,0,0,.8), inset 0 0 0 1px rgba(255,209,102,.18);
  animation:popIn .25s ease-out; z-index:5; user-select:text; -webkit-user-select:text;
}
@keyframes popIn{ from{ opacity:0; transform:translateY(10px) scale(.97);} to{ opacity:1; transform:none; } }
.tutor-head{ display:flex; align-items:center; gap:8px; padding:10px 10px 8px 14px; }
.tutor-title{ font-family:var(--font-display); font-weight:700; font-size:13px; flex:1; color:var(--gold); letter-spacing:.3px; }
.lang{ display:flex; gap:4px; }
.lang button{ padding:5px 9px; border-radius:999px; font-size:11px; font-weight:700; background:rgba(255,255,255,.05); color:rgba(245,239,224,.65); }
.lang button.on{ background:var(--gold); color:#241005; }
.tutor-close{ width:30px; height:30px; border-radius:50%; display:grid; place-items:center; color:rgba(245,239,224,.6); }
.tutor-close svg{ width:14px; height:14px; }
.tutor-log{ flex:1; overflow-y:auto; padding:6px 14px 10px; display:flex; flex-direction:column; gap:8px; min-height:90px; }
.msg{ max-width:88%; padding:9px 12px; border-radius:14px; font-size:14px; line-height:1.4; white-space:pre-wrap; word-wrap:break-word; }
.msg.wick{ align-self:flex-start; background:var(--shell-cream); color:#2a2418; border-bottom-left-radius:4px; }
.msg.me{ align-self:flex-end; background:var(--shell-teal); color:var(--parchment); border-bottom-right-radius:4px; }
.msg.note{ align-self:center; max-width:100%; font-size:12px; background:rgba(255,255,255,.05); color:rgba(245,239,224,.7); text-align:center; }
.msg.typing{ opacity:.7; }
.tutor-input{ display:flex; gap:8px; padding:10px; border-top:1px solid rgba(255,255,255,.06); align-items:center; }
.tutor-input input{ flex:1; min-width:0; padding:11px 14px; border-radius:999px; border:0; background:rgba(0,0,0,.3); color:var(--parchment); font:inherit; font-size:16px; box-shadow:inset 0 0 0 1px rgba(255,255,255,.08); outline:none; user-select:text; -webkit-user-select:text; }
.tutor-input input:focus{ box-shadow:inset 0 0 0 2px var(--spirit); }
.tutor-input button{ width:42px; height:42px; border-radius:50%; display:grid; place-items:center; background:rgba(255,255,255,.07); }
.tutor-input button.send{ background:var(--gold); color:#241005; }
.tutor-input button svg{ width:18px; height:18px; }
.tutor-input button[disabled]{ opacity:.4; }

/* ---------------------------------------------------------------- world animations */
@keyframes flickReached{ 0%,100%{opacity:.9} 45%{opacity:1} 60%{opacity:.85} }
@keyframes anticipate{ 0%,100%{opacity:.5} 50%{opacity:.95} }
@keyframes sway{ 0%,100%{transform:rotate(-1.2deg)} 50%{transform:rotate(1.2deg)} }
@keyframes swaySlow{ 0%,100%{transform:rotate(.9deg)} 50%{transform:rotate(-.9deg)} }
@keyframes rootGlow{ 0%,100%{opacity:.45} 50%{opacity:.7} }
@keyframes trailGlow{ 0%,100%{opacity:.55} 50%{opacity:.85} }
@keyframes windowGlow{ 0%,100%{opacity:.75} 50%{opacity:.92} }
.sway{ animation:sway 6.5s ease-in-out infinite; transform-box:fill-box; transform-origin:bottom center; }
.swaySlow{ animation:swaySlow 8s ease-in-out infinite; transform-box:fill-box; transform-origin:bottom center; }
.root-vein{ animation:rootGlow 4.5s ease-in-out infinite; }
.trail{ animation:trailGlow 3.5s ease-in-out infinite; }
.window-glow{ animation:windowGlow 4s ease-in-out infinite; }
.flame-reached{ animation:flickReached 3.4s ease-in-out infinite; }
.flame-wait{ animation:anticipate 2.4s ease-in-out infinite; }
.target-ring{ animation:ringBreathe 2.4s ease-in-out infinite; transform-box:fill-box; transform-origin:center; }
@keyframes ringBreathe{ 0%,100%{ transform:scale(1); opacity:.55;} 50%{ transform:scale(1.22); opacity:.15;} }
.lantern{ transform-box:view-box; }
.lantern.nudge .flame-wait, .lantern.nudge .target-ring{ animation:nudgeFlame .9s ease-in-out 2; }
@keyframes nudgeFlame{ 0%,100%{ opacity:.55;} 50%{ opacity:1;} }
.lantern.just-lit .flame-reached{ animation:litIn 1.2s ease-out 1, flickReached 3.4s ease-in-out 1.2s infinite; }
@keyframes litIn{ 0%{ opacity:0; } 100%{ opacity:.95; } }
.bloom{ transform-box:fill-box; transform-origin:center; animation:bloomOut 1.9s ease-out forwards; }
@keyframes bloomOut{ 0%{ transform:scale(.3); opacity:0;} 25%{ opacity:1;} 100%{ transform:scale(2.6); opacity:0;} }
.trace-in{ opacity:0; animation:traceIn 1.2s ease-out forwards, trailGlow 3.5s ease-in-out 1.2s infinite; }
@keyframes traceIn{ to{ opacity:.55; } }
.heading-mark{ animation:headingPulse 2.2s ease-in-out infinite; transition:opacity .4s; }
@keyframes headingPulse{ 0%,100%{ opacity:.45;} 50%{ opacity:.85;} }
.where-ring{ transform-box:fill-box; transform-origin:center; animation:whereRing 1.2s ease-out 2; }
.where-ring.r2{ animation-delay:.25s; }
@keyframes whereRing{ 0%{ transform:scale(.5); opacity:0;} 30%{ opacity:1;} 100%{ transform:scale(1.5); opacity:0;} }
.wick-pos{ will-change:transform; }

/* ---------------------------------------------------------------- responsive compositions */

/* iPad & wide tablets in landscape: same side-tray composition, larger touch targets (via pointer:coarse tokens). */
@media (min-width:900px) and (max-width:1200px){ .app{ grid-template-columns:minmax(0,1fr) 340px; } }

/* Portrait (iPad portrait, phones): world on top, tray as a bottom dock. */
@media (max-aspect-ratio:1/1){
  .app{ grid-template-columns:1fr; grid-template-rows:minmax(0,1fr) auto; gap:10px; padding:10px; }
  .tray{ padding:16px 14px 14px; gap:12px; justify-content:flex-start; }
  .seq-row{ align-items:center; }
  .seq-actions{ flex-direction:row; flex-wrap:wrap; justify-content:flex-end; max-width:150px; }
  .cmd{ aspect-ratio:auto; min-height:var(--cmd-min); height:64px; flex-direction:row; gap:8px; }
  .commands{ gap:8px; }
  .record{ padding:10px; gap:10px; }
  .code-panel{ min-height:0; padding:10px 14px; }
  .tutor{ bottom:78px; }
}
/* iPad portrait gets a roomier two-column dock. */
@media (max-aspect-ratio:1/1) and (min-width:700px){
  .app{ padding:16px; gap:14px; }
  .tray{ display:grid; grid-template-columns:1.15fr 1fr; grid-template-areas:"cmds code" "rec code" "run run"; gap:14px; }
  .commands{ grid-area:cmds; } .record{ grid-area:rec; } .run-row{ grid-area:run; }
  .record{ background:none; box-shadow:none; padding:0; display:contents; }
  .seq-row{ grid-area:rec; background:rgba(0,0,0,.17); border-radius:16px; padding:12px; box-shadow:inset 0 2px 6px rgba(0,0,0,.32); }
  .code-panel{ grid-area:code; grid-row:1 / span 2; min-height:150px; }
  .code-toggle{ display:none !important; }
}
/* Phones in portrait: code folds into a drawer so the world stays dominant. */
@media (max-aspect-ratio:1/1) and (max-width:699px){
  .brand{ top:12px; left:14px; }
  .code-toggle{ display:grid; width:34px; height:34px; border-radius:10px; place-items:center; background:rgba(255,255,255,.04); box-shadow:inset 0 0 0 1px rgba(255,255,255,.06); color:var(--gold); }
  .code-toggle svg{ width:17px; height:17px; }
  .code-toggle.on{ background:var(--gold); color:#241005; }
  .code-panel{ display:none; }
  .code-panel.open{ display:flex; }
  .tray{ gap:10px; }
  .cmd{ height:58px; }
  .cmd-lb{ font-size:11px; }
  /* Tutor = bottom sheet over the tray, so Wick and the path stay visible above it. */
  .tutor{ position:fixed; left:8px; right:8px; bottom:8px; width:auto; height:min(48vh, 420px); height:min(48dvh, 420px); min-height:250px; max-height:none; border-radius:22px; padding-bottom:env(safe-area-inset-bottom); z-index:20; }
  .tutor-log{ min-height:0; }
  .tutor-fab{ left:10px; bottom:10px; width:52px; height:52px; }
  .tutor-fab.on{ visibility:hidden; }
}
/* Phones in landscape: slim side tray, code in a drawer. */
@media (max-height:520px) and (min-aspect-ratio:1/1){
  .app{ grid-template-columns:minmax(0,1fr) 250px; padding:8px; gap:8px; }
  .tray{ padding:12px 12px 10px; gap:8px; justify-content:center; }
  .cmd{ aspect-ratio:auto; height:52px; flex-direction:row; }
  .cmd-lb{ display:none; }
  .record{ padding:8px; gap:8px; }
  .code-toggle{ display:grid; width:34px; height:34px; border-radius:10px; place-items:center; background:rgba(255,255,255,.04); color:var(--gold); }
  .code-toggle svg{ width:17px; height:17px; }
  .code-panel{ display:none; }
  .code-panel.open{ display:flex; position:absolute; left:10px; right:10px; bottom:76px; z-index:4; box-shadow:0 20px 40px -10px #000; }
  .run-btn{ min-height:44px; padding:10px; }
  .brand{ display:none; }
  /* Tutor docks over the tray column on the right, so Wick (left) stays visible. */
  .tutor{ position:fixed; top:8px; right:8px; bottom:8px; left:auto; width:min(340px,46vw); max-height:none; height:auto; z-index:20; }
  .tutor-fab.on{ visibility:hidden; }
}

@media (prefers-reduced-motion: reduce){
  .cmd.nudge,.sway,.swaySlow,.root-vein,.trail,.window-glow,.flame-reached,.flame-wait,.target-ring,.heading-mark,.run-btn{ animation:none !important; }
}
