/* ─── Tokens ─────────────────────────────────────────────────────────────── */

:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar-h: 52px;
  --sidebar-w: 304px;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --stage: #ececee;
  --stage-dot: #d4d4d9;
  --border: #e7e7ea;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --muted: #8b8b94;
  --hover: rgba(24, 24, 27, .05);
  --accent: #3e63dd;
  --accent-soft: rgba(62, 99, 221, .1);
  --tip-bg: #18181b;
  --tip-fg: #fafafa;
  --shadow-sm: 0 1px 2px rgba(16, 16, 20, .06);
  --shadow: 0 1px 2px rgba(16, 16, 20, .05), 0 8px 24px -8px rgba(16, 16, 20, .16);
  --shadow-lg: 0 2px 6px rgba(16, 16, 20, .06), 0 24px 48px -12px rgba(16, 16, 20, .28);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0f;
    --surface: #151517;
    --surface-2: #1d1d20;
    --stage: #0a0a0b;
    --stage-dot: #212126;
    --border: #252529;
    --border-strong: #34343a;
    --text: #ededef;
    --text-2: #b2b2ba;
    --muted: #76767f;
    --hover: rgba(255, 255, 255, .06);
    --accent: #7091ff;
    --accent-soft: rgba(112, 145, 255, .15);
    --tip-bg: #2a2a2f;
    --tip-fg: #f4f4f5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -8px rgba(0, 0, 0, .6);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .4), 0 24px 48px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0d0f;
  --surface: #151517;
  --surface-2: #1d1d20;
  --stage: #0a0a0b;
  --stage-dot: #212126;
  --border: #252529;
  --border-strong: #34343a;
  --text: #ededef;
  --text-2: #b2b2ba;
  --muted: #76767f;
  --hover: rgba(255, 255, 255, .06);
  --accent: #7091ff;
  --accent-soft: rgba(112, 145, 255, .15);
  --tip-bg: #2a2a2f;
  --tip-fg: #f4f4f5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -8px rgba(0, 0, 0, .6);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .4), 0 24px 48px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */

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

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spacer { flex: 1; }
.muted { color: var(--muted); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.sm { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.icon-btn.xs { width: 24px; height: 24px; border-radius: 6px; }
.icon-btn.xs svg { width: 14px; height: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; background: var(--surface); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.sm svg { width: 14px; height: 14px; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.primary { border-color: transparent; background: var(--text); color: var(--surface); }
.btn.primary:hover { opacity: .88; background: var(--text); }

.text-btn {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.text-btn:hover { color: var(--text); }

/* Tooltips */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 100;
  top: calc(100% + 8px);
  left: 50%;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--tip-bg);
  color: var(--tip-fg);
  font: 500 11.5px/1.2 var(--font);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -2px);
  transition: opacity .12s, transform .12s;
}
[data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .4s; }
[data-tip-pos="top"]::after { top: auto; bottom: calc(100% + 8px); transform: translate(-50%, 2px); }
[data-tip-align="end"]::after { left: auto; right: 0; transform: translateY(-2px); }
[data-tip-align="end"]:hover::after { transform: none; }
[data-tip-pos="top"][data-tip-align="end"]::after { transform: translateY(2px); }
[aria-expanded="true"]::after { display: none; }

/* ─── Top bar ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--text);
  color: var(--surface);
}
.logo svg { width: 16px; height: 16px; stroke-width: 2; }

.file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 20px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.file-name { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-dims { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.actions { display: flex; align-items: center; gap: 2px; flex: none; }
.divider { width: 1px; height: 20px; margin: 0 6px; background: var(--border); }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  right: 0;
  min-width: 232px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop-in .14s ease-out;
}
.menu-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.menu-item svg { width: 16px; height: 16px; margin-top: 1px; color: var(--text-2); }
.menu-item small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; }
.menu-item:hover { background: var(--hover); }

.settings-menu { min-width: 248px; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 38px;
  padding: 4px 10px;
  border-radius: 8px;
}
label.set-row { cursor: pointer; }
label.set-row:hover { background: var(--hover); }

.seg {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.seg button {
  min-width: 26px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 30px;
  height: 18px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background .15s;
}
.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(12px); }

/* ─── Workspace ──────────────────────────────────────────────────────────── */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  min-height: 0;
}

.stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background-color: var(--stage);
  background-image: radial-gradient(var(--stage-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  user-select: none;
  -webkit-user-select: none;
}

#view {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

.toolbar {
  position: absolute;
  z-index: 5;
  top: 14px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}
.tool {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.tool svg { width: 18px; height: 18px; }
.tool:hover { background: var(--hover); color: var(--text); }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.tool-sep { width: 1px; height: 20px; margin: 0 4px; background: var(--border); }

.hint {
  position: absolute;
  z-index: 4;
  top: 72px;
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 20, 23, .84);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity .15s, transform .15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }
.hint kbd {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .16);
  font: 500 11px/17px var(--font);
}

.coords,
.zoombar {
  position: absolute;
  z-index: 4;
  bottom: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.coords {
  left: 16px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: pre;
  pointer-events: none;
}
.zoombar {
  right: 16px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
}
.zoombar button {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.zoombar button:hover { background: var(--hover); color: var(--text); }
.zoombar svg { width: 15px; height: 15px; }
#zoomLabel { min-width: 50px; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.zsep { width: 1px; height: 16px; margin: 0 2px; background: var(--border); }

.loupe {
  position: absolute;
  z-index: 6;
  top: 0;
  left: 0;
  width: 136px;
  height: 136px;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 0 0 4px #fff, 0 0 0 5px rgba(0, 0, 0, .12), 0 12px 32px rgba(0, 0, 0, .3);
  will-change: transform;
}

.no-image .toolbar,
.no-image .hint,
.no-image .coords,
.no-image .zoombar { display: none; }

/* Empty state */
.empty { display: none; }
.no-image .empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 16px;
}
.empty-card {
  width: min(440px, 100%);
  padding: 40px 32px 28px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-2);
}
.empty-icon svg { width: 24px; height: 24px; stroke-width: 1.5; }
.empty h1 { margin: 0 0 6px; font-size: 17px; font-weight: 600; letter-spacing: -.015em; }
.empty p { margin: 0 0 22px; color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.empty-feats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin: 26px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}
.empty-feats li { display: inline-flex; align-items: center; gap: 6px; }
.empty-feats svg { width: 14px; height: 14px; }

.drop-overlay {
  position: absolute;
  z-index: 10;
  inset: 10px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}
.drop-overlay div { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-overlay svg { width: 28px; height: 28px; }
body.dragging .drop-overlay { opacity: 1; }

/* Calibration popover */
.popover {
  position: absolute;
  z-index: 8;
  width: min(328px, calc(100% - 24px));
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop-in .14s ease-out;
}
.popover h3 { margin: 0 0 2px; font-size: 13.5px; font-weight: 600; }
.pop-sub { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; }
.calib-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.5fr); align-items: end; gap: 8px; }
.eq { padding-bottom: 7px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { color: var(--text-2); font-size: 11.5px; font-weight: 500; }
.input-affix { position: relative; display: flex; }
.input-affix .input { width: 100%; padding-right: 28px; }
.input-affix span { position: absolute; top: 50%; right: 10px; color: var(--muted); font-size: 12px; transform: translateY(-50%); pointer-events: none; }
.input-group { display: flex; gap: 6px; }
.input-group .input:first-child { flex: 1; width: 100%; }
.pop-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 16px; }

.input {
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.sm { height: 28px; font-size: 12.5px; }
select.input {
  appearance: none;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8b94' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 7px center;
  background-repeat: no-repeat;
  background-size: 14px;
  cursor: pointer;
}
.input.shake { animation: shake .3s; border-color: #e5484d; }

/* ─── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.panel { padding: 16px; border-bottom: 1px solid var(--border); }
.panel-head { display: flex; align-items: center; gap: 8px; min-height: 26px; margin-bottom: 8px; }
.panel-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.count {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}
.count:empty { display: none; }

.scale-panel { transition: background .15s; }
.scale-panel.selected { background: var(--accent-soft); }
.scale-value { font-size: 20px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.scale-value span { margin-left: 2px; color: var(--muted); font-size: 12.5px; font-weight: 500; letter-spacing: 0; }
.scale-value.off { color: var(--text-2); font-size: 15px; letter-spacing: -.01em; }
.scale-sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.scale-actions { display: flex; gap: 6px; margin-top: 12px; }
.scale-units {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--text-2);
  font-size: 12.5px;
}

.list-panel { display: flex; flex: 1; flex-direction: column; min-height: 0; padding: 16px 8px 8px; border-bottom: 0; }
.list-panel .panel-head { padding: 0 8px; }
.m-list { flex: 1; min-height: 0; margin: 0; padding: 0; overflow: auto; list-style: none; }
.m-list:empty { display: none; }

.m-item { margin: 1px 0; border-radius: 9px; }
.m-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 4px 0 10px;
  border-radius: 9px;
  cursor: pointer;
}
.m-item:hover .m-row,
.m-item.hovered .m-row { background: var(--hover); }
.m-item.selected { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.m-item.selected .m-row { background: transparent; }
.m-icon { display: grid; color: var(--c); }
.m-icon svg { width: 16px; height: 16px; stroke-width: 2; }
.m-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.m-name-input {
  flex: 1;
  min-width: 0;
  height: 26px;
  margin-left: -6px;
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 500;
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.m-value { color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.m-tools { display: flex; opacity: 0; transition: opacity .12s; }
.m-item:hover .m-tools,
.m-item.selected .m-tools,
.m-item.is-hidden .m-tools { opacity: 1; }
.m-item.is-hidden .m-icon,
.m-item.is-hidden .m-name,
.m-item.is-hidden .m-value { opacity: .45; }

.m-details { display: none; padding: 0 8px 8px 34px; }
.m-item.selected .m-details { display: block; }
.m-metric {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: calc(100% + 16px);
  margin: 0 -8px;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 12.5px;
  text-align: left;
  cursor: copy;
}
.m-metric:hover { background: var(--hover); }
.m-metric .k { color: var(--muted); }
.m-metric .v { font-weight: 500; font-variant-numeric: tabular-nums; }

.m-empty { padding: 28px 16px; color: var(--text-2); text-align: center; }
.m-empty p { margin: 0 0 4px; }
.m-empty .muted { font-size: 12px; }

/* ─── Modal & toasts ─────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
  background: rgba(10, 10, 12, .45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in .15s;
}
.modal-card {
  width: min(760px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 20px 24px 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  outline: none;
  animation: pop-in .18s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.kbd-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 28px; }
.kbd-cols h3 {
  margin: 16px 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.kbd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  box-shadow: 0 1px 0 var(--border);
  color: var(--text);
  font: 500 11px/18px var(--font);
  text-align: center;
  white-space: nowrap;
}

.toasts {
  position: fixed;
  z-index: 60;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 14px;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in .2s cubic-bezier(.2, .8, .2, 1);
  transition: opacity .2s, transform .2s;
}
.toast span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.toast:not(:has(button)) { padding-right: 14px; }
.toast button {
  padding: 3px 10px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 18%, transparent);
  color: inherit;
  font-weight: 600;
  cursor: pointer;
}
.toast.out { opacity: 0; transform: translateY(6px); }

@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

.only-narrow { display: none; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    z-index: 30;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    right: 0;
    bottom: 0;
    width: min(320px, 88vw);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: var(--shadow-lg);
    transform: translateX(105%);
    transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  }
  body.panel-open .sidebar { transform: none; }
  .only-narrow { display: grid; }
  .file-info { display: none; }
  #openBtn span, #exportBtn span { display: none; }
  #openBtn, #exportBtn { width: 32px; padding: 0; }
  #exportBtn { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-2); }
  .kbd-cols { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .topbar { gap: 6px; }
  .brand-name, .hide-mobile { display: none; }
  .divider { margin: 0 2px; }
  .tool { width: 32px; height: 32px; }
  .tool-sep { margin: 0 2px; }
  .hint { top: 62px; }
  .kbd-cols { grid-template-columns: 1fr; }
}

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

@media (hover: none) {
  .m-tools { opacity: 1; }
  [data-tip]::after { display: none; }
}
