:root {
  color-scheme: dark;
  --bg: #080b12;
  --surface: #111722;
  --surface-raised: #182131;
  --surface-soft: #202b3e;
  --line: #2c384d;
  --line-strong: #43536d;
  --text: #f3f6fb;
  --muted: #aab6c8;
  --faint: #75839a;
  --accent: #8da2ff;
  --accent-strong: #b9c5ff;
  --accent-ink: #09101f;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #fb7185;
  --control-height: 44px;
  --header-height: 56px;
  --tool-rail-width: 54px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 320px;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 20% -20%, rgb(80 96 175 / 22%), transparent 36rem),
    radial-gradient(circle at 100% 40%, rgb(86 50 145 / 12%), transparent 32rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button,
.button-label {
  min-height: var(--control-height);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--text);
  background: linear-gradient(180deg, #253149, #182235);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

button {
  padding: 0.55rem 0.72rem;
}

:where(button):hover:not(:disabled):not(:where(.brush-swatch, .selection-swatch, .recent-color)),
.button-label:hover {
  border-color: var(--accent);
  background: linear-gradient(180deg, #303f5d, #202c43);
}

.brush-swatch:hover:not(:disabled),
.selection-swatch:hover:not(:disabled),
.recent-color:hover:not(:disabled) {
  border-color: var(--accent);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.58;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.button-label:focus-within {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.icon-button {
  position: relative;
  display: inline-grid;
  width: var(--control-height);
  min-width: var(--control-height);
  height: var(--control-height);
  place-items: center;
  padding: 0;
}

.context-action-label {
  display: none;
}

#tool-context-action.context-action-labeled {
  display: inline-flex;
  gap: 0.12rem;
  align-items: center;
  justify-content: center;
  padding-inline: 0.12rem;
  font-size: 0.62rem;
  font-weight: 800;
}

#tool-context-action.context-action-labeled .icon {
  width: 0.72rem;
  height: 0.72rem;
}

#tool-context-action.context-action-labeled .context-action-label {
  display: inline;
}

.primary-button {
  border-color: transparent;
  color: var(--accent-ink);
  background: linear-gradient(135deg, #b8c4ff, #849cff);
  font-weight: 850;
}

.primary-button:hover:not(:disabled) {
  border-color: #dce3ff;
  background: linear-gradient(135deg, #d0d8ff, #9badff);
}

.quiet-button {
  color: var(--muted);
  background: transparent;
}

.danger-button {
  border-color: rgb(251 113 133 / 58%);
  color: #ffd7df;
  background: rgb(127 29 52 / 35%);
}

.danger-button:hover:not(:disabled) {
  border-color: var(--danger);
  color: #fff1f2;
  background: rgb(159 18 57 / 55%);
}

.app-header {
  position: relative;
  z-index: 80;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.8rem;
  height: var(--header-height);
  min-height: var(--header-height);
  padding: 0 0.65rem;
  border-bottom: 1px solid rgb(102 125 169 / 30%);
  background: rgb(9 13 21 / 94%);
  box-shadow: 0 8px 35px rgb(0 0 0 / 22%);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.55rem;
}

.brand-mark {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgb(178 190 255 / 65%);
  border-radius: 9px;
  color: #0b1221;
  background: linear-gradient(135deg, #e2e7ff, #8299ff 62%, #a36cff);
  box-shadow: 0 8px 24px rgb(78 98 219 / 25%);
  font-weight: 950;
}

.brand-copy {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.03rem;
  line-height: 1;
  letter-spacing: -0.025em;
}

.brand-copy > span {
  display: block;
  margin-top: 0.16rem;
  color: var(--faint);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-state {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7rem;
}

.document-counts {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.document-counts strong {
  color: var(--text);
}

.status-stack {
  min-width: 8rem;
  max-width: 26rem;
  text-align: right;
}

.editor-state-chip {
  padding: 0.2rem 0.42rem;
  border: 1px solid rgb(141 162 255 / 28%);
  border-radius: 9px;
  background: rgb(35 46 69 / 72%);
}

.operation-status,
.persistence-status {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-status[data-tone="error"],
.operation-status[data-tone="unexpected"] {
  color: #fecdd3;
}

.operation-status[data-tone="unexpected"] {
  text-decoration: underline wavy var(--danger);
}

.compact-operation-status {
  display: none;
}

.selection-operation-status {
  display: none;
}

.persistence-status {
  margin-top: 0.08rem;
  color: var(--faint);
  font-size: 0.62rem;
}

.persistence-status[data-kind="saved"] {
  color: #86efac;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.repl-launch {
  position: relative;
  display: inline-flex;
  min-height: var(--control-height);
  align-items: center;
  gap: 0.42rem;
  padding: 0 0.72rem;
  border-color: #7187df;
  color: #f8faff;
  background: linear-gradient(180deg, #455a9b, #314477);
  font-weight: 850;
}

.repl-launch[aria-expanded="true"] {
  border-color: #b8c5ff;
  background: linear-gradient(180deg, #5a70b6, #40548f);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 10%);
}

[data-tooltip]::after {
  position: absolute;
  z-index: 200;
  top: calc(100% + 0.5rem);
  left: 50%;
  width: max-content;
  max-width: 14rem;
  padding: 0.36rem 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: #070b12;
  box-shadow: 0 10px 30px rgb(0 0 0 / 45%);
  content: attr(data-tooltip);
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -0.2rem);
  transition: opacity 100ms ease, transform 100ms ease;
  white-space: normal;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.header-actions [data-tooltip]::after {
  right: 0;
  left: auto;
  transform: translate(0, -0.2rem);
}

.header-actions [data-tooltip]:hover::after,
.header-actions [data-tooltip]:focus-visible::after {
  transform: translate(0, 0);
}

.app-popover {
  position: fixed;
  z-index: 150;
  top: calc(var(--header-height) + 0.5rem);
  right: 0.65rem;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(22rem, calc(100vw - 1.3rem));
  max-height: calc(100dvh - var(--header-height) - 1rem);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: #121a28;
  box-shadow: 0 24px 80px rgb(0 0 0 / 58%);
}

.popover-heading,
.repl-dock-heading,
.command-help-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.58rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 0.08rem;
  color: var(--faint);
  font-size: 0.61rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

h3 {
  margin-bottom: 0;
  font-size: 0.84rem;
}

.popover-scroll {
  display: grid;
  gap: 0.45rem;
  min-height: 0;
  overflow: auto;
  padding: 0.65rem;
  overscroll-behavior: contain;
}

.popover-scroll > button,
.popover-scroll > .button-label {
  width: 100%;
}

.popover-scroll > p,
.help-copy p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.5;
}

.help-copy {
  gap: 0.85rem;
}

.help-copy section {
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.help-copy section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

kbd {
  display: inline-grid;
  min-width: 1.35rem;
  min-height: 1.35rem;
  place-items: center;
  padding: 0 0.28rem;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 4px;
  color: var(--muted);
  background: rgb(0 0 0 / 20%);
  font: 700 0.67rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.button-label {
  display: grid;
  place-items: center;
  padding: 0.55rem 0.72rem;
  text-align: center;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.persistence-warning {
  position: fixed;
  z-index: 240;
  right: 0.7rem;
  bottom: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: min(40rem, calc(100vw - 1.4rem));
  padding: 0.55rem 0.65rem;
  border: 1px solid rgb(251 191 36 / 65%);
  border-radius: 11px;
  color: #fef3c7;
  background: #3d2b0d;
  box-shadow: 0 18px 60px rgb(0 0 0 / 48%);
  font-size: 0.74rem;
}

.persistence-warning span {
  flex: 1 1 auto;
}

.editor-main {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-columns: var(--tool-rail-width) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.workspace[data-repl-visible="true"] {
  grid-template-columns: var(--tool-rail-width) minmax(0, 1fr) 22rem;
}

.tool-rail {
  position: relative;
  z-index: 40;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.3rem;
  border-right: 1px solid var(--line);
  background: rgb(14 20 31 / 96%);
}

.tool-button[aria-pressed="true"] {
  border-color: #aab9ff;
  color: #fff;
  background: linear-gradient(180deg, #5368aa, #394d85);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 10%);
}

.tool-divider {
  width: 1.65rem;
  height: 1px;
  margin: 0.08rem 0;
  background: var(--line);
}

.tool-rail [data-tooltip]::after {
  top: 50%;
  left: calc(100% + 0.5rem);
  transform: translate(-0.2rem, -50%);
}

.tool-rail [data-tooltip]:hover::after,
.tool-rail [data-tooltip]:focus-visible::after {
  transform: translate(0, -50%);
}

.compact-only {
  display: none;
}

.canvas-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgb(64 79 108 / 16%), transparent 34rem),
    #0d121b;
}

.canvas-stage {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: stretch;
  justify-items: stretch;
  overflow: hidden;
  padding: 0.75rem;
}

.draw-shape-rail {
  position: relative;
  z-index: 23;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 0.24rem;
  justify-self: center;
  width: min(34rem, 100%);
  min-width: 0;
  padding: 0.3rem;
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  background: rgb(17 24 37 / 96%);
  box-shadow: 0 8px 28px rgb(0 0 0 / 28%);
}

.draw-shape-button {
  display: grid;
  min-width: 44px;
  min-height: 44px;
  grid-template-rows: 1fr auto;
  place-items: center;
  gap: 0.08rem;
  padding: 0.25rem 0.15rem;
  border-color: rgb(148 163 184 / 55%);
  border-radius: 8px;
  background: #0b111c;
}

.draw-shape-button .icon {
  width: 1.15rem;
  height: 1.15rem;
}

.draw-shape-button > span {
  overflow: hidden;
  width: 100%;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 760;
  line-height: 1;
  text-align: center;
  text-overflow: clip;
  white-space: nowrap;
}

.draw-shape-button[aria-pressed="true"] {
  border-color: #aab9ff;
  color: #fff;
  background: linear-gradient(180deg, #5368aa, #394d85);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%);
}

.canvas-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  grid-row: 2;
  overflow: hidden;
  border: 1px solid #64738b;
  border-radius: 7px;
  background:
    linear-gradient(45deg, #dfe4eb 25%, transparent 25%),
    linear-gradient(-45deg, #dfe4eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe4eb 75%),
    linear-gradient(-45deg, transparent 75%, #dfe4eb 75%),
    #f5f7fa;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  box-shadow: 0 26px 85px rgb(0 0 0 / 44%);
}

.canvas {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.canvas[data-tool="paint"] {
  cursor: crosshair;
}

.canvas[data-tool="paint"][data-brush-cursor="visible"] {
  cursor: none;
}

.canvas[data-tool="select"] {
  cursor: default;
}

.canvas[data-tool="hand"] {
  cursor: grab;
}

.canvas[data-tool="hand"]:active {
  cursor: grabbing;
}

.artboard-border {
  stroke: #64748b;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.canvas-empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  box-sizing: border-box;
  width: fit-content;
  max-width: calc(100% - 1rem);
  margin: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid rgb(55 65 81 / 18%);
  border-radius: 999px;
  color: #4b5563;
  background: rgb(255 255 255 / 82%);
  box-shadow: 0 8px 25px rgb(15 23 42 / 10%);
  font-size: 0.78rem;
  font-weight: 720;
  line-height: 1.35;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -50%);
  white-space: normal;
}

.brush-cursor {
  fill-opacity: 0.28;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.brush-cursor[hidden] {
  display: none;
}

.stroke-mark,
.stroke-preview,
.selection-halo,
.selection-bounds {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rendered-stroke,
.stroke-mark,
.stroke-tap {
  pointer-events: none;
}

.selection-halo,
.selection-bounds {
  stroke: #172554;
  stroke-dasharray: 10 8;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.selection-halo {
  animation: selection-flow 1.8s linear infinite;
}

.selection-bounds {
  fill: rgb(124 156 255 / 8%);
  stroke-width: 3;
  animation: none;
}

@keyframes selection-flow {
  to { stroke-dashoffset: -36; }
}

.stroke-preview {
  pointer-events: none;
}

.marquee-preview {
  fill: rgb(124 156 255 / 12%);
  stroke: var(--accent-strong);
  stroke-width: 2;
  stroke-dasharray: 10 7;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.brush-bar {
  position: absolute;
  z-index: 25;
  top: 4.45rem;
  left: 50%;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.48rem;
  max-width: calc(100% - 1.5rem);
  padding: 0.42rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgb(17 24 37 / 95%);
  box-shadow: 0 14px 42px rgb(0 0 0 / 36%);
  transform: translateX(-50%);
}

.brush-colors-hint {
  display: none;
}

.brush-swatches,
.selection-swatches {
  display: grid;
  grid-template-rows: repeat(2, 44px);
  grid-auto-flow: column;
  grid-auto-columns: 44px;
  gap: 0.25rem;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.brush-swatch,
.selection-swatch {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 35%);
  border-radius: 10px;
  color: #111827;
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 25%);
  forced-color-adjust: none;
}

.palette-swatch svg {
  width: 32px;
  height: 32px;
  pointer-events: none;
}

.brush-swatch[aria-pressed="true"] {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.brush-swatch[aria-pressed="true"]:focus-visible,
.selection-swatch[aria-pressed="true"]:focus-visible,
.recent-color[aria-pressed="true"]:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 3px;
}

.recent-colors-block {
  display: grid;
  min-width: 0;
  max-width: 12rem;
  gap: 0.18rem;
}

.recent-colors-label {
  color: var(--faint);
  font-size: 0.6rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.recent-colors-row {
  display: flex;
  min-width: 0;
  min-height: 44px;
  gap: 0.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px;
  flex-wrap: nowrap;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.recent-color {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 42%);
  border-radius: 10px;
  background: var(--recent-color);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 32%);
  forced-color-adjust: none;
}

.recent-color[aria-pressed="true"] {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.recent-colors-empty {
  align-content: center;
  min-height: 44px;
  color: var(--faint);
  font-size: 0.64rem;
  white-space: nowrap;
}

input[type="color"] {
  width: 2.4rem;
  height: 2.2rem;
  padding: 0.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
}

input[type="range"] {
  min-height: 1.25rem;
  accent-color: var(--accent);
}

input[type="number"],
input[type="text"],
input[type="search"],
textarea {
  min-height: var(--control-height);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #090f19;
}

input[type="number"] {
  width: 4.6rem;
  padding: 0.4rem 0.5rem;
}

.brush-range {
  display: grid;
  grid-template-columns: minmax(6rem, 8rem);
  gap: 0.1rem;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 720;
}

.brush-range > span {
  display: flex;
  justify-content: space-between;
}

.selection-inspector {
  position: absolute;
  z-index: 24;
  right: 0.75rem;
  bottom: 0.75rem;
  left: 0.75rem;
  display: grid;
  grid-template-columns: minmax(8rem, 0.8fr) minmax(18rem, 1.8fr) repeat(3, minmax(8rem, 1fr)) minmax(8rem, 0.7fr);
  align-items: end;
  gap: 0.48rem;
  max-height: 9.5rem;
  overflow: auto;
  padding: 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgb(17 24 37 / 96%);
  box-shadow: 0 14px 42px rgb(0 0 0 / 38%);
  overscroll-behavior: contain;
}

.selection-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.3rem;
}

.arrange-group {
  display: grid;
  align-self: stretch;
  align-content: start;
  gap: 0.28rem;
  min-width: 0;
}

.arrange-heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
}

.arrange-heading h4 {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.arrange-heading span {
  overflow: hidden;
  color: var(--faint);
  font-size: 0.6rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arrange-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(44px, 1fr));
  gap: 0.28rem;
}

.arrange-actions button {
  min-width: 44px;
  min-height: 44px;
  padding: 0.3rem 0.22rem;
  font-size: 0.64rem;
}

.selection-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 0.38rem 0.48rem;
  font-size: 0.68rem;
}

.inspector-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-self: center;
  align-items: center;
  gap: 0.25rem;
}

.inspector-title .shortcut-hint {
  grid-column: 1;
}

#close-selection-inspector {
  grid-column: 2;
  grid-row: 1 / 4;
}

.inspector-title h3 {
  font-size: 0.8rem;
}

.shortcut-hint,
.current-value {
  display: block;
  margin-top: 0.14rem;
  color: var(--faint);
  font-size: 0.61rem;
}

.inspector-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.18rem 0.32rem;
  min-width: 0;
}

.inspector-control .current-value {
  grid-column: 1 / -1;
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspector-control label {
  color: var(--muted);
  font-size: 0.64rem;
}

.inspector-control button {
  grid-column: 1 / -1;
  min-height: 32px;
  padding: 0.28rem 0.45rem;
  font-size: 0.67rem;
}

.selection-swatches {
  grid-column: 1 / -1;
}

.inspector-control .recent-colors-block {
  grid-column: 1 / -1;
  width: 100%;
  max-width: none;
}

.inspector-control .selection-swatch {
  grid-column: auto;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
}

.selection-swatch[aria-pressed="true"] {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.inspector-control input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
}

.scale-control {
  grid-template-columns: auto 1fr;
}

.repl-panel {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #121a29, #0c121d);
  box-shadow: -15px 0 45px rgb(0 0 0 / 20%);
}

.repl-dock-heading {
  flex: 0 0 auto;
  min-height: 54px;
}

.engine-status {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 720;
  white-space: nowrap;
}

.engine-status[data-kind="ready"] {
  color: #86efac;
}

.engine-status[data-kind="running"] {
  color: #fde68a;
}

.engine-status[data-kind="unavailable"] {
  color: #fda4af;
}

.repl-form {
  flex: 0 0 auto;
  padding: 0.62rem 0.65rem 0.48rem;
}

.repl-form > label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.32rem;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 720;
}

.command-context {
  color: var(--faint);
  font-weight: 500;
}

.command-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(4, auto);
  gap: 0.36rem;
}

#command-input {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  min-height: 7.4rem;
  resize: vertical;
  padding: 0.55rem 0.62rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.73rem;
  line-height: 1.45;
  tab-size: 2;
}

.command-help-toggle,
.run-button,
.cancel-button,
.recall-button {
  display: inline-flex;
  min-height: var(--control-height);
  align-items: center;
  gap: 0.32rem;
  padding: 0 0.55rem;
  font-size: 0.7rem;
  font-weight: 760;
}

.recall-button {
  min-width: 4.3rem;
  justify-content: center;
}

#next-command {
  min-width: 44px;
}

.command-help-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  background: #34466f;
}

.command-help-panel {
  position: absolute;
  z-index: 60;
  top: 3.7rem;
  right: 0.5rem;
  left: 0.5rem;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  max-height: calc(100% - 4.2rem);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #111a2a;
  box-shadow: 0 20px 65px rgb(0 0 0 / 62%);
}

.command-search {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.4rem;
  margin: 0.55rem 0.6rem 0;
}

.command-search > .icon {
  margin-left: 0.55rem;
  color: var(--faint);
}

.command-search input {
  width: 100%;
  min-width: 0;
  padding: 0.45rem 0.58rem;
}

.command-help-intro {
  margin: 0;
  padding: 0.42rem 0.65rem;
  color: var(--muted);
  font-size: 0.67rem;
}

.command-help-recipes {
  display: grid;
  grid-auto-rows: max-content;
  gap: 0.4rem;
  min-height: 0;
  overflow: auto;
  padding: 0 0.6rem 0.58rem;
  overscroll-behavior: contain;
}

.example-command {
  display: grid;
  width: 100%;
  height: auto;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  gap: 0.18rem;
  padding: 0.5rem 0.55rem;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}

.example-command > *,
.recipe-meta > *,
.command-help-reference > *,
.transcript-entry > * {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.recipe-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.recipe-title {
  font-size: 0.72rem;
  font-weight: 820;
}

.recipe-category {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.recipe-description {
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.35;
}

.example-command code {
  overflow-wrap: anywhere;
  color: #c8d3ff;
  font-size: 0.62rem;
}

.command-help-empty {
  margin: 1rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.command-help-reference {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.38rem;
  max-height: 12rem;
  overflow: auto;
  padding: 0.55rem 0.6rem 0.65rem;
  border-top: 1px solid var(--line);
  overscroll-behavior: contain;
}

.reference-card {
  min-width: 0;
}

.reference-card h4 {
  margin: 0 0 0.15rem;
  color: var(--text);
  font-size: 0.65rem;
}

.reference-card code,
.reference-card p {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 0.59rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.reference-card code {
  margin-bottom: 0.15rem;
  color: #c7d2fe;
}

.repl-latest {
  flex: 0 0 auto;
  margin: 0 0.65rem 0.45rem;
  padding: 0.46rem 0.55rem;
  border: 1px solid #2d3b55;
  border-radius: 8px;
  color: #dbe4f7;
  background: #09111d;
  font-size: 0.68rem;
}

.repl-latest[data-kind="error"] {
  border-color: rgb(251 113 133 / 48%);
  color: #fecdd3;
}

.transcript-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 0.28rem 0.65rem;
  border-top: 1px solid var(--line);
}

.transcript-header h3 {
  font-size: 0.74rem;
}

.transcript-header .quiet-button {
  min-height: 32px;
  padding: 0.2rem 0.45rem;
  font-size: 0.65rem;
}

.transcript {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  margin: 0;
  padding: 0.2rem 0.65rem 0.65rem 2.05rem;
  overscroll-behavior: contain;
  scrollbar-color: #43516b transparent;
}

.transcript-entry {
  margin: 0.34rem 0;
  padding: 0.45rem 0.5rem;
  border-left: 3px solid #53688f;
  border-radius: 0 7px 7px 0;
  background: rgb(6 11 19 / 62%);
  font-size: 0.66rem;
}

.transcript-entry[data-kind="error"] {
  border-left-color: var(--danger);
}

.transcript-entry[data-kind="boundary"] {
  border-left-color: var(--warning);
}

.transcript-entry[data-prior="true"] {
  opacity: 0.57;
}

.transcript-command,
.transcript-message,
.transcript-meta {
  display: block;
  overflow-wrap: anywhere;
}

.transcript-command {
  color: #adbdff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.transcript-message {
  margin-top: 0.22rem;
  color: #dbe3f2;
  white-space: pre-wrap;
}

.transcript-meta {
  margin-top: 0.24rem;
  color: var(--faint);
  font-size: 0.58rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 1100px) {
  .status-stack {
    max-width: 14rem;
  }

  .document-counts {
    display: none;
  }

  .selection-inspector {
    grid-template-columns: minmax(7rem, 0.7fr) minmax(18rem, 1.8fr) repeat(2, minmax(7rem, 1fr)) minmax(7rem, 0.7fr);
  }

  .workspace[data-compact="true"][data-surface="selection"] .selection-operation-status {
    display: block;
    overflow: hidden;
    grid-column: 1;
    margin: 0;
    color: #dbeafe;
    font-size: 0.66rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace[data-compact="true"][data-surface="selection"] .selection-operation-status[data-tone="error"],
  .workspace[data-compact="true"][data-surface="selection"] .selection-operation-status[data-tone="unexpected"] {
    color: #fecdd3;
  }
}

@media (max-width: 850px), (any-pointer: coarse) {
  :root {
    --header-height: 52px;
  }

  .app-header {
    gap: 0.35rem;
    padding-right: max(0.35rem, env(safe-area-inset-right));
    padding-left: max(0.35rem, env(safe-area-inset-left));
  }

  .brand-copy > span,
  .document-counts {
    display: none;
  }

  .editor-state-chip {
    display: block;
    min-width: 0;
    max-width: 8.5rem;
    text-align: left;
  }

  .header-state {
    min-width: 0;
  }

  .header-actions {
    gap: 0.22rem;
  }

  .repl-launch {
    padding-inline: 0.55rem;
  }

  .workspace[data-compact="true"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .workspace[data-compact="true"] .canvas-panel {
    grid-column: 1;
    grid-row: 1;
  }

  .workspace[data-compact="true"][data-surface="none"] .compact-operation-status {
    position: absolute;
    z-index: 24;
    right: 0.45rem;
    bottom: 0.45rem;
    left: 0.45rem;
    display: block;
    overflow: hidden;
    margin: 0;
    padding: 0.3rem 0.5rem;
    border: 1px solid rgb(141 162 255 / 32%);
    border-radius: 8px;
    background: rgb(15 23 42 / 92%);
    box-shadow: 0 4px 18px rgb(0 0 0 / 28%);
    color: #dbeafe;
    font-size: 0.7rem;
    line-height: 1.2;
    pointer-events: none;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace[data-compact="true"][data-surface="none"] .compact-operation-status[data-tone="error"],
  .workspace[data-compact="true"][data-surface="none"] .compact-operation-status[data-tone="unexpected"] {
    color: #fecdd3;
  }

  .workspace[data-compact="true"] .tool-rail {
    grid-column: 1;
    grid-row: 2;
  }

  .workspace[data-compact="true"] .repl-panel {
    grid-column: 1;
    grid-row: 1 / 3;
  }

  .workspace[data-compact="true"][data-repl-visible="true"] .tool-rail {
    display: none;
  }

  .tool-rail {
    display: grid;
    grid-template-columns: repeat(6, minmax(var(--control-height), 1fr));
    gap: 0.2rem;
    min-height: calc(52px + env(safe-area-inset-bottom));
    padding: 0.25rem 0.3rem calc(0.25rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .tool-rail .icon-button {
    width: 100%;
  }

  .tool-divider {
    display: none;
  }

  .compact-only {
    display: inline-grid;
  }

  .tool-rail [data-tooltip]::after {
    top: auto;
    bottom: calc(100% + 0.45rem);
    left: 50%;
    transform: translate(-50%, 0.2rem);
  }

  .tool-rail [data-tooltip]:hover::after,
  .tool-rail [data-tooltip]:focus-visible::after {
    transform: translate(-50%, 0);
  }

  .canvas-stage {
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 0;
    padding: 0;
  }

  .draw-shape-rail {
    grid-row: 1;
    width: 100%;
    padding: 0.22rem 0.25rem;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .canvas-frame {
    grid-row: 2;
    border-radius: 0;
  }

  .brush-bar {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: auto 98px auto auto auto;
    grid-row: 3;
    align-items: stretch;
    width: 100%;
    max-width: none;
    max-height: min(13rem, 42dvh);
    overflow: auto;
    transform: none;
    overscroll-behavior: contain;
  }

  .brush-swatches {
    grid-column: 1;
    grid-row: 2;
  }

  .brush-colors-hint {
    display: block;
    grid-column: 1 / 3;
    grid-row: 1;
    color: var(--faint);
    font-size: 0.62rem;
    font-weight: 720;
    letter-spacing: 0.02em;
  }

  .brush-color-control {
    position: static;
    grid-column: 2;
    grid-row: 2;
    align-self: center;
  }

  .brush-bar > .recent-colors-block {
    grid-column: 1 / 3;
    grid-row: 3;
    width: 100%;
    max-width: none;
  }

  .brush-range {
    grid-column: 1 / 3;
    grid-template-columns: minmax(0, 1fr);
  }

  #close-brush-settings {
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: start;
    height: var(--control-height);
  }

  .selection-inspector {
    position: static;
    grid-row: 3;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    max-height: min(19rem, 48dvh);
  }

  .selection-actions {
    grid-column: 1 / -1;
  }

  .arrange-group {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .inspector-title {
    grid-column: 1 / -1;
  }

  .selection-inspector > .danger-button {
    align-self: stretch;
  }

  .repl-panel {
    border-left: 0;
  }

  .app-popover {
    top: calc(var(--header-height) + 0.35rem);
    right: 0.35rem;
    left: 0.35rem;
    width: auto;
    max-height: calc(100dvh - var(--header-height) - 0.7rem);
  }

  .persistence-warning {
    right: 0.45rem;
    bottom: calc(56px + env(safe-area-inset-bottom));
    width: calc(100vw - 0.9rem);
  }
}

@media (max-width: 480px) {
  .command-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .recall-button {
    min-width: 0;
  }

  .brand-copy {
    display: none;
  }

  .brand-mark {
    width: 1.85rem;
    height: 1.85rem;
  }

  .header-actions .icon-button {
    width: var(--control-height);
    min-width: var(--control-height);
    height: var(--control-height);
  }

  .repl-launch {
    min-height: var(--control-height);
    padding-inline: 0.48rem;
    font-size: 0.75rem;
  }

  .command-help-toggle span,
  .run-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .command-help-toggle,
  .run-button {
    width: var(--control-height);
    padding: 0;
    justify-content: center;
  }

  .command-help-reference {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) and (max-height: 650px) {
  .command-help-panel {
    grid-template-rows: auto auto auto minmax(4.5rem, 1fr) minmax(0, 6.5rem);
  }

  .command-help-recipes {
    min-height: 4.5rem;
  }

  .command-help-reference {
    max-height: none;
  }
}

@media (max-width: 340px) {
  .header-state {
    display: none;
  }

  .app-popover {
    max-height: calc(100dvh - var(--header-height) - 6rem);
  }

  .workspace[data-compact="true"][data-surface="none"] .compact-operation-status,
  .workspace[data-compact="true"][data-surface="project"] .compact-operation-status {
    position: fixed;
    z-index: 160;
    right: 0.35rem;
    bottom: calc(58px + env(safe-area-inset-bottom));
    left: 0.35rem;
    display: block;
    overflow: hidden;
    margin: 0;
    padding: 0.3rem 0.5rem;
    border: 1px solid rgb(141 162 255 / 32%);
    border-radius: 8px;
    background: rgb(15 23 42 / 92%);
    box-shadow: 0 4px 18px rgb(0 0 0 / 28%);
    color: #dbeafe;
    font-size: 0.7rem;
    line-height: 1.2;
    pointer-events: none;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace[data-compact="true"][data-surface="project"] .compact-operation-status[data-tone="error"],
  .workspace[data-compact="true"][data-surface="project"] .compact-operation-status[data-tone="unexpected"] {
    color: #fecdd3;
  }
}

@media (min-width: 700px) and (max-width: 850px) and (max-height: 430px),
       (min-width: 700px) and (any-pointer: coarse) and (max-height: 430px) {
  :root {
    --header-height: 44px;
  }

  .brand-copy,
  .header-state {
    display: none;
  }

  .brand-mark {
    width: 1.7rem;
    height: 1.7rem;
  }

  .app-header {
    min-height: var(--header-height);
  }

  .tool-rail {
    min-height: calc(52px + env(safe-area-inset-bottom));
  }

  .brush-bar,
  .selection-inspector {
    max-height: calc(100% - 0.5rem);
  }

  .canvas-stage {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(250px, 1fr);
  }

  .draw-shape-rail {
    grid-column: 1;
    grid-row: 1;
    grid-template-columns: 44px;
    grid-template-rows: repeat(6, 44px);
    gap: 0;
    width: auto;
    height: 100%;
    align-self: stretch;
    padding: 0;
    border: 0;
    border-right: 1px solid var(--line-strong);
  }

  .draw-shape-button > span {
    display: none;
  }

  .canvas-frame {
    grid-column: 2;
    grid-row: 1;
  }

  .workspace[data-surface="brush"] .canvas-stage,
  .workspace[data-surface="selection"] .canvas-stage {
    grid-template-columns: auto minmax(0, 1fr) clamp(260px, 42%, 300px);
  }

  .workspace[data-surface="brush"] .canvas-frame,
  .workspace[data-surface="selection"] .canvas-frame {
    grid-column: 2;
  }

  .brush-bar,
  .selection-inspector {
    grid-column: 3;
    grid-row: 1;
    width: 100%;
    max-height: 100%;
  }

  .command-help-panel {
    top: 0.35rem;
    max-height: calc(100% - 0.7rem);
  }

  .command-help-recipes {
    min-height: 5rem;
  }

  .command-help-reference {
    max-height: 4rem;
  }

  .app-popover {
    max-height: calc(100dvh - var(--header-height) - 0.4rem);
  }
}

@media (any-pointer: coarse) {
  [data-tooltip]:hover:not(:focus-visible)::after {
    opacity: 0;
  }

  :root .app-header button,
  :root .workspace button,
  :root .app-popover button,
  :root .persistence-warning button,
  :root .app-header .button-label,
  :root .workspace .button-label,
  :root .app-popover .button-label,
  :root .persistence-warning .button-label,
  :root .app-header input:not(.file-input):not([type="hidden"]),
  :root .workspace input:not(.file-input):not([type="hidden"]),
  :root .app-popover input:not(.file-input):not([type="hidden"]),
  :root .persistence-warning input:not(.file-input):not([type="hidden"]) {
    min-width: var(--control-height);
    min-inline-size: var(--control-height);
    min-height: var(--control-height);
    min-block-size: var(--control-height);
  }

  :root .app-header .header-actions .icon-button {
    min-width: var(--control-height);
    min-inline-size: var(--control-height);
    min-height: var(--control-height);
    min-block-size: var(--control-height);
  }

  :root .workspace .transcript-header .quiet-button {
    min-width: var(--control-height);
    min-inline-size: var(--control-height);
    min-height: var(--control-height);
    min-block-size: var(--control-height);
  }

  :root .workspace input[type="color"],
  :root .app-popover input[type="color"],
  :root .persistence-warning input[type="color"] {
    width: var(--control-height);
    height: var(--control-height);
  }

  .inspector-control .selection-swatch {
    min-width: var(--control-height);
    min-height: var(--control-height);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .selection-halo,
  .selection-bounds {
    animation: none;
  }
}

@media (forced-colors: active) {
  button,
  .button-label,
  .app-popover,
  .brush-bar,
  .draw-shape-rail,
  .selection-inspector,
  .command-help-panel {
    border: 1px solid ButtonText;
  }

  :root button[aria-pressed="true"],
  :root button[aria-expanded="true"] {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }

  :root button.brush-swatch[aria-pressed="true"]:focus-visible,
  :root button.selection-swatch[aria-pressed="true"]:focus-visible,
  :root button.recent-color[aria-pressed="true"]:focus-visible {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }

  .canvas-frame,
  .canvas,
  .brush-swatch,
  .selection-swatch,
  .recent-color {
    forced-color-adjust: none;
  }
}

@media print {
  .app-header,
  .tool-rail,
  .repl-panel,
  .brush-bar,
  .draw-shape-rail,
  .selection-inspector,
  .app-popover,
  .persistence-warning,
  .canvas-empty-hint {
    display: none !important;
  }

  html,
  body,
  .editor-main,
  .workspace,
  .canvas-panel,
  .canvas-stage {
    width: auto;
    height: auto;
    overflow: visible;
    padding: 0;
    margin: 0;
    background: #fff;
  }

  .canvas-frame { border: 0; box-shadow: none; }
}
