:root{
  --navy:#0b1220; --navy2:#10182a; --gold:#d4b56a; --cream:#f4ead8; --paper:#fffdf8;
  --ink:#1a140c;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{-webkit-user-select:none;user-select:none;background:var(--navy);color:var(--cream);font-family:"Figtree",system-ui,-apple-system,"Segoe UI",sans-serif;font-size:16px;line-height:1.4}
button,input{font:inherit}
button{min-height:44px;min-width:44px;padding:10px 16px;border-radius:12px;border:2px solid rgba(212,181,106,.45);background:var(--navy2);color:var(--cream);font-size:16px;font-weight:700;cursor:pointer}
button:hover{border-color:var(--gold)}
button:disabled{opacity:.45;cursor:not-allowed}
button.gold{background:var(--gold);color:var(--ink);border-color:var(--gold)}
button.danger{background:#b4232e;color:#fff;border-color:#b4232e}
button.active{outline:3px solid var(--gold);outline-offset:1px;background:#24365e;color:#fff}
button.big{font-size:18px;padding:12px 22px}
h1,h2,.brand-name{font-family:"Cinzel",Georgia,serif}
.visually-hidden{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.topbar{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding:10px 14px;background:var(--navy2);border-bottom:2px solid rgba(212,181,106,.35);position:sticky;top:0;z-index:20}
.brand{display:flex;align-items:center;gap:10px;font-size:22px;color:var(--gold)}
.brand-mark{font-size:26px}
.top-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.button-link{min-height:44px;display:inline-flex;align-items:center;padding:10px 16px;border-radius:12px;border:2px solid rgba(212,181,106,.45);background:var(--navy);color:var(--gold);font-size:16px;font-weight:700;text-decoration:none}
.button-link:hover{border-color:var(--gold)}
main{max-width:1100px;margin:0 auto;padding:12px 12px 20px}
.title-row{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-bottom:10px}
.title-row input{flex:1;min-width:200px;min-height:48px;padding:10px 14px;border-radius:12px;border:2px solid rgba(212,181,106,.5);background:var(--paper);color:var(--ink);font-size:18px;font-weight:700}
#frame-count{font-weight:800;color:var(--cream)}
#playing-banner{display:flex;gap:14px;align-items:center;flex-wrap:wrap;background:var(--gold);color:var(--ink);padding:10px 14px;border-radius:12px;margin-bottom:10px;font-size:18px}
#playing-banner[hidden]{display:none}
.stage-shell{background:#05080f;border:2px solid rgba(212,181,106,.35);border-radius:16px;padding:8px;overflow:hidden}
#stage-wrap{position:relative;width:100%;aspect-ratio:16/9;background:var(--paper);border-radius:10px;overflow:hidden;transform-origin:center center}
#stage,#wipe{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none}
#wipe{pointer-events:none}
#stage{cursor:crosshair}
#status{min-height:24px;color:var(--gold);font-weight:700;margin:8px 2px}
.quest{background:var(--cream);color:var(--ink);border-radius:14px;padding:12px 14px;margin:10px 0}
.quest-head{display:flex;justify-content:space-between;align-items:center;gap:10px}
.quest h2{margin:6px 0;font-size:22px}
.quest p{font-size:16px;margin:6px 0}
.quest-frames{font-weight:800}
.how ul{margin:6px 0;padding-left:22px}
.how li{font-size:16px;margin:4px 0}
.timeline-wrap{background:var(--navy2);border:2px solid rgba(212,181,106,.3);border-radius:14px;padding:10px;margin:12px 0}
.frame-actions{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:10px}
#timeline{display:flex;gap:10px;overflow-x:auto;padding:6px 2px 10px}
.thumb{flex:0 0 auto;width:104px;padding:6px;background:var(--navy);border:3px solid transparent;border-radius:12px;color:var(--cream)}
.thumb canvas{width:96px;height:54px;display:block;background:var(--paper);border-radius:6px}
.thumb span{display:block;text-align:center;font-size:16px;font-weight:800;margin-top:4px}
.thumb.current{border-color:var(--gold);background:#24365e}
.tray{background:var(--navy2);border:2px solid rgba(212,181,106,.3);border-radius:16px;padding:12px;display:flex;flex-direction:column;gap:16px}
.tool-row{display:flex;gap:8px;flex-wrap:wrap}
.tool{flex:1 1 120px}
.tray-group{display:flex;flex-direction:column;gap:8px}
.group-label{font-weight:800;font-size:16px;color:var(--gold)}
.swatches{display:flex;gap:8px;flex-wrap:wrap}
.swatch{width:44px;height:44px;min-width:44px;padding:0;border-radius:10px;border:3px solid rgba(255,255,255,.35)}
.swatch.active{border-color:var(--gold);outline:3px solid var(--gold)}
.custom-colour,.slider-label,.file-label{min-height:44px;display:flex;align-items:center;gap:10px;font-weight:700;flex-wrap:wrap}
.custom-colour input[type=color]{width:56px;height:44px;padding:0;border:none;background:none}
input[type=range]{flex:1;min-width:140px;height:44px;accent-color:var(--gold)}
.brush-presets{display:flex;gap:8px;flex-wrap:wrap}
.brush-presets button{min-width:52px}
.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.inline-groups{display:grid;grid-template-columns:1fr;gap:16px}
.play-row{flex-direction:row;align-items:center;flex-wrap:wrap}
.play-row .grow{flex:1}
.file-row{flex-direction:row;flex-wrap:wrap;align-items:center}
.file-label{background:var(--navy);border:2px dashed rgba(212,181,106,.6);border-radius:12px;padding:8px 12px;cursor:pointer}
.file-label input{max-width:200px;color:var(--cream)}
#zoom-label{min-width:56px;text-align:center;font-weight:800}
.gallery-head{display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap}
.stored-note{font-size:17px;font-weight:700;color:var(--gold)}
.gallery-item{background:var(--navy2);border:2px solid rgba(212,181,106,.3);border-radius:14px;padding:12px;margin:10px 0;display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.gallery-item strong{font-size:18px;flex:1}
@media (min-width:900px){
  .inline-groups{grid-template-columns:1fr 1fr 1fr}
  .stage-shell{padding:12px}
  main{padding:16px}
}
@media (prefers-reduced-motion: reduce){
  *{scroll-behavior:auto}
}

input,textarea{-webkit-user-select:text;user-select:text}
#stage-wrap{touch-action:none}
@media (max-width:700px){
  /* Phone: canvas top/largest, timeline just above a fixed bottom tray.
     DOM/flex order on phone: title, Playing banner, canvas, status,
     timeline, quest card. The tray leaves the flow and sticks to the
     bottom of the screen, capped in height and scrollable inside, so
     the canvas stays visible while tools are always in reach. */
  #studio{display:flex;flex-direction:column;padding-bottom:44vh}
  .title-row{order:1} #playing-banner{order:2} .stage-shell{order:3}
  #status{order:4} .timeline-wrap{order:5;margin-bottom:8px} .quest{order:6} .how{order:7}
  .tray{position:fixed;left:0;right:0;bottom:0;z-index:40;max-height:42vh;overflow-y:auto;overflow-x:hidden;border-radius:16px 16px 0 0;padding:8px 10px calc(8px + env(safe-area-inset-bottom));gap:8px;box-shadow:0 -6px 24px rgba(0,0,0,.5)}
  .tray .tool-row,.tray .swatches,.tray .brush-presets,.tray .row,.tray .play-row,.tray .file-row,.tray .frame-actions{flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;padding-bottom:4px}
  .tray button{flex:0 0 auto;padding:8px 12px}
  .tray .tool{flex:0 0 auto}
  .tray-group{gap:4px}
  .group-label{font-size:15px}
  .thumb{width:88px} .thumb canvas{width:80px;height:45px}
}
