@font-face {
  font-family: 'OT Jubilee Platinum';
  src: url('../Fonts/OTJubilee-PlatinumExtralightItalic.otf') format('opentype');
  font-weight: 200;
  font-style: italic;
}

@font-face {
  font-family: 'ABC Diatype';
  src: url('../Fonts/ABCDiatype-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f5f3f0;
  --surface: rgba(255,255,255,0.82);
  --surface-hover: #eae6e0;
  --border: rgba(0,0,0,0.10);
  --border-strong: rgba(0,0,0,0.18);
  --text: #1a1918;
  --text-dim: #8a8680;
  --accent: #016F17;
  --accent-dim: rgba(1,111,23,0.08);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'ABC Diatype', sans-serif;
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
}

canvas#c {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* ── Panel ──────────────────────────────────────────────── */

.panel {
  position: fixed;
  top: 16px; left: 16px; bottom: 16px;
  width: 310px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transition: transform 0.45s cubic-bezier(0.22,1,0.36,1), opacity 0.35s ease;
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
  background: var(--surface);
  box-shadow: 0 8px 40px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
}
.panel.collapsed {
  transform: translateX(calc(-100% - 32px));
  opacity: 0; pointer-events: none;
}

.panel-toggle {
  position: fixed;
  top: 16px; left: 16px;
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 9;
  transition: all 0.3s ease;
  color: var(--text);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.panel-toggle:hover { border-color: var(--accent); }
.panel-toggle svg { width: 18px; height: 18px; }
.panel:not(.collapsed) ~ .panel-toggle { opacity: 0; pointer-events: none; }

.mobile-toolbar,
.mobile-sheet,
.mobile-sheet-backdrop {
  display: none;
}

.panel-header {
  padding: 20px 20px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.panel-title {
  font-family: 'OT Jubilee Platinum', serif;
  font-weight: 200;
  font-style: italic;
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: 0;
  max-width: 220px;
}
.panel-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: transparent; color: var(--text-dim);
  cursor: pointer; transition: all 0.2s;
}
.panel-close:hover { background: var(--surface-hover); color: var(--text); }

.panel-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Controls ───────────────────────────────────────────── */

.section { margin-bottom: 24px; }
.section:last-child { margin-bottom: 0; }
.section-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); margin-bottom: 12px;
}

.control-row { margin-bottom: 14px; }
.control-row:last-child { margin-bottom: 0; }
.control-label {
  display: flex; justify-content: space-between;
  align-items: baseline; margin-bottom: 6px;
}
.control-name { font-size: 13px; color: var(--text); font-weight: 500; }
.control-value {
  font-size: 12px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: var(--border-strong);
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 8px; height: 16px;
  background: var(--accent);
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
  cursor: pointer; transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scaleY(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 8px; height: 16px;
  background: var(--accent);
  border: none; border-radius: 0;
  cursor: pointer;
}

/* ── Pills ──────────────────────────────────────────────── */

.pill-row {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.pill {
  padding: 6px 12px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); font-family: inherit;
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: all 0.2s ease; white-space: nowrap;
}
.pill.active {
  background: var(--accent-dim);
  color: var(--accent); border-color: var(--accent);
}
.pill:hover:not(.active) { color: var(--text); border-color: var(--border-strong); }

.ratio-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; border: 1px solid var(--border);
  background: transparent; cursor: pointer; transition: all 0.2s ease;
  min-width: 36px;
}
.ratio-btn .shape {
  border: 1.5px solid var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s;
}
.ratio-btn .lbl {
  font-family: inherit; font-size: 9px; font-weight: 500;
  color: var(--text-dim); transition: color 0.2s; line-height: 1;
}
.ratio-btn.active { background: var(--accent-dim); border-color: var(--accent); }
.ratio-btn.active .shape { border-color: var(--accent); }
.ratio-btn.active .lbl { color: var(--accent); }
.ratio-btn:hover:not(.active) { border-color: var(--border-strong); }
.ratio-btn:hover:not(.active) .shape { border-color: var(--text); }
.ratio-btn:hover:not(.active) .lbl { color: var(--text); }

/* custom ratio — always visible, mini preview + drag handle */
.custom-ratio {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 10px;
}

/* ── Text-section style row (fonts + layout icons) ──────── */
.style-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px;
  flex-wrap: nowrap;
}
.style-row .pill-row {
  flex-wrap: nowrap;
  gap: 4px;
}
.style-divider {
  width: 1px; height: 16px;
  background: var(--border);
  flex-shrink: 0;
}
.font-select {
  min-width: 0;
  flex: 1 1 auto;
  height: 30px;
  padding: 5px 28px 5px 9px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.42);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  outline: none;
  cursor: pointer;
}
.font-select:focus { border-color: var(--accent); }
.font-scan-btn {
  height: 30px;
  padding: 5px 9px;
  flex: 0 0 auto;
}
.icon-pill {
  padding: 0;
  width: 26px; height: 24px;
  min-width: 0;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-pill svg {
  width: 12px; height: 12px; display: block;
}
.font-icon {
  font-size: 13px; line-height: 1;
  letter-spacing: 0;
}
.font-icon-serif {
  font-family: 'OT Jubilee Platinum', serif;
  font-style: italic;
  font-weight: 200;
  font-size: 16px;
}
.font-icon-sans {
  font-family: 'ABC Diatype', sans-serif;
  font-weight: 700;
}

/* ── Mini flag preview ──────────────────────────────────── */
.mini-flag-preview {
  display: flex; justify-content: center; align-items: center;
  padding: 20px 22px 28px;
  background: rgba(0,0,0,0.025);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.mini-flag-stage {
  position: relative;
  width: 170px; height: 100px;
  display: flex; align-items: center; justify-content: center;
}
.mini-flag-rect {
  position: relative;
  background: linear-gradient(135deg, rgba(1,111,23,0.06), rgba(1,111,23,0.02));
  border: 1.5px solid var(--border-strong);
  will-change: width, height;
}
.mini-edge {
  position: absolute;
  background: transparent;
  transition: background 0.18s ease, box-shadow 0.18s ease;
  pointer-events: auto;
}
.mini-edge-top    { top: -5px; left: -1px; right: -1px; height: 10px; cursor: ns-resize; }
.mini-edge-bottom { bottom: -5px; left: -1px; right: -1px; height: 10px; cursor: ns-resize; }
.mini-edge-left   { left: -5px; top: -1px; bottom: -1px; width: 10px; cursor: ew-resize; }
.mini-edge-right  { right: -5px; top: -1px; bottom: -1px; width: 10px; cursor: ew-resize; }
.mini-edge::after {
  content: ''; position: absolute; inset: 0;
  margin: auto;
  background: var(--accent);
  opacity: 0; transition: opacity 0.15s ease;
}
.mini-edge-top::after, .mini-edge-bottom::after { height: 2px; left: 0; right: 0; top: 4px; }
.mini-edge-left::after, .mini-edge-right::after { width: 2px; top: 0; bottom: 0; left: 4px; }
.mini-edge:hover::after { opacity: 0.55; }
.mini-flag-rect.editing-w .mini-edge-left::after,
.mini-flag-rect.editing-w .mini-edge-right::after,
.mini-flag-rect.editing-h .mini-edge-top::after,
.mini-flag-rect.editing-h .mini-edge-bottom::after {
  opacity: 1;
}
.mini-flag-rect.editing-w { border-left-color: var(--accent); border-right-color: var(--accent); }
.mini-flag-rect.editing-h { border-top-color: var(--accent); border-bottom-color: var(--accent); }

.mini-handle-corner {
  position: absolute;
  right: -6px; bottom: -6px;
  width: 13px; height: 13px;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  cursor: nwse-resize;
  transition: transform 0.15s ease;
  z-index: 3; /* above shape dots — bbox resize wins at the corner */
}
.mini-handle-corner:hover { transform: scale(1.18); }
.mini-handle-corner:active { transform: scale(0.92); }

.mini-dim {
  position: absolute;
  font-size: 12px; font-weight: 400;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  transition: color 0.15s ease, background 0.15s ease;
  cursor: text;
  padding: 1px 4px;
  outline: none;
  min-width: 24px;
  text-align: center;
  user-select: none;
}
.mini-dim:hover { color: var(--text); background: rgba(0,0,0,0.05); }
.mini-dim:focus,
.mini-dim.editing {
  color: var(--accent);
  background: var(--accent-dim);
  user-select: text;
  cursor: text;
}
.mini-dim-w { bottom: -24px; left: 50%; transform: translateX(-50%); }
.mini-dim-h { left: -30px; top: 50%; transform: translateY(-50%); }
.mini-flag-rect.editing-w .mini-dim-w,
.mini-flag-rect.editing-h .mini-dim-h {
  color: var(--accent);
}

/* ── Custom shape editor (mini box) ─────────────────────── */
.mini-shape-svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
  display: none;
}
.mini-shape-svg polygon {
  fill: rgba(1,111,23,0.05);
  stroke: var(--border-strong);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
/* custom shape active: the SVG outline replaces the rect border */
.mini-flag-rect.shaped { border-color: transparent; background: none; }
.mini-flag-rect.shaped .mini-handle-corner { display: none; }
.mini-shape-dot {
  position: absolute;
  width: 9px; height: 9px;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: grab;
  z-index: 2;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}
.mini-flag-rect.shaped .mini-shape-dot,
.mini-shape-dot:hover { opacity: 1; }
.mini-shape-dot:active { cursor: grabbing; }
.mini-shape-dot.removing {
  background: #d94b43;
  border-color: #d94b43;
  opacity: 0.45;
}

/* ── Dropzone ───────────────────────────────────────────── */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  padding: 20px 14px;
  text-align: center; cursor: pointer;
  transition: all 0.3s ease; position: relative; overflow: hidden;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent); background: var(--accent-dim);
}
.dropzone-icon { width: 28px; height: 28px; margin: 0 auto 8px; color: var(--text-dim); }
.dropzone:hover .dropzone-icon { color: var(--accent); }
.dropzone-text { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.dropzone-text strong { color: var(--text); font-weight: 500; }
.dropzone-hint { font-size: 10px; color: var(--text-dim); margin-top: 4px; opacity: 0.6; }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.csv-template-link {
  display: block; width: 100%; margin-top: 8px; padding: 0;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 10px; text-align: center;
  color: var(--text-dim); text-decoration: underline; text-underline-offset: 2px;
}
.csv-template-link:hover { color: var(--accent); }

.texture-preview {
  margin-top: 10px; overflow: hidden;
  border: 1px solid var(--border); position: relative; display: none;
}
.texture-preview img,
.texture-preview video {
  width: 100%; display: block; object-fit: cover;
  background: repeating-conic-gradient(#eee 0% 25%, #ddd 0% 50%) 50% / 10px 10px;
}
.texture-preview video { display: none; }
.texture-remove {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; border: none;
  background: rgba(255,255,255,0.85); color: var(--text);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: background 0.2s;
  backdrop-filter: blur(6px); box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.texture-remove:hover { background: rgba(200,50,50,0.85); color: #fff; }

/* ── Text input ─────────────────────────────────────────── */

.text-input-wrap textarea,
.text-input-wrap input[type="text"] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border);
  background: transparent; color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 14px; line-height: 1.35;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
  min-height: 74px;
  display: block;
}
.text-input-wrap textarea::placeholder,
.text-input-wrap input[type="text"]::placeholder { color: var(--text-dim); opacity: 0.5; }
.text-input-wrap textarea:focus,
.text-input-wrap input[type="text"]:focus { border-color: var(--accent); }

/* ── Stretch/Fit toggle ─────────────────────────────────── */

.fit-toggle {
  display: flex; gap: 2px; padding: 2px;
  border: 1px solid var(--border);
  margin-top: 10px;
}
.fit-toggle button {
  flex: 1; padding: 6px 8px; border: none;
  background: transparent; color: var(--text-dim);
  font-family: inherit; font-size: 11px;
  font-weight: 500; cursor: pointer; transition: all 0.2s ease;
}
.fit-toggle button.active {
  background: var(--accent-dim); color: var(--accent);
}

/* ── Color pickers ──────────────────────────────────────── */

.color-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.color-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 4px;
  align-items: center;
}
.color-item-label {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
}
.color-item .color-swatch { width: 28px; height: 28px; }
.color-item .hex-input { width: 100%; }
.bg-source-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
  margin-top: 12px;
}
.bg-source-row label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
  white-space: nowrap;
}
.bg-source-row .font-select {
  width: 100%;
  height: 30px;
}
.bg-source-row .pill {
  height: 30px;
  padding: 5px 9px;
}

.color-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.color-row:last-child { margin-bottom: 0; }
.color-swatch {
  width: 32px; height: 32px;
  border: 1px solid var(--border); cursor: pointer;
  position: relative; overflow: hidden; flex-shrink: 0;
}
.color-swatch input[type="color"] {
  position: absolute; inset: -4px;
  width: calc(100% + 8px); height: calc(100% + 8px);
  border: none; cursor: pointer; background: none;
}
.color-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch input[type="color"]::-webkit-color-swatch { border: none; }
.color-label { font-size: 12px; color: var(--text); }

.hex-input {
  width: 72px; padding: 5px 8px;
  border: 1px solid var(--border);
  background: transparent; color: var(--text);
  font-family: inherit; font-size: 12px;
  font-variant-numeric: tabular-nums;
  outline: none; text-transform: uppercase;
}
.hex-input:focus { border-color: var(--accent); }

.size-inputs {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px;
}
.size-field {
  display: flex; align-items: center; gap: 6px; flex: 1;
}
.size-field label {
  font-size: 11px; color: var(--text-dim);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.size-num {
  flex: 1; width: auto; text-transform: none;
  -moz-appearance: textfield;
}
.size-num::-webkit-outer-spin-button,
.size-num::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.size-x { color: var(--text-dim); font-size: 12px; }
.size-unit { color: var(--text-dim); font-size: 11px; }

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

.btn-export {
  width: 100%; padding: 9px;
  border: 1px solid var(--accent);
  background: var(--accent-dim); color: var(--accent);
  font-family: inherit;
  font-size: 11px; font-weight: 500; cursor: pointer;
  transition: all 0.2s; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.btn-export:hover {
  background: var(--accent); color: #fff;
}
.btn-export:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-export:disabled:hover { background: var(--accent-dim); color: var(--accent); }
.btn-export.batch-cancel {
  border-color: var(--text-dim); color: var(--text-dim); background: transparent;
}
.btn-export.batch-cancel:hover { background: var(--text-dim); color: #fff; }

.batch-status {
  font-size: 10px; color: var(--text-dim);
  margin: 8px 0; line-height: 1.5; letter-spacing: 0.02em;
}
.matte-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-dim);
  margin-bottom: 10px; cursor: pointer; user-select: none;
}
.matte-row input { accent-color: var(--accent); cursor: pointer; }
.dropzone.has-file { border-color: var(--accent); border-style: solid; }
.dropzone.has-file .dropzone-icon,
.dropzone.has-file .dropzone-text strong { color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-dim); }
.image-action-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.image-action-btn {
  width: 100%;
  min-height: 34px;
}

.btn-reset {
  width: 100%; padding: 9px;
  border: 1px solid var(--border);
  background: transparent; color: var(--text-dim);
  font-family: inherit;
  font-size: 11px; font-weight: 500; cursor: pointer;
  transition: all 0.2s; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.btn-reset:hover {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}

/* ── Global drop overlay ────────────────────────────────── */

.global-drop-overlay {
  position: fixed; inset: 0;
  background: rgba(245,243,240,0.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(12px);
}
.global-drop-overlay.active { opacity: 1; pointer-events: all; }
.global-drop-content { text-align: center; }
.global-drop-content svg { width: 48px; height: 48px; color: var(--accent); margin-bottom: 14px; }
.global-drop-content p { font-family: inherit; font-weight: 700; font-size: 20px; color: var(--text); }
.global-drop-content span {
  display: block; font-family: inherit;
  font-size: 12px; color: var(--text-dim); margin-top: 5px;
}

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

@media (max-width: 740px) {
  .panel {
    top: auto; left: 0; bottom: 0; right: 0;
    width: 100%; max-height: 55vh;
  }
  .panel.collapsed { transform: translateY(100%); }
  .panel-toggle { top: auto; bottom: 16px; left: 16px; }
}

/* ── SoMe Export ────────────────────────────────────────────── */

.some-frame {
  position: fixed;
  display: none;
  z-index: 5;
  border: 1.5px solid rgba(255,255,255,0.85);
  /* Heavy surround so the bright interior = exactly what gets exported. */
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.66);
  user-select: none;
  pointer-events: none;
}
.some-frame.recording {
  border-color: #e74c3c;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.74);
}
.some-guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.some-guides::before,
.some-guides::after {
  content: '';
  position: absolute;
}
.some-guides::before {
  left: 33.333%; right: 33.333%;
  top: 0; bottom: 0;
  border-left: 1px solid rgba(255,255,255,0.10);
  border-right: 1px solid rgba(255,255,255,0.10);
}
.some-guides::after {
  top: 33.333%; bottom: 33.333%;
  left: 0; right: 0;
  border-top: 1px solid rgba(255,255,255,0.10);
  border-bottom: 1px solid rgba(255,255,255,0.10);
}
.some-label {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ── Panel Tabs ────────────────────────────────────────────── */

.panel-tabs {
  display: flex;
  padding: 12px 20px 0;
  gap: 2px;
}
.panel-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  text-align: center;
}
.panel-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.panel-tab:hover:not(.active) { color: var(--text); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Orbit Ball ───────────────────────────────────────────── */

.orbit-ball {
  border-radius: 50%;
  position: fixed;
  bottom: 24px; right: 24px;
  width: 72px; height: 72px;
  background: radial-gradient(circle at 38% 35%, rgba(255,255,255,0.25), rgba(0,0,0,0.06) 70%);
  border: 1px solid var(--border);
  cursor: grab;
  z-index: 8;
  overflow: hidden;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 2px 16px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.3);
  user-select: none;
  touch-action: none;
}
.orbit-ball:active { cursor: grabbing; }
.orbit-ball-ring {
  border-radius: 50%;
  position: absolute;
  border: 1px solid rgba(0,0,0,0.08);
  pointer-events: none;
  transition: transform 0.12s ease-out;
}
.orbit-ball-equator {
  width: 64px; height: 20px;
  left: 4px; top: 26px;
}
.orbit-ball-meridian {
  width: 20px; height: 64px;
  left: 26px; top: 4px;
}
.orbit-ball-dot {
  border-radius: 50%;
  position: absolute;
  width: 8px; height: 8px;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 1px 4px rgba(0,0,0,0.2);
  pointer-events: none;
  transition: transform 0.12s ease-out;
  left: 32px; top: 32px;
  transform: translate(-50%, -50%);
}

/* ── Film Festival Intro (FFI) ───────────────────────────── */
.ffi-block {
  background: rgba(0,0,0,0.025);
  border: 1px solid var(--border);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.ffi-block:last-child { margin-bottom: 0; }
.ffi-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ffi-block-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}
.ffi-block-font {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ffi-text {
  width: 100%;
  margin-bottom: 10px;
  text-transform: none;
}
.ffi-textarea {
  resize: vertical;
  min-height: 48px;
  font-family: inherit;
  line-height: 1.3;
}
.ffi-block .control-row { margin-bottom: 0; }

/* Mini flag preview with draggable block handles (Y-only). */
.ffi-layout {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}
.ffi-layout-flag {
  position: relative;
  width: 180px;
  /* aspect 2.4 wide × 2.9 tall → height = width × (2.9/2.4) */
  height: 217px;
  border: 1px solid var(--border-strong);
  background: var(--accent-dim);
  overflow: hidden;
}
.ffi-layout-block {
  position: absolute;
  left: 6%;
  width: 88%;
  min-height: 10px;
  background: rgba(1,111,23,0.45);
  color: #fff;
  font-family: 'ABC Diatype', sans-serif;
  font-weight: 700;
  font-size: 9px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  user-select: none;
  transform: translateY(-50%);
  transition: background 0.12s ease;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.6);
}
.ffi-layout-block:hover { background: rgba(1,111,23,0.7); }
.ffi-layout-block.dragging { background: var(--accent); }

/* ── Mobile canvas-first controls ─────────────────────────── */

@media (max-width: 740px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: min(78dvh, 720px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .panel.collapsed { transform: translateY(100%); }

  .panel-header {
    padding: 14px 16px 0;
  }

  .panel-title {
    font-size: 23px;
  }

  .panel-tabs {
    padding: 10px 16px 0;
  }

  .panel-tab {
    min-height: 42px;
    padding: 10px 0;
  }

  .panel-body {
    padding: 14px 16px max(24px, calc(20px + env(safe-area-inset-bottom, 0px)));
  }

  .section {
    margin-bottom: 18px;
  }

  .pill,
  .ratio-btn,
  .fit-toggle button,
  .btn-export,
  .btn-reset {
    min-height: 40px;
  }

  .pill {
    padding: 8px 12px;
    font-size: 12px;
  }

  .icon-pill {
    width: 40px;
    height: 38px;
  }

  input[type="range"] {
    height: 6px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  .text-input-wrap textarea,
  .text-input-wrap input[type="text"],
  .hex-input {
    font-size: 16px;
  }

  .dropzone {
    padding: 18px 14px;
  }

  #someRow,
  #audioRow,
  #clothModeRow,
  #lookRow,
  #loopModeRow {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  #someRow::-webkit-scrollbar,
  #audioRow::-webkit-scrollbar,
  #clothModeRow::-webkit-scrollbar,
  #lookRow::-webkit-scrollbar,
  #loopModeRow::-webkit-scrollbar {
    display: none;
  }

  #someRow .pill,
  #audioRow .pill,
  #clothModeRow .pill,
  #lookRow .pill,
  #loopModeRow .pill {
    flex: 0 0 auto;
  }

  .mobile-toolbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: blur(24px) saturate(1.35);
    -webkit-backdrop-filter: blur(24px) saturate(1.35);
    box-shadow: 0 8px 30px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
    z-index: 12;
    transition: transform 0.25s ease, opacity 0.2s ease;
  }

  .mobile-tool {
    min-width: 0;
    min-height: 52px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
  }

  .mobile-tool svg {
    width: 20px;
    height: 20px;
  }

  .mobile-tool.active {
    color: var(--accent);
    background: var(--accent-dim);
    border-color: var(--accent);
  }

  .mobile-sheet-backdrop {
    position: fixed;
    inset: 0;
    display: block;
    background: rgba(0,0,0,0.18);
    opacity: 0;
    pointer-events: none;
    z-index: 24;
    transition: opacity 0.2s ease;
  }

  .mobile-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    max-height: min(78dvh, 720px);
    border: 1px solid var(--border);
    border-bottom: none;
    background: var(--surface);
    backdrop-filter: blur(28px) saturate(1.4);
    -webkit-backdrop-filter: blur(28px) saturate(1.4);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.10);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
    z-index: 25;
    transition: transform 0.32s cubic-bezier(0.22,1,0.36,1), opacity 0.2s ease;
  }

  .mobile-sheet.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sheet-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--border);
  }

  .mobile-sheet-title {
    font-family: 'OT Jubilee Platinum', serif;
    font-size: 22px;
    font-style: italic;
    font-weight: 200;
  }

  .mobile-sheet-close {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .mobile-sheet-close svg {
    width: 20px;
    height: 20px;
  }

  .mobile-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px max(24px, calc(20px + env(safe-area-inset-bottom, 0px)));
  }

  .mobile-sheet-body .section:last-child {
    margin-bottom: 0;
  }

  body.mobile-sheet-open .mobile-toolbar,
  .panel:not(.collapsed) ~ .mobile-toolbar {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
  }

  .panel-toggle {
    top: auto;
    left: 12px;
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    width: 42px;
    height: 42px;
    z-index: 13;
  }

  .orbit-ball {
    width: 58px;
    height: 58px;
    right: 12px;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }

  .orbit-ball-equator {
    width: 50px;
    height: 16px;
    left: 4px;
    top: 21px;
  }

  .orbit-ball-meridian {
    width: 16px;
    height: 50px;
    left: 21px;
    top: 4px;
  }

  .orbit-ball-dot {
    left: 29px;
    top: 29px;
  }

  body.mobile-sheet-open .orbit-ball,
  .panel:not(.collapsed) ~ .orbit-ball {
    opacity: 0;
    pointer-events: none;
  }

  .some-label {
    bottom: auto;
    top: calc(100% + 8px);
  }
}

/* Gust — press and hold; the fill is the charge. */
.btn-gust {
  position: relative;
  display: block;
  width: 100%;
  padding: 10px 12px;
  overflow: hidden;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  color: var(--text, #1a1a1a);
  text-align: center;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.12);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.btn-gust:active { background: rgba(0, 0, 0, 0.07); }
.btn-gust-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(0, 0, 0, 0.14);
}
.btn-gust-label { position: relative; }
.btn-gust kbd {
  padding: 1px 5px;
  font: inherit;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.07);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

/* ── About ──────────────────────────────────────────────── */
/* The header carries the name only; what the tool is for, how to drive it and
   where it comes from live one tap away rather than crowding the title. */
.panel-header-actions { display: flex; align-items: center; gap: 4px; }
.panel-icon {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: transparent; color: var(--text-dim);
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.panel-icon:hover { border-color: var(--border-strong); color: var(--text); }
.panel-icon[aria-expanded="true"] {
  background: var(--accent-dim); border-color: var(--accent); color: var(--accent);
}

.panel-about {
  margin: 14px 20px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.025);
  font-size: 11px; line-height: 1.55; color: var(--text-dim);
}
.panel-about p { margin: 0 0 10px; }
.panel-about strong { color: var(--text); font-weight: 600; }
/* Relative, so it works the same on localhost and on Pages. */
.about-links { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.about-link {
  display: inline-block;
  color: var(--accent); text-decoration: none;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--accent);
}
.about-link:hover { opacity: 0.65; }

/* ── Control legend ─────────────────────────────────────── */
/* Sits over the bottom of the flag. Centred in the space beside the panel so
   it never lands on top of it; recentres on the viewport once the panel is
   away. Translucent because the backdrop can be anything from pale green to a
   video. */
.canvas-legend {
  position: fixed;
  bottom: 16px;
  left: calc(50% + 163px);
  transform: translateX(-50%);
  z-index: 6;
  display: flex; align-items: center; gap: 14px;
  padding: 7px 12px;
  max-width: calc(100vw - 360px);
  background: rgba(255,255,255,0.62);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 10px; letter-spacing: 0.02em; color: var(--text-dim);
  white-space: nowrap; overflow: hidden;
  pointer-events: none; user-select: none;
}
body:has(.panel.collapsed) .canvas-legend {
  left: 50%;
  max-width: calc(100vw - 32px);
}
.canvas-legend kbd {
  margin-right: 5px; padding: 1px 5px;
  border: 1px solid var(--border);
  font-family: inherit; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text);
}
/* Narrow windows keep only the two that are not guessable; drag, right-drag
   and scroll are conventions people already have. */
@media (max-width: 980px) { .canvas-legend .legend-mouse { display: none; } }
/* The mobile toolbar owns the bottom edge, and none of these are touch gestures. */
@media (max-width: 740px) { .canvas-legend { display: none; } }
