/* Night-navy control room, one accent. Mobile-first: written for 320px, scaled up. */
:root {
  --bg: #0b1020;
  --surface: #141b31;
  --surface-2: #1a2340;
  --line: #26304d;
  --text: #e8ecf8;
  --muted: #8f9bbd;
  --accent: #ff9a1f;
  --error: #ff5d6c;
  --ok: #7be0a0;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r1: 8px; --r2: 14px;
  --shadow: 0 8px 24px rgba(3, 6, 16, .55);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 180ms;

  /* type scale, ratio 1.25 from 16px */
  --t-1: 0.8rem; --t0: 1rem; --t1: 1.25rem; --t2: 1.5625rem; --t3: 1.953rem;
  --f-display: "Fredoka", "Nunito Sans", ui-rounded, system-ui, sans-serif;
  --f-body: "Nunito Sans", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 400 var(--t0)/1.55 var(--f-body);
  min-height: 100dvh; overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: var(--f-mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--s2); top: -64px; background: var(--accent); color: #1a1000; padding: var(--s2) var(--s3); border-radius: var(--r1); z-index: 40; }
.skip:focus { top: var(--s2); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: flex; flex-direction: column; height: 100dvh; }
.eyebrow { font: 600 var(--t-1)/1.2 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 var(--s2); }
.eyebrow .opt { text-transform: none; letter-spacing: 0; font-weight: 400; }

/* screens */
body[data-screen="home"] .levelscreen, body[data-screen="home"] .actions, body[data-screen="home"] .title, body[data-screen="home"] #homeBtn, body[data-screen="home"] .lvl { display: none; }
body[data-screen="level"] .home, body[data-screen="level"] .brand { display: none; }

/* header */
.bar {
  display: flex; align-items: center; gap: var(--s1);
  padding: var(--s2) var(--s2); min-height: 64px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex: none;
}
.brand { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); font: 600 var(--t1)/1 var(--f-display); }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--bg); position: relative; border: 1px solid var(--line); }
.logo::before { content: ""; position: absolute; left: 4px; right: 4px; top: 14px; height: 8px; border-radius: 50%; background: var(--accent); }
.logo::after { content: ""; position: absolute; left: 10px; right: 10px; top: 6px; height: 9px; border-radius: 50%; background: var(--text); }
.title { min-width: 0; flex: 1; }
.namebtn { display: flex; align-items: center; gap: var(--s2); max-width: 100%; min-height: 32px; padding: 0; background: none; border: 0; color: var(--text); cursor: pointer; border-radius: var(--r1); }
.namebtn svg { width: 18px; height: 18px; color: var(--muted); }
.namebtn:hover svg { color: var(--accent); }
h1 { font: 600 var(--t1)/1.15 var(--f-display); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .01em; }
.nameinput { width: 100%; min-height: 44px; padding: 0 var(--s3); font: 600 var(--t0)/1 var(--f-display); color: var(--text); background: var(--bg); border: 2px solid var(--accent); border-radius: var(--r1); }
.subline { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s1) var(--s3); min-height: 24px; }
.pill {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 var(--s3); border-radius: 999px;
  border: 1px solid var(--line); font: 700 .8rem/1.1 var(--f-body); max-width: 100%;
}
.pill.ok { color: var(--ok); border-color: var(--ok); background: rgba(123, 224, 160, .08); }
.pill.bad { color: var(--error); border-color: var(--error); background: rgba(255, 93, 108, .08); }
.pill.wait { color: var(--muted); }
.save { font: 400 .78rem/1 var(--f-mono); color: var(--muted); }
.save.ok { color: var(--ok); }
.save.bad { color: var(--error); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; min-width: 48px; padding: 0 var(--s4);
  border-radius: var(--r1); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font: 700 var(--t0)/1 var(--f-body); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn.icon { padding: 0; background: transparent; border-color: transparent; }
.btn.icon:hover:not(:disabled) { background: var(--surface-2); }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1000; }
.btn.primary:hover:not(:disabled) { background: #ffab45; border-color: #ffab45; }
.btn.primary.ok { background: var(--ok); border-color: var(--ok); }
.btn.primary.bad { background: var(--error); border-color: var(--error); color: #1b0508; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.btn.big { min-height: 52px; padding: 0 var(--s5); font-size: 1.05rem; }
.btn[aria-busy="true"] { opacity: .7; cursor: progress; }

/* overflow menu */
.menuwrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 230px; z-index: 30; padding: var(--s1); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r1); box-shadow: var(--shadow); }
.menuitem { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); width: 100%; min-height: 48px; padding: 0 var(--s3); background: none; border: 0; border-radius: 6px; color: var(--text); font: 600 var(--t0)/1 var(--f-body); text-align: left; cursor: pointer; }
.menuitem:hover:not(:disabled) { background: var(--surface-2); }
.menuitem:disabled { color: var(--muted); cursor: not-allowed; }
.soon { font: 400 .72rem var(--f-mono); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }

/* ---------- home ---------- */
.home { flex: 1; overflow: auto; padding: var(--s4); }
.home-grid { display: grid; gap: var(--s4); max-width: 1200px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); padding: var(--s5) var(--s4); display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.card h2 { font: 600 var(--t2)/1.1 var(--f-display); margin: 0; text-wrap: balance; }
.lead { margin: calc(-1 * var(--s2)) 0 0; color: var(--muted); }
.diff input[type="range"] { width: 100%; height: 48px; margin: 0; accent-color: var(--accent); background: transparent; cursor: pointer; }
.stops { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s1); margin-top: calc(-1 * var(--s1)); }
.stops button { min-height: 40px; padding: 0 2px; background: none; border: 0; color: var(--muted); font: 700 .78rem/1.1 var(--f-body); cursor: pointer; border-radius: 6px; }
.stops button.on { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chipbtn { min-height: 48px; padding: 0 var(--s4); border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--text); font: 700 .95rem/1 var(--f-body); cursor: pointer; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.chipbtn:hover { border-color: var(--muted); }
.chipbtn[aria-pressed="true"] { background: rgba(255, 154, 31, .14); border-color: var(--accent); color: var(--accent); }
#genBtn { width: 100%; font-size: 1.15rem; min-height: 60px; font-family: var(--f-display); letter-spacing: .02em; }

.mine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: var(--s3); }
.lcard { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s2); text-align: left; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--r1); cursor: pointer; font: inherit; min-width: 0; transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease); }
.lcard:hover { border-color: var(--accent); transform: translateY(-2px); }
.lcard canvas { width: 100%; aspect-ratio: 2 / 1; border-radius: 6px; background: #0e1530; display: block; }
.lcard .nm { font: 600 var(--t0)/1.2 var(--f-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { align-self: flex-start; display: inline-flex; align-items: center; min-height: 26px; padding: 0 var(--s2); border-radius: 999px; border: 1px solid var(--line); font: 700 .75rem/1 var(--f-body); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.bad { color: var(--error); border-color: var(--error); }
.empty { color: var(--muted); margin: 0; }

/* ---------- level screen ---------- */
.levelscreen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* level actions live in the header: own row under 768, same row from 768 */
body[data-screen="level"] .bar { flex-wrap: wrap; }
.actions { order: 6; flex: 1 1 100%; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); padding: 0 var(--s1) var(--s1); }
.actions .btn { width: 100%; min-height: 44px; padding: 0 var(--s2); font-size: .95rem; }
.wide-only { display: none; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--bg); }
canvas#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline-offset: -3px; }
canvas#cv.dragging { cursor: grabbing; }
.toolbar { position: absolute; right: var(--s3); top: var(--s3); display: flex; flex-direction: column; gap: var(--s2); }
.toolbar .btn { background: rgba(20, 27, 49, .94); border-color: var(--line); box-shadow: var(--shadow); }
.topleft { position: absolute; left: var(--s3); top: var(--s3); z-index: 5; display: flex; gap: var(--s2); max-width: calc(100% - 96px); }
.replay, .layertoggle { background: rgba(20, 27, 49, .94); box-shadow: var(--shadow); padding: 0 var(--s3); font-size: .9rem; text-align: left; }
.layertoggle { display: none; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); box-shadow: var(--shadow); padding: var(--s3); }

/* floating toolbar next to the selection */
.floatbar { position: absolute; z-index: 6; display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--r1); box-shadow: var(--shadow); }
.floatbar .btn { min-height: 48px; min-width: 48px; position: relative; }
.tip::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 14px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; padding: 4px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line);
  font: 600 .75rem/1.2 var(--f-body); color: var(--text); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); z-index: 2;
}
.tip:hover::after, .tip:focus-visible::after { opacity: 1; }
.floatbar.below .tip::after { bottom: auto; top: calc(100% + 14px); }

.hint-bar {
  position: absolute; left: var(--s3); right: calc(var(--s3) + 48px + var(--s2)); top: calc(var(--s3) + 56px); z-index: 7;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s1) var(--s1) var(--s1) var(--s3); background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--r2); box-shadow: var(--shadow); font-size: .85rem;
}

/* quick palette (edit mode) */
.quickbar { display: none; align-items: stretch; gap: var(--s1); flex: none; padding: var(--s2); background: var(--surface); border-top: 1px solid var(--line); }
body[data-edit="1"] .quickbar { display: flex; }
.quicklist { display: flex; gap: var(--s1); overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: thin; padding-bottom: 2px; }
.quick {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 76px; min-height: 76px; padding: var(--s1); background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r1); cursor: pointer; font: 700 .72rem/1.1 var(--f-body); text-align: center;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.quick:hover { border-color: var(--accent); }
.quick:active { transform: scale(.97); }
.quick img { width: 40px; height: 40px; object-fit: contain; }
.quick.more { width: 64px; background: var(--surface-2); }
.quick .noicon { width: 40px; height: 40px; display: grid; place-content: center; border: 1px dashed var(--line); border-radius: 6px; color: var(--muted); font: 600 1rem var(--f-mono); }

/* settings: bottom sheet on phones, side panel from 768 */
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); position: sticky; top: calc(-1 * var(--s3)); background: var(--surface); padding: var(--s1) 0; z-index: 1; }
.sheet-head h2 { font: 600 var(--t1)/1.15 var(--f-display); margin: 0; }
.settings { position: absolute; left: 0; right: 0; bottom: 0; max-height: 62%; overflow: auto; z-index: 8; border-radius: var(--r2) var(--r2) 0 0; font-size: var(--t0); }
.sub { color: var(--muted); font: 400 .8rem/1.4 var(--f-mono); margin: var(--s1) 0 0; }
.field { display: grid; gap: 2px; margin-top: var(--s2); font-size: .8rem; color: var(--muted); }
.field > span { font: 400 .8rem/1.3 var(--f-body); }
input[type="text"], input[type="number"], input[type="search"], select {
  width: 100%; min-height: 48px; padding: 0 var(--s3); font: 400 1rem/1.2 var(--f-body); color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r1);
}
.check { display: flex; align-items: center; gap: var(--s3); min-height: 48px; cursor: pointer; color: var(--text); }
.check input { appearance: none; width: 22px; height: 22px; margin: 0; border: 1.5px solid var(--muted); border-radius: 6px; background: transparent; display: grid; place-content: center; cursor: pointer; flex: none; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 11px; height: 6px; border: 2px solid #1a1000; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s3); }
.row-actions .sub { flex: 1 1 100%; margin: 0; }
.btn.small { padding: 0 var(--s3); }
.btn.danger { color: var(--error); border-color: rgba(255, 93, 108, .5); }
.prop { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: var(--s2); }
.links { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: var(--s1); }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; padding: 0 var(--s1); min-height: 48px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.problems, .lint { margin-top: var(--s3); padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--r1); font-size: .85rem; }
.problems { border-color: var(--error); color: var(--error); }
.lint { border-color: var(--accent); }
.problems ul, .lint ul { margin: var(--s1) 0 0; padding-left: var(--s4); color: var(--text); }
.hint { margin: 0; color: var(--muted); }

.toast { position: absolute; left: 50%; top: calc(var(--s3) + 56px); transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); z-index: 20; padding: var(--s3) var(--s4); border-radius: var(--r1); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: .9rem; font-weight: 600; text-align: center; }
.toast.ok { border-color: var(--ok); } .toast.bad { border-color: var(--error); }

.state { position: fixed; inset: 0; display: grid; place-content: center; gap: var(--s3); padding: var(--s5); text-align: center; background: rgba(11, 16, 32, .94); z-index: 50; }
.state h2 { font: 600 var(--t2)/1.15 var(--f-display); margin: 0; text-wrap: balance; }
.state p { margin: 0 auto; max-width: 52ch; color: var(--muted); }
.state .btn { justify-self: center; }
.state.error h2 { color: var(--error); }
.spin { width: 36px; height: 36px; margin: 0 auto; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* catalog dialog */
.dlg { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r2); padding: var(--s4); width: min(560px, calc(100% - 24px)); max-height: 86dvh; }
.dlg::backdrop { background: rgba(3, 6, 16, .72); }
.dlg .sheet-head { top: calc(-1 * var(--s4)); }
.pal-group { margin-top: var(--s4); }
.pal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s2); }
.pal-item { display: flex; align-items: center; gap: var(--s2); min-height: 52px; padding: var(--s1) var(--s2); text-align: left; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--r1); font: 700 .85rem/1.15 var(--f-body); cursor: pointer; }
.pal-item:hover { border-color: var(--accent); }
.pal-item img, .pal-item .noicon { width: 36px; height: 36px; object-fit: contain; flex: none; }
.pal-item .noicon { display: grid; place-content: center; border: 1px dashed var(--line); border-radius: 4px; font: 600 .8rem var(--f-mono); color: var(--muted); }

@media (min-width: 480px) {
  .actions { padding: 0 var(--s2) var(--s1); }
  .actions .btn { font-size: 1.05rem; }
}

@media (min-width: 768px) {
  .bar { padding: var(--s2) var(--s4); gap: var(--s2); }
  .home { padding: var(--s5); }
  .home-grid { grid-template-columns: minmax(300px, 4fr) 8fr; align-items: start; }
  .card { padding: var(--s5); }
  .card.mine { min-height: 60dvh; }
  .bar, body[data-screen="level"] .bar { min-height: 56px; padding-top: var(--s1); padding-bottom: var(--s1); flex-wrap: nowrap; }
  .actions { order: 0; flex: none; display: flex; gap: var(--s2); padding: 0; margin-left: auto; }
  .actions .btn { width: auto; min-width: 0; padding: 0 var(--s3); font-size: .9rem; white-space: nowrap; }
  .bar .btn.icon, .bar .acc { min-width: 44px; min-height: 44px; }
  .bar .title { order: 0; flex: 1 1 120px; padding: 0; }
  .bar .namebtn { position: relative; min-height: 28px; }
  .bar .namebtn::before { content: ""; position: absolute; inset: -8px -4px; }
  .bar .subline { min-height: 20px; flex-wrap: nowrap; overflow: hidden; }
  .bar .save { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar .pill { min-height: 20px; padding: 0 var(--s2); font-size: .75rem; white-space: nowrap; }
  body[data-screen="level"] .acc { width: 44px; padding: 0; }
  body[data-screen="level"] .acc .acc-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .topleft { left: var(--s4); top: var(--s4); }
  body[data-edit="1"] .layertoggle:not([hidden]) { display: inline-flex; }
  body[data-edit="1"] .layerpop:not([hidden]) { display: block; }
  .stage.layers-open .hint-bar { left: calc(var(--s4) + 300px + var(--s2)); }
  .toolbar { right: var(--s4); top: var(--s4); }
  .settings { left: auto; right: calc(var(--s4) + 48px + var(--s2)); top: var(--s4); bottom: var(--s4); width: 320px; max-height: none; border-radius: var(--r2); }
  .hint-bar { top: calc(var(--s4) + 56px); left: var(--s4); }
  .toast { top: calc(var(--s4) + 56px); }
  .quick { width: 88px; min-height: 80px; }
}
@media (min-width: 1024px) {
  .settings { width: 360px; }
  body[data-screen="level"] .acc { width: auto; padding: 0 var(--s3); }
  body[data-screen="level"] .acc .acc-label { position: static; width: auto; height: auto; overflow: hidden; clip-path: none; }
}
@media (min-width: 1200px) { .wide-only { display: inline-flex; } .narrow-only { display: none; } }
@media (min-width: 1440px) { .settings { width: 400px; } .home-grid { grid-template-columns: 4fr 8fr; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
}

/* phones: identity on its own row so the name and the pill stay readable at 320px */
@media (max-width: 479px) {
  body[data-screen="level"] .bar { flex-wrap: wrap; row-gap: 0; padding-bottom: var(--s1); }
  .title { order: 5; flex: 1 1 100%; padding: 0 var(--s2) var(--s1); }
  .bar .actions { padding-bottom: 0; }
  body[data-screen="level"] .bar { padding-top: var(--s1); }
  body[data-screen="level"] .title { padding-bottom: var(--s1); }
  body[data-screen="level"] .namebtn { min-height: 28px; }
  body[data-screen="level"] .subline { min-height: 22px; }
  body[data-screen="level"] .pill { min-height: 24px; }
  body[data-screen="home"] .acc { max-width: 9.5rem; }
  #btnUndo { margin-left: auto; }
}

/* ---------- brand + account ---------- */
.brand-img { width: 34px; height: 40px; object-fit: contain; display: block; }
.brand-name { white-space: nowrap; }
.account { margin-left: auto; }
body[data-screen="level"] .account { margin-left: 0; }
.acc { max-width: 11rem; padding: 0 var(--s3); min-height: 48px; }
.acc .acc-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-who { margin: 0; padding: var(--s2) var(--s3); color: var(--muted); font: 400 .8rem/1.3 var(--f-mono); overflow-wrap: anywhere; }
.menu-who:empty { display: none; }
@media (max-width: 479px) {
  body[data-screen="level"] .acc { padding: 0; width: 48px; }
  body[data-screen="level"] .acc .acc-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .brand { padding: 0 var(--s1); gap: var(--s2); }
  .account { margin-left: auto; }
  body[data-screen="level"] .account { margin-left: 0; }
}

/* ---------- hero (home) ---------- */
.hero { position: relative; max-width: 1200px; margin: 0 auto var(--s4); border: 1px solid var(--line); border-radius: var(--r2); overflow: hidden; background: #0e1633; }
.hero-bg {
  position: absolute; inset: 0; opacity: .42;
  background:
    url("/public/assets/backgrounds/0_l0_00_Moon.png") no-repeat right 6% top 12% / clamp(56px, 13vw, 128px),
    url("/public/assets/backgrounds/0_l0_08_ThirdLayer.png") repeat-x left bottom / auto 62%,
    url("/public/assets/backgrounds/0_l0_05_MountainRange.png") repeat-x left bottom / auto 82%,
    linear-gradient(180deg, #0e1633, #16224a);
}
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(11, 16, 32, .92) 0%, rgba(11, 16, 32, .7) 55%, rgba(11, 16, 32, .25) 100%); }
.hero-in { position: relative; z-index: 1; display: flex; align-items: center; gap: var(--s4); padding: var(--s4); }
.hero-logo { width: clamp(84px, 24vw, 168px); height: auto; flex: none; filter: drop-shadow(0 6px 14px rgba(3, 6, 16, .6)); }
.hero-copy { min-width: 0; }
.hero-title { font: 600 var(--t2)/1.1 var(--f-display); margin: 0 0 var(--s2); text-wrap: balance; }
.hero-sub { margin: 0; color: var(--muted); max-width: 52ch; }
.hero .eyebrow { color: var(--accent); }
@media (min-width: 768px) { .hero-in { padding: var(--s5) var(--s6); gap: var(--s6); } .hero-title { font-size: var(--t3); } }

/* ---------- home groups ---------- */
.group { display: grid; gap: var(--s3); }
.group + .group { margin-top: var(--s2); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.group-head .eyebrow, .group .eyebrow { margin: 0; }
.card h3 { margin: 0; }
.sub-text, .open .sub { color: var(--muted); font: 400 .8rem/1.4 var(--f-mono); margin: 0; }
.online-prompt { display: grid; gap: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line); }
.online-prompt .lead { margin: 0; }
.lwrap { display: grid; gap: var(--s2); align-content: start; min-width: 0; }
.lwrap .btn { min-height: 44px; }
.textcard { min-height: 96px; justify-content: center; }
.textcard .sub { color: var(--muted); font: 400 .8rem/1.4 var(--f-mono); }

/* ---------- level actions ---------- */
.note-line { margin: 0; font-size: .85rem; line-height: 1.4; color: var(--text); }
.note-line:empty { display: none; }
.note-line code { color: var(--text); }

/* ---------- dialogs: publish + login ---------- */
.lead-dlg { margin: var(--s3) 0; color: var(--text); }
.pub-name { margin: 0 0 var(--s2); color: var(--muted); }
.pub-name strong { color: var(--text); overflow-wrap: anywhere; }
.pub-status { margin: var(--s3) 0 0; min-height: 1.5em; color: var(--muted); font-weight: 600; overflow-wrap: anywhere; }
.pub-status.ok { color: var(--ok); } .pub-status.bad { color: var(--error); }
.login-err { margin: var(--s2) 0 0; min-height: 1.4em; color: var(--error); font-weight: 600; }
.login-links { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2); margin: var(--s3) 0 0; }
.login-links a { color: var(--accent); min-height: 48px; display: inline-flex; align-items: center; text-underline-offset: 3px; }
input[type="email"], input[type="password"] {
  width: 100%; min-height: 48px; padding: 0 var(--s3); font: 400 1rem/1.2 var(--f-body); color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r1);
}
#loginDlg .row-actions .btn, #publishDlg .row-actions .btn { flex: 1 1 140px; }

/* ---------- fiches (beginner panel) ---------- */
.fhead { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s2) 0 var(--s3); border-bottom: 1px solid var(--line); }
.ficon { width: 48px; height: 48px; object-fit: contain; flex: none; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r1); padding: 4px; }
.ficon.noicon { display: grid; place-content: center; color: var(--muted); font: 600 1rem var(--f-mono); }
.ftext { min-width: 0; }
.fname { font: 600 var(--t1)/1.15 var(--f-display); display: block; }
.fdesc { margin: var(--s1) 0 0; color: var(--muted); font-size: .9rem; line-height: 1.4; }
.fsec { margin-top: var(--s3); }
.flabel { font: 700 .85rem/1.2 var(--f-body); margin: 0 0 var(--s1); color: var(--text); }
.flabel-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); }
.fval { font: 600 .85rem var(--f-mono); color: var(--accent); }
.fnote { margin: var(--s2) 0 0; color: var(--muted); font-size: .8rem; line-height: 1.4; }
.fsec input[type="range"] { width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent); background: transparent; cursor: pointer; }
.fsec .chips { gap: var(--s1); }
.fsec .chipbtn { min-height: 44px; padding: 0 var(--s3); font-size: .9rem; }
.chips.pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.chipbtn.pic { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; border-radius: var(--r1); min-height: 72px; font-size: .75rem; }
.chipbtn.pic img { width: 72px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.compass { display: grid; grid-template-columns: repeat(3, 56px); grid-auto-rows: 48px; gap: var(--s1); justify-content: start; }
.compass-btn { min-width: 0; padding: 0; font-size: 1.3rem; }
.compass-mid { display: grid; place-content: center; font: 600 .8rem var(--f-mono); color: var(--muted); }
.mlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--s1); }
.mbtn { min-height: 44px; padding: 0 var(--s2); font-size: .85rem; }
.linkbig { width: 100%; }
.adv { margin-top: var(--s4); border-top: 1px solid var(--line); padding-top: var(--s2); }
.adv > summary { min-height: 48px; display: flex; align-items: center; cursor: pointer; font-weight: 700; color: var(--muted); list-style: none; }
.adv > summary::before { content: "▸"; margin-right: var(--s2); transition: transform var(--dur) var(--ease); }
.adv[open] > summary::before { transform: rotate(90deg); }
.adv > summary::-webkit-details-marker { display: none; }
.org { border-top: 1px solid var(--line); padding-top: var(--s2); }

/* layers: docked panel (desktop, left under the replay button) and the same rows inside the phone drawer */
.layerpop { position: absolute; left: var(--s4); top: calc(var(--s4) + 48px + var(--s2)); z-index: 6; display: none; width: 300px; max-height: calc(100% - var(--s4) * 2 - 48px - var(--s2)); overflow: auto; padding: var(--s4); overscroll-behavior: contain; }
.layerpop .sheet-head { top: calc(-1 * var(--s4)); margin-bottom: var(--s2); }
.layerpop .tipbtn.wide { margin-bottom: var(--s3); }
.layer-head { display: flex; align-items: flex-end; gap: var(--s2); margin-bottom: var(--s2); }
.layer-head .field { flex: 1; margin-top: 0; }
.layers { display: grid; }
.lrow { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; align-items: center; gap: var(--s1); padding: var(--s1) 0; border-bottom: 1px solid var(--line); }
.lname { display: grid; gap: 2px; min-height: 44px; padding: var(--s1) var(--s2); text-align: left; background: none; border: 0; border-radius: var(--r1); color: var(--text); font: inherit; cursor: pointer; }
.lname:hover { background: var(--surface-2); }
.lname-t { font: 700 var(--t0)/1.2 var(--f-body); }
.lname-s { font: 400 .75rem/1.3 var(--f-mono); color: var(--muted); }
.lrow.cur .lname { box-shadow: inset 3px 0 0 var(--accent); padding-left: var(--s3); }
.lrow.cur .lname-t { color: var(--accent); }
.lrow.off .lname { opacity: .55; }
.lrow .lbtn { min-width: 44px; min-height: 44px; padding: 0; font-size: 1.3rem; line-height: 1; border-color: var(--line); background: var(--surface-2); color: var(--text); }
.lrow .lbtn[aria-pressed="true"] { color: var(--text); }
.lrow .lbtn[aria-label^="Déverrouiller"] { border-color: var(--accent); background: rgba(255, 154, 31, .14); }
.lrow .lbtn[aria-label^="Montrer"] { background: transparent; }
.decorlock { width: 100%; margin-top: var(--s4); font-size: .95rem; }
.layers .row-actions { margin-top: var(--s3); }

/* why it is impossible: floats at the bottom of the stage so it never costs header space */
.why-row { position: absolute; left: var(--s3); right: var(--s3); bottom: var(--s3); z-index: 6; display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s1) var(--s1) var(--s3); background: var(--surface); border: 1px solid var(--error); border-radius: var(--r2); box-shadow: var(--shadow); }
.why-row .note-line { color: var(--error); flex: 1; }
@media (min-width: 768px) { .why-row { left: var(--s4); right: auto; bottom: var(--s4); max-width: min(560px, calc(100% - 96px)); } }

canvas#cv.panning { cursor: grab; }
.col { display: grid; gap: var(--s4); align-content: start; min-width: 0; }
.pal-txt { display: grid; gap: 1px; min-width: 0; }
.pal-txt small { color: var(--muted); font: 400 .72rem/1.25 var(--f-body); }

/* open in game dialog */
.game-body { display: grid; gap: var(--s3); margin-top: var(--s3); }
.game-body p { margin: 0; }
.steps { margin: 0; padding-left: var(--s5); display: grid; gap: var(--s1); }
.dirbox { display: block; padding: var(--s2) var(--s3); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r1); overflow-wrap: anywhere; font-size: .8rem; }
.steamlink { color: var(--accent); min-height: 44px; display: inline-flex; align-items: center; text-underline-offset: 3px; }

/* ---------- tutorial: Krew talks, the page is dimmed, a spotlight shows the target ---------- */
.tuto { position: fixed; inset: 0; z-index: 100; }
.tuto-dim { position: absolute; inset: 0; background: rgba(5, 8, 20, .74); }
.tuto-spot { position: absolute; display: none; border-radius: 12px; border: 2px solid var(--accent); box-shadow: 0 0 0 100vmax rgba(5, 8, 20, .74); pointer-events: none; transition: left 220ms var(--ease), top 220ms var(--ease), width 220ms var(--ease), height 220ms var(--ease); }
.tuto-card { position: absolute; display: flex; align-items: flex-end; gap: var(--s2); max-width: 560px; margin: 0 auto; }
.tuto-krew { width: 52px; height: auto; flex: none; margin-bottom: -4px; animation: krewbob 1.8s var(--ease) infinite alternate; filter: drop-shadow(0 4px 8px rgba(3, 6, 16, .6)); }
@keyframes krewbob { to { transform: translateY(-4px) rotate(-2deg); } }
.tuto-bubble { position: relative; flex: 1; min-width: 0; background: #fff; color: #1b2140; border-radius: 20px; padding: var(--s3) var(--s4); box-shadow: var(--shadow); font-family: var(--f-display); }
.tuto-bubble::before { content: ""; position: absolute; left: -8px; bottom: 18px; width: 16px; height: 16px; background: #fff; transform: rotate(45deg); border-radius: 3px; }
.tuto-text { margin: 0 0 var(--s2); font: 600 1rem/1.4 var(--f-display); }
.tuto-dots { display: flex; gap: 6px; margin-bottom: var(--s2); }
.tuto-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: #d3d8ea; }
.tuto-dots .dot.on { background: var(--accent); }
.tuto-row { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); }
.tuto-btn { min-height: 44px; padding: 0 var(--s4); border-radius: 999px; border: 2px solid transparent; font: 600 1rem/1 var(--f-display); cursor: pointer; }
.tuto-btn.primary { background: var(--accent); color: #1a1000; margin-left: auto; }
.tuto-btn.ghost { background: transparent; color: #5b6488; }
.tuto-btn:focus-visible { outline: 3px solid #1b2140; outline-offset: 2px; }

@media (max-width: 479px) {
  .bar .btn.icon { min-width: 44px; min-height: 44px; }
  body[data-screen="level"] .acc { width: 44px; min-height: 44px; }
}
@media (min-width: 768px) {
  .tuto-krew { width: 72px; }
  .tuto-text { font-size: 1.1rem; }
}

/* ---------- crew bubbles (characters.js) ---------- */
.speak { --ch: #ff9900; --ch-ink: #1a1000; display: flex; align-items: flex-end; gap: var(--s2); max-width: 520px; font-family: var(--f-display); }
.speak-face { width: 64px; height: 64px; flex: none; object-fit: contain; object-position: bottom; filter: drop-shadow(0 3px 6px rgba(3, 6, 16, .5)); }
.speak-bubble { position: relative; flex: 1; min-width: 0; background: #fff; color: #1b2140; border: 2px solid #1b2140; border-radius: 18px; padding: var(--s3) var(--s4); box-shadow: var(--shadow); }
.speak-bubble::before { content: ""; position: absolute; left: -9px; bottom: 16px; width: 14px; height: 14px; background: #fff; border-left: 2px solid #1b2140; border-bottom: 2px solid #1b2140; transform: rotate(45deg); border-radius: 0 0 0 4px; }
.speak-name { display: inline-block; margin: -2px 0 var(--s1); padding: 2px 10px; border-radius: 999px; background: var(--ch); color: var(--ch-ink); font: 600 .8rem/1.4 var(--f-display); letter-spacing: .02em; }
.speak-text { margin: 0; font: 600 1rem/1.4 var(--f-display); overflow-wrap: anywhere; }
.speak-x { position: absolute; top: 2px; right: 4px; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: #5b6488; font-size: 1.4rem; line-height: 1; cursor: pointer; border-radius: 50%; }
.speak-x:focus-visible { outline: 3px solid #1b2140; outline-offset: -4px; }
.speak-x + .speak-text, .speak-bubble:has(.speak-x) .speak-text { padding-right: var(--s5); }
.voice { position: absolute; left: var(--s3); bottom: calc(var(--s3) + 64px); z-index: 22; max-width: min(420px, calc(100% - 24px)); }
.voice .speak { animation: speakin 220ms var(--ease); }
.voice-slot { margin: var(--s3) 0; }
.voice-slot:empty { display: none; }
.hero-copy .voice-slot { margin-top: var(--s4); }
.fnamerow { display: flex; align-items: center; gap: var(--s2); }
.tipbtn { flex: none; min-width: 44px; min-height: 44px; margin: -8px 0; border-radius: 999px; border: 2px solid #FDFE05; background: transparent; color: #FDFE05; font: 600 1rem/1 var(--f-display); cursor: pointer; }
.tipbtn:hover { background: rgba(253, 254, 5, .14); }
.tipbtn.wide { width: 100%; margin: 0 0 var(--s3); padding: 0 var(--s3); }
.tuto-speak { max-width: 560px; width: 100%; }
.tuto-speak .speak-bubble { padding-bottom: var(--s3); }
.tuto-speak .speak-text { margin-bottom: var(--s2); padding-right: 0; }
@keyframes speakin { from { transform: translateY(8px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .voice .speak { animation: none; } }
@media (min-width: 768px) { .speak-face { width: 84px; height: 84px; } .speak-text { font-size: 1.05rem; } }
@media (max-width: 479px) { .voice .speak-face { width: 48px; height: 48px; } .voice .speak-text { font-size: .9rem; } .voice .speak-bubble { padding: var(--s2) var(--s3); } }

.hosted-only { display: none; }
body.hosted .hosted-only { display: block; }
.host-note { margin: var(--s3) 0 0; max-width: 60ch; font-size: .875rem; line-height: 1.5; color: var(--muted); }
.onlinebox { display: grid; gap: var(--s2); padding: var(--s3); border: 1px solid var(--accent); border-radius: var(--r1); }
.onlinepitch { font-weight: 600; }

/* Line icons inside text (status pill, badges, buttons, headings): no emoji in the UI. */
svg.ic { width: 15px; height: 15px; stroke-width: 2.2; margin-right: 6px; }
.badge svg.ic { width: 13px; height: 13px; margin-right: 4px; }
.with-ic { display: inline-flex; align-items: center; gap: var(--s2); }
.with-ic > svg { width: 20px; height: 20px; }
.decorlock.with-ic { display: flex; justify-content: center; }
.compass-btn svg { width: 22px; height: 22px; stroke-width: 2.2; }
.lbtn svg { width: 20px; height: 20px; }
