/* ui.css — the one place the look of Game Builder is defined.
 *
 * Before this file, every page carried its own copy of the same styles and they had
 * drifted: four different font stacks across five pages, four near-identical copies of
 * `.site-nav` with different sizes and spacings, and colours written as raw hex in some
 * pages and as variables in others. That drift is the whole reason this exists — a page
 * should not be able to look different by accident.
 *
 * Rules for anyone editing a page:
 *   - Never re-declare a colour, font or spacing value in a page. Use a token below.
 *   - If a page needs something this file doesn't have, add it HERE, not there.
 *   - Orange means "press this" and nothing else. Selection is quiet grey (--sel).
 *
 * Loaded by every page as the first stylesheet, before that page's own <style>.
 */

/* ---------------------------------------------------------------------------
   Type. Two roles, deliberately: words in a friendly sans, and numbers in mono
   ONLY where digits need to line up or be read precisely (coordinates, sizes,
   counts, fps). The old app was monospace everywhere, which read as a developer
   tool rather than something children use.
   --------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  color-scheme: dark;   /* so native controls, scroll gutters and form fields match */

  --font-ui: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Dark is the default: this is an art tool, and colours read truer against a
     dark ground. The neutrals are blue-shifted rather than flat grey. */
  --bg: #12141a;
  --surface: #191c24;
  --raised: #222632;
  --sunken: #0d0f14;
  --border: #2b303c;
  --border-soft: #21252f;

  --text: #e9ebf1;
  --dim: #98a0b2;
  --faint: #6a7180;

  /* Orange = an action you can take. Never used for "you are here". */
  --accent: #ffb03b;
  --accent-ink: #2b1c05;
  --accent-soft: rgba(255, 176, 59, .13);

  /* "You are here" / "this one is chosen" — deliberately quiet, so selection and
     actions never compete for the same meaning. */
  --sel: #333b4b;

  --ok: #5ad48a;
  --warn: #ffb03b;
  --danger: #f8776f;

  --rail: 214px;
  --rail-collapsed: 64px;
  --r: 10px;
  --r-lg: 14px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f5;
  --surface: #ffffff;
  --raised: #f6f7fa;
  --sunken: #e4e7ee;
  --border: #d7dce6;
  --border-soft: #e6eaf1;

  --text: #171a21;
  --dim: #5c6472;
  --faint: #868d9b;

  --accent: #e08b16;
  --accent-ink: #ffffff;
  --accent-soft: rgba(224, 139, 22, .12);
  --sel: #dde4f0;
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }   /* display:flex would otherwise beat the attribute */

html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
}
/* RULE: no scrollbars — canvases get a camera instead. Applied by pages that are
   genuinely built as a fixed viewport. It is NOT global: the four builder pages
   still lay out taller than the screen and would have content clipped by it. They
   opt in one at a time as each is converted. */
.app.fixed { height: 100dvh; overflow: hidden; }
.app.fixed body, body:has(.app.fixed) { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); }

/* Anything showing digits that must line up or be read precisely. */
.num, .mono { font-family: var(--font-num); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------------------
   App shell: rail + stage
   --------------------------------------------------------------------------- */
/* The rail is fixed to the viewport rather than a flex sibling, so it works
   identically on a page that scrolls and one that doesn't. Content reserves its
   width with padding, so nothing needs to know the rail is there. */
.app { min-height: 100dvh; padding-left: var(--rail); transition: padding-left .22s cubic-bezier(.4, 0, .2, 1); }
.app.collapsed { padding-left: var(--rail-collapsed); }
.app.fixed { display: flex; padding-left: 0; }
.app.fixed .app-main { padding-left: var(--rail); }
.app.fixed.collapsed .app-main { padding-left: var(--rail-collapsed); }

.rail {
  position: fixed; top: 0; left: 0; z-index: 30;
  width: var(--rail); height: 100dvh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .22s cubic-bezier(.4, 0, .2, 1);
  overflow: hidden;
}
.app.collapsed .rail { width: var(--rail-collapsed); }

.rail-brand { display: flex; align-items: center; gap: 10px; padding: 14px; flex: none; }
.rail-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(145deg, var(--accent), #ff8f2e);
  display: grid; place-items: center; color: var(--accent-ink);
}
.rail-name { font-weight: 600; font-size: 16px; white-space: nowrap; }

.rail-project {
  margin: 2px 10px 12px;
  width: calc(100% - 20px);
  padding: 9px 10px;
  background: var(--raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  display: flex; align-items: center; gap: 9px;
  cursor: pointer; text-align: left;
  font: inherit; color: inherit;
}
.rail-project:hover { border-color: var(--border); }
.rail-project .swatch {
  width: 24px; height: 24px; border-radius: 6px; flex: none;
  background: #4c7ef3; color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.rail-project .pmeta { min-width: 0; flex: 1; }
.rail-project .plabel {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--faint);
}
.rail-project .pname {
  display: block; font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.rail nav { padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.navitem {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--dim); text-decoration: none;
  font-family: inherit; font-size: 14px; white-space: nowrap;
  border: 0; background: transparent; cursor: pointer;
  width: 100%; text-align: left;
}
.navitem svg { flex: none; }
.navitem:hover { background: var(--raised); color: var(--text); }
.navitem.on { background: var(--sel); color: var(--text); font-weight: 500; }

.rail-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--border-soft); }
.rail-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.rail-user .av {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: #4c7ef3; color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.rail-user .uname { font-size: 13px; white-space: nowrap; }
.rail-collapse {
  width: 100%; margin-top: 4px; padding: 8px;
  background: transparent; border: 0; border-radius: 8px;
  color: var(--faint); cursor: pointer;
  font-family: inherit; font-size: 13px;
  display: flex; align-items: center; gap: 10px;
}
.rail-collapse:hover { background: var(--raised); color: var(--text); }
.app.collapsed .rail-collapse svg { transform: rotate(180deg); }

/* Collapsed: labels leave the layout entirely, so every icon sits dead-centre
   in the narrow rail rather than being nudged by an invisible label box. */
.app.collapsed .rail-name,
.app.collapsed .rail-project .pmeta,
.app.collapsed .rail-project .caret,
.app.collapsed .navitem > span,
.app.collapsed .rail-collapse > span,
.app.collapsed .rail-user .uname { display: none; }
.app.collapsed .rail-brand { justify-content: center; padding: 14px 0; }
.app.collapsed .rail-project { width: 42px; margin: 2px auto 14px; padding: 8px; justify-content: center; }
.app.collapsed .rail nav { padding: 0 12px; }
.app.collapsed .navitem { justify-content: center; gap: 0; padding: 10px 0; }
.app.collapsed .rail-foot { padding: 10px 12px; }
.app.collapsed .rail-user { justify-content: center; padding: 6px 0; }
.app.collapsed .rail-collapse { justify-content: center; gap: 0; padding: 8px 0; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------------------
   Top bar — the same on every tool: where you are, then actions on the right.
   --------------------------------------------------------------------------- */
.topbar {
  height: 52px; flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h2 { font-size: 15px; }
.topbar .crumb { color: var(--faint); font-size: 14px; }
.topbar .spacer { flex: 1; }
.saved { font-size: 12.5px; color: var(--ok); display: flex; align-items: center; gap: 6px; }
.saved .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.saved.pending { color: var(--dim); }

/* ---------------------------------------------------------------------------
   Controls
   --------------------------------------------------------------------------- */
.btn {
  font-family: inherit; font-size: 13px; padding: 7px 13px;
  border-radius: 8px; cursor: pointer;
  background: var(--raised); border: 1px solid var(--border); color: var(--text);
}
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }

input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--raised); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 9px; font: inherit; font-size: 13.5px;
}
input:disabled, select:disabled { opacity: .5; }
label { font-size: 13.5px; color: var(--dim); }

/* Tool rail down the side of a canvas. Every button says what it does —
   a picture alone makes a child guess. */
.tools {
  width: 80px; flex: none; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 10px 0;
}
.tool {
  width: 66px; border-radius: var(--r); border: 0;
  padding: 8px 2px 7px;
  background: transparent; color: var(--dim); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-family: inherit; font-size: 11px; line-height: 1;
}
.tool:hover { background: var(--raised); color: var(--text); }
.tool.on { background: var(--sel); color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------------------
   Canvas area — a fixed viewport with a camera, never a scrollbar.
   --------------------------------------------------------------------------- */
.canvas-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--sunken); }
.canvas-box { flex: 1; min-height: 0; display: grid; place-items: center; padding: 14px; }
.canvas-box canvas { display: block; max-width: 100%; max-height: 100%; border-radius: 8px; }

.hint {
  height: 34px; flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; border-top: 1px solid var(--border);
  background: var(--surface); font-size: 12.5px; color: var(--faint);
}
.hint b { color: var(--dim); font-weight: 500; }
.hint .spacer { flex: 1; }

/* ---------------------------------------------------------------------------
   Side panels
   --------------------------------------------------------------------------- */
.side {
  width: 244px; flex: none; background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sect { padding: 13px 14px; border-bottom: 1px solid var(--border-soft); }
.sect:last-child { border-bottom: 0; }
.sect h4 {
  margin-bottom: 10px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--faint); font-weight: 600;
}

.row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 9px; border-radius: 8px; font-size: 13.5px;
  cursor: pointer;
}
.row + .row { margin-top: 3px; }
.row.on { background: var(--sel); color: var(--text); font-weight: 500; }
.row:not(.on):hover { background: var(--raised); }
.row .rnum { font-family: var(--font-num); font-size: 12px; color: var(--faint); }

.field { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; font-size: 13.5px; }
.field .k { color: var(--dim); }
.field .v {
  font-family: var(--font-num); font-size: 12.5px;
  background: var(--raised); border: 1px solid var(--border-soft);
  padding: 3px 8px; border-radius: 6px;
}

.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.sw { aspect-ratio: 1; border-radius: 5px; border: 1px solid rgba(255,255,255,.08); cursor: pointer; padding: 0; }
.sw.on { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------------------------------------------------------------------------
   Cards (hub, pickers)
   --------------------------------------------------------------------------- */
.cards { display: flex; flex-wrap: wrap; gap: 14px; align-content: flex-start; }
.card {
  flex: 1 1 170px; max-width: clamp(200px, 19vw, 310px); aspect-ratio: 1 / 1;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px;
  display: flex; flex-direction: column; gap: 7px;
  cursor: pointer; text-align: left; font-family: inherit; color: inherit;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .ci {
  width: 38px; height: 38px; border-radius: var(--r);
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.card h3 { font-size: 16px; }
.card p { margin: 0; font-size: 13.5px; color: var(--dim); line-height: 1.45; }
.card .last { margin-top: auto; font-family: var(--font-num); font-size: 11.5px; color: var(--faint); }

/* ---------------------------------------------------------------------------
   Dialogs
   --------------------------------------------------------------------------- */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 8, 12, .66);
  display: grid; place-items: center; padding: 24px;
}
.dlg {
  width: min(720px, 100%); background: var(--surface);
  border: 1px solid var(--border); border-radius: 15px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  overflow: hidden;
}
.dlg header { padding: 16px 20px 14px; border-bottom: 1px solid var(--border-soft); }
.dlg header h3 { font-size: 17px; }
.dlg header p { margin: 3px 0 0; font-size: 13.5px; color: var(--dim); }
.dlg .dlg-body { padding: 18px 20px; }
.dlg footer {
  padding: 14px 20px; border-top: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 10px;
}
.dlg footer .spacer { flex: 1; }

/* ---------------------------------------------------------------------------
   Status text
   --------------------------------------------------------------------------- */
.status { font-size: 13px; color: var(--dim); }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }
.hint-text { font-size: 12.5px; color: var(--faint); }
