/* ─────────────────────────────────────────────
   Untitled Grid — interface
   A design tool's chrome, drawn like a technical instrument.
   ───────────────────────────────────────────── */

:root {
  --bar: #FFFFFF;
  --hover: #F2F2F5;
  --panel: #FFFFFF;
  --line: #E4E4E9;
  --field: #F1F1F4;
  --track: #E8E8ED;
  --text: #0A0A0A;
  --soft: #4A4A52;
  --muted: #8C8C96;
  --ink: #0A0A0A;
  --sys: #4B57F5;
  --sys-soft: #ECEEFF;
  --signal: #D4157D;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --left: 240px;
  --right: 264px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 400 11px/1.4 var(--ui);
  color: var(--text);
  background: var(--panel);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .35; }
svg { display: block; }
.mono { font-family: var(--mono); font-size: 10.5px; }
.muted { color: var(--muted); font-weight: 400; }
kbd {
  font: 400 9.5px var(--mono);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel);
}
:focus-visible { outline: 1.5px solid var(--sys); outline-offset: -1.5px; }

/* ───── Layout ───── */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  grid-template-rows: 48px minmax(0, 1fr) 44px;
  grid-template-areas:
    "top top top"
    "left stage right"
    "left time right";
}

/* ───── Top bar ───── */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  user-select: none;
}
.tb-left, .tb-right { display: flex; align-items: center; height: 100%; }
.tb-left { padding-left: 4px; gap: 4px; }
.tb-right { gap: 6px; padding-right: 10px; }
.logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--ink);
}
.logo:hover { background: var(--hover); }
.tools { display: flex; align-items: center; gap: 2px; height: 100%; }
.tool {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--ink);
}
.tool svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; stroke-linecap: round; }
.tool:hover { background: var(--hover); }
.tool.active { background: var(--ink); color: #fff; }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }

.tb-center {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; white-space: nowrap; overflow: hidden;
}
.crumb, .slash { color: var(--muted); }
.filename { font-weight: 500; }
.badge {
  font: 400 10px var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 6px;
  margin-left: 6px;
  letter-spacing: .04em;
}

.btn-dark {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-dark:hover { background: var(--hover); }
.btn-dark.active { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-primary {
  height: 30px; padding: 0 14px;
  border-radius: 6px;
  background: var(--ink); color: #fff;
  font-weight: 500;
}
.btn-primary:hover { background: #2A2A30; }
.zoom { display: flex; align-items: center; font-family: var(--mono); font-size: 10.5px; }
.zoom button { height: 30px; min-width: 22px; padding: 0 6px; border-radius: 6px; }
.zoom button:hover { background: var(--hover); }
#zoomVal { min-width: 48px; font-variant-numeric: tabular-nums; }

/* Visitors */
.presence { display: flex; align-items: center; margin-right: 4px; }
.presence:empty { display: none; }
.av {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  margin-left: -6px;
  border-radius: 50%;
  border: 1.5px solid var(--bar);
  background: var(--ink); color: #fff;
  font: 500 9px var(--mono);
}
.av:first-child { margin-left: 0; }
.av.ghost { background: var(--bar); color: #6069E8; outline: 1px dashed #7A83F2; outline-offset: -3px; }
.av-count { margin-left: 6px; font: 400 10px var(--mono); color: var(--muted); }

/* ───── Panels ───── */
.panel {
  background: var(--panel);
  display: flex; flex-direction: column;
  min-height: 0;
  user-select: none;
}
.panel.left { grid-area: left; border-right: 1px solid var(--line); }
.panel.right { grid-area: right; border-left: 1px solid var(--line); }
.scroll { overflow-y: auto; min-height: 0; flex: 1; }
.tabs {
  display: flex; gap: 2px;
  height: 40px; flex: none;
  padding: 0 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.tab { padding: 5px 8px; border-radius: 5px; font-weight: 500; color: var(--muted); }
.tab.active { color: var(--text); background: var(--field); }
.section { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.section.grow { flex: 1; min-height: 0; overflow-y: auto; padding-left: 0; padding-right: 0; border-bottom: 0; }
.section.grow .sec-title { padding: 0 16px; }
.sec-title {
  display: flex; align-items: center; gap: 6px;
  justify-content: space-between;
  margin-bottom: 12px;
  font: 400 9.5px/1 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.sec-title kbd { text-transform: none; }
.page-item { padding: 6px 8px; margin: 0 -8px; border-radius: 5px; }
.page-item span { display: inline-block; width: 14px; color: var(--muted); }
.page-item.active { background: var(--field); font-weight: 500; }

/* Layers */
.layers { list-style: none; margin: 0; padding: 0; }
.layers li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center; gap: 8px;
  height: 26px; padding: 0 16px;
  cursor: default;
  white-space: nowrap;
}
.layers li:hover { box-shadow: inset 0 0 0 1px var(--sys); }
.layers li.current { background: var(--sys-soft); }
.layers li.future { opacity: .35; }
.layers li.new { animation: flash 600ms steps(4) both; }
.layers .ico svg { width: 12px; height: 12px; fill: none; stroke: var(--soft); stroke-width: 1.3; stroke-linejoin: round; stroke-linecap: round; }
.layers .ico svg [fill="currentColor"] { fill: var(--soft); }
.layers .nm { overflow: hidden; text-overflow: ellipsis; }
.layers .meta { font: 400 9.5px var(--mono); color: var(--muted); }
@keyframes flash { from { background: var(--signal); color: #fff; } to { background: transparent; } }
.empty { color: var(--muted); padding: 2px 16px; margin: 0; line-height: 1.6; }

/* Fields */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.field {
  display: flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 8px;
  background: var(--field);
  border-radius: 6px;
  border: 1px solid transparent;
  font: 400 10.5px var(--mono);
  font-variant-numeric: tabular-nums;
}
.field:hover { border-color: var(--line); }
.field i { font-style: normal; color: var(--muted); width: 10px; }
.props { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-name { font: 500 22px/1 var(--ui); letter-spacing: -.025em; margin-bottom: 8px; }
.rule-desc { margin: 0; color: var(--soft); line-height: 1.55; min-height: 3.1em; }
.note { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.sub { color: var(--muted); margin: 12px 0 6px; }
.row { display: flex; gap: 8px; align-items: center; }

/* Sliders — pill track, white knob */
.slider { display: grid; grid-template-columns: 72px 1fr 30px; align-items: center; gap: 10px; height: 28px; }
.slider span { color: var(--soft); }
.slider output { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 14px; margin: 0;
  background: transparent;
}
input[type=range]::-webkit-slider-runnable-track { height: 14px; background: var(--track); border-radius: 7px; }
input[type=range]::-moz-range-track { height: 14px; background: var(--track); border-radius: 7px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%; background: #fff; border: 0;
  box-shadow: 0 0 0 .5px rgba(0,0,0,.12), 0 1px 3px rgba(0,0,0,.22);
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0;
  box-shadow: 0 0 0 .5px rgba(0,0,0,.12), 0 1px 3px rgba(0,0,0,.22);
}
input[type=range]:active::-webkit-slider-thumb { box-shadow: 0 0 0 1.5px var(--signal), 0 1px 3px rgba(0,0,0,.22); }

.segmented { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--track); border-radius: 7px; padding: 2px; }
.segmented button { height: 22px; border-radius: 5px; color: var(--soft); font-size: 10.5px; }
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.14); font-weight: 500; }

.text-input {
  width: 100%; height: 28px; padding: 0 8px;
  background: var(--field);
  border: 1px solid transparent; border-radius: 6px;
  outline: none;
}
.text-input:hover { border-color: var(--line); }
.text-input:focus { border-color: var(--sys); background: #fff; }
select.text-input { margin-bottom: 6px; }

/* Checkbox as a pill switch */
.check { display: flex; align-items: center; gap: 10px; height: 28px; color: var(--soft); }
.check kbd { margin-left: auto; }
.check input {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 14px; margin: 0;
  border-radius: 7px; background: var(--track);
  position: relative; cursor: pointer; flex: none;
  transition: background .15s steps(2);
}
.check input::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .15s steps(2);
}
.check input:checked { background: var(--ink); }
.check input:checked::before { transform: translateX(12px); }

.icon-btn { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; flex: none; }
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; stroke-linecap: round; }
.icon-btn:hover { background: var(--hover); }
.icon-btn.boxed { border: 1px solid var(--line); }
.icon-btn.active { background: var(--signal); color: #fff; }
.btn-light { flex: 1; height: 28px; border: 1px solid var(--line); border-radius: 6px; font-weight: 500; }
.btn-light:hover { background: var(--hover); }

/* ───── Stage ───── */
.stage { grid-area: stage; position: relative; overflow: hidden; background: #E6E6EA; min-width: 0; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#canvas.panning { cursor: grabbing !important; }

.hint, .toast {
  position: absolute; left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
}
.hint {
  bottom: 16px; padding: 10px 16px;
  display: flex; flex-direction: column; gap: 3px;
  width: max-content; max-width: calc(100% - 32px);
  background: #fff; color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(20,20,40,.10);
  transition: opacity .3s steps(3), transform .3s steps(3);
}
.hint strong { font-weight: 500; font-size: 12px; }
.hint span { font: 400 10px var(--mono); color: var(--muted); }
.hint.gone { opacity: 0; transform: translate(-50%, 8px); }
.toast {
  top: 16px; padding: 7px 12px;
  background: var(--ink); color: #fff;
  border-radius: 6px;
  font: 400 10.5px var(--mono);
  opacity: 0; transition: opacity .2s steps(2);
}
.toast.show { opacity: 1; }

.mobile-toggles { display: none; }

/* ───── Timeline ───── */
.timeline {
  grid-area: time;
  display: flex; align-items: center; gap: 4px;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  user-select: none;
  min-width: 0;
}
.tl-label { font: 400 9.5px var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin: 0 10px 0 6px; }
#rngTime { flex: 1; min-width: 40px; }
#rngTime::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; }
#rngTime::-moz-range-track { height: 6px; }
#rngTime::-webkit-slider-thumb { margin-top: -4px; }
.tl-count { color: var(--muted); min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }

/* ───── About ───── */
dialog#about {
  padding: 0; border: 1px solid var(--line);
  border-radius: 14px;
  width: min(580px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 30px 90px rgba(10,10,30,.28);
  color: var(--text);
  overflow: auto;
}
dialog#about::backdrop { background: rgba(230,230,234,.72); backdrop-filter: blur(2px); }
.about-art { border-bottom: 1px solid var(--line); }
.about-art canvas { display: block; width: 100%; height: auto; }
.about-body { padding: 24px 28px; font-size: 13px; line-height: 1.6; }
.about-body h1 { font: 500 38px/1 var(--ui); letter-spacing: -.04em; margin: 0 0 6px; }
.about-body .lede { font: 400 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; margin: 0 0 18px; color: var(--signal); }
.about-body p { margin: 0 0 12px; color: var(--soft); }
.shortcuts {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 7px 12px; margin: 20px 0 22px;
  padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--soft);
}
.shortcuts kbd { margin-right: 5px; }
.about-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.about-body .credit { margin: 0; font: 400 10px/1.7 var(--mono); color: var(--muted); }
.about-body .credit strong { font-weight: 500; color: var(--text); }
.about-body .credit a { color: var(--text); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.about-body .credit a:hover { text-decoration-color: var(--signal); }

/* ───── Poster ───── */
dialog#posterDlg {
  padding: 0; border: 1px solid var(--line);
  border-radius: 14px;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 30px 90px rgba(10,10,30,.28);
  color: var(--text);
  overflow: auto;
}
dialog#posterDlg::backdrop { background: rgba(230,230,234,.72); backdrop-filter: blur(2px); }
.poster-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; }
.poster-head h2 { font: 500 18px/1.2 var(--ui); letter-spacing: -.01em; margin: 0 0 4px; }
.poster-head p { margin: 0; font-size: 10px; }
.poster-stage { display: grid; place-items: center; padding: 24px 20px; background: #E6E6EA; border-block: 1px solid var(--line); }
#posterCanvas { display: block; width: 100%; max-width: 420px; height: auto; box-shadow: 0 10px 32px rgba(10,10,30,.18); }
.poster-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 20px 18px; }
.poster-foot .note { margin: 0; max-width: 34ch; }
.poster-foot .btn-light { flex: none; padding: 0 14px; height: 30px; }

/* ───── Responsive ───── */
@media (max-width: 1080px) {
  :root { --left: 200px; --right: 240px; }
  .tb-center .crumb, .tb-center .slash { display: none; }
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px minmax(0, 1fr) 44px 52px;
    grid-template-areas: "top" "stage" "time" "tools";
  }
  .tb-center { display: none; }
  .btn-dark span { display: none; }
  #zoomOut, #zoomIn { display: none; }
  .tools {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: calc(52px + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: var(--bar);
    border-top: 1px solid var(--line);
    justify-content: safe center;
    gap: 0;
    overflow-x: auto;
    z-index: 5;
  }
  .tool { width: 34px; height: 34px; flex: none; }
  .tools .tb-sep { margin: 0 3px; }
  .panel {
    position: fixed;
    left: 8px; right: 8px;
    bottom: calc(104px + env(safe-area-inset-bottom));
    max-height: 62dvh;
    border: 1px solid var(--line) !important;
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(10,10,30,.18);
    z-index: 10;
    transform: translateY(calc(100% + 120px));
    transition: transform .28s steps(5);
    overflow: hidden;
  }
  body.sheet-left .panel.left,
  body.sheet-right .panel.right { transform: none; }
  .mobile-toggles {
    display: flex; gap: 6px;
    position: absolute; top: 12px; left: 12px; z-index: 2;
  }
  .mobile-toggles button {
    height: 28px; padding: 0 12px;
    background: #fff; border-radius: 14px;
    border: 1px solid var(--line);
    font-weight: 500;
  }
  .mobile-toggles button.active { background: var(--ink); border-color: var(--ink); color: #fff; }
  .tl-label { display: none; }
  .hint { bottom: 12px; }
  .shortcuts { grid-template-columns: repeat(2, 1fr); }
}

/* ───── Erosion — the grid writes the interface ───── */
.topbar, .panel, .timeline { transition: background-color .6s steps(6); }
#leak {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 6;
  mix-blend-mode: multiply;
}
.ug-e { transition: background-color .3s steps(3), color .3s steps(3), transform .3s steps(3), border-radius .3s steps(3), outline-color .3s steps(3); }
span.ug-mir, span.ug-rot { display: inline-block; }
.ug-mir { transform: scaleX(-1); }
.ug-rot { transform: rotate(180deg); }
.ug-inv { background-color: var(--ink) !important; color: #fff !important; border-color: var(--ink) !important; }
.ug-inv * { color: inherit !important; }
.ug-bond { background-color: var(--ink) !important; color: transparent !important; border-color: transparent !important; border-radius: 999px !important; box-shadow: none !important; }
.ug-bond > * { visibility: hidden; }
.ug-split { position: relative; }
.ug-split::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; right: 0;
  background: repeating-linear-gradient(135deg, var(--ink) 0 1px, transparent 1px 5px);
  border-left: 1px solid var(--signal);
  pointer-events: none;
}
.ug-void { color: transparent !important; background-color: transparent !important; box-shadow: none !important; outline: 1px dashed rgba(88, 100, 240, .75); outline-offset: -1px; }
.ug-void > * { visibility: hidden; }
.ug-type { font-family: var(--mono) !important; letter-spacing: .12em; text-transform: uppercase; }

body.ug-collapse .stage { position: fixed; inset: 0; z-index: 0; }
body.ug-collapse .topbar,
body.ug-collapse .timeline { position: relative; z-index: 1; background: rgba(255, 255, 255, .42); border-color: rgba(88, 100, 240, .55); border-style: dashed; }
body.ug-collapse .panel { background: rgba(255, 255, 255, .42); border-color: rgba(88, 100, 240, .55); border-style: dashed; }
@media (min-width: 821px) {
  body.ug-collapse .panel { position: relative; z-index: 1; }
}

/* ───── Demo (#demo) ───── */
#demoPointer {
  position: fixed; inset: 0 auto auto 0;
  width: 26px; height: 26px;
  margin: 0; padding: 0; border: 0;
  background: transparent; overflow: visible;
  pointer-events: none;
  z-index: 2147483647;
  will-change: transform;
}
#demoPointer svg { display: block; transform-origin: 5px 3px; transition: transform .12s steps(2); }
#demoPointer.press svg { animation: demoPress .22s steps(3); }
#demoPointer.hold svg { transform: scale(.88); }
@keyframes demoPress { 50% { transform: scale(.82); } }
.demo-ring {
  position: absolute; left: 5px; top: 3px;
  width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border: 1.5px solid var(--signal); border-radius: 50%;
  animation: demoRing .55s steps(6) forwards;
}
@keyframes demoRing { from { transform: scale(.2); opacity: 1; } to { transform: scale(1); opacity: 0; } }
#demoStart {
  position: fixed; inset: 0; z-index: 2147483646;
  display: grid; place-items: center;
  background: rgba(230, 230, 234, .35);
  border: 0; cursor: pointer;
}
#demoStart span { padding: 10px 16px; border-radius: 8px; background: var(--ink); color: #fff; font: 400 12px var(--mono); letter-spacing: .04em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
