/* Divs & Spans chrome. Deliberately quiet: the frames are the content. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#ececea, #161617);
  --dot: light-dark(#d2d2ce, #2a2a2c);
  --panel: light-dark(#ffffff, #222224);
  --panel-2: light-dark(#f6f6f4, #2b2b2e);
  --line: light-dark(#dcdcd8, #38383b);
  --text: light-dark(#1d1d1f, #ececee);
  --muted: light-dark(#76767a, #9a9aa0);
  --accent: light-dark(#4f46e5, #8b85ff);
  --accent-soft: light-dark(#4f46e51a, #8b85ff26);
  --danger: light-dark(#d93d42, #ff6b6b);
  --shadow: 0 1px 2px #0000000f, 0 8px 24px #0000001a;
  --radius: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  /* room the phone dock takes at the bottom; 0 on desktop */
  --dock: 0px;
}
:root[data-chrome="light"] { color-scheme: light; }
:root[data-chrome="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font: 13px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- toolbar ---------- */
.bar {
  position: fixed;
  inset: 12px 12px auto 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.bar > *, .bar .group { pointer-events: auto; flex: none; }
.bar > .group:first-child { flex: 0 1 auto; min-width: 0; }
/* the view settings sit in the bar like any other group; on phones they become a sheet */
.view-sheet { display: contents; }
.group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.spacer { flex: 1; pointer-events: none; }
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 8px;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-mark { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.file-name {
  border: 0;
  background: transparent;
  padding: 4px 8px;
  border-radius: 6px;
  width: 22ch;
  min-width: 0;
  flex: 1 1 auto;
}
.file-name:hover { background: var(--panel-2); }
.file-name:focus { outline: 2px solid var(--accent); background: var(--panel-2); }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--panel-2); }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.btn.primary { background: var(--accent); color: white; }
/* keycaps: every action shows its key, Fizzy-style */
.btn kbd, .menu .item kbd, .pick-bar kbd, .group > kbd.hint {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font: 600 11px/1 var(--font);
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  white-space: nowrap;
}
.btn[aria-pressed="true"] kbd { color: inherit; border-color: currentColor; background: transparent; }
.btn.primary kbd { color: white; background: transparent; border-color: rgb(255 255 255 / 0.55); }
.group > kbd.hint { margin: 0 2px; cursor: default; }
.group > kbd.hint + kbd.hint { margin-left: -1px; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }
.zoom { min-width: 5ch; justify-content: center; font-variant-numeric: tabular-nums; }
select.btn { appearance: none; padding-right: 10px; field-sizing: content; }

/* ---------- viewport ---------- */
.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: calc(24px * var(--z, 1)) calc(24px * var(--z, 1));
  background-position: var(--bx, 0) var(--by, 0);
  cursor: default;
  touch-action: none;
}
.viewport.panning, .viewport.panning * { cursor: grabbing !important; }
.viewport.space { cursor: grab; }
.viewport.space iframe, .viewport.panning iframe { pointer-events: none; }
.world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: flex;
  align-items: flex-start;
  gap: 120px;
  padding: 0;
}

/* ---------- flows ---------- */
.flows { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.flows .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.flows .hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.flows .src { fill: var(--accent); }
.flows .src.off { fill: var(--panel); stroke: var(--accent); stroke-width: 1.5; }
.flows .box { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; }
.flows marker path { fill: var(--accent); stroke: var(--accent); stroke-width: 1; stroke-linejoin: round; }
.flows .rest { opacity: 0.6; }
.flows .dim { opacity: 0.3; }
.flows .faint { opacity: 0.12; }
.flows .flow:hover { opacity: 1; }
.flows .flow:hover .line { stroke-width: 3; }
.flows .dead .line { stroke: var(--danger); stroke-dasharray: 4 4; }
.flows .dead .src, .flows .dead .end { fill: var(--danger); stroke: none; }
.flows .dead .x { stroke: var(--panel); stroke-width: 1.75; stroke-linecap: round; }
.viewport.panning .flows .hit, .viewport.space .flows .hit { pointer-events: none; }

/* ---------- frames ---------- */
.frame { position: relative; flex: none; }
/* name, version and device run down the left edge, so long names don't fight the copy button for width */
.frame-label {
  position: absolute;
  top: 0;
  right: 100%;
  max-height: 100%;
  writing-mode: vertical-rl;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: calc(8px / var(--z, 1));
  font-size: calc(13px / var(--z, 1));
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.frame-label .name { flex: 0 1 auto; min-inline-size: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.frame-label .meta { flex: 0 1000 auto; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 0.85em; }
/* copy link, and on hover or selection the image actions, above the frame's top right */
.frame-actions {
  position: absolute;
  bottom: 100%;
  right: 0;
  display: flex;
  gap: calc(16px / var(--z, 1));
  padding: 0 0 calc(8px / var(--z, 1));
}
.frame-actions button, .frame-actions a {
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: calc(13px / var(--z, 1));
  white-space: nowrap;
}
.frame-actions a { text-decoration: none; }
.frame-actions button:hover, .frame-actions a:hover { color: var(--accent); }
.frame-label kbd, .frame-actions kbd {
  font: 600 0.8em var(--font);
  border: calc(1px / var(--z, 1)) solid var(--line);
  border-bottom-width: calc(2px / var(--z, 1));
  border-radius: 0.38em;
  padding: 0.05em 0.35em;
  margin-inline-start: 0.3em;
}
.frame.selected .frame-label .name { color: var(--accent); }
.frame-label .key { display: none; margin: 0; flex: none; text-orientation: upright; }
.frame:is(:hover, .selected) .frame-label .key:not(:empty) { display: inline; }
/* zoomed far out the rail would run into the neighbouring frame, so the name goes back on top */
.viewport.tiny .frame-label {
  writing-mode: horizontal-tb;
  top: auto;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: none;
  padding: 0 0 calc(8px / var(--z, 1));
}
.viewport.tiny .frame-label .meta, .viewport.tiny .frame-actions, .viewport.tiny .frame-label .key { display: none !important; }
.viewport.tiny .task-text { display: none; }
.frame-body { display: flex; gap: 40px; }
.screen {
  position: relative;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line), var(--shadow);
  overflow: hidden;
}
.frame.selected .screen { box-shadow: 0 0 0 calc(2px / var(--z, 1)) var(--accent), var(--shadow); }
.screen[data-scheme="light"] { color-scheme: light; }
.screen[data-scheme="dark"] { color-scheme: dark; }
.screen iframe {
  display: block;
  border: 0;
  width: 100%;
  height: 100%;
  background: transparent;
}
/* device chrome (D): drawn in CSS so it stays sharp at any zoom */
.frame.dressed .frame-body { gap: 80px; }
.frame.dressed .frame-label { margin-right: 24px; }
.viewport.tiny .frame.dressed .frame-label { margin: 0 0 24px; }
.frame.dressed .frame-actions { margin-bottom: 24px; }
/* the bezel ring and the status bar, island and home indicator live in src/chrome.ts */
.screen.device { box-shadow: var(--bezel-ring), var(--shadow); }
.frame.selected .screen.device {
  box-shadow: 0 0 0 var(--bezel) #0b0b0d, 0 0 0 calc(var(--bezel) + 2px / var(--z, 1)) var(--accent), var(--shadow);
}

/* resize handles: drag any frame and every frame follows */
.resize {
  position: absolute;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s;
  touch-action: none;
}
.frame:hover .resize, .viewport.resizing .resize { opacity: 1; }
.resize::after { content: ""; position: absolute; inset: 0; margin: auto; border-radius: 99px; background: var(--muted); }
.resize:hover::after, .viewport.resizing .resize::after { background: var(--accent); }
.resize.e {
  left: 100%;
  top: 0;
  bottom: 0;
  width: calc(24px / var(--z, 1));
  cursor: ew-resize;
}
.resize.e::after { width: calc(5px / var(--z, 1)); height: calc(56px / var(--z, 1)); }
.resize.s {
  top: 100%;
  left: 0;
  right: 0;
  height: calc(24px / var(--z, 1));
  cursor: ns-resize;
}
.resize.s::after { height: calc(5px / var(--z, 1)); width: calc(56px / var(--z, 1)); }
.resize.se {
  left: 100%;
  top: 100%;
  width: calc(24px / var(--z, 1));
  height: calc(24px / var(--z, 1));
  cursor: nwse-resize;
}
.resize.se::after { width: calc(9px / var(--z, 1)); height: calc(9px / var(--z, 1)); }
.frame.dressed .resize.e { margin-left: 16px; }
.frame.dressed .resize.s { margin-top: 16px; }
.frame.dressed .resize.se { margin: 16px 0 0 16px; }
.full-height .resize.s, .full-height .resize.se { display: none; }
.viewport.resizing, .viewport.resizing * { cursor: grabbing; }
.viewport.resizing iframe { pointer-events: none; }

.screen .scheme {
  position: absolute;
  top: 100%;
  left: 0;
  padding-top: calc(6px / var(--z, 1));
  font: calc(11px / var(--z, 1)) var(--mono);
  color: var(--muted);
}

/* working state: shimmer over the frame (or an empty skeleton) */
.working-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  padding: 24px;
  background: linear-gradient(100deg, transparent 20%, light-dark(#ffffff99, #ffffff14) 50%, transparent 80%) 0 0 / 300% 100%,
    light-dark(#f2f2f0cc, #1c1c1ecc);
  animation: shimmer 1.8s linear infinite;
  pointer-events: none;
}
.frame.working .working-overlay { display: flex; }
.working-overlay .skeleton {
  position: absolute;
  inset: 48px 48px auto 48px;
  display: grid;
  gap: 18px;
}
.frame.has-content .working-overlay .skeleton { display: none; }
.skeleton i {
  display: block;
  height: 14px;
  border-radius: 7px;
  background: light-dark(#00000012, #ffffff12);
}
.skeleton i:nth-child(1) { width: 40%; height: 28px; }
.skeleton i:nth-child(2) { width: 75%; }
.skeleton i:nth-child(3) { width: 60%; }
.skeleton i:nth-child(4) { width: 100%; height: 160px; border-radius: 12px; }
.skeleton i:nth-child(5) { width: 50%; }
.working-overlay .task {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: calc(13px / var(--z, 1));
  transform-origin: 0 100%;
}
.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
  flex: none;
}
@keyframes shimmer { to { background-position: -300% 0, 0 0; } }
@keyframes pulse { 50% { opacity: 0.3; transform: scale(0.7); } }
@media (prefers-reduced-motion: reduce) {
  .working-overlay, .pulse { animation: none; }
}

/* ---------- empty state ---------- */
.empty {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.empty-card {
  max-width: 460px;
  padding: 28px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.empty-card h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -0.01em; }
.empty-card p { margin: 0 0 14px; color: var(--muted); }

/* ---------- popover / connect ---------- */
.pop {
  position: fixed;
  top: 56px;
  right: 12px;
  z-index: 20;
  width: min(420px, calc(100vw - 24px));
  padding: 16px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.pop[hidden] { display: none; }
.pop h3 { margin: 0 0 4px; font-size: 13px; }
/* export menu: one row per format */
.pop.menu { width: min(320px, calc(100vw - 24px)); padding: 6px; }
.menu .item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu .item:hover { background: var(--panel-2); }
.menu .item[aria-disabled] { color: var(--muted); }
.menu .item span { grid-column: 1; color: var(--muted); font-size: 12px; }
.menu .item kbd { grid-column: 2; grid-row: 1; align-self: center; }
.pop p { margin: 0 0 12px; color: var(--muted); }
.menu .item.danger { color: var(--danger); }
.menu .item.danger[data-confirm] { background: color-mix(in oklab, var(--danger) 14%, transparent); }

/* trash: deleted frames with a restore each, then deleting the file */
.pop.trash h3 { padding: 8px 10px 2px; }
.trash-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }
.trash-list li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.trash-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-list time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.trash-list .btn { border: 1px solid var(--line); }
.trash-list .none { color: var(--muted); }
.pop.trash .trash-note { margin: 4px 10px 6px; font-size: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

/* a file in the trash covers the canvas with its restore card */
.trashed { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.trashed .row { display: flex; gap: 8px; }
.trashed .row .btn { height: 32px; padding: 0 14px; border: 1px solid var(--line); text-decoration: none; }
.field { display: flex; gap: 6px; margin-bottom: 14px; }
.field input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  font: 12px var(--mono);
}
.field .btn { border: 1px solid var(--line); }
/* embed: link, then device/theme/iframe/preview, then turning it off */
.embed-opts { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 14px; }
.embed-opts .btn { border: 1px solid var(--line); }
.pop.embed .btn.danger { color: var(--danger); padding: 0; height: auto; }
.pop.embed .btn.danger:hover { background: none; text-decoration: underline; }
.pop.embed .btn.danger[data-confirm] { font-weight: 600; }
.prompt {
  font: 12px/1.5 var(--mono);
  padding: 10px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  margin: 0 0 8px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock) + 20px);
  z-index: 30;
  transform: translate(-50%, 12px);
  opacity: 0;
  max-width: calc(100vw - 32px);
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.picking .toast { bottom: calc(var(--dock) + 72px); }

/* shown while selecting elements */
.pick-bar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock) + 20px);
  z-index: 29;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
}
.pick-bar[hidden] { display: none; }
.pick-bar b { color: var(--accent); font-weight: 600; }
.pick-bar .btn { pointer-events: auto; color: var(--text); }
.pick-bar .actions { display: flex; gap: 2px; margin-left: auto; }
.pick-bar kbd { color: var(--text); margin-right: 4px; }
@media (max-width: 640px) { .pick-bar span:nth-of-type(n+3) { display: none; } }
.toast code { font: 12px var(--mono); opacity: 0.75; }
.toast kbd { font: 600 11px var(--font); padding: 1px 5px; border-radius: 4px; border: 1px solid currentColor; opacity: 0.75; }

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin: 0 6px; }
.status-dot.live { background: #22a06b; }

/* ---------- home ---------- */
.home {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 48px 16px;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 24px 24px;
}
.home-card {
  width: min(520px, 100%);
  padding: 32px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.home-card h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.02em; }
.home-card h1 span { font-family: var(--mono); font-weight: 400; font-size: 15px; color: var(--accent); margin-left: 6px; }
.home-card > p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.home-card form { display: flex; gap: 8px; margin-bottom: 24px; }
.home-card form input {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
.home-card form .btn { height: 36px; padding: 0 16px; }
.home-card h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.recent { list-style: none; margin: 0 0 24px; padding: 0; }
.recent a {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  margin: 0 -10px;
  border-radius: 8px;
  text-decoration: none;
}
.recent a:hover { background: var(--panel-2); }
.recent li { position: relative; }
.recent li a { padding-right: 40px; }
.recent .forget {
  position: absolute; right: -6px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border: 0; border-radius: 6px; background: none;
  color: var(--muted); font-size: 16px; cursor: pointer; opacity: 0;
}
.recent li:hover .forget, .recent .forget:focus-visible { opacity: 1; }
.recent .forget:hover { background: var(--panel); color: var(--text); }
@media (pointer: coarse) { .recent .forget { opacity: 1; } }
.recent time { color: var(--muted); font-size: 12px; }

/* ---------- comments ---------- */
.btn .badge {
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 99px;
  background: var(--accent); color: white; font: 600 11px/17px var(--font); text-align: center;
}
.pins { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pin {
  position: absolute; left: 0; top: -28px;
  display: flex; align-items: center; gap: 2px;
  padding: 2px; border: 0; border-radius: 15px 15px 15px 3px;
  background: var(--panel); box-shadow: 0 1px 3px #0003, 0 4px 14px #0002;
  pointer-events: auto; cursor: pointer;
  transform-origin: 0 100%;
}
.pin:hover, .pin.active { box-shadow: 0 0 0 2px var(--accent), 0 4px 14px #0003; z-index: 1; }
.pin i { font: 600 11px var(--font); font-style: normal; color: var(--muted); padding: 0 6px 0 2px; }
.pin.resolved { opacity: 0.7; }
.pin.off, .pin.detached { opacity: 0.55; }
.pin.detached .av { outline: 2px dashed var(--danger); outline-offset: 1px; }
.viewport.panning .pin { pointer-events: none; }
.av {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c, var(--muted)); color: white; font: 600 10px/1 var(--font); letter-spacing: 0.02em;
}
.av.agent { font-size: 12px; }

.comments-panel {
  position: fixed; top: 60px; right: 12px; bottom: 12px; z-index: 15;
  width: 300px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  overflow: hidden;
}
.comments-panel header { display: flex; align-items: center; gap: 6px; padding: 6px; border-bottom: 1px solid var(--line); }
.comments-panel header > .btn { margin-left: auto; }
.seg { display: flex; gap: 2px; }
.seg .btn span { color: var(--muted); font-variant-numeric: tabular-nums; }
.seg .btn[aria-pressed="true"] span { color: inherit; }
.threads { list-style: none; margin: 0; padding: 4px; overflow: auto; flex: 1; touch-action: pan-y; overscroll-behavior: contain; }
.threads button {
  display: flex; gap: 10px; width: 100%; padding: 8px; border: 0; border-radius: 8px;
  background: none; text-align: left; cursor: pointer;
}
.threads button:hover { background: var(--panel-2); }
.threads button[aria-current="true"] { background: var(--accent-soft); }
.threads .txt { display: grid; gap: 2px; min-width: 0; flex: 1; }
.threads .meta, .thread-pop .meta { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.threads time, .thread-pop time { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.threads .excerpt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.threads .where, .thread-pop .where { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads code, .thread-pop code { font: 11px var(--mono); }
.threads .empty { padding: 16px 12px; color: var(--muted); }
.comments-panel footer {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 6px 6px 12px; border-top: 1px solid var(--line); color: var(--muted);
}
.comments-panel footer span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me { border: 0; background: none; padding: 0; font-weight: 600; cursor: text; text-decoration: underline dotted; text-underline-offset: 3px; }
.rename { width: 15ch; padding: 2px 6px; border: 1px solid var(--accent); border-radius: 6px; background: var(--panel-2); }

/* ---------- notes: the selected frame's markdown, on the left so comments can stay open on the right ---------- */
.notes-panel {
  position: fixed; top: 60px; left: 12px; bottom: 12px; z-index: 15;
  width: 380px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  overflow: hidden;
}
.notes-panel header { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); }
.notes-panel h2 { flex: 1; min-width: 0; margin: 0; display: flex; gap: 6px; align-items: baseline; font-size: 13px; font-weight: 600; white-space: nowrap; }
.notes-panel h2 .frame { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-weight: 400; }
.notes-panel .md { flex: 1; overflow: auto; padding: 4px 16px 16px; touch-action: pan-y; overscroll-behavior: contain; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.notes-panel .md .notes-empty { color: var(--muted); }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 18px 0 6px; line-height: 1.3; }
.md h1 { font-size: 18px; } .md h2 { font-size: 15px; } .md h3, .md h4, .md h5, .md h6 { font-size: 13.5px; }
.md h4, .md h5, .md h6 { color: var(--muted); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 8px 0; }
.md ul, .md ol { padding-left: 20px; }
.md li.task { list-style: none; margin-left: -20px; }
.md li.task input { margin: 0 4px 0 0; vertical-align: -1px; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md a.ref { border-bottom: 1px dashed currentColor; }
.md a.ref:hover { text-decoration: none; background: var(--accent-soft); }
.md code { font: 0.92em var(--mono); background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.md pre { background: var(--panel-2); padding: 8px 10px; border-radius: 8px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md table { border-collapse: collapse; display: block; overflow: auto; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel-2); }
.notes-panel form { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 8px; gap: 8px; }
.notes-panel textarea {
  flex: 1; width: 100%; resize: none; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); font: 12.5px/1.55 var(--mono); color: inherit; tab-size: 2;
}
.notes-panel textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.notes-panel .row { display: flex; align-items: center; gap: 6px; }
.notes-panel .hint { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes-panel .banner { padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); font-size: 12.5px; }
.notes-panel .banner .btn { height: 24px; padding: 0 8px; margin-top: 4px; }
.notes-panel .by { padding: 6px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-panel .by:empty { display: none; }

.thread-pop {
  position: fixed; left: 0; top: 0; z-index: 25;
  width: 320px; max-height: min(520px, calc(100dvh - 80px));
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 32px rgb(0 0 0 / 0.25);
}
.thread-pop .head { display: flex; align-items: center; gap: 2px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); }
.thread-pop .head .where { flex: 1; min-width: 0; }
.thread-pop .head .btn { height: 26px; padding: 0 8px; }
.thread-pop .head [data-act="status"] { color: var(--accent); }
.thread-pop .items { list-style: none; margin: 0; padding: 4px 0; overflow: auto; touch-action: pan-y; overscroll-behavior: contain; }
.thread-pop .items:empty { display: none; }
.thread-pop .items li { display: flex; gap: 10px; padding: 8px 12px; }
.thread-pop .items .body { min-width: 0; flex: 1; }
.thread-pop .items p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.thread-pop .items .note { color: var(--muted); font-size: 12px; }
.thread-pop .tag { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 0 5px; border-radius: 4px; }
.thread-pop .own { display: none; gap: 6px; }
.thread-pop li:hover .own, .thread-pop li:focus-within .own { display: inline-flex; }
.thread-pop .own button, .thread-pop .as button { border: 0; background: none; padding: 0; color: var(--muted); font-size: 12px; cursor: pointer; }
.thread-pop .own button:hover, .thread-pop .as button:hover { color: var(--accent); }
.thread-pop form { padding: 8px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.thread-pop textarea {
  width: 100%; resize: none; min-height: 40px; max-height: 160px; field-sizing: content;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font: inherit; color: inherit;
}
.thread-pop textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.thread-pop .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.thread-pop .as { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.commenting .toast { bottom: calc(var(--dock) + 20px); }

/* the bar is full: secondary keycaps go first, then all of them (tooltips still name every key) */
@media (max-width: 1519px) {
  .bar kbd.k2 { display: none !important; }
}
@media (max-width: 1379px) {
  .bar kbd { display: none !important; }
}
@media (max-width: 1180px) {
  .hide-lg { display: none !important; }
}
@media (max-width: 1100px) {
  .hide-md { display: none !important; }
}
@media (max-width: 820px) {
  .not-phone { display: none !important; }
}
/* the dock holds more tools than a 375px phone has room for at full padding */
@media (max-width: 430px) {
  nav.tools .btn { padding: 0 6px; }
  .tools .stepper .btn { padding: 0 4px; }
  .tools .sep { margin: 0 1px; }
}
@media (min-width: 821px) {
  .phone-only { display: none !important; }
}

/* ---------- phones: identity on top, tools in a dock at the thumb, view settings in a sheet ---------- */
@media (max-width: 820px) {
  :root { --dock: calc(64px + env(safe-area-inset-bottom)); }
  .bar {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    right: calc(8px + env(safe-area-inset-right));
  }
  .bar, .tools, .view-sheet, .pick-bar { touch-action: none; }
  .bar .btn { height: 36px; }
  .file-name { width: auto; }

  .tools {
    position: fixed;
    left: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom));
    translate: -50% 0;
    max-width: calc(100vw - 16px);
  }
  .tools .btn { height: 40px; padding: 0 11px; }
  .tools .btn .badge { margin-left: -2px; }
  .stepper { display: flex; align-items: center; }
  .stepper .btn { padding: 0 9px; font-size: 17px; }
  .stepper .count { font-size: 13px; min-width: 4.5ch; justify-content: center; padding: 0 2px; font-variant-numeric: tabular-nums; }
  .tools .btn:disabled { opacity: 0.35; }
  .tools .btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }

  .view-sheet {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--dock) + 8px);
    max-width: 420px;
    margin: 0 auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  }
  body:not(.view-open) .view-sheet { display: none; }
  .view-sheet .group { padding: 0; border: 0; box-shadow: none; background: none; }
  .view-sheet .view { flex: 1 1 100%; flex-wrap: wrap; gap: 6px; }
  .view-sheet .view .sep { display: none; }
  .view-sheet .view [data-theme-mode] { flex: 1; justify-content: center; background: var(--panel-2); }
  .view-sheet .view [data-theme-mode][aria-pressed="true"] { background: var(--accent-soft); }
  .view-sheet #deviceSel { flex: 1 1 100%; border: 1px solid var(--line); }
  .view-sheet #chromeBtn, .view-sheet #fullBtn { flex: 1; justify-content: center; border: 1px solid var(--line); }
  .view-sheet .group:last-child { margin-left: auto; }

  .pop { top: calc(56px + env(safe-area-inset-top)); left: 8px; right: 8px; width: auto; max-height: calc(100dvh - var(--dock) - 72px); overflow: auto; touch-action: pan-y; }

  .pick-bar {
    left: 8px;
    right: 8px;
    bottom: calc(var(--dock) + 8px);
    transform: none;
    max-width: 420px;
    margin: 0 auto;
    gap: 8px;
    padding: 4px 4px 4px 14px;
    border-radius: 14px;
    min-height: 48px;
  }
  .pick-bar span:nth-of-type(n+3) { display: none; }
  .pick-bar .btn { height: 38px; padding: 0 10px; }
  .pick-bar .btn[aria-pressed="true"] { color: var(--accent); }
  body.picking .toast { bottom: calc(var(--dock) + 68px); }

  .comments-panel { top: auto; left: 8px; right: 8px; bottom: calc(var(--dock) + 8px); width: auto; max-width: 420px; margin: 0 auto; max-height: 38dvh; border-radius: 14px; }
  .thread-pop {
    left: 8px; right: 8px; top: auto; bottom: calc(var(--dock) + 8px); width: auto; max-width: 420px; margin: 0 auto;
    transform: none !important; max-height: calc(100dvh - var(--dock) - 80px); border-radius: 14px;
  }
  .thread-pop textarea { font-size: 16px; }
  .notes-panel { top: auto; left: 8px; right: 8px; bottom: calc(var(--dock) + 8px); width: auto; max-width: 420px; margin: 0 auto; height: 50dvh; border-radius: 14px; }
  .notes-panel textarea { font-size: 16px; }
  body.commenting .notes-panel { display: none; }
  .thread-pop .own { display: inline-flex; }
  .threads button { padding: 10px 8px; }
}

/* ---------- touch: no hover, so show what hover would on the selected frame ---------- */
@media (pointer: coarse) {
  /* Move: frames don't take touches, so one finger pans and two pinch anywhere */
  body:not(.picking, .commenting) .screen iframe { pointer-events: none; }
  .frame:not(.selected) .resize { display: none; }
  .frame.selected .resize { opacity: 1; }
  .frame-label kbd, .frame-actions kbd, .menu .item kbd, .thread-pop kbd, .comments-panel kbd, .notes-panel kbd { display: none !important; }
}
