/* ── Interfaces — an infinite board of every screen ────────────────────────
   Light is the default: white paper, grey furniture, one blue accent, the way
   Figma and Miro read. Dark mode swaps the tokens, never the rules. */

:root {
  color-scheme: light;

  --paper:      #f4f5f7;   /* the canvas behind the boards */
  --grid:       #dfe2e8;   /* faint dot grid on it */
  --surface:    #ffffff;   /* panels, cards, toolbar */
  --surface-2:  #f7f8fa;   /* inset rows */
  --line:       #e3e6ec;
  --line-2:     #ced3dd;
  --ink:        #14161a;
  --ink-2:      #5c6373;
  --ink-3:      #8a92a4;
  --accent:     #2b6cff;
  --accent-sub: rgba(43,108,255,0.12);
  --note:       #ffe27a;   /* sticky note */
  --note-ink:   #4a3c00;
  --danger:     #e5484d;
  --shadow-sm:  0 1px 2px rgba(16,20,30,0.06), 0 1px 1px rgba(16,20,30,0.04);
  --shadow:     0 4px 16px rgba(16,20,30,0.10), 0 1px 3px rgba(16,20,30,0.06);
  --shadow-lg:  0 18px 50px rgba(16,20,30,0.18), 0 3px 10px rgba(16,20,30,0.08);

  --topbar-h:   96px;
  --panel-w:    248px;
  --insp-w:     272px;
  --radius:     10px;
  --ease:       cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper:      #16181d;
  --grid:       #24272f;
  --surface:    #1d2026;
  --surface-2:  #23262d;
  --line:       #2c3038;
  --line-2:     #3a3f4a;
  --ink:        #eef0f4;
  --ink-2:      #a4abba;
  --ink-3:      #767e8f;
  --accent:     #5b8cff;
  --accent-sub: rgba(91,140,255,0.16);
  --note:       #d8b74a;
  --note-ink:   #241d00;
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.4);
  --shadow:     0 6px 20px rgba(0,0,0,0.45);
  --shadow-lg:  0 24px 60px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 400 13px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
        Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

a:focus-visible, button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px;
}

/* ── Loader ─────────────────────────────────────────────────────────────── */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--paper);
  transition: opacity 0.5s var(--ease), visibility 0.5s;
}
.loader.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-inner { display: grid; justify-items: center; gap: 0.9rem; width: 220px; }
.loader-mark {
  width: 52px; height: 52px;
  animation: markIn 0.7s var(--ease-out) both, markPulse 2.4s 0.7s ease-in-out infinite;
}
html[data-theme="dark"] .loader-mark { filter: invert(1); }
@keyframes markIn { from { opacity: 0; transform: translateY(8px) scale(0.94); } }
@keyframes markPulse { 50% { opacity: 0.55; } }
.loader-name {
  margin: 0; font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-3);
}
.loader-track {
  width: 100%; height: 2px; border-radius: 2px;
  background: var(--line); overflow: hidden;
}
.loader-bar {
  display: block; height: 100%; width: 0;
  background: var(--accent); border-radius: 2px;
  transition: width 0.35s var(--ease);
}
.loader-step {
  margin: 0; font-size: 0.7rem; color: var(--ink-3);
  min-height: 1em; transition: opacity 0.2s;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
.app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr var(--insp-w);
  grid-template-rows: auto 1fr;   /* the bar is exactly as tall as its two rows; --topbar-h is synced from JS for the fixed panels */
  grid-template-areas: "top top top" "layers stage inspector";
  opacity: 0; transition: opacity 0.6s var(--ease) 0.1s;
}
.app.is-ready { opacity: 1; }
.app.no-layers { grid-template-columns: 0 1fr var(--insp-w); }
.app.no-inspector { grid-template-columns: var(--panel-w) 1fr 0; }
.app.no-layers.no-inspector { grid-template-columns: 0 1fr 0; }

/* Rails: what a collapsed panel leaves behind */
.rail {
  position: absolute; top: 0; bottom: 0; z-index: 15;
  display: none; flex-direction: column; align-items: center; gap: 0.5rem;
  width: 28px; padding: 0.6rem 0 0; border: 0;
  background: var(--surface); color: var(--ink-3); cursor: pointer;
  transition: color 0.18s, background 0.18s;
}
.rail-l { left: 0; border-right: 1px solid var(--line); }
.rail-r { right: 0; border-left: 1px solid var(--line); }
.rail:hover { color: var(--accent); background: var(--surface-2); }
.rail svg { width: 14px; height: 14px; flex: 0 0 auto; }
.rail-txt {
  writing-mode: vertical-rl; font-size: 0.6rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase;
}
.rail-r .rail-txt { transform: rotate(180deg); }
.app.no-layers .rail-l { display: flex; }
.app.no-inspector .rail-r { display: flex; }

/* ── Top bar ────────────────────────────────────────────────────────────── */
.topbar {
  grid-area: top; position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
/* row one: sidebar toggle | KK mark with the section name beneath | theme + inspector */
.tb-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0.5rem 0.7rem 0.45rem;
}
.tb-left { display: flex; align-items: center; justify-self: start; min-width: 60px; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; text-decoration: none; color: inherit; }
.brand img { width: 24px; height: 24px; display: block; }
html[data-theme="dark"] .brand img { filter: invert(1); }
.doc-name {
  margin: 0; font-size: 0.56rem; font-weight: 500; letter-spacing: 0.32em; text-transform: uppercase;
  color: var(--ink-2); white-space: nowrap;
}
.home {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 7px;
  transition: background 0.18s;
}
.home:hover { background: var(--surface-2); }
.home img { width: 22px; height: 22px; }
html[data-theme="dark"] .home img { filter: invert(1); }

.tb-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 7px; background: none;
  color: var(--ink-2); cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.18s var(--ease);
}
.tb-btn:hover { background: var(--surface-2); color: var(--ink); }
.tb-btn:active { transform: scale(0.92); }
.tb-btn svg { width: 16px; height: 16px; }
.tb-btn[aria-pressed="false"] { color: var(--ink-3); }

.ico-moon { display: none; }
html[data-theme="dark"] .ico-sun { display: none; }
html[data-theme="dark"] .ico-moon { display: block; }

/* row two: the views as a Library-style tab strip, centred, active one filled */
.views {
  display: flex; justify-content: center; align-self: stretch;
  border-top: 1px solid var(--line); margin-bottom: -1px;
}
.view-tab {
  flex: 0 0 auto; padding: 0.6rem 1.3rem; border: 0; border-left: 1px solid var(--line);
  background: none; color: var(--ink); cursor: pointer;
  font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.view-tab:first-child { border-left: 0; }
.view-tab:hover { background: var(--surface-2); }
.view-tab.is-on { background: var(--ink); color: var(--surface); }
.view-ink { display: none; }
.topbar-right { display: flex; align-items: center; gap: 0.15rem; justify-self: end; }

/* ── Panels ─────────────────────────────────────────────────────────────── */
.layers, .inspector {
  background: var(--surface);
  display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
  transition: opacity 0.24s var(--ease), transform 0.3s var(--ease);
}
.layers { grid-area: layers; border-right: 1px solid var(--line); }
.inspector { grid-area: inspector; border-left: 1px solid var(--line); }
.app.no-layers .layers { opacity: 0; transform: translateX(-12px); pointer-events: none; }
.app.no-inspector .inspector { opacity: 0; transform: translateX(12px); pointer-events: none; }

.panel-head {
  display: flex; align-items: center; gap: 0.5rem;
  height: 34px; padding: 0 0.5rem 0 0.7rem; flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
}
.panel-collapse {
  margin-left: auto; width: 26px; height: 26px; border: 0; border-radius: 7px;
  background: transparent; color: var(--ink-3, var(--ink-2)); font-size: 18px; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
  transition: background 0.16s, color 0.16s, transform 0.2s var(--ease);
}
.panel-collapse:hover { background: var(--surface-2); color: var(--ink); }
.panel-collapse:active { transform: scale(0.9); }
.panel-title {
  font-size: 0.66rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3);
}
.panel-count { font-size: 0.66rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.layers-search { position: relative; padding: 0.5rem 0.6rem; flex: 0 0 auto; }
.layers-search svg {
  position: absolute; left: 1.05rem; top: 50%; transform: translateY(-50%);
  width: 12px; height: 12px; color: var(--ink-3); pointer-events: none;
}
.layers-search input {
  width: 100%; padding: 0.36rem 0.5rem 0.36rem 1.6rem;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface-2); color: var(--ink);
  font-size: 0.74rem; outline: none;
  transition: border-color 0.18s, background 0.18s;
}
.layers-search input:focus { border-color: var(--accent); background: var(--surface); }
.layers-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.layers-tree { flex: 1 1 auto; overflow-y: auto; padding: 0.15rem 0 0.6rem; }
.layers-foot { flex: 0 0 auto; padding: 0.5rem 0.6rem; border-top: 1px solid var(--line); }

.ghost-btn {
  width: 100%; padding: 0.4rem 0.6rem;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: var(--ink-2);
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.18s var(--ease);
}
.ghost-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-2); }
.ghost-btn:active { transform: scale(0.97); }

/* Tree rows */
.tr {
  display: flex; align-items: center; gap: 0.4rem;
  width: 100%; padding: 0.28rem 0.6rem; border: 0; background: none;
  color: var(--ink-2); font-size: 0.74rem; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.14s, color 0.14s;
}
.tr:hover { background: var(--surface-2); color: var(--ink); }
.tr.is-on { background: var(--accent-sub); color: var(--accent); }
.tr-cat { font-weight: 700; font-size: 0.64rem; letter-spacing: 0.1em;
          text-transform: uppercase; color: var(--ink-3); }
.tr-board { padding-left: 1.2rem; font-weight: 500; }
.tr-item { padding-left: 2.1rem; font-size: 0.71rem; color: var(--ink-3); }
.tr-item:hover { color: var(--ink-2); }
.tw {
  display: grid; place-items: center; width: 12px; height: 12px; flex: 0 0 auto;
  color: var(--ink-3);
}
.tw svg { width: 8px; height: 8px; transition: transform 0.22s var(--ease); }
.tr[aria-expanded="true"] .tw svg { transform: rotate(90deg); }
.tr-dot {
  width: 6px; height: 6px; border-radius: 2px; flex: 0 0 auto;
  background: var(--line-2);
}
.tr-n { margin-left: auto; font-size: 0.65rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tr-kids { overflow: hidden; }
.tr-kids[hidden] { display: none; }

/* Inspector */
.insp-body { flex: 1 1 auto; overflow-y: auto; padding: 0.7rem 0.75rem 1.4rem; }
.insp-thumb-wrap {
  max-height: 220px; overflow: hidden; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); margin-bottom: 0.7rem;
  animation: fadeUp 0.3s var(--ease) both;
}
/* a long page scrolls inside its preview instead of pushing the actions off screen */
.insp-thumb-wrap.is-long { overflow-y: auto; overscroll-behavior: contain; }
.insp-thumb-wrap.is-long::-webkit-scrollbar { width: 7px; }
.insp-thumb-wrap.is-long::-webkit-scrollbar-track { background: var(--surface-2); }
.insp-thumb-wrap.is-long::-webkit-scrollbar-thumb { background: var(--ink-3, var(--ink-2)); border-radius: 7px; }
.insp-thumb-wrap.is-tiny { display: grid; place-items: center; min-height: 90px; }
.insp-thumb-wrap.is-tiny .insp-thumb { width: auto; }
.insp-thumb { width: 100%; display: block; }
.insp-actions { display: grid; gap: 0.4rem; margin: 0.2rem 0 0.9rem; }
.insp-actions .insp-btn--ghost { margin-top: 0; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(5px); } }
.insp-title {
  margin: 0 0 0.15rem; font-size: 0.92rem; font-weight: 650; letter-spacing: -0.01em;
  line-height: 1.25;
}
.insp-sub { margin: 0 0 0.8rem; font-size: 0.72rem; color: var(--ink-3); }
.insp-group { margin: 0 0 0.85rem; }
.insp-label {
  margin: 0 0 0.35rem; font-size: 0.6rem; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-3);
}
.insp-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; }
.field {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.45rem; border-radius: 6px; background: var(--surface-2);
  font-size: 0.72rem; font-variant-numeric: tabular-nums;
}
.field b { color: var(--ink-3); font-weight: 600; font-size: 0.66rem; }
.insp-text { margin: 0 0 0.7rem; font-size: 0.76rem; line-height: 1.6; color: var(--ink-2); }
.insp-tags { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.chip {
  padding: 0.18rem 0.45rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 0.66rem; color: var(--ink-2);
}
.insp-empty { color: var(--ink-3); font-size: 0.76rem; line-height: 1.6; }
.insp-empty kbd {
  display: inline-block; padding: 0.05rem 0.3rem; margin: 0 0.1rem;
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px;
  background: var(--surface-2); font: inherit; font-size: 0.68rem; color: var(--ink-2);
}
.insp-btn {
  width: 100%; margin-top: 0.2rem; padding: 0.45rem;
  border: 0; border-radius: 7px; background: var(--accent); color: #fff;
  font-size: 0.74rem; font-weight: 600; cursor: pointer;
  transition: filter 0.18s, transform 0.18s var(--ease);
}
.insp-btn:hover { filter: brightness(1.08); }
.insp-btn:active { transform: scale(0.98); }
.insp-btn--ghost { margin-top: 0.4rem; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.insp-btn--ghost:hover { filter: none; background: var(--line); }

/* ── Stage + canvas ─────────────────────────────────────────────────────── */
.stage { grid-area: stage; position: relative; overflow: hidden; }

.viewport {
  position: absolute; inset: 0;
  overflow: hidden;
  background-color: var(--paper);
  /* the faint dot grid the boards sit on */
  background-image: radial-gradient(var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: var(--dot-x, 0) var(--dot-y, 0);
  touch-action: none;
  cursor: default;
}
.viewport.t-hand { cursor: grab; }
.viewport.t-hand.is-panning { cursor: grabbing; }
.viewport.t-note, .viewport.t-text { cursor: crosshair; }
.viewport.t-pen, .viewport.t-marker { cursor: crosshair; }
.viewport.t-zoom { cursor: zoom-in; }
.viewport.t-zoom.is-alt { cursor: zoom-out; }
.marquee {
  position: absolute; pointer-events: none; z-index: 8;
  border: 1px solid var(--accent); background: var(--accent-sub);
  border-radius: 3px;
}
.viewport.is-spacing { cursor: grab; }

.world {
  position: absolute; top: 0; left: 0; width: 0; height: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.world.is-tweening { transition: transform 0.5s var(--ease); }
.items { position: absolute; top: 0; left: 0; }
.ink { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.ink path { fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* Board frame */
.frame {
  position: absolute;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.25s var(--ease), border-color 0.2s;
}
.frame.is-sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.frame-name {
  position: absolute; left: 2px; bottom: 100%; margin-bottom: 5px;
  font-size: 11px; font-weight: 600; color: var(--ink-3);
  white-space: nowrap; pointer-events: auto; cursor: pointer;
  transition: color 0.18s;
}
.frame-name:hover { color: var(--accent); }
.frame.is-sel .frame-name { color: var(--accent); }
.frame-cat {
  position: absolute; left: 2px; bottom: 100%; margin-bottom: 22px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-3); opacity: 0.55;
  white-space: nowrap; pointer-events: none;
}

/* Sticky note holding the project title */
.note {
  position: absolute;
  display: flex; flex-direction: column; justify-content: center;
  padding: 14px 16px;
  background: var(--note); color: var(--note-ink);
  border-radius: 3px;
  box-shadow: var(--shadow);
  cursor: grab;
  transform-origin: 50% 50%;
  transition: box-shadow 0.25s var(--ease), transform 0.25s var(--ease);
}
.note:hover { box-shadow: var(--shadow-lg); }
.note.is-drag { cursor: grabbing; box-shadow: var(--shadow-lg); }
.note.is-sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.note-title { font-size: 17px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.note-sub { margin-top: 6px; font-size: 11px; opacity: 0.7; line-height: 1.35; }
.note[contenteditable="true"] { cursor: text; }

/* Cards */
.card {
  position: absolute;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.22s var(--ease), transform 0.22s var(--ease),
              border-color 0.18s, opacity 0.3s;
}
.card img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity 0.35s var(--ease);
}
.card img.is-in { opacity: 1; }
.app.is-ready .card img { transition: none; }
/* a tiny source (EPG sprites, 81x46) is drawn pixel for pixel instead of stretched */
.card.is-tiny img { object-fit: none; background: #101216; }
.cs-tile.is-tiny img { object-fit: none; background: #101216; }
.card:hover { box-shadow: var(--shadow); transform: translate(var(--tx,0), var(--ty,0)) scale(1.012); z-index: 3; }
.card.is-sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); z-index: 4; }
.card.is-drag { box-shadow: var(--shadow-lg); z-index: 6; cursor: grabbing; transform: translate(var(--tx,0), var(--ty,0)) scale(1.03); }
.card-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: linear-gradient(to top, rgba(0,0,0,0.35), rgba(0,0,0,0.05));
  pointer-events: none;
}
.card-play span {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.92);
  display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  transition: transform 0.25s var(--ease);
}
.card.is-video { cursor: pointer; }
.card:hover .card-play span { transform: scale(1.12); }
.card-play span::after {
  content: ''; width: 0; height: 0; margin-left: 3px;
  border-left: 10px solid #14161a;
  border-top: 6.5px solid transparent;
  border-bottom: 6.5px solid transparent;
}
.card-dev {
  position: absolute; left: 5px; top: 5px;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(20,22,26,0.62); color: #fff;
  font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0; transition: opacity 0.2s;
}
.card:hover .card-dev { opacity: 1; }

/* Group label inside a frame */
.glabel {
  position: absolute;
  font-size: 11px; font-weight: 600; color: var(--ink-3);
  letter-spacing: 0.02em; pointer-events: none; white-space: nowrap;
}

/* User annotations */
.anno {
  position: absolute; cursor: grab;
  transition: box-shadow 0.2s var(--ease);
}
.anno.is-drag { cursor: grabbing; }
.anno-note {
  background: var(--note); color: var(--note-ink);
  padding: 12px 13px; border-radius: 3px; box-shadow: var(--shadow);
  font-size: 14px; line-height: 1.35; min-width: 150px; min-height: 90px;
  outline: none;
}
.anno-text {
  color: var(--ink); font-size: 18px; font-weight: 600; padding: 3px 5px;
  outline: none; min-width: 40px;
}
.anno.is-sel { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Cloud view */
.hub {
  position: absolute; left: 0; top: 0;
  padding: 5px 11px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 11px; font-weight: 600; white-space: nowrap;
  box-shadow: var(--shadow); cursor: pointer;
  transform-origin: 50% 50%;
}
.hub:hover { background: var(--accent); color: #fff; }
.world.v-cloud .hub { background: var(--pc, var(--ink)); color: #fff; }
.world.v-cloud .card { border-color: var(--pc, var(--line)); box-shadow: 0 0 0 1px var(--pc, transparent); }
.world.v-cloud .frame, .world.v-cloud .note, .world.v-cloud .glabel { display: none; }
/* the orb writes every card's transform and opacity each frame; the card's own transitions
   on top of that would keep all 300 cards composited and mid-animation for as long as the
   view is open, so they are switched off here */
.world.v-cloud .card { transition: box-shadow 0.22s var(--ease), border-color 0.18s; }
.orb { position: absolute; transform-style: preserve-3d; pointer-events: none; }
.orb .card { pointer-events: auto; }

/* ── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px;
  padding: 5px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  z-index: 12;
  animation: barIn 0.5s var(--ease-out) 0.25s both;
}
@keyframes barIn { from { opacity: 0; transform: translate(-50%, 14px); } }
.tool {
  display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 8px; background: none;
  color: var(--ink-2); cursor: pointer;
  transition: background 0.16s, color 0.16s, transform 0.16s var(--ease);
}
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool:active { transform: scale(0.9); }
.tool.is-on { background: var(--accent); color: #fff; }
.tool svg { width: 16px; height: 16px; }
.tool-sm { width: 26px; height: 26px; }
.tool-sm svg { width: 13px; height: 13px; }
.tool-danger:hover { background: rgba(229,72,77,0.12); color: var(--danger); }
.tool-sep { width: 1px; height: 20px; margin: 0 3px; background: var(--line); }

/* Stroke sizes: appears above the toolbar while the pen or marker is active */
.sizes {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 4px;
  border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: sizesIn 0.22s var(--ease-out) both;
}
@keyframes sizesIn { from { opacity: 0; transform: translate(-50%, 6px); } }
.size {
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--ink-2);
  transition: background 0.16s, color 0.16s;
}
.size:hover { background: var(--surface-2); color: var(--ink); }
.size.is-on { background: var(--accent-sub); color: var(--accent); }
.size i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: currentColor; }
.size-row { display: flex; gap: 2px; padding-left: 4px; border-left: 1px solid var(--line); }
.size-row[hidden] { display: none !important; }
.swatches { display: flex; gap: 3px; padding: 0 2px; }
.swatch {
  width: 22px; height: 22px; padding: 0; border: 2px solid transparent; border-radius: 50%;
  background: var(--c); cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  transition: transform 0.16s var(--ease), border-color 0.16s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.is-on { border-color: var(--ink); transform: scale(1.12); }
.swatch-ink { background: var(--ink); }
/* the chosen colour shows on the tool that will use it */
.tool.is-on.has-color { background: var(--sel, var(--accent)); }
.anno-note { background: var(--nc, var(--note)); }
.anno-text { color: var(--tc, var(--ink)); }
.zoom { display: flex; align-items: center; gap: 1px; }
.zoom-val {
  min-width: 48px; padding: 0.25rem 0.3rem;
  border: 0; border-radius: 6px; background: none; color: var(--ink-2);
  font-size: 0.7rem; font-weight: 600; font-variant-numeric: tabular-nums;
  cursor: pointer; transition: background 0.16s, color 0.16s;
}
.zoom-val:hover { background: var(--surface-2); color: var(--ink); }

/* Hint toast */
.hint {
  position: absolute; left: 50%; bottom: 68px; transform: translate(-50%, 6px);
  padding: 0.4rem 0.75rem; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 0.71rem; font-weight: 500; white-space: nowrap;
  opacity: 0; pointer-events: none; z-index: 13;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
}
.hint.is-on { opacity: 0.95; transform: translate(-50%, 0); }

/* ── Mobile preview ─────────────────────────────────────────────────────── */
.preview, .film {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; gap: 1rem;
  grid-template-rows: 1fr auto;
  padding: 2.2rem 1rem 1.4rem;
  background: rgba(16,18,22,0.62);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  animation: veilIn 0.28s var(--ease) both;
}
@keyframes veilIn { from { opacity: 0; } }
.preview-close {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.14); color: #fff; font-size: 15px;
  cursor: pointer; transition: background 0.18s, transform 0.18s var(--ease);
}
.preview-close:hover { background: rgba(255,255,255,0.26); }
.preview-close:active { transform: scale(0.92); }

.phone {
  position: relative;
  width: min(330px, 78vw);
  aspect-ratio: 9 / 19.5;
  max-height: 74vh;
  transition: width 0.4s var(--ease);
  border-radius: 42px;
  background: #0b0c0e;
  border: 9px solid #1c1e22;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06) inset;
  overflow: hidden;
  animation: phoneIn 0.42s var(--ease-out) both;
}
@keyframes phoneIn { from { opacity: 0; transform: translateY(18px) scale(0.96); } }
.phone-notch {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 40%; height: 22px; border-radius: 0 0 14px 14px;
  background: #1c1e22; z-index: 2;
}
/* A landscape screen or a film turns the phone on its side */
.phone.is-landscape {
  width: min(680px, 92vw);
  aspect-ratio: 19.5 / 9;
  max-height: 60vh;
}
.phone.is-landscape .phone-notch {
  top: 50%; left: 0; transform: translateY(-50%);
  width: 22px; height: 40%; border-radius: 0 14px 14px 0;
}
/* A page taller than the screen scrolls inside it, the way it would on the phone */
.phone-screen.is-long { display: block; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
.phone-screen.is-long img { width: 100%; max-height: none; height: auto; object-fit: unset; transform: none !important; }
.phone-screen.is-long::-webkit-scrollbar { width: 7px; }
.phone-screen.is-long::-webkit-scrollbar-track { background: rgba(255,255,255,0.1); }
.phone-screen.is-long::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.6); border-radius: 7px; }
.phone-scroll-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  padding: 3px 9px; border-radius: 999px; background: rgba(0,0,0,0.55); color: #fff;
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; pointer-events: none;
  animation: hintFade 2.6s ease-out forwards;
}
@keyframes hintFade { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }
.phone-screen {
  position: absolute; inset: 0; overflow: hidden;
  /* flex, not grid: a percentage max-height on the image has to resolve
     against the screen, and a centred grid item's does not */
  display: flex; align-items: center; justify-content: center;
  background: #0b0c0e;
  touch-action: none;
}
.phone-screen img {
  display: block; max-width: 100%; max-height: 100%;
  object-fit: contain; transform-origin: 50% 50%;
  transition: transform 0.28s var(--ease);
  user-select: none; -webkit-user-drag: none;
}
.phone-screen iframe { width: 100%; height: 100%; border: 0; }
.preview-bar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.35rem 0.4rem; border-radius: 999px;
  background: rgba(255,255,255,0.12);
}
.preview-bar .ghost-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  border-color: transparent; background: rgba(255,255,255,0.14); color: #fff;
  font-size: 17px; line-height: 1;
}
.preview-bar .ghost-btn:hover { background: rgba(255,255,255,0.26); color: #fff; }
.preview-meta {
  min-width: 150px; text-align: center;
  font-size: 0.72rem; color: rgba(255,255,255,0.86);
  font-variant-numeric: tabular-nums;
}

/* Constellation (cloud view): a project's images in a grid, joined by their connections */
.constel {
  position: fixed; inset: 0; z-index: 61;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: 1.2rem 1.4rem 0.9rem;
  background: rgba(12,13,16,0.9);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  animation: veilIn 0.24s var(--ease) both;
  color: #fff;
}
.cs-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.2rem 3rem 0.9rem 0.2rem; font-size: 0.86rem; }
.cs-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--pc, #fff); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc, #fff) 28%, transparent); }
.cs-head b { font-weight: 600; }
.cs-meta { color: rgba(255,255,255,0.58); font-variant-numeric: tabular-nums; }
.cs-body { position: relative; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0.4rem; }
.cs-body::-webkit-scrollbar { width: 6px; }
.cs-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.28); border-radius: 6px; }
.cs-lines { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.cs-lines line { stroke: var(--pc, #fff); stroke-width: 1.4; opacity: 0.55; stroke-linecap: round; }
.cs-lines circle { fill: var(--pc, #fff); opacity: 0.9; }
.cs-grid { position: relative; }
.cs-tile {
  position: absolute; border-radius: 8px; overflow: hidden; cursor: pointer;
  background: #1a1c21; border: 1.5px solid color-mix(in srgb, var(--pc, #fff) 55%, transparent);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.18s;
  animation: phoneIn 0.32s var(--ease-out) both;
}
.cs-tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cs-tile:hover { transform: translateY(-3px); border-color: var(--pc, #fff); box-shadow: 0 16px 40px rgba(0,0,0,0.55); }
.cs-tile.is-focus { border-color: var(--pc, #fff); box-shadow: 0 0 0 3px var(--pc, #fff), 0 16px 40px rgba(0,0,0,0.55); }
.cs-tile .card-play { pointer-events: none; }
.cs-tile .cs-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 0.35rem 0.5rem;
  font-size: 0.64rem; color: #fff; background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity 0.18s;
}
.cs-tile:hover .cs-name, .cs-tile.is-focus .cs-name { opacity: 1; }
.cs-hint { text-align: center; font-size: 0.68rem; color: rgba(255,255,255,0.5); padding-top: 0.7rem; }
@media (max-width: 640px) {
  .constel { padding: 0.9rem 0.7rem 0.7rem; }
  .cs-hint { display: none; }
}

/* Viewer */
.viewer {
  position: fixed; inset: 0; z-index: 62;
  display: grid; grid-template-rows: 1fr auto; place-items: center;
  padding: 2.4rem 4.5rem 1.2rem;
  background: rgba(12,13,16,0.9);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  animation: veilIn 0.24s var(--ease) both;
}
.vw-stage {
  position: relative; width: 100%; height: 100%; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
.vw-stage img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 6px; box-shadow: 0 24px 70px rgba(0,0,0,0.6);
  user-select: none; -webkit-user-drag: none;
  animation: phoneIn 0.32s var(--ease-out) both;
}
/* a scrolling page keeps its width and scrolls inside the stage */
.vw-stage.is-long { align-items: flex-start; overflow: hidden; }
/* the scrolling column: exactly as wide as the page, so its bar sits right beside the image */
.vw-scroll {
  height: 100%; width: min(100%, 720px); margin: 0 auto;
  overflow-y: scroll; overscroll-behavior: contain; touch-action: pan-y;
  scrollbar-gutter: stable;
  border-radius: 6px;
}
/* ::-webkit-scrollbar styling only applies while the standard properties are unset (Chrome) */
@supports not selector(::-webkit-scrollbar) {
  .vw-scroll { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.55) rgba(255,255,255,0.08); }
  .phone-screen.is-long { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.6) rgba(255,255,255,0.1); }
  .insp-thumb-wrap.is-long { scrollbar-width: thin; scrollbar-color: var(--ink-3, var(--ink-2)) var(--surface-2); }
}
.vw-scroll img { display: block; max-height: none; width: 100%; height: auto; border-radius: 6px 0 0 6px; }
.vw-scroll::-webkit-scrollbar { width: 10px; }
.vw-scroll::-webkit-scrollbar-track { background: rgba(255,255,255,0.08); border-radius: 10px; }
.vw-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.55); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
.vw-scroll::-webkit-scrollbar-thumb:hover { background-color: rgba(255,255,255,0.8); }
.vw-more {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  padding: 0.35rem 0.8rem 0.35rem 0.7rem; border-radius: 999px;
  background: rgba(20,22,26,0.82); color: #fff; font-size: 0.7rem; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4); pointer-events: none;
  animation: bob 1.6s ease-in-out infinite; transition: opacity 0.3s;
}
.vw-more::before { content: '↓ '; }
.vw-more.is-gone { opacity: 0; animation: none; }
@keyframes bob { 50% { transform: translate(-50%, -5px); } }
.vw-stage iframe {
  width: min(1100px, 100%); aspect-ratio: 16 / 9; max-height: 100%;
  border: 0; border-radius: 10px; background: #000;
}
.vw-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.12); color: #fff; font-size: 26px; line-height: 1;
  cursor: pointer; z-index: 2;
  transition: background 0.18s, transform 0.18s var(--ease);
}
.vw-arrow:hover { background: rgba(255,255,255,0.26); }
.vw-arrow:active { transform: translateY(-50%) scale(0.92); }
.vw-prev { left: 14px; } .vw-next { right: 14px; }
.vw-cap {
  padding: 0.35rem 0.9rem; border-radius: 999px;
  background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.86);
  font-size: 0.72rem; font-variant-numeric: tabular-nums; white-space: nowrap;
  max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.vw-cap b { color: #fff; font-weight: 600; }
@media (max-width: 640px) {
  .viewer { padding: 3rem 0.5rem 0.9rem; }
  .vw-arrow { width: 40px; height: 40px; bottom: 60px; top: auto; transform: none; }
  .vw-arrow:active { transform: scale(0.92); }
  .vw-prev { left: 10px; } .vw-next { right: 10px; }
}

/* Film */
.film { grid-template-rows: 1fr; }
.film-frame {
  width: min(1100px, 92vw); aspect-ratio: 16 / 9;
  border-radius: 12px; overflow: hidden; background: #000;
  box-shadow: var(--shadow-lg);
  animation: phoneIn 0.4s var(--ease-out) both;
}
.film-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  :root { --panel-w: 210px; --insp-w: 234px; }
}

/* Tablet: panels become overlays so the board keeps the full width */
@media (max-width: 900px) {
  .app,
  .app.no-layers, .app.no-inspector, .app.no-layers.no-inspector {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "stage";
  }
  .layers, .inspector {
    position: fixed; top: var(--topbar-h); bottom: 0; z-index: 30;
    width: min(300px, 84vw);
    box-shadow: var(--shadow-lg);
  }
  .layers { left: 0; }
  .inspector { right: 0; }
  .app.no-layers .layers { transform: translateX(-102%); opacity: 1; }
  .app.no-inspector .inspector { transform: translateX(102%); opacity: 1; }
  .doc-sub { display: none; }
}

@media (max-width: 640px) {
  .tb-row { padding: 0.45rem 0.5rem 0.35rem; }
  .view-tab { padding: 0.55rem 1rem; font-size: 0.64rem; }
  .view-tab { padding: 0.3rem 0.5rem; font-size: 0.68rem; }
  .toolbar { bottom: max(12px, env(safe-area-inset-bottom)); padding: 4px; gap: 0; }
  .tool { width: 34px; height: 34px; }
  .tool-sep { margin: 0 1px; }
  /* the zoom stepper is redundant next to pinch-zoom */
  .zoom-val { min-width: 42px; }
  .hint { bottom: 74px; font-size: 0.68rem; }
}

/* Touch: every control keeps its drawn size and gains a 44px hit area */
/* ── Phone: a touch-first layout ─────────────────────────────────────────── */
@media (pointer: coarse) and (max-width: 760px), (max-width: 640px) {
  /* toolbar: only what a finger needs, 44px each, always fits */
  .toolbar { left: 50%; transform: translateX(-50%); max-width: calc(100vw - 16px); padding: 6px; gap: 2px; bottom: max(10px, env(safe-area-inset-bottom)); }
  .tool, .zoom-val { width: 42px; height: 42px; }
  .zoom { gap: 0; }
  .zoom .tool-sm { display: grid; width: 42px; height: 42px; }
  .zoom .tool-sm svg { width: 16px; height: 16px; }
  .tool[data-tool="move"], .tool[data-tool="hand"], .tool[data-tool="zoom"], .tool[data-tool="text"],
  #btn-mobile, .tool-sep { display: none; }
  .zoom-val { width: auto; min-width: 46px; font-size: 0.78rem; }
  .sizes { bottom: 64px; }
  /* viewer: image fills the screen, arrows sit where the thumbs are */
  .viewer { padding: max(0.6rem, env(safe-area-inset-top)) 0.5rem 4.6rem; grid-template-rows: 1fr auto; }
  .vw-stage img { border-radius: 4px; box-shadow: none; }
  .vw-scroll { width: 100% !important; }
  .vw-more { bottom: 74px; }
  .vw-stage iframe { width: 100%; }
  .vw-arrow { width: 48px; height: 48px; top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; font-size: 30px; }
  .vw-arrow:active { transform: scale(0.92); }
  .vw-prev { left: 16px; } .vw-next { right: 16px; }
  .vw-cap { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(26px, calc(env(safe-area-inset-bottom) + 12px)); max-width: calc(100vw - 150px); font-size: 0.68rem; }
  .preview-close { top: max(10px, env(safe-area-inset-top)); right: 10px; width: 44px; height: 44px; }
  .constel { padding-bottom: 0.5rem; }
  .cs-head { padding-right: 3.4rem; }
  /* hover-only affordances are noise on touch */
  .card:hover { transform: translate(var(--tx,0), var(--ty,0)); box-shadow: none; }
  .hint { bottom: 72px; max-width: calc(100vw - 24px); text-align: center; }
}

@media (pointer: coarse), (max-width: 1024px) {
  /* .preview-close stays absolute: an absolute box is a containing block too */
  .tb-btn, .view-tab, .tool, .tr, .ghost-btn { position: relative; }
  .tb-btn::after, .view-tab::after, .tool::after, .preview-close::after {
    content: ''; position: absolute; left: 50%; top: 50%;
    width: max(100%, 44px); height: max(100%, 44px);
    transform: translate(-50%, -50%);
  }
  .tr { padding-top: 0.5rem; padding-bottom: 0.5rem; }
  .rail { width: 34px; }
  .card:hover { transform: none; }          /* no hover lift under a thumb */
  /* iOS WebKit rasterises a composited layer at its LAYOUT size, not its on-screen size: the
     board scaled to 11% still cost ~600 MB of GPU tiles on a phone (measured), and the tab
     was killed for it. Without will-change or a transform transition the world is never
     promoted to a layer; it is painted straight into the viewport at screen resolution. */
  .world { will-change: auto; }
  .world.is-tweening { transition: none; }
  /* no transform/opacity transitions on touch: an animating card is a composited layer at
     the zoomed-in scale, and hundreds of those is what crashed the tab on a phone */
  .card { transition: box-shadow 0.22s var(--ease), border-color 0.18s; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .world.is-tweening { transition: none; }
}
