:root {
  --bg: #05080c;
  --hud: rgba(10, 14, 20, 0.92);
  --line: #243246;
  --accent: #3dffa8;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --tile: #121a26;
  /* Idle guide: outline only. Snappable uses the former low-opacity fill. */
  --guide: rgba(61, 255, 168, 0.18);
  --guide-outline: rgba(61, 255, 168, 0.45);
  --danger: #ff5c7a;
  --hud-h: 52px;
  --board-dock-h: 28vh;
  --board-dock-visible: 3;
  --ui-scale: 1;
  --touch-min: 36px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}

#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--hud-h);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 12px; gap: 10px;
  background: var(--hud); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 10px;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
}
.ghost-btn:hover { color: var(--accent); border-color: rgba(61, 255, 168, 0.4); }

/* CLOUD vs LOCAL — always visible in top bar (not a fleeting toast) */
.hud-mode {
  display: inline-flex;
  align-items: center;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  user-select: none;
  flex-shrink: 0;
}
.hud-mode.cloud {
  color: #04140c;
  background: var(--accent);
  border-color: rgba(61, 255, 168, 0.9);
  box-shadow: 0 0 12px rgba(61, 255, 168, 0.35);
}
.hud-mode.local {
  color: #ffc07a;
  border-color: rgba(255, 180, 80, 0.45);
  background: rgba(255, 160, 60, 0.12);
}
.hud-user-mode-line {
  padding: 6px 12px 10px;
  font-size: 0.78rem;
  color: var(--muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  white-space: pre-line;
  line-height: 1.35;
}

/* Account whoami — left of clock */
.hud-user-wrap {
  position: relative;
  flex-shrink: 0;
}
.hud-user-wrap.hidden { display: none !important; }
.hud-user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(61, 255, 168, 0.35);
  background: rgba(61, 255, 168, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  font-weight: 700;
  cursor: pointer;
  min-height: 38px;
  max-width: min(240px, 28vw);
}
.hud-user-btn:hover {
  border-color: rgba(61, 255, 168, 0.7);
  background: rgba(61, 255, 168, 0.14);
}
.hud-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #0a1018;
  color: var(--accent);
  font-size: 0.85rem;
  border: 1px solid rgba(61, 255, 168, 0.35);
}
.hud-user-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  color: var(--accent);
}
.hud-user-caret {
  color: var(--muted);
  font-size: 0.75rem;
}
.hud-user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(10, 14, 20, 0.98);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hud-user-menu.hidden { display: none !important; }
.hud-user-who {
  padding: 10px 12px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: pre-line;
  line-height: 1.35;
}
.hud-user-menu button {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 12px;
  font-weight: 650;
  font-size: 0.95rem;
  cursor: pointer;
}
.hud-user-menu button:hover {
  background: rgba(61, 255, 168, 0.1);
  color: var(--accent);
}
.hud-user-menu button.danger-item {
  color: var(--danger);
}
.hud-user-menu button.danger-item:hover {
  background: rgba(255, 92, 122, 0.12);
  color: #ff8aa0;
}
#clock {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 5.5ch;
}

/* ---- Device form factors (set by cloud/device-ui.js) ---- */
body.form-phone #hud {
  padding: 0 10px;
}
body.form-phone .hud-brand {
  font-size: 1rem;
  letter-spacing: 0.1em;
  padding: 8px 10px;
}
body.form-phone .hud-user-label {
  max-width: 72px;
}
body.form-phone .tile-actions button,
body.form-tablet .tile-actions button {
  width: max(40px, var(--touch-min));
  height: max(40px, var(--touch-min));
}
body.form-phone .tile-close-fab,
body.form-tablet .tile-close-fab {
  width: max(36px, calc(var(--touch-min) - 4px));
  height: max(36px, calc(var(--touch-min) - 4px));
  opacity: 0.85;
}
body.form-phone .tile-activate-corner,
body.form-tablet .tile-activate-corner {
  width: max(44px, var(--touch-min));
  height: max(44px, var(--touch-min));
  opacity: 0.75;
}
body.form-phone .board-dock-toggle {
  /* chevron already large via prefs; bump default feel */
  min-width: 56px;
  min-height: 56px;
}
body.form-tablet .hud-brand {
  font-size: 1.08rem;
}
/* Fullscreen chip */
.kanvus-fs-btn {
  position: fixed;
  z-index: 140;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border: 1px solid rgba(61, 255, 168, 0.45);
  background: rgba(6, 10, 16, 0.92);
  color: var(--accent);
  border-radius: 999px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
  min-height: var(--touch-min);
  transition: opacity 0.3s ease, transform 0.2s ease;
}
.kanvus-fs-btn.fs-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}
.kanvus-fs-btn.fs-soft {
  opacity: 0.55;
}
body.form-desktop .kanvus-fs-btn {
  display: none;
}
/* Safe areas for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  body.form-phone #hud {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--hud-h) + env(safe-area-inset-top, 0px));
  }
  body.form-phone #canvas {
    top: calc(var(--hud-h) + env(safe-area-inset-top, 0px));
  }
}
.hud-brand {
  letter-spacing: 0.14em;
  color: var(--accent);
  font-size: 1.12rem;
  font-weight: 800;
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 10px;
  margin: -4px -2px;
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.hud-brand:hover,
.hud-brand:focus-visible {
  background: rgba(61, 255, 168, 0.12);
  border-color: rgba(61, 255, 168, 0.35);
  outline: none;
}
.hud-brand:active {
  transform: scale(0.97);
  background: rgba(61, 255, 168, 0.18);
}
.hud-build {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #04140c;
  border: 1px solid rgba(61, 255, 168, 0.85);
  background: var(--accent);
  border-radius: 6px;
  padding: 4px 9px;
  flex-shrink: 0;
  user-select: text;
}
.hud-custom-items {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0;
}
#hud button, .hud-item, .hud-add {
  background: #0f1620; color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: 0.85rem; min-height: 36px;
  touch-action: manipulation;
}
#hud button.danger { border-color: rgba(255,92,122,0.5); color: var(--danger); }
#hud button:active, .hud-item:active, .hud-add:active { transform: scale(0.97); }
.hud-item {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 160px;
}
.hud-item-icon { font-size: 1rem; line-height: 1; }
.hud-item-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 110px;
}
.hud-add {
  border-style: dashed;
  color: var(--accent);
  min-width: 40px;
  padding: 8px 10px;
  font-size: 1.15rem;
  line-height: 1;
}

#canvas {
  position: fixed;
  top: var(--hud-h); left: 0; right: 0; bottom: 0;
  overflow: hidden;
  background: #000;
  touch-action: none; /* we own pan/zoom on the board */
}
/* Logical board world — pan/zoom via transform (UI chrome stays fixed) */
#canvas-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
  z-index: 1;
}
#canvas-bg, .canvas-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: #000;
}
/*
 * Viewport zoom / follow — right edge, ABOVE board-dock chevron.
 * Never centered over the dock.
 */
#viewport-ui {
  position: absolute;
  z-index: 30;
  right: max(10px, env(safe-area-inset-right, 0px));
  /* Clear board-dock chevron (~bottom center) and FS chip */
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  top: auto;
  left: auto;
  transform: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 18px;
  background: rgba(6, 10, 16, 0.92);
  border: 1px solid rgba(61, 255, 168, 0.32);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  touch-action: manipulation;
}
#viewport-ui .vp-slider-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 140px;
  justify-content: center;
}
#viewport-ui .vp-zoom-mark {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  line-height: 1;
  user-select: none;
}
#viewport-zoom-slider {
  /* Vertical fluid zoom */
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: slider-vertical;
  width: 28px;
  height: 120px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  accent-color: var(--accent);
}
#viewport-zoom-slider::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #04140c;
  box-shadow: 0 0 10px rgba(61, 255, 168, 0.45);
}
#viewport-zoom-slider::-webkit-slider-runnable-track {
  width: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
}
#viewport-ui button {
  border: 0;
  background: #0f1620;
  color: var(--accent);
  font-weight: 800;
  min-width: 40px;
  min-height: 40px;
  border-radius: 12px;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 8px;
}
#viewport-ui button.vp-fit {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text);
  min-width: 44px;
  padding: 6px 8px;
}
#viewport-ui button.vp-follow {
  font-size: 1.15rem;
  color: var(--muted);
}
#viewport-ui button.vp-follow.on {
  color: #04140c;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(61, 255, 168, 0.4);
}
#viewport-ui button:active {
  transform: scale(0.96);
}
body.form-desktop #viewport-ui {
  opacity: 0.78;
}
body.form-desktop #viewport-ui:hover {
  opacity: 1;
}
/* Board camera chrome only when scale is allowed (mobile auto / pref on) */
body.canvas-scale-off #viewport-ui {
  display: none !important;
}
body.form-phone #viewport-ui .vp-slider-wrap {
  height: 160px;
}
body.form-phone #viewport-zoom-slider {
  height: 140px;
}

/* Ultrawide / height-locked world: minimap strip (total canvas + viewable box) */
#canvas-minimap {
  position: absolute;
  z-index: 28;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(420px, 56vw);
  height: 28px;
  padding: 4px;
  border-radius: 10px;
  background: rgba(6, 10, 16, 0.88);
  border: 1px solid rgba(61, 255, 168, 0.28);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
  display: none;
  pointer-events: auto;
  touch-action: none;
}
#canvas-minimap.visible {
  display: block;
}
#canvas-minimap .mm-track {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  cursor: grab;
}
#canvas-minimap .mm-view {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  min-width: 12%;
  border-radius: 5px;
  background: rgba(61, 255, 168, 0.35);
  border: 1px solid rgba(61, 255, 168, 0.7);
  box-shadow: 0 0 10px rgba(61, 255, 168, 0.25);
  pointer-events: none;
}

#guides, #tiles { z-index: 1; }
#tiles { z-index: 2; }

#guides, #tiles { position: absolute; inset: 0; }
#guides {
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.42s ease, visibility 0.42s ease;
}
#guides.visible {
  opacity: 1;
  visibility: visible;
}

.guide {
  position: absolute;
  /* Thin outline only until snappable */
  border: 1.5px solid var(--guide-outline);
  background: transparent;
  border-radius: 8px;
  transition:
    background 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    opacity 0.42s ease;
  opacity: 0.95;
  box-shadow: none;
}
.guide.hot,
.guide.snappable {
  /* Former low-opacity fill = snappable indicator */
  background: var(--guide);
  border-color: var(--accent);
  border-style: solid;
  box-shadow: inset 0 0 0 1px rgba(61, 255, 168, 0.2);
}
.guide-label {
  position: absolute; top: 6px; left: 8px;
  font-size: 0.7rem; color: var(--muted); letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
}
.guide.hot .guide-label,
.guide.snappable .guide-label {
  color: var(--accent);
  opacity: 1;
}
.tile.just-snapped {
  box-shadow: 0 0 0 2px rgba(61, 255, 168, 0.65), 0 12px 40px rgba(0,0,0,0.35);
  transition: box-shadow 0.3s ease;
}
.tile.activated {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px rgba(61, 255, 168, 0.75),
    0 0 24px rgba(61, 255, 168, 0.2),
    0 12px 40px rgba(0,0,0,0.35);
  /* z-index comes from JS (last interacted tile) — do not force a fixed stack */
}
/* While activated: content cannot be used; full surface is for move/scale */
.tile.activated .tile-body {
  pointer-events: none;
  touch-action: none;
  user-select: none;
}
.tile.activated .tile-body iframe,
.tile.activated .tile-body video,
.tile.activated .tile-body input,
.tile.activated .tile-body a {
  pointer-events: none !important;
}
.tile-interact-layer {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  touch-action: none;
  cursor: grab;
  background: transparent;
}
.tile.activated .tile-interact-layer {
  display: block;
  /* Desktop: wheel scales; middle-click deactivates; drag moves */
  cursor: grab;
}
.tile.activated .tile-interact-layer:active {
  cursor: grabbing;
}
.tile.activated .tile-resize {
  z-index: 20;
  opacity: 1;
  pointer-events: auto;
}
.tile.locked-tile {
  pointer-events: auto;
}

.tile {
  position: absolute;
  display: block;
  background: linear-gradient(180deg, #172231, var(--tile));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  overflow: hidden;
  min-width: 80px; min-height: 60px;
  touch-action: manipulation;
}
.tile.dragging {
  opacity: 0.95;
  /* z-index set inline via bringTileToFront — avoid !important fights */
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.tile.snapped { border-color: rgba(61,255,168,0.55); }

/* Content fills tile; header overlays on top when open */
.tile-body {
  position: absolute;
  inset: 0;
  height: 100% !important;
  min-height: 0;
  overflow: auto;
  font-size: 0.88rem;
  color: #c9d7e8;
  touch-action: pan-y;
  user-select: text;
  z-index: 1;
  background: inherit;
}
.tile-body.padded {
  padding: 10px 12px;
}

/* Header bar: overlaps content; rolls out from top-right → top-left */
.tile-chrome {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 52px 6px 10px; /* leave room for activate corner (= header height) */
  min-height: 44px;
  background: rgba(6, 10, 16, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  cursor: grab;
  transform-origin: right center;
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.28s ease;
}
.tile.header-open .tile-chrome,
.tile.activated .tile-chrome {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.tile.chrome-hidden:not(.activated) .tile-chrome {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}
.tile-chrome:active { cursor: grabbing; }

/*
 * Upper-right activate — same height as tile header bar (44px).
 * Always hittable; faintly visible so the hit zone is discoverable.
 */
.tile-activate-corner {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 20;
  width: 44px;
  height: 44px;
  border: 0;
  padding: 0;
  border-radius: 0 14px 0 10px;
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
  background:
    linear-gradient(
      225deg,
      rgba(61, 255, 168, 0.7) 0%,
      rgba(61, 255, 168, 0.7) 48%,
      transparent 49%
    );
  box-shadow: none;
  opacity: 0.28;
  transition: opacity 0.18s ease, filter 0.12s ease;
}
.tile:hover .tile-activate-corner,
.tile.activated .tile-activate-corner,
.tile.corners-visible .tile-activate-corner {
  opacity: 0.95;
}
.tile-activate-corner:active {
  filter: brightness(1.2);
  opacity: 1;
}
.tile-activate-corner.active {
  background:
    linear-gradient(225deg, var(--accent) 0%, var(--accent) 48%, transparent 49%);
  box-shadow: 0 0 14px rgba(61, 255, 168, 0.5);
  opacity: 1;
}
/* Always-hittable remove control — LEFT so it never sits on the activate corner */
.tile-close-fab {
  position: absolute;
  top: 6px;
  left: 6px;
  right: auto;
  z-index: 24;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 92, 122, 0.45);
  border-radius: 10px;
  background: rgba(8, 10, 14, 0.82);
  color: #ff8aa0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  opacity: 0.35;
  transition: opacity 0.15s ease, background 0.12s ease;
}
.tile:hover .tile-close-fab,
.tile.activated .tile-close-fab,
.tile.corners-visible .tile-close-fab {
  opacity: 1;
}
.tile-close-fab:hover,
.tile-close-fab:active {
  opacity: 1;
  background: rgba(255, 92, 122, 0.22);
  color: #ffc0cb;
}

.tile-title {
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; flex: 1;
}
.tile-actions {
  display: flex;
  gap: 4px;
  position: relative;
  z-index: 22;
  pointer-events: auto;
  flex-shrink: 0;
}
.tile-actions button {
  border: 0; background: rgba(0,0,0,0.35); color: var(--text);
  font-size: 1.05rem; width: 40px; height: 40px; border-radius: 10px;
  pointer-events: auto;
  touch-action: manipulation;
}
.tile-actions button[data-act="close"] {
  color: #ff8fa3;
  background: rgba(80, 20, 30, 0.55);
}
.tile-actions button[data-act="settings"] {
  color: #c9d7e8;
}
.tile-actions button[data-act="markup"] {
  color: #ff9ad5;
}
.tile-actions button[data-act="markup"].active {
  color: #04140c;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(61, 255, 168, 0.7);
}
.tile-actions button[data-act="snapshot"] {
  color: #9ecbff;
}
.tile-actions button[data-act="osk"] {
  color: #c9b0ff;
}
.tile-actions button[data-act="osk"].active {
  color: #04140c;
  background: #c9b0ff;
  box-shadow: 0 0 0 1px rgba(201, 176, 255, 0.7);
}
.tile-actions button.hidden {
  display: none !important;
}
.tile-actions button:active { background: rgba(255,255,255,0.12); color: var(--text); }

/* Markup / annotation overlay */
.tile-markup-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
  display: block;
}
.tile.markup-mode .tile-markup-canvas {
  pointer-events: auto;
  cursor: crosshair;
}
.tile.markup-mode .tile-interact-layer {
  display: none !important;
}
.tile-markup-toolbar {
  position: absolute;
  /* Sit just under the header so tools are obvious while markup is on */
  top: 48px;
  left: 8px;
  right: 8px;
  bottom: auto;
  z-index: 18;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(6, 10, 16, 0.96);
  border: 1px solid rgba(61, 255, 168, 0.45);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  touch-action: manipulation;
}
.tile-markup-toolbar.hidden {
  display: none !important;
}
.tile.markup-mode .tile-markup-toolbar:not(.hidden) {
  display: flex !important;
}
.tile-markup-toolbar .mk-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.tile-markup-toolbar .mk-swatch {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: var(--mk, #fff);
  padding: 0;
  cursor: pointer;
}
.tile-markup-toolbar .mk-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(61, 255, 168, 0.75);
}
.tile-markup-toolbar .mk-size {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tile-markup-toolbar .mk-size span {
  display: block;
  border-radius: 999px;
  background: var(--text);
}
.tile-markup-toolbar .mk-size.active {
  border-color: var(--accent);
  background: rgba(61, 255, 168, 0.12);
}
.tile-markup-toolbar .mk-tools button {
  min-height: 40px;
  min-width: 40px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  font-weight: 700;
  /* Larger glyphs inside the same button chrome */
  font-size: 1.35rem;
  line-height: 1;
}
.tile-markup-toolbar .mk-tools button[data-mk-act="done"] {
  border-color: rgba(61, 255, 168, 0.45);
  color: var(--accent);
  font-size: 0.9rem; /* text label, not icon */
}
.tile-markup-toolbar .mk-tool {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  font-weight: 800;
  /* Tool icons (✎ ▭ ◯ ➔ …) — keep button size modest, icon large */
  font-size: 1.55rem;
  line-height: 1;
}
.tile-markup-toolbar .mk-tool.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(61, 255, 168, 0.12);
}
.tile-markup-toolbar .mk-fill {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
}
.tile-markup-toolbar .mk-fill.active {
  border-color: rgba(255, 176, 32, 0.7);
  color: #ffb020;
}
.markup-text-editor {
  position: fixed;
  z-index: 200;
  margin: 0;
  padding: 2px 6px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: rgba(6, 10, 16, 0.96);
  color: var(--text);
  font-weight: 600;
  font-family: "Segoe UI", system-ui, sans-serif;
  resize: none;
  min-width: 48px;
  min-height: 24px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  outline: none;
  overflow: hidden;
  white-space: pre;
  field-sizing: content; /* when supported: grow with text */
  line-height: 1.05;
  box-sizing: border-box;
}

/* Full-tile note editor */
.note-field,
textarea.note-field {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: 1rem/1.45 "Segoe UI", system-ui, sans-serif;
  outline: none;
  box-sizing: border-box;
  overflow: auto;
  touch-action: pan-y;
}
.note-field::placeholder {
  color: var(--muted);
  opacity: 0.85;
}
.tile.activated .note-field {
  pointer-events: none;
}

/* Standalone text tile — transparent always; box hugs content (like markup text) */
.tile.tile-text {
  background: transparent !important;
  border-color: transparent;
  box-shadow: none;
  min-width: 0 !important;
  min-height: 0 !important;
  border-radius: 6px;
  /* No container-query font scaling — fontPx drives size; frame follows text */
}
.tile.tile-text .tile-body {
  background: transparent !important;
  padding: 0 !important;
  overflow: hidden !important;
}
.tile.tile-text.padded .tile-body {
  padding: 0 !important;
}
/* Activated: outline only — NO header bar, still fully transparent */
.tile.tile-text.activated,
.tile.tile-text.header-open {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px rgba(61, 255, 168, 0.75),
    0 0 18px rgba(61, 255, 168, 0.18);
  background: transparent !important;
}
/* Never show the slide-out title/actions bar on text tiles */
.tile.tile-text .tile-chrome,
.tile.tile-text.activated .tile-chrome,
.tile.tile-text.header-open .tile-chrome {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
/* Exactly one close control (fab) — left; activate stays top-right */
.tile.tile-text .tile-close-fab {
  left: 6px;
  right: auto;
  top: 6px;
  opacity: 0.55;
}
.tile.tile-text:hover .tile-close-fab,
.tile.tile-text.activated .tile-close-fab {
  opacity: 1;
}
.tile.tile-text .tile-title {
  display: none;
}
.tile.tile-text .tile-actions {
  display: none !important;
}
/* Hide markup canvas/toolbar on text tiles (no annotations) */
.tile.tile-text .tile-markup-canvas,
.tile.tile-text .tile-markup-toolbar {
  display: none !important;
  pointer-events: none !important;
}
.text-field {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 6px 10px;
  border: 0;
  resize: none;
  background: transparent !important;
  color: var(--text);
  /* Explicit font from --text-tile-fs (tile.fontPx); box is measured to fit */
  font-size: var(--text-tile-fs, 28px);
  line-height: 1.2;
  font-weight: 700;
  font-family: "Segoe UI", system-ui, sans-serif;
  outline: none;
  box-sizing: border-box;
  overflow: hidden;
  /* pre: width = longest line (matches measure). Newlines still wrap height. */
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  touch-action: pan-y;
  /* No scrollbars — tile grows with content */
  scrollbar-width: none;
}
.text-field::-webkit-scrollbar {
  display: none;
}
.text-field::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
.tile.activated .text-field {
  pointer-events: none;
}
.tile.tile-text:not(.activated) .text-field {
  pointer-events: auto;
}

/* Snapshot / image tiles */
.image-tile {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.image-tile-img,
.image-tile img {
  width: 100%;
  height: 100%;
  /* Frame is locked to asset aspect — fill the border without letterboxing */
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.tile.lock-aspect .tile-resize {
  /* Visual cue: aspect-locked resize (image/snapshot tiles) */
  box-shadow: inset 0 0 0 1px rgba(61, 255, 168, 0.35);
}
.tile-settings {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(6, 10, 16, 0.94);
  backdrop-filter: blur(8px);
  overflow: auto;
  pointer-events: auto;
  touch-action: manipulation;
}
.tile-settings.hidden { display: none !important; }
.tile-settings-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 16px;
  min-height: 100%;
}
.tile-settings-inner header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tile-settings-inner header strong {
  color: var(--accent);
  letter-spacing: 0.04em;
  font-size: 0.85rem;
}
.tile-settings-inner label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}
.tile-settings-inner label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.85rem;
}
.tile-settings-inner input[type="text"],
.tile-settings-inner input[type="url"],
.tile-settings-inner select {
  background: #0a1018;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
}
.tile-settings-inner .muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.tile-settings-inner .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.tile-settings-inner button {
  background: #0f1620;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  min-height: 40px;
  touch-action: manipulation;
}
.tile-settings-inner button.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.tile-settings-inner header button {
  width: 40px;
  height: 40px;
  padding: 0;
}
.tile-body pre {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem;
}
/*
 * Lower-right resize — only exists while tile is activated (or pref forces corners).
 * No hover-only ghost when inactive — that was showing a corner users couldn't use.
 */
.tile-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 48%, rgba(61, 255, 168, 0.55) 48%);
  border-bottom-right-radius: 14px;
  touch-action: none;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.tile.activated .tile-resize,
.tile.corners-visible .tile-resize {
  opacity: 1;
  pointer-events: auto;
}

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 200; padding: 12px 18px; border-radius: 12px;
  background: rgba(16,24,36,0.95); border: 1px solid var(--accent);
  font-weight: 600;
}
#toast.hidden { display: none; }

.usage-bar {
  height: 12px; border-radius: 999px; background: #0a1018;
  border: 1px solid var(--line); overflow: hidden; margin-top: 8px;
}
.usage-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #3dffa8, #ffd54f 55%, #ff3b5c);
  transition: width 0.4s ease;
}
.pct { font-size: 2rem; font-weight: 700; color: var(--accent); }
.badge {
  display: inline-block; font-size: 0.7rem; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); margin-left: 6px;
}
.badge.ok { color: var(--accent); }
.badge.bad { color: var(--danger); }

/* ---- Hex radial menus (multi-instance) ---- */
#hexmenus {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
}
.hexmenu {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hexmenu-svg {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  overflow: visible;
}
.hexmenu .hex {
  pointer-events: auto;
  touch-action: manipulation;
  transition: transform 0.12s ease;
}
.hexmenu .hex polygon {
  fill: rgba(18, 28, 42, 0.94);
  stroke: rgba(61, 255, 168, 0.55);
  stroke-width: 2;
  pointer-events: all;
  /* Larger invisible stroke expands touch target */
  paint-order: stroke fill;
}
.hexmenu .hex.center polygon {
  fill: rgba(25, 40, 58, 0.96);
  stroke: var(--accent);
  stroke-width: 2.5;
}
.hexmenu .hex.config polygon {
  stroke: #ffd54f;
}
.hexmenu .hex:active {
  transform: scale(0.94);
}
.hexmenu .hex:active polygon {
  fill: rgba(61, 255, 168, 0.18);
}
.hex-label {
  fill: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 600;
  pointer-events: none;
  opacity: 0.95;
  letter-spacing: 0.02em;
}
.hexmenu .hex.mono .hex-label {
  fill: var(--accent);
  font-weight: 700;
  letter-spacing: 0.06em;
}
.hexmenu .hex.config .hex-label {
  fill: #ffd54f;
}
.hexmenu .hex.center .hex-label {
  fill: var(--accent);
}
.hexmenu .hex.empty-slot polygon {
  fill: rgba(18, 28, 42, 0.35) !important;
  stroke: rgba(61, 255, 168, 0.35) !important;
  stroke-width: 1.5 !important;
  stroke-dasharray: 4 3;
}
.hex-hit.empty {
  opacity: 0.9;
}
.hexmenu .hex.center polygon {
  fill: rgba(25, 40, 58, 0.96);
}

/* Fixed left configure dock — always above canvas tiles when open */
.config-dock {
  position: fixed;
  top: var(--hud-h);
  left: 0;
  bottom: 0;
  z-index: 10000;
  width: 420px;
  max-width: 90vw;
  background: rgba(8, 12, 18, 0.98);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 40px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}
/* While configure is open, canvas tiles cannot steal pointers / wheel scale */
body.config-open #canvas,
body.config-open #tiles,
body.config-open #guides {
  pointer-events: none !important;
}
body.config-open .config-dock {
  pointer-events: auto !important;
}
.config-dock.hidden {
  display: none !important;
}
.config-dock-inner {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.config-dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 4px;
  flex-shrink: 0;
}
.config-dock-header strong {
  color: var(--accent);
  letter-spacing: 0.04em;
}
.config-dock-header button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
}

/* config editor (tabbed) */
.config-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 0;
  padding: 0 12px 16px;
}
.config-editor.tabs {
  gap: 0;
}
.config-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  flex-shrink: 0;
}
.config-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  min-height: 40px;
}
.config-tab.active {
  color: var(--accent);
  border-color: rgba(61, 255, 168, 0.4);
  background: rgba(61, 255, 168, 0.08);
}
.config-panel {
  display: none;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.config-panel.active {
  display: flex;
}
.config-editor textarea {
  flex: 1;
  min-height: 160px;
  width: 100%;
  background: #0a1018;
  color: #c9d7e8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.75rem;
  resize: none;
}
.config-editor .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.config-editor button {
  background: #0f1620;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  min-height: 40px;
  touch-action: manipulation;
}
.config-editor button.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.cfg-lead {
  margin: 0;
  color: var(--text);
  font-size: 0.85rem;
}
.cfg-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}
.cfg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}
.cfg-field input[type="number"] {
  background: #0a1018;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  max-width: 160px;
}
.cfg-range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cfg-range-row input[type="range"] {
  flex: 1;
}
.cfg-range-row output {
  min-width: 3.2rem;
  color: var(--accent);
  font-weight: 700;
}
.cfg-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.85rem;
}
.cfg-hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 6px 0;
}
.cfg-grid-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(42vh, 320px);
  overflow: auto;
  padding-right: 2px;
}
.cfg-grid-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0a1018;
  font-size: 0.8rem;
}
.cfg-grid-row.active-grid {
  border-color: rgba(61, 255, 168, 0.55);
  background: rgba(61, 255, 168, 0.08);
}
.cfg-grid-row em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.72rem;
}
.cfg-grid-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cfg-grid-meta strong {
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cfg-grid-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.cfg-grid-actions button {
  padding: 6px 10px;
  min-height: 36px;
  font-size: 0.75rem;
}
.cfg-new-grid-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.cfg-new-grid-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}
.cfg-new-grid-row input[type="number"],
.cfg-new-grid-row input[type="text"] {
  background: #0a1018;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  min-height: 40px;
}
.cfg-new-grid-row input[type="number"] {
  width: 3.4rem;
  text-align: center;
}
.cfg-new-grid-row input[type="text"] {
  width: 8.5rem;
  min-width: 0;
}
.cfg-layout-times {
  color: var(--muted);
  font-weight: 700;
}

/* Snap grid editor overlay */
.grid-editor {
  position: fixed;
  inset: 0;
  z-index: 130;
  pointer-events: none;
}
.grid-editor.hidden {
  display: none !important;
}
.grid-editor-toolbar {
  pointer-events: auto;
  position: fixed;
  top: calc(var(--hud-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(10, 14, 20, 0.94);
  border: 1px solid var(--line);
  z-index: 132;
  max-width: 96vw;
}
.grid-editor-toolbar strong {
  color: var(--accent);
  margin-right: 6px;
  font-size: 0.85rem;
}
.grid-editor-toolbar button {
  background: #0f1620;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  min-height: 40px;
  touch-action: manipulation;
}
.grid-editor-toolbar button.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.grid-editor-toolbar label.ge-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.grid-editor-toolbar input[type="text"],
.grid-editor-toolbar input[type="number"] {
  background: #0a1018;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  min-height: 40px;
  font-weight: 600;
}
.grid-editor-toolbar input[type="text"] {
  width: 9.5rem;
  max-width: 28vw;
}
.grid-editor-toolbar input[type="number"] {
  width: 3.2rem;
  text-align: center;
}
.grid-editor-toolbar .ge-times {
  color: var(--muted);
  font-weight: 800;
}
.grid-editor-hint {
  pointer-events: none;
  position: fixed;
  top: calc(var(--hud-h) + 64px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.45);
  color: var(--muted);
  font-size: 0.72rem;
  z-index: 131;
  white-space: nowrap;
  max-width: 96vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-editor-regions {
  position: fixed;
  inset: 0;
  z-index: 131;
  pointer-events: none;
}
.grid-edit-region {
  position: fixed;
  pointer-events: auto;
  border: 2px dashed rgba(61, 255, 168, 0.55);
  background: rgba(61, 255, 168, 0.08);
  border-radius: 10px;
  box-sizing: border-box;
  touch-action: none;
  min-width: 48px;
  min-height: 48px;
}
.grid-edit-region.locked {
  border-style: solid;
  border-color: rgba(61, 255, 168, 0.35);
  background: rgba(61, 255, 168, 0.04);
  cursor: default;
}
.grid-edit-region.unlocked {
  border-color: #ffd54f;
  background: rgba(255, 213, 79, 0.12);
  cursor: grab;
  box-shadow: 0 0 0 1px rgba(255, 213, 79, 0.35);
}
.grid-edit-region.unlocked:active {
  cursor: grabbing;
}
.grid-edit-label {
  position: absolute;
  top: 6px;
  left: 8px;
  right: 40px;
  font-size: 0.72rem;
  color: var(--text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-edit-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: rgba(80, 20, 30, 0.7);
  color: #ff8fa3;
  font-size: 1rem;
  touch-action: manipulation;
}
.grid-edit-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 28px;
  height: 28px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(255, 213, 79, 0.55) 50%);
  border-bottom-right-radius: 8px;
  touch-action: none;
}
.grid-edit-region.locked .grid-edit-resize {
  opacity: 0.35;
  pointer-events: none;
}

.tile-body {
  padding: 0;
  background: #000;
}
.tile-body.padded {
  padding: 10px 12px;
  background: transparent;
}
/* Keep absolute fill even after type-specific padding rules */
.tile > .tile-body {
  position: absolute;
  inset: 0;
  height: 100%;
  z-index: 1;
}

/* Browser tile — dark, collapsible chrome */
.browser-tile.dark {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #000;
  color: #e8eef6;
}
.browser-chrome {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #0a0a0a;
  border-bottom: 1px solid #1a1a1a;
  flex-shrink: 0;
  transition: max-height 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
  max-height: 52px;
  overflow: hidden;
}
.browser-chrome.collapsed {
  max-height: 28px;
  padding: 2px 6px;
}
.browser-chrome.collapsed .browser-url,
.browser-chrome.collapsed .browser-go {
  display: none;
}
.browser-chrome.hidden {
  display: none !important;
}
.browser-chevron {
  width: 28px; height: 28px;
  border: 0; border-radius: 8px;
  background: #141414; color: #3dffa8;
  font-size: 1.1rem; line-height: 1;
  flex-shrink: 0;
}
.browser-url {
  flex: 1;
  min-width: 0;
  background: #111;
  color: #e8eef6;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
}
.browser-go {
  border: 1px solid #2a2a2a;
  background: #141414;
  color: #3dffa8;
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  min-width: 40px;
}
/*
 * Idle content shield: captures middle-click over iframe/video (parent never
 * receives those events from cross-origin frames). Left-click unlocks content.
 */
.tile-content-shield {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: transparent;
  cursor: default;
  touch-action: none;
  pointer-events: auto;
}
.tile.activated .tile-content-shield,
.tile-content-shield.content-live {
  /* Must not intercept touch/click — Docker stream needs direct input */
  pointer-events: none !important;
  touch-action: auto;
}
/* Stream tiles: never leave a full-surface blocker over the remote browser */
.browser-tile[data-stream="1"] > .tile-content-shield.content-live,
.browser-tile[data-stream="1"] .tile-content-shield.content-live {
  pointer-events: none !important;
}

/* Always-available hit strip to reopen address bar (no pop-out escapes) */
.browser-nav-edge {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 14px;
  z-index: 6;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: linear-gradient(
    180deg,
    rgba(61, 255, 168, 0.28) 0%,
    rgba(61, 255, 168, 0.08) 55%,
    transparent 100%
  );
  touch-action: manipulation;
}
.browser-nav-edge.hidden {
  display: none !important;
}
.browser-nav-edge:hover,
.browser-nav-edge:active {
  background: linear-gradient(
    180deg,
    rgba(61, 255, 168, 0.45) 0%,
    rgba(61, 255, 168, 0.12) 60%,
    transparent 100%
  );
}
.tile-actions button[data-act="browser-bar"] {
  color: #9ecbff;
}
.browser-links-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: #0a0a0a;
  border-bottom: 1px solid #1a1a1a;
  flex-shrink: 0;
  min-height: 36px;
}
.browser-links-scroll {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}
.browser-quick-link {
  flex-shrink: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 10px;
  white-space: nowrap;
  touch-action: manipulation;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}
.browser-quick-link:active {
  opacity: 0.7;
}
.browser-chrome.nav-hidden,
.browser-links-bar.nav-hidden {
  display: none !important;
}
.browser-link-add {
  flex-shrink: 0;
  width: 36px;
  height: 32px;
  border: 1px dashed rgba(61,255,168,0.45);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 1.1rem;
  touch-action: manipulation;
}
.browser-stream-badge {
  flex-shrink: 0;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  border: 1px solid rgba(61,255,168,0.35);
  border-radius: 999px;
  padding: 2px 8px;
  opacity: 0.9;
}

/* Floating virtual OSK — tight box around keys; --osk-scale sizes everything */
.kanvus-osk {
  --osk-scale: 1;
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 180;
  width: max-content;
  max-width: 96vw;
  background: rgba(10, 14, 20, 0.97);
  border: 1px solid var(--line);
  border-radius: calc(12px * var(--osk-scale));
  padding: calc(4px * var(--osk-scale)) calc(6px * var(--osk-scale))
    calc(6px * var(--osk-scale));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
}
.kanvus-osk.hidden {
  display: none !important;
}
.kanvus-osk.dragging {
  opacity: 0.95;
  cursor: grabbing;
}
.kanvus-osk-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(6px * var(--osk-scale));
  padding: calc(2px * var(--osk-scale)) calc(2px * var(--osk-scale))
    calc(4px * var(--osk-scale));
  cursor: grab;
  touch-action: none;
}
.kanvus-osk-grip {
  color: var(--muted);
  font-size: calc(0.72rem * var(--osk-scale));
  font-weight: 700;
  letter-spacing: 0.04em;
  flex: 1;
  min-width: 0;
}
.kanvus-osk-size {
  display: inline-flex;
  gap: calc(3px * var(--osk-scale));
}
.kanvus-osk-sz {
  width: calc(28px * var(--osk-scale));
  height: calc(26px * var(--osk-scale));
  border-radius: calc(7px * var(--osk-scale));
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--accent);
  font-weight: 800;
  font-size: calc(0.95rem * var(--osk-scale));
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}
.kanvus-osk-inner {
  display: flex;
  flex-direction: column;
  gap: calc(3px * var(--osk-scale));
  width: max-content;
}
.kanvus-osk-row {
  display: flex;
  justify-content: center;
  gap: calc(3px * var(--osk-scale));
  flex-wrap: nowrap;
  width: max-content;
}
.kanvus-osk-key {
  min-width: calc(30px * var(--osk-scale));
  min-height: calc(36px * var(--osk-scale));
  padding: 0 calc(8px * var(--osk-scale));
  border-radius: calc(7px * var(--osk-scale));
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  font-weight: 600;
  font-size: calc(0.9rem * var(--osk-scale));
  touch-action: manipulation;
  flex: 0 0 auto;
}
.kanvus-osk-key.wide {
  min-width: calc(100px * var(--osk-scale));
}
.kanvus-osk-key.mod {
  color: var(--accent);
}
.kanvus-osk.shift .kanvus-osk-key.mod {
  border-color: var(--accent);
}
.kanvus-osk-hide {
  width: calc(28px * var(--osk-scale));
  height: calc(26px * var(--osk-scale));
  border-radius: calc(7px * var(--osk-scale));
  background: #0f1620;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: calc(1rem * var(--osk-scale));
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
  line-height: 1;
}
.kanvus-osk-resize {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: calc(16px * var(--osk-scale));
  height: calc(16px * var(--osk-scale));
  cursor: nwse-resize;
  touch-action: none;
  background:
    linear-gradient(
      135deg,
      transparent 0 45%,
      rgba(61, 255, 168, 0.55) 46% 54%,
      transparent 55% 70%,
      rgba(61, 255, 168, 0.55) 71% 79%,
      transparent 80%
    );
  border-radius: 2px;
}
.browser-chrome.mini {
  max-height: 36px;
  padding: 4px 6px;
}
.browser-chrome.mini .browser-url,
.browser-chrome.mini .browser-go {
  display: none;
}
.browser-stream-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.82);
  color: #c9d7e8;
  font-size: 0.9rem;
  pointer-events: none;
  text-align: center;
  padding: 16px;
}
.browser-stream-loading.hidden {
  display: none !important;
}
.browser-stream-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(61, 255, 168, 0.2);
  border-top-color: var(--accent);
  animation: kanvus-spin 0.8s linear infinite;
}
@keyframes kanvus-spin {
  to {
    transform: rotate(360deg);
  }
}
.browser-tile {
  position: relative;
}
.browser-fallback {
  position: absolute;
  inset: 40px 12px 12px;
  background: rgba(8,8,8,0.92);
  border: 1px solid #333;
  border-radius: 12px;
  padding: 16px;
  color: #ddd;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  align-items: flex-start;
}
.browser-fallback.hidden { display: none !important; }
.browser-pop-lg, .browser-retry {
  border: 1px solid #3dffa8;
  background: #111;
  color: #3dffa8;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
}
.browser-loadbar {
  width: 100%;
  background: #111;
  flex-shrink: 0;
  overflow: hidden;
}
.browser-loadfill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3dffa8, #5b9dff);
  opacity: 0;
  transition: width 0.2s ease, opacity 0.2s ease;
}
.browser-frame, .doc-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #000;
  min-height: 0;
}
/* Stream browsers: lock iframe edges to the tile body — no empty gutters */
.browser-tile[data-stream="1"] {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #000;
}
.browser-tile[data-stream="1"] .browser-frame {
  flex: 1 1 auto;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  align-self: stretch;
  background: #000;
  /* Fill the tile; stream AR is matched server-side */
  object-fit: fill;
  /* Wall touch must reach Selkies/Firefox inside the iframe */
  touch-action: auto;
  pointer-events: auto;
}
.browser-tile[data-stream="1"]:not(.activated) {
  touch-action: auto;
}
.browser-tile[data-stream="1"] .browser-chrome.nav-hidden + .browser-loadbar,
.browser-tile[data-stream="1"] .browser-loadbar {
  flex-shrink: 0;
}
.browser-tile[data-stream="1"] .browser-stream-loading {
  inset: 0;
}

/* Document / camera / image: content edge-to-edge with the tile frame */
.tile[data-type="document"],
.tile[data-type="camera"],
.tile[data-type="image"] {
  overflow: hidden;
}
.tile[data-type="document"] .tile-body,
.tile[data-type="camera"] .tile-body,
.tile[data-type="image"] .tile-body {
  overflow: hidden !important;
  padding: 0 !important;
  background: #000;
}
.doc-tile,
.doc-tile.dark {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
.doc-tile .doc-frame,
.doc-frame {
  flex: 1 1 auto !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  border: 0 !important;
  display: block;
  background: #000;
  /* Scale with the tile box — iframe viewport tracks the frame */
  align-self: stretch;
}
.doc-picker {
  padding: 12px 14px;
  color: #e8eef6;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  overflow: hidden;
}
.doc-picker-title {
  margin: 0;
  font-size: 0.95rem;
}
.doc-picker-lead {
  margin: 0;
  color: #8b9bb0;
  font-size: 0.78rem;
  line-height: 1.35;
}
.doc-picker-tabs {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.doc-tab {
  flex: 1;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  background: rgba(12, 16, 24, 0.75);
  color: #9aabbf;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.doc-tab.active {
  border-color: rgba(61, 255, 168, 0.45);
  background: rgba(61, 255, 168, 0.12);
  color: #c8ffe4;
}
.doc-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.doc-panel.hidden {
  display: none !important;
}
.doc-cloud-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.doc-refresh {
  border: 1px solid rgba(91, 157, 255, 0.35);
  border-radius: 8px;
  background: rgba(20, 28, 40, 0.9);
  color: #a8c8ff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.doc-cloud-status {
  font-size: 0.72rem;
  color: #6b7c92;
}
.doc-cloud-list {
  flex: 1;
  min-height: 80px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}
.doc-cloud-empty {
  margin: 8px 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  color: #8b9bb0;
  font-size: 0.78rem;
  line-height: 1.4;
}
.doc-cloud-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  background: rgba(8, 12, 18, 0.72);
  color: #e8eef6;
  padding: 8px 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.doc-cloud-item:hover,
.doc-cloud-item:active {
  border-color: rgba(61, 255, 168, 0.4);
  background: rgba(61, 255, 168, 0.08);
}
.doc-cloud-ico {
  font-size: 1.15rem;
  flex-shrink: 0;
  width: 1.5rem;
  text-align: center;
}
.doc-cloud-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.doc-cloud-name {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-cloud-sub {
  font-size: 0.68rem;
  color: #6b7c92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-local-hint {
  margin: 0;
  color: #8b9bb0;
  font-size: 0.78rem;
  line-height: 1.35;
}
.doc-local-panel .file-btn {
  align-self: flex-start;
}

/* ---- 3D model document viewer (STL / OBJ / 3MF / STEP) ---- */
.doc-tile.model-doc {
  background: #0a0e14;
}
.model-host {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #0a0e14;
  touch-action: none;
}
.model-host.hidden {
  display: none !important;
}
.model-host .model-canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
  touch-action: none;
  cursor: grab;
}
.model-host .model-canvas:active {
  cursor: grabbing;
}
.model-status {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 48px;
  z-index: 4;
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(8, 12, 18, 0.82);
  border: 1px solid rgba(91, 157, 255, 0.28);
  color: #c5d0e0;
  font-size: 0.8rem;
  text-align: center;
  pointer-events: none;
}
.model-toolbar {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(6, 10, 16, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: auto;
  touch-action: manipulation;
}
.model-toolbar button {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(61, 255, 168, 0.35);
  border-radius: 8px;
  background: rgba(12, 18, 26, 0.9);
  color: #9dffd0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.model-toolbar button:active {
  background: rgba(61, 255, 168, 0.18);
}
.model-toolbar .model-hint {
  flex: 1;
  min-width: 0;
  font-size: 0.68rem;
  color: #6b7c92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 4px;
}
.tile.activated .model-host,
.tile .model-host {
  /* model receives input when content-live / activated */
}
@media (max-width: 700px) {
  .model-toolbar .model-hint {
    display: none;
  }
}

/* Camera / capture — video fills tile edges */
.camera-tile,
.camera-tile.dark {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}
.camera-tile video,
.tile[data-type="camera"] video {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  border-radius: 0 !important;
  background: #000;
  display: block;
}
.camera-tile .cam-hint,
.tile[data-type="camera"] .cam-hint {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  margin: 0;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #8b9bb0;
  font-size: 0.75rem;
  pointer-events: none;
}
.tile.media-live {
  box-shadow: 0 0 0 2px rgba(91, 157, 255, 0.55), 0 12px 40px rgba(0, 0, 0, 0.35);
}

/* Image tiles edge-to-edge */
.tile[data-type="image"] .image-tile {
  position: absolute;
  inset: 0;
}
.tile[data-type="image"] .image-tile-img,
.tile[data-type="image"] img {
  width: 100% !important;
  height: 100% !important;
  object-fit: fill !important;
}

/* ---- Board dock (footer) ---- */
#board-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
#board-dock > * {
  pointer-events: auto;
}
.board-dock-toggle {
  /* Just the chevron — no box / border / chrome */
  width: var(--board-dock-chevron-w, 72px);
  height: var(--board-dock-chevron-w, 72px);
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  color: var(--accent);
  font-size: var(--board-dock-chevron-font, 42px);
  line-height: 1;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  text-shadow: 0 2px 12px rgba(0,0,0,0.65);
  opacity: 0.9;
}
.board-dock-toggle:active {
  transform: scale(0.94);
  opacity: 1;
}
#board-dock.open .board-dock-toggle {
  opacity: 1;
}
.board-dock-panel {
  width: 100%;
  height: var(--board-dock-h, 28vh);
  max-height: 70vh;
  background: rgba(8, 12, 18, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 40px rgba(0,0,0,0.45);
  backdrop-filter: blur(12px);
  /* no header — just the scroller */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 0.28s ease, opacity 0.28s ease, transform 0.28s ease;
}
.board-dock-panel.hidden {
  display: none !important;
}
.board-dock-scroller {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: thin;
  scrollbar-color: rgba(61,255,168,0.35) transparent;
}
.board-card {
  position: relative;
  flex: 0 0 calc((100% - (var(--board-dock-visible, 3) - 1) * 12px) / var(--board-dock-visible, 3));
  max-width: 420px;
  min-width: 148px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  overflow: hidden;
}
.board-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(61, 255, 168, 0.35);
}
.board-card-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.board-card-main:active {
  transform: scale(0.99);
}
.board-card-gear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0,0,0,0.55);
  color: var(--text);
  font-size: 1.05rem;
  z-index: 2;
  touch-action: manipulation;
}
.board-card-gear:active {
  border-color: var(--accent);
  color: var(--accent);
}
.board-card-preview {
  flex: 1;
  min-height: 88px;
  border-radius: 10px;
  overflow: hidden;
  background: #05080c;
  border: 1px solid #1a2433;
  position: relative;
}
.board-preview-svg,
.board-preview-img {
  width: 100%;
  height: 100%;
  display: block;
  min-height: 88px;
  object-fit: cover;
}
.board-preview-blank {
  width: 100%;
  height: 100%;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: repeating-linear-gradient(
    -45deg,
    #0a1018,
    #0a1018 8px,
    #0d1420 8px,
    #0d1420 16px
  );
}
.board-card-label {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  padding-right: 36px;
}
.board-card-meta {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-card.active .board-card-label {
  color: var(--accent);
}
.board-card-add {
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-style: dashed;
  background: rgba(15, 22, 32, 0.6);
  cursor: pointer;
  touch-action: manipulation;
  min-height: 140px;
}
.board-card-add .board-add-plus {
  font-size: 2rem;
  color: var(--accent);
  line-height: 1;
}
.board-card-add .board-card-label {
  padding-right: 0;
  color: var(--muted);
}
#board-dock.force-open .board-dock-toggle {
  opacity: 0.85;
}

/* Board settings overlay */
.board-settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 160;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
}
.board-settings-overlay.hidden {
  display: none !important;
}
.board-settings-sheet {
  width: 100%;
  max-height: min(86vh, 720px);
  overflow: auto;
  background: #0c121c;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 -16px 48px rgba(0,0,0,0.5);
}
.board-settings-sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.board-settings-sheet header strong {
  color: var(--accent);
  letter-spacing: 0.04em;
}
.board-settings-sheet header button {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  font-size: 1.1rem;
}
.board-settings-sheet label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}
.board-settings-sheet input[type="text"] {
  background: #0a1018;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
}
.board-settings-sheet .muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.board-settings-sheet .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.board-settings-sheet .row button,
.board-settings-sheet .shot-row button {
  background: #0f1620;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  min-height: 44px;
  touch-action: manipulation;
}
.board-settings-sheet .row button.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.grid-pick-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.grid-pick-card {
  flex: 0 0 140px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0a1018;
  color: var(--text);
  font-size: 0.75rem;
  touch-action: manipulation;
}
.grid-pick-card.active {
  border-color: var(--accent);
  color: var(--accent);
}
.grid-pick-preview {
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  background: #05080c;
  border: 1px solid #1a2433;
}
.grid-pick-preview .board-preview-svg {
  min-height: 72px;
}
.preview-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.preview-mode-btn {
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  min-height: 40px;
  touch-action: manipulation;
}
.preview-mode-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}
.asset-row.hidden,
.shot-row.hidden {
  display: none !important;
}
.asset-row .file-btn {
  margin-top: 8px;
  display: inline-block;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.picker-choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 120px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f1620;
  color: var(--text);
  font-weight: 600;
  text-align: left;
  touch-action: manipulation;
}
.picker-choice span {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}
.picker-choice:active {
  border-color: var(--accent);
}
.hud-picker-sheet {
  max-height: min(80vh, 640px);
}
.file-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid #3dffa8;
  color: #3dffa8;
  font-weight: 600;
  cursor: pointer;
}
.hidden { display: none !important; }
