/* ───────────────────────────────────────────────────────────────
   Paint & Animation Studio (owned by paint.js)
   ─────────────────────────────────────────────────────────────── */
#native-canvas-view {
  --pt-surface: rgba(255, 255, 255, 0.03);
  --pt-btn: rgba(255, 255, 255, 0.05);
  --pt-hover: rgba(255, 255, 255, 0.1);
  --pt-overlay: rgba(10, 14, 28, 0.62);
  --pt-solid: #161a2c;
  --pt-stage-bg: #0b0f1d;
  width: 100%;
}
[data-theme="light"] #native-canvas-view {
  --pt-surface: rgba(15, 23, 42, 0.025);
  --pt-btn: #ffffff;
  --pt-hover: rgba(99, 102, 241, 0.08);
  --pt-solid: #ffffff;
  --pt-stage-bg: #e7eaf3;
}

.pt-studio {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; min-width: 0;
}
.pt-studio button { font-family: var(--font-display); -webkit-tap-highlight-color: transparent; }
.pt-studio button:focus-visible, .pt-modal button:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; }
.pt-emo { line-height: 1; }
.pt-studio [hidden], .pt-modal [hidden] { display: none !important; }

/* ── Chips & small buttons ───────────────────────────────────── */
.pt-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 7px 12px;
  border-radius: 12px; border: 1px solid var(--border-color);
  background: var(--pt-btn); color: var(--text-main);
  font-weight: 600; font-size: 0.9rem; cursor: pointer; white-space: nowrap;
  transition: background 0.2s, transform 0.15s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.pt-chip .pt-emo { font-size: 1.1rem; }
.pt-chip:hover:not(:disabled) { background: var(--pt-hover); border-color: var(--primary); }
.pt-chip:active:not(:disabled) { transform: scale(0.95); }
.pt-chip.active { background: var(--primary); color: #fff; border-color: transparent; }
.pt-chip:disabled { opacity: 0.38; cursor: not-allowed; }
.pt-group .pt-chip { background: transparent; border-color: transparent; }
.pt-group .pt-chip:hover:not(:disabled) { background: var(--pt-hover); border-color: transparent; }
.pt-group .pt-chip.active { background: var(--primary); color: #fff; }
.pt-chip.pt-icon { min-width: 42px; padding: 7px 8px; font-size: 1.05rem; }
.pt-danger { color: var(--danger) !important; }
.pt-chip.pt-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.12); border-color: var(--danger); }
.pt-go { color: var(--success); border-color: rgba(16, 185, 129, 0.35); }
.pt-chip.pt-go:hover:not(:disabled) { background: rgba(16, 185, 129, 0.14); border-color: var(--success); }
.pt-magic { border-color: rgba(236, 72, 153, 0.4); }
.pt-chip.pt-magic:hover:not(:disabled) { background: rgba(236, 72, 153, 0.12); border-color: var(--secondary); }
.pt-danger-solid { background: var(--danger) !important; color: #fff !important; border-color: transparent !important; }
.pt-chip.pt-big { min-height: 48px; font-size: 1rem; padding: 8px 18px; background: var(--grad-main); color: #fff; border: none; box-shadow: 0 6px 16px var(--primary-glow); }

.pt-mini-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 34px; padding: 5px 10px; border-radius: 10px;
  border: 1px solid var(--border-color); background: var(--pt-btn); color: var(--text-main);
  font-weight: 600; font-size: 0.78rem; cursor: pointer; white-space: nowrap;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
}
.pt-mini-btn:hover:not(:disabled) { border-color: var(--primary); }
.pt-mini-btn:active:not(:disabled) { transform: scale(0.95); }
.pt-mini-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pt-mini-btn.active { background: var(--primary); color: #fff; border-color: transparent; }
.pt-mini-btn.pt-go-solid { background: var(--success); color: #fff; border-color: transparent; }
.pt-mini-label { font-family: var(--font-display); font-weight: 700; font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.pt-step {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  border: 1px solid var(--border-color); background: var(--pt-btn); color: var(--text-main);
  font-size: 1.1rem; font-weight: 700; cursor: pointer; line-height: 1;
}
.pt-step:hover { border-color: var(--primary); }
.pt-step:active { transform: scale(0.92); }
.pt-studio output, .pt-modal output { font-family: var(--font-display); font-weight: 700; font-size: 0.9rem; color: var(--primary); min-width: 2.4ch; text-align: center; }
.pt-toggle {
  min-width: 48px; min-height: 30px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border-color); background: var(--pt-btn); color: var(--text-muted);
  font-weight: 700; font-size: 0.78rem; cursor: pointer;
}
.pt-toggle.on { background: var(--success); color: #fff; border-color: transparent; }
.pt-btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Top bar ─────────────────────────────────────────────────── */
.pt-topbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.pt-group {
  display: flex; align-items: center; gap: 4px;
  background: var(--pt-surface); border: 1px solid var(--border-color);
  border-radius: 16px; padding: 4px;
}
.pt-slider { padding: 4px 12px; gap: 10px; flex: 1 1 170px; min-height: 50px; min-width: 0; }
.pt-slider label { font-family: var(--font-display); font-weight: 700; font-size: 0.9rem; color: var(--text-muted); white-space: nowrap; cursor: help; }
.pt-slider input[type="range"] { flex: 1 1 60px; width: 0; min-width: 60px; accent-color: var(--primary); cursor: pointer; height: 24px; }
.pt-slider output { min-width: 3.4ch; text-align: right; }

/* ── Main layout ─────────────────────────────────────────────── */
.pt-main {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr) 256px;
  gap: 12px;
  align-items: start;
}
.pt-tools, .pt-side {
  background: var(--pt-surface); border: 1px solid var(--border-color);
  border-radius: 20px; padding: 12px;
  display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.pt-section { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pt-panel-title { font-family: var(--font-display); font-weight: 700; font-size: 0.88rem; color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.pt-title-row { justify-content: space-between; white-space: nowrap; }
.pt-has-sel .pt-zoombar { display: none; }
.pt-subtitle { margin-top: 4px; }
.pt-side .pt-section + .pt-section { border-top: 1px dashed var(--border-color); padding-top: 12px; }

.pt-tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.pt-tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 54px; padding: 5px 2px; min-width: 0;
  border-radius: 14px; border: 1px solid var(--border-color);
  background: var(--pt-btn); color: var(--text-main);
  font-weight: 600; font-size: 0.7rem; line-height: 1.1; text-align: center; cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.pt-tool .pt-emo { font-size: 1.35rem; }
.pt-tool:hover { transform: translateY(-1px); border-color: var(--primary); }
.pt-tool:active { transform: scale(0.94); }
.pt-tool.active { background: var(--grad-main); color: #fff; border-color: transparent; box-shadow: 0 6px 16px var(--primary-glow); }
.pt-tool-options { border-top: 1px dashed var(--border-color); padding-top: 10px; }
.pt-tip { font-size: 0.8rem; line-height: 1.35; color: var(--text-muted); font-weight: 500; }
.pt-faint { color: var(--text-faint); font-size: 0.74rem; }
.pt-stickers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.pt-sticker {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--border-color); background: var(--pt-btn);
  font-size: 1.15rem; cursor: pointer; padding: 0; line-height: 1;
}
.pt-sticker.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }

/* ── Stage ───────────────────────────────────────────────────── */
.pt-stage-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; position: relative; }
.pt-stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: 20px; overflow: hidden;
  border: 2px solid var(--border-color);
  background: var(--pt-stage-bg);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.15), var(--shadow-sm);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.pt-canvas-wrap { position: absolute; inset: 0; transform-origin: 50% 50%; will-change: transform; }
#native-canvas-view #sketchpad,
#native-canvas-view #pt-overlay {
  position: absolute !important; inset: 0 !important;
  width: 100% !important; height: 100% !important; max-width: none !important;
  border: none !important; border-radius: 0 !important; box-shadow: none !important;
  background: transparent; display: block;
}
#native-canvas-view #sketchpad { background: #ffffff; pointer-events: none; }
#native-canvas-view #pt-overlay { cursor: crosshair; touch-action: none !important; z-index: 2; }
.pt-studio[data-tool="move"] #pt-overlay { cursor: crosshair; }
.pt-studio[data-tool="picker"] #pt-overlay { cursor: copy; }
.pt-studio[data-tool="fill"] #pt-overlay { cursor: cell; }
.pt-studio.pt-is-playing #pt-overlay { cursor: pointer; }
.pt-stage-badge {
  position: absolute; top: 10px; left: 10px; z-index: 4; pointer-events: none;
  background: var(--pt-overlay); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 5px 12px; border-radius: 999px;
  font-family: var(--font-display); font-weight: 600; font-size: 0.78rem;
  max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pt-is-playing .pt-stage-badge { background: rgba(16, 185, 129, 0.85); }
.pt-target-bg .pt-stage { border-color: var(--warning); }
.pt-stage.pt-drop { border-color: var(--success); box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.35); }
.pt-stage.pt-drop::after {
  content: '📥 Drop your picture here!'; position: absolute; inset: 0; z-index: 6; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(16, 185, 129, 0.18); color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 1.3rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.pt-layer-head-btns { display: inline-flex; gap: 6px; margin-left: auto; }
.pt-zoombar {
  position: absolute; right: 10px; bottom: 10px; z-index: 4;
  display: flex; gap: 3px; padding: 4px; border-radius: 14px;
  background: var(--pt-overlay); border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  opacity: 0.55; transition: opacity 0.2s;
}
.pt-zoombar:hover, .pt-zoombar:focus-within { opacity: 1; }
.pt-zoom-btn { min-width: 34px; height: 32px; border-radius: 10px; border: none; background: transparent; color: #fff; font-size: 0.85rem; cursor: pointer; font-weight: 700; }
.pt-zoom-btn:hover { background: rgba(255, 255, 255, 0.16); }
.pt-zoom-label { min-width: 52px; font-size: 0.78rem; }

/* Coach (guides) + Motion Magic panel */
.pt-coach, .pt-motion {
  border-radius: 16px; padding: 10px 12px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(236, 72, 153, 0.14));
  border: 1px solid rgba(168, 85, 247, 0.35);
  display: flex; flex-direction: column; gap: 8px;
  animation: pt-slide 0.25s ease-out;
}
@keyframes pt-slide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.pt-coach-step { font-size: 0.92rem; line-height: 1.4; font-weight: 500; }
.pt-coach-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pt-coach-dots { display: inline-flex; gap: 5px; margin-right: auto; }
.pt-coach-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--border-hover); display: block; }
.pt-coach-dots i.on { background: var(--secondary); width: 20px; border-radius: 99px; }
.pt-motion-head { display: flex; gap: 10px; align-items: center; font-size: 0.86rem; line-height: 1.3; }
.pt-motion-head strong { font-family: var(--font-display); font-size: 1rem; }
.pt-motion-head span { color: var(--text-muted); }
.pt-motion-emo { font-size: 1.8rem; }
.pt-motion-row { display: flex; align-items: center; gap: 6px; }
.pt-motion-row.pt-wrap { flex-wrap: wrap; }
.pt-motion .pt-chip { min-height: 38px; font-size: 0.82rem; padding: 6px 10px; }

/* ── Side panels ─────────────────────────────────────────────── */
.pt-current-color {
  width: 22px; height: 22px; border-radius: 8px; display: inline-block; margin-left: auto;
  border: 2px solid var(--border-hover); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.pt-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pt-swatch {
  aspect-ratio: 1; width: 100%; border-radius: 50%; padding: 0; cursor: pointer;
  border: 2px solid rgba(127, 127, 127, 0.35); position: relative; overflow: hidden;
  transition: transform 0.15s, box-shadow 0.2s; display: block;
}
.pt-swatch:hover { transform: scale(1.1); }
.pt-swatch.active { box-shadow: 0 0 0 3px var(--bg-app, #0f111a), 0 0 0 5px var(--primary); transform: scale(1.06); }
.pt-swatch-rainbow { background: conic-gradient(#ff6b6b, #feca57, #1dd1a1, #48dbfb, #8e7dff, #ff9ff3, #ff6b6b); }
.pt-swatch-rainbow.active { background: radial-gradient(circle, var(--pt-custom, #fff) 0 45%, transparent 47%), conic-gradient(#ff6b6b, #feca57, #1dd1a1, #48dbfb, #8e7dff, #ff9ff3, #ff6b6b); }
.pt-swatch-rainbow input { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); opacity: 0; cursor: pointer; border: none; padding: 0; }
.pt-custom-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
#native-canvas-view #custom-color-palette { gap: 6px !important; padding: 2px !important; min-width: 0; }
#native-canvas-view #custom-color-palette .color-swatch { width: 26px !important; height: 26px !important; flex: 0 0 auto; font-size: 0.8rem; }

.pt-layer-list { display: flex; flex-direction: column; gap: 5px; max-height: 260px; overflow-y: auto; scrollbar-width: thin; padding: 2px; }
.pt-layer {
  display: grid; grid-template-columns: minmax(0, 1fr) 32px; align-items: center; gap: 2px;
  border-radius: 12px; border: 1px solid var(--border-color); background: var(--pt-btn);
  padding: 3px; transition: border-color 0.2s, background 0.2s;
}
.pt-layer.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; background: var(--pt-hover); }
.pt-layer.hidden-layer .pt-layer-main { opacity: 0.5; }
.pt-layer-bg { border-style: dashed; }
.pt-layer-bg.active { border-color: var(--warning); box-shadow: 0 0 0 1px var(--warning) inset; }
.pt-layer-main {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: none; border: none; color: var(--text-main); cursor: pointer; padding: 3px; text-align: left;
  font-size: 0.82rem; font-weight: 600;
}
.pt-layer-thumb { flex: 0 0 auto; width: 48px; height: 27px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border-hover);
  background: #fff linear-gradient(45deg, #eef0f5 25%, transparent 25%, transparent 75%, #eef0f5 75%) 0 0 / 8px 8px; }
.pt-layer-canvas { width: 100%; height: 100%; display: block; }
.pt-layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pt-layer-name small { color: var(--text-faint); font-weight: 500; }
.pt-layer-btn { width: 30px; height: 30px; border-radius: 8px; border: none; background: transparent; cursor: pointer; font-size: 0.85rem; padding: 0; }
.pt-layer-btn:hover:not(:disabled) { background: var(--pt-hover); }
.pt-layer-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.pt-layer-opacity { grid-column: 1 / -1; display: flex; align-items: center; gap: 4px; padding: 0 2px 2px; border-top: 1px dashed var(--border-color); }
.pt-layer-opacity input { flex: 1; min-width: 0; accent-color: var(--primary); }
.pt-rename { width: 100%; min-width: 0; font: inherit; font-size: 0.82rem; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--primary); background: var(--pt-solid); color: var(--text-main); }
.pt-bg-row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pt-stepper-row { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.pt-stepper { display: inline-flex; align-items: center; gap: 4px; flex: 1 1 auto; }
.pt-stepper output { min-width: 1.6ch; }
.pt-inline-slider { display: flex; align-items: center; gap: 8px; }
.pt-inline-slider label { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); white-space: nowrap; font-family: var(--font-display); }
.pt-inline-slider input[type="range"] { flex: 1; min-width: 0; accent-color: var(--primary); }

/* ── Timeline ────────────────────────────────────────────────── */
.pt-timeline {
  background: var(--pt-surface); border: 1px solid var(--border-color);
  border-radius: 20px; padding: 10px;
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.pt-transport { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pt-transport .pt-fps { flex: 1 1 200px; }
.pt-chip.pt-play { min-width: 104px; font-size: 1rem; background: var(--success) !important; color: #fff !important; box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35); }
.pt-chip.pt-play.active { background: var(--warning) !important; box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35); }
.pt-frame-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pt-frame-actions .pt-chip { min-height: 40px; font-size: 0.84rem; padding: 6px 10px; }
.pt-hold {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px 3px 10px;
  border: 1px solid var(--border-color); border-radius: 12px; background: var(--pt-btn); min-height: 40px;
}

.pt-filmstrip {
  display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden;
  padding: 8px 6px 10px; border-radius: 14px;
  background: rgba(0, 0, 0, 0.14);
  scrollbar-width: thin; touch-action: pan-x; overscroll-behavior-x: contain;
  -webkit-user-select: none; user-select: none;
}
[data-theme="light"] .pt-filmstrip { background: rgba(15, 23, 42, 0.05); }
.pt-frame {
  position: relative; flex: 0 0 auto; width: 128px;
  border-radius: 12px; border: 3px solid transparent; cursor: pointer;
  background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.2s;
}
.pt-frame:hover { transform: translateY(-2px); }
.pt-frame .pt-thumb { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 9px; pointer-events: none; }
.pt-frame.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow), 0 6px 16px rgba(0, 0, 0, 0.3); }
.pt-frame.playing { border-color: var(--success); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.35); }
.pt-frame.dragging { z-index: 5; opacity: 0.92; box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45); transition: none; }
.pt-frame.drop-before::before {
  content: ''; position: absolute; left: -9px; top: 4px; bottom: 4px; width: 4px; border-radius: 4px; background: var(--secondary);
}
.pt-frame-num {
  position: absolute; left: 4px; top: 4px; min-width: 22px; padding: 1px 6px; border-radius: 999px;
  background: rgba(15, 17, 26, 0.72); color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 0.72rem; text-align: center; pointer-events: none;
}
.pt-frame.active .pt-frame-num { background: var(--primary); }
.pt-frame-hold {
  position: absolute; right: 4px; top: 4px; padding: 1px 6px; border-radius: 999px;
  background: var(--warning); color: #1f1300; font-family: var(--font-display); font-weight: 700; font-size: 0.68rem; pointer-events: none;
}
.pt-frame-bar {
  position: absolute; left: 6px; bottom: 4px; height: 4px; border-radius: 4px; pointer-events: none;
  width: calc((100% - 12px) * var(--hold, 1) / 8); background: var(--primary); opacity: 0.75;
}
.pt-frame-add {
  flex: 0 0 auto; width: 72px; border-radius: 12px; border: 2px dashed var(--border-hover);
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 1.2rem;
}
.pt-frame-add small { font-size: 0.72rem; font-weight: 700; }
.pt-frame-add:hover { border-color: var(--success); color: var(--success); }
.pt-dragging { cursor: grabbing; }
.pt-scrub-row { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.pt-scrub-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--secondary); height: 26px; cursor: pointer; }
.pt-scrub-row output { min-width: 9ch; font-size: 0.78rem; color: var(--text-muted); }

/* ── Bottom bar + submit ─────────────────────────────────────── */
.pt-bottombar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: var(--pt-surface); border: 1px solid var(--border-color);
  border-radius: 16px; padding: 6px 8px;
}
.pt-spacer { flex: 1 1 0; }
.pt-studio .pt-submit-bar {
  display: flex; gap: 8px; flex-wrap: wrap; width: 100%;
  border-top: 1px dashed var(--border-color); padding-top: 14px; margin-top: 2px;
}
.pt-studio .pt-submit-bar button {
  flex: 1 1 160px; margin: 0; height: 46px; padding: 10px 16px;
  border-radius: 14px; font-size: 1rem; font-weight: 700; cursor: pointer;
}
.pt-studio .pt-submit-bar .btn-gate { width: auto; background: var(--grad-main); border: none; color: #fff; }

/* ── Modals ──────────────────────────────────────────────────── */
.pt-modal {
  position: fixed; inset: 0; z-index: 1600;
  background: rgba(5, 8, 18, 0.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: pt-fade 0.18s ease-out;
}
@keyframes pt-fade { from { opacity: 0; } to { opacity: 1; } }
.pt-modal-card {
  width: min(520px, 100%); max-height: min(88vh, 760px); overflow-y: auto;
  background: var(--bg-app, #0f111a); color: var(--text-main);
  border: 1px solid var(--border-hover); border-radius: 24px; box-shadow: var(--shadow-lg);
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
  animation: pt-pop 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}
@keyframes pt-pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
.pt-modal-wide { width: min(760px, 100%); }
.pt-modal-small { width: min(400px, 100%); }
.pt-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pt-modal-head h3 { font-family: var(--font-display); font-size: 1.3rem; margin: 0; }
.pt-modal-x { width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--border-color); background: var(--pt-btn, transparent); color: var(--text-main); cursor: pointer; font-size: 0.95rem; }
.pt-modal-body { display: flex; flex-direction: column; gap: 12px; }
.pt-modal-text { color: var(--text-muted); font-size: 0.95rem; line-height: 1.45; }
.pt-modal-note { color: var(--text-faint); font-size: 0.8rem; line-height: 1.4; }
.pt-modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.pt-modal .pt-chip, .pt-modal .pt-mini-btn { background: rgba(127, 127, 127, 0.08); }
.pt-modal .pt-chip.pt-go { background: rgba(16, 185, 129, 0.12); }
.pt-empty { text-align: center; padding: 20px 0; }

.pt-export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.pt-export-card {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left;
  padding: 12px 14px; border-radius: 16px; border: 1px solid var(--border-color);
  background: rgba(127, 127, 127, 0.06); color: var(--text-main); cursor: pointer;
  font-family: var(--font-display); transition: border-color 0.2s, transform 0.15s;
}
button.pt-export-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.pt-export-main { grid-column: 1 / -1; cursor: default; background: linear-gradient(135deg, rgba(99, 102, 241, 0.14), rgba(236, 72, 153, 0.12)); border-color: rgba(168, 85, 247, 0.35); }
.pt-export-title { font-weight: 700; font-size: 1rem; }
.pt-export-desc { font-size: 0.8rem; color: var(--text-muted); font-family: var(--font-body); }
.pt-progress { width: 100%; height: 8px; border-radius: 99px; background: rgba(127, 127, 127, 0.2); overflow: hidden; margin-top: 4px; }
.pt-progress i { display: block; height: 100%; width: 0; background: var(--grad-main); transition: width 0.15s; }

.pt-lib-save { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pt-lib-save label { font-family: var(--font-display); font-weight: 700; color: var(--text-muted); }
.pt-lib-save input { flex: 1 1 180px; min-width: 0; font: inherit; font-size: 1rem; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--border-hover); background: rgba(127, 127, 127, 0.08); color: var(--text-main); }
.pt-lib-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.pt-lib-card { border: 1px solid var(--border-color); border-radius: 16px; overflow: hidden; background: rgba(127, 127, 127, 0.06); display: flex; flex-direction: column; }
.pt-lib-card.current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.pt-lib-card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #fff; display: block; }
.pt-lib-info { padding: 8px 10px 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pt-lib-info strong { font-family: var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pt-lib-info span { font-size: 0.75rem; color: var(--text-muted); }
.pt-lib-btns { display: flex; gap: 6px; padding: 8px 10px 10px; }
.pt-lib-btns .pt-mini-btn:first-child { flex: 1; }

.pt-starter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.pt-starter {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 14px; border-radius: 18px; border: 1px solid var(--border-color);
  background: rgba(127, 127, 127, 0.06); color: var(--text-main); cursor: pointer; font-family: var(--font-display);
  transition: border-color 0.2s, transform 0.15s;
}
.pt-starter:hover { border-color: var(--primary); transform: translateY(-2px); }
.pt-starter-emo { font-size: 2rem; }
.pt-starter strong { font-size: 1rem; }
.pt-starter span:last-child { font-size: 0.8rem; color: var(--text-muted); font-family: var(--font-body); }
.pt-keys { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; align-items: center; font-size: 0.88rem; }
.pt-keys kbd { font-family: var(--font-display); font-weight: 700; font-size: 0.8rem; padding: 3px 8px; border-radius: 8px; border: 1px solid var(--border-hover); background: rgba(127, 127, 127, 0.1); white-space: nowrap; }

/* ── Big screen (pop-out) ────────────────────────────────────── */
body.pt-popout-open { overflow: hidden; }
#native-canvas-view .pt-studio.pt-popout {
  position: fixed; inset: 0; z-index: 1050; /* above the sticky mobile header (1010) */
  width: 100vw; height: 100vh; height: 100dvh;
  border-radius: 0; margin: 0; padding: 10px; gap: 8px;
  background: var(--bg-app, #0f111a);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  animation: pt-pop 0.22s ease-out;
}
.pt-popout .pt-bottombar, .pt-popout .pt-submit-bar { display: none !important; }
.pt-popout .pt-main { min-height: 0; height: 100%; align-items: stretch; }
.pt-popout .pt-tools, .pt-popout .pt-side { overflow-y: auto; max-height: 100%; }
.pt-popout .pt-stage-col { min-height: 0; }
.pt-popout .pt-stage { flex: 1 1 0; min-height: 140px; aspect-ratio: auto; container-type: size; }
.pt-popout .pt-canvas-wrap {
  inset: 0; margin: auto;
  width: min(100cqw, 100cqh * 16 / 9); height: min(100cqh, 100cqw * 9 / 16);
}
.pt-popout .pt-filmstrip { padding-top: 6px; padding-bottom: 6px; }
.pt-popout .pt-coach, .pt-popout .pt-motion { position: absolute; top: 8px; left: 8px; right: 8px; z-index: 8; background: var(--pt-solid); }
.pt-popout .pt-timeline { padding: 6px 8px; gap: 6px; }
.pt-popout .pt-frame { width: 104px; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .pt-main { grid-template-columns: 172px minmax(0, 1fr); }
  .pt-side {
    grid-column: 1 / -1;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px;
  }
  .pt-side .pt-section + .pt-section { border-top: none; padding-top: 0; }
  .pt-popout .pt-main { grid-template-columns: 172px minmax(0, 1fr) 240px; }
  .pt-popout .pt-side { grid-column: auto; display: flex; }
}

@media (max-width: 820px) {
  .pt-studio { padding: 12px; gap: 10px; border-radius: 22px; }
  /* Flatten the main grid so the order becomes: canvas, tools, timeline, panels */
  .pt-main, .pt-stage-col { display: contents; }
  .pt-topbar { order: 0; }
  .pt-coach, .pt-motion, .pt-stage { order: 1; }
  .pt-tools { order: 2; display: grid; grid-template-columns: 1fr; }
  .pt-timeline { order: 3; }
  .pt-side { order: 4; }
  .pt-bottombar { order: 5; }
  .pt-submit-bar { order: 6; }
  .pt-tool-grid { grid-template-columns: repeat(4, 1fr); }
  .pt-slider { flex-basis: 100%; }
  .pt-topbar .pt-group:not(.pt-slider) { flex: 1 1 auto; justify-content: center; }
  .pt-transport .pt-group:first-child { flex: 1 1 100%; justify-content: center; }
  .pt-transport .pt-group { flex: 1 1 auto; justify-content: center; }
  .pt-frame { width: 108px; }
  .pt-layer-list { max-height: none; }

  #native-canvas-view .pt-studio.pt-popout { display: flex; flex-direction: column; overflow-y: auto; }
  .pt-popout .pt-topbar, .pt-popout .pt-tools, .pt-popout .pt-side, .pt-popout .pt-timeline, .pt-popout .pt-stage, .pt-popout .pt-coach, .pt-popout .pt-motion { flex-shrink: 0; }
  .pt-popout .pt-tools, .pt-popout .pt-side { max-height: none; overflow: visible; }
  .pt-popout .pt-stage { flex: 0 0 auto; aspect-ratio: 16 / 9; container-type: normal; }
  .pt-popout .pt-canvas-wrap { width: auto; height: auto; margin: 0; }
  .pt-popout .pt-coach, .pt-popout .pt-motion { position: static; }
  .pt-popout .pt-side { display: grid; }
}

@media (max-width: 520px) {
  .pt-studio { padding: 10px; border-radius: 18px; }
  .pt-topbar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .pt-topbar > .pt-group { justify-content: center; min-width: 0; }
  .pt-topbar > .pt-slider { order: 2; padding: 2px 8px; gap: 6px; min-height: 44px; }
  .pt-topbar .pt-slider input[type="range"] { min-width: 40px; }
  .pt-topbar .pt-slider output { min-width: 3ch; font-size: 0.8rem; }
  .pt-view-group .pt-chip span:not(.pt-emo) { display: none; }
  .pt-view-group .pt-chip { padding: 6px 10px; }
  .pt-hide-sm { display: none; }
  .pt-chip { padding: 6px 9px; font-size: 0.82rem; min-height: 40px; }
  .pt-frame-actions .pt-chip { font-size: 0.76rem; padding: 5px 8px; min-height: 38px; }
  .pt-frame-actions .pt-chip .pt-emo { font-size: 1rem; }
  .pt-tool { min-height: 52px; font-size: 0.66rem; }
  .pt-tool .pt-emo { font-size: 1.2rem; }
  .pt-stage { border-radius: 14px; }
  .pt-stage-badge { font-size: 0.68rem; padding: 3px 9px; top: 6px; left: 6px; }
  .pt-zoombar { right: 6px; bottom: 6px; }
  .pt-swatches { grid-template-columns: repeat(9, 1fr); gap: 5px; }
  .pt-frame { width: 96px; }
  .pt-bottombar .pt-chip span:not(.pt-emo) { font-size: 0.76rem; }
  .pt-spacer { display: none; }
  .pt-studio .pt-submit-bar button { flex-basis: 100%; }
  .pt-export-grid, .pt-lib-list, .pt-starter-grid { grid-template-columns: 1fr 1fr; }
  .pt-starter { padding: 10px; }
  .pt-modal-card { padding: 14px; border-radius: 20px; }
}
