/* ============================================================
   MAIN.CSS — Boarderless
   Primary layout and component styles.
   Imports nothing — relies on theme.css custom properties.
   Organized: Layout → Splash → Canvas → Gallery → Bar →
              Context Menu → Stack UI → Overlays → Utilities
   ============================================================ */

/* ── BODY / APP SHELL ──────────────────────────────────────── */

body {
  font-family: var(--font-ui);
  background: var(--color-canvas-bg);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  z-index: var(--z-app);
}

/* ── SPLASH SCREEN ─────────────────────────────────────────── */

#splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-splash);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-splash-bg);
  animation: splashFade 2.8s ease forwards;
  pointer-events: none;
}

.splash-word {
  font-family: var(--font-brand);
  font-size: clamp(28px, 7vw, 58px);
  color: #ffffff;
  letter-spacing: 0.06em;
  animation: splashText 2.8s ease forwards;
}

.splash-tag {
  font-family: var(--font-brand);
  font-size: clamp(11px, 1.8vw, 14px);
  color: rgba(255, 255, 255, 0.32);
  letter-spacing: 0.20em;
  margin-top: 10px;
  animation: splashText 2.8s ease forwards;
}

/* ── CANVAS / STAGE ────────────────────────────────────────── */

#stage-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--bottom-safe);
  z-index: var(--z-canvas);
  cursor: grab;
  /* CRITICAL: prevents browser from stealing touch events */
  touch-action: none;
}

#stage-wrap.grabbing {
  cursor: grabbing;
}

/* The checkerboard transparent indicator — pure CSS, zero canvas cost */
#stage-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-color: var(--color-checker-dark);
  background-image:
    linear-gradient(45deg,  var(--color-checker-light) 25%, transparent 25%),
    linear-gradient(135deg, var(--color-checker-light) 25%, transparent 25%),
    linear-gradient(45deg,  transparent 75%, var(--color-checker-light) 75%),
    linear-gradient(135deg, transparent 75%, var(--color-checker-light) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 0, 12px -12px, 0 12px;
  pointer-events: none;
  z-index: 0;
}

#stage-wrap.has-bg-color::before {
  display: none;
}

#stage-wrap canvas {
  position: relative;
  z-index: 1;
}

/* ── CANVAS HINT (empty state) ─────────────────────────────── */

#hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  transition: opacity var(--transition-med);
  z-index: var(--z-overlay);
  background: rgba(0, 0, 0, 0.1); /* 90% transparent black */
  padding: 30px 50px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(2px);            /* Barely there blur */
  -webkit-backdrop-filter: blur(2px);
  max-width: 90%;
  width: 420px;
  box-shadow: none;                      /* Removed shadow */
}

#hint p {
  font-family: var(--font-brand);
  color: rgba(255, 255, 255, 0.75);
  font-size: 16px;
  line-height: 1.6;
}

#hint p strong {
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 8px;
  border-radius: 6px;
}

#hint span {
  display: block;
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.12em;
  margin-top: 10px;
}

/* ── GALLERY STRIP ─────────────────────────────────────────── */

#gallery {
  position: absolute;
  bottom: 44px;
  left: 0;
  right: 0;
  height: 106px;
  background: var(--color-gallery-bg);
  border-top: 0.5px solid var(--color-border);
  z-index: var(--z-gallery);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.gallery-label {
  font-family: var(--font-brand);
  font-size: 9px;
  color: rgba(255, 255, 255, 0.18);
  letter-spacing: 0.16em;
  padding: 0 14px 2px;
}

#gallery-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

#gallery-scroll::-webkit-scrollbar {
  height: 3px;
}
#gallery-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
}

/* Add (+) button */
#add-btn {
  width: 68px;
  height: 68px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  border: 1.5px dashed var(--color-border-strong);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.32);
  flex-direction: column;
  gap: 2px;
  transition: all var(--transition-fast);
}

#add-btn:hover {
  border-color: rgba(255, 255, 255, 0.42);
  color: rgba(255, 255, 255, 0.60);
  background: rgba(255, 255, 255, 0.05);
}

.add-icon {
  font-size: 22px;
  line-height: 1;
}
.add-label {
  font-family: var(--font-brand);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.20);
}

/* Gallery thumbnails — created dynamically by JS */
.g-thumb-wrap {
  position: relative;
  flex-shrink: 0;
  display: block;
}

.g-thumb {
  width: 68px;
  height: 68px;
  border-radius: var(--radius-md);
  object-fit: cover;
  cursor: pointer;
  border: 1.5px solid var(--color-border);
  transition: all var(--transition-fast);
  display: block;
}
.g-thumb-wrap:hover .g-thumb {
  border-color: var(--color-accent-border);
  transform: scale(1.06);
}
.g-thumb.active {
  border-color: var(--color-accent);
  box-shadow: 0 0 10px var(--color-accent-glow);
}

.g-thumb-del {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.4;
  transition: all var(--transition-fast);
  z-index: 2;
}
.g-thumb-wrap:hover .g-thumb-del {
  opacity: 1;
  color: var(--color-text);
  border-color: var(--color-border-medium);
}
.g-thumb-del:hover {
  background: var(--color-danger) !important;
  color: #fff !important;
  border-color: var(--color-danger) !important;
}

/* Hidden file input */
#file-input {
  display: none;
}

/* ── BOTTOM BAR ────────────────────────────────────────────── */

#bottom-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--color-bar-bg);
  border-top: 0.5px solid rgba(255, 255, 255, 0.05);
  z-index: var(--z-bar);
}

#obj-count,
#zoom-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-secondary);
  letter-spacing: 0.07em;
  min-width: 48px;
}

#top-left-controls {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 4px;
  z-index: var(--z-bar);
  background: var(--color-bar-bg);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--color-border-medium);
}

#top-right-controls {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 4px;
  z-index: var(--z-bar);
}

.accent-btn {
  background: transparent;
  color: #00a8ff;
  border: 1px solid #00a8ff;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-family: var(--font-brand);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all var(--transition-fast);
}
.accent-btn:hover {
  background: #00a8ff;
  color: white;
  box-shadow: 0 4px 14px rgba(0, 168, 255, 0.30);
}
.accent-btn:active {
  transform: translateY(1px);
}

.bar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-btn {
  width: 29px;
  height: 29px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid rgba(0, 168, 255, 0.35);
  color: #00a8ff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.history-btn:not(:disabled):hover {
  background: #00a8ff;
  border-color: #00a8ff;
  color: #0c1020;
}
.history-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.bar-sep {
  width: 1px;
  height: 14px;
  background: var(--color-border-medium);
  margin: 0 2px;
}

#reset-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.22);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}
#reset-btn:hover {
  color: rgba(255, 255, 255, 0.55);
}

.zoom-btn {
  width: 29px;
  height: 29px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 0.5px solid var(--color-border-medium);
  color: rgba(255, 255, 255, 0.45);
  font-size: 15px;
  transition: background var(--transition-fast);
}
.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.10);
}

/* ── CONTEXT MENU ──────────────────────────────────────────── */

#ctx-menu, #stage-ctx-menu {
  position: fixed;
  z-index: var(--z-ctx-menu);
  background: var(--color-surface);
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-lg);
  padding: 6px;
  min-width: 158px;
  box-shadow: var(--shadow-menu);
  animation: menuAppear 0.13s ease;
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-family: var(--font-brand);
  transition: background var(--transition-fast);
  text-align: left;
  white-space: nowrap;
}
.ctx-item:hover {
  background: var(--color-surface-hover);
}
.ctx-item.ctx-danger {
  color: var(--color-danger);
}
.ctx-item.ctx-danger:hover {
  background: var(--color-danger-hover);
}

.ctx-sep {
  height: 0.5px;
  background: var(--color-border);
  margin: 4px 6px;
}

/* ── STACK UI ──────────────────────────────────────────────── */

#stack-ui {
  position: fixed;
  right: 14px;
  top: 0;
  bottom: var(--bottom-safe);
  margin: auto 0;
  height: fit-content;
  z-index: var(--z-stack-ui);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  background: rgba(11, 11, 15, 0.93);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  animation: stackSlideIn 0.16s ease;
}

.stack-label {
  font-family: var(--font-brand);
  font-size: 9px;
  color: rgba(100, 160, 255, 0.42);
  letter-spacing: 0.14em;
}

.stack-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-accent-dim);
  border: 0.5px solid var(--color-accent-border);
  color: var(--color-accent);
  font-size: 18px;
  transition: all var(--transition-fast);
}
.stack-btn:hover  { background: rgba(100, 160, 255, 0.22); }
.stack-btn:active { transform: scale(0.91); }

#stack-dots {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 5px 0;
}

.stack-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  transition: all 0.18s ease;
}
.stack-dot.active {
  background: var(--color-accent);
  box-shadow: 0 0 5px var(--color-accent-glow);
  transform: scale(1.45);
}


#stack-done {
  font-family: var(--font-brand);
  font-size: 11px;
  font-weight: 500;
  color: #00a8ff;
  border: 1px solid #00a8ff;
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  letter-spacing: 0.05em;
  cursor: pointer;
  margin-top: 2px;
  transition: all var(--transition-fast);
}
#stack-done:hover {
  background: #00a8ff;
  color: white;
  box-shadow: 0 4px 14px rgba(0, 168, 255, 0.30);
}
#stack-done:active {
  transform: translateY(1px);
}

/* ── DROP OVERLAY ──────────────────────────────────────────── */

#drop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(100, 160, 255, 0.04);
  border: 1.5px dashed rgba(100, 160, 255, 0.30);
  pointer-events: none;
  z-index: var(--z-drop-overlay);
  animation: dropPulse 1.2s ease infinite;
}
#drop-overlay span {
  font-family: var(--font-brand);
  font-size: 15px;
  color: rgba(150, 190, 255, 0.65);
}

/* ── UTILITIES ─────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* Responsive: very small screens */
@media (max-width: 480px) {
  #hint {
    width: 85%;
    padding: 20px;
  }
  #hint p {
    font-size: 15px;
  }
  #hint span {
    font-size: 11px;
    margin-top: 12px;
    line-height: 1.4;
  }
}

@media (max-width: 380px) {
  .g-thumb, #add-btn { width: 56px; height: 56px; }
  #gallery { height: 88px; }
  :root { --bottom-safe: 132px; }
  #gallery { bottom: 40px; }
  #bottom-bar { height: 40px; }
}

/* ── WELCOME MODAL (first launch) ──────────────────────────── */

#welcome-modal {
  position: fixed;
  inset: 0;
  z-index: 90;   /* below splash (100), above everything else */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.welcome-card {
  background: rgba(16, 16, 22, 0.98);
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-xl);
  padding: 36px 32px 28px;
  width: min(420px, calc(100vw - 40px));
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
}

.welcome-logo {
  font-family: var(--font-brand);
  font-size: clamp(24px, 5vw, 38px);
  color: #ffffff;
  letter-spacing: 0.06em;
  margin-bottom: 20px;
}

.welcome-title {
  font-family: var(--font-ui);
  font-size: clamp(16px, 3vw, 20px);
  font-weight: 500;
  color: var(--color-text-primary);
  line-height: 1.4;
  margin-bottom: 10px;
}

.tt-more {
  color: var(--color-primary);
  font-weight: 600;
  cursor: pointer;
  margin-left: 4px;
}

/* Custom Builder's Square Icon */
.icon-builder-square {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border-right: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: translateY(-2px);
  opacity: 0.9;
}

.welcome-body {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.7;
  margin-bottom: 28px;
}

.welcome-btn-primary {
  display: block;
  width: 100%;
  padding: 13px 20px;
  background: var(--color-accent-dim);
  border: 1px solid var(--color-accent-border);
  border-radius: var(--radius-md);
  color: var(--color-accent);
  font-size: 15px;
  font-family: var(--font-brand);
  letter-spacing: 0.03em;
  margin-bottom: 10px;
  transition: all var(--transition-fast);
  cursor: pointer;
}
.welcome-btn-primary:hover {
  background: rgba(100, 160, 255, 0.25);
  border-color: rgba(100, 160, 255, 0.50);
}

.welcome-btn-secondary {
  display: block;
  width: 100%;
  padding: 10px 20px;
  background: transparent;
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-family: var(--font-brand);
  letter-spacing: 0.03em;
  transition: all var(--transition-fast);
  cursor: pointer;
  margin-bottom: 16px;
}
.welcome-btn-secondary:hover {
  color: var(--color-text-primary);
  border-color: var(--color-border-medium);
}

.welcome-note {
  font-size: 11px;
  color: var(--color-text-hint);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  min-height: 14px;
}

/* ── PRIVATE BETA WALL ─────────────────────────────────────── */

#beta-wall {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-canvas-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.5s ease;
}

.beta-card {
  background: rgba(16, 16, 22, 0.98);
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-xl);
  padding: 36px 32px 28px;
  width: min(380px, calc(100vw - 40px));
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
}

.beta-logo {
  font-family: var(--font-brand);
  font-size: clamp(24px, 5vw, 38px);
  color: #ffffff;
  letter-spacing: 0.06em;
  margin-bottom: 20px;
}

.beta-title {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: 10px;
}

.beta-body {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 24px;
}

#beta-password {
  width: 100%;
  padding: 12px 16px;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: white;
  font-family: var(--font-ui);
  font-size: 15px;
  margin-bottom: 16px;
  outline: none;
  text-align: center;
  letter-spacing: 0.2em;
}

#beta-password:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 8px rgba(0, 168, 255, 0.2);
}

#beta-error {
  color: var(--color-danger);
  font-size: 12px;
  margin-top: 12px;
  font-family: var(--font-ui);
}

/* ── PROPORTIONAL RESIZE CURSOR ────────────────────────────── */
/* Class added/removed by JS on brAnchor mousemove/mouseleave.  */
/* !important beats Konva's inline style.cursor on every frame. */
#stage-wrap.prop-resize-cursor,
#stage-wrap.prop-resize-cursor canvas {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M 20 3 L 20 20 L 3 20' fill='none' stroke='%2300a8ff' stroke-width='2.5' stroke-linecap='square' stroke-linejoin='miter'/%3E%3C/svg%3E") 20 20, nwse-resize !important;
}


/* ── EDIT UI PANEL ─────────────────────────────────────────── */

#edit-ui {
  position: fixed;
  right: 14px;
  top: 0;
  bottom: var(--bottom-safe);
  margin: auto 0;
  height: fit-content;
  z-index: var(--z-stack-ui);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  padding: 10px 8px;
  min-width: 116px;
  background: rgba(11, 11, 15, 0.95);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  animation: stackSlideIn 0.16s ease;
}

.edit-label {
  font-family: var(--font-brand);
  font-size: 9px;
  color: rgba(100, 160, 255, 0.42);
  letter-spacing: 0.14em;
  text-align: center;
  padding-bottom: 4px;
}

.edit-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0.5px solid transparent;
  color: rgba(255, 255, 255, 0.68);
  font-family: var(--font-brand);
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-align: left;
}
.edit-btn:hover:not(:disabled) {
  background: rgba(100, 160, 255, 0.12);
  border-color: var(--color-accent-border);
  color: #ffffff;
}
.edit-btn:active:not(:disabled) {
  transform: scale(0.95);
}
.edit-stub {
  opacity: 0.36;
  cursor: default;
}
.edit-soon {
  margin-left: auto;
  font-size: 8px;
  color: rgba(100, 160, 255, 0.55);
  background: rgba(100, 160, 255, 0.10);
  border: 0.5px solid rgba(100, 160, 255, 0.22);
  border-radius: 3px;
  padding: 1px 4px;
  letter-spacing: 0.06em;
}
.edit-sep {
  height: 0.5px;
  background: var(--color-border);
  margin: 2px 0;
}
.edit-close {
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: #00a8ff !important;
  border: 1px solid #00a8ff !important;
  border-radius: var(--radius-sm) !important;
  padding: 7px 10px !important;
  margin-top: 6px;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.edit-close:hover {
  background: #00a8ff !important;
  color: white !important;
  border-color: #00a8ff !important;
  box-shadow: 0 4px 14px rgba(0, 168, 255, 0.30);
}
.edit-close:active {
  transform: translateY(1px);
}

/* ── CROP CONFIRM BAR ──────────────────────────────────────── */

#crop-confirm {
  position: fixed;
  bottom: 168px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-stack-ui);
  display: flex;
  gap: 8px;
  padding: 7px;
  background: rgba(11, 11, 15, 0.92);
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
}

.crop-btn {
  padding: 8px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-brand);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.crop-btn-cancel {
  background: transparent;
  border: 0.5px solid var(--color-border-medium);
  color: rgba(255, 255, 255, 0.50);
}
.crop-btn-cancel:hover {
  border-color: var(--color-border-strong);
  color: rgba(255, 255, 255, 0.85);
}
.crop-btn-apply {
  background: #00a8ff;
  border: none;
  color: #ffffff;
}
.crop-btn-apply:hover {
  background: #33bbff;
  box-shadow: 0 4px 14px rgba(0, 168, 255, 0.35);
}

/* ── DRAGGABLE PANELS ───────────────────────────────────────── */

.panel-grab {
  cursor: grab;
  font-size: 14px;
  line-height: 1;
  color: var(--color-text-tertiary);
  opacity: 0.6;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2px 0 8px 0;
  width: 100%;
  user-select: none;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}

.panel-grab:hover {
  opacity: 1;
  color: var(--color-accent);
}

.panel-grab:active {
  cursor: grabbing;
}

.is-dragging {
  z-index: 99999 !important;
  user-select: none;
}

/* ── TOOL PALETTE ──────────────────────────────────────────── */

#tool-palette {
  position: absolute;
  top: 0;
  bottom: var(--bottom-safe);
  margin: auto 0;
  height: fit-content;
  left: 14px;
  z-index: var(--z-bar);
  display: flex;
  flex-direction: column;
  align-items: center;   /* centers narrower children (stroke bar, sep) without forcing a width */
  gap: 6px;
  padding: 8px;
  background: var(--color-bar-bg);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--color-border-medium);
  box-shadow: var(--shadow-panel);
}

.tool-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: rgba(255, 255, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.8);
}

.tool-btn.active {
  background: rgba(0, 168, 255, 0.15);
  border-color: rgba(0, 168, 255, 0.4);
  color: #00a8ff;
}

.tool-sep {
  height: 1px;
  background: var(--color-border-medium);
  margin: 2px 4px;
  align-self: stretch;   /* overrides parent align-items:center so the line spans full width */
}

.tool-color-wrapper {
  position: relative;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tool-color-picker {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.tool-color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

/* ── TOOL CONTROLS (Stroke) ────────────────────────────────── */

.tool-control-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.tool-stroke-preview-wrap {
  width: 24px;
  height: 24px;          /* fixed height — bar grows inside here, never shifts layout */
  display: flex;
  align-items: center;   /* bar is vertically centered in the fixed cell */
  justify-content: center;
  flex-shrink: 0;
}

.tool-stroke-preview {
  width: 24px;           /* fixed — never changes */
  height: 3px;           /* JS drives height only (1:1px with stroke value) */
  min-height: 1px;
  max-height: 24px;
  background: white;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(255,255,255,0.25);
  transition: height 0.1s ease;
}

#tool-stroke-slider {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 4px;
  height: 80px;
  appearance: none;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  cursor: pointer;
}

#tool-stroke-slider::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #00a8ff;
  border: 2px solid white;
}

/* ── FONT PICKER ───────────────────────────────────────────── */

#font-picker {
  position: fixed;
  left: 112px;
  top: 0;
  bottom: var(--bottom-safe);
  margin: auto 0;
  height: fit-content;
  z-index: var(--z-ctx-menu);
  background: rgba(11, 11, 15, 0.96);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  min-width: 180px;
  box-shadow: var(--shadow-panel);
  animation: menuAppear 0.15s ease;
}

.font-picker-header {
  font-family: var(--font-brand);
  font-size: 9px;
  color: rgba(100, 160, 255, 0.45);
  letter-spacing: 0.14em;
  margin-bottom: 12px;
  text-align: center;
}

.font-style-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.style-btn {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: white;
  font-size: 14px;
  font-family: var(--font-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.style-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.style-btn.active {
  background: rgba(0, 168, 255, 0.2);
  border-color: #00a8ff;
  color: #00a8ff;
}

.style-btn[data-style="italic"] { font-style: italic; }
.style-btn[data-style="bold"] { font-weight: bold; }
.style-btn[data-decoration="underline"] { text-decoration: underline; }
.style-btn[data-decoration="line-through"] { text-decoration: line-through; }

.font-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 10px;
}

.font-item {
  padding: 10px 14px;
  text-align: left;
  background: transparent;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  transition: all var(--transition-fast);
}

.font-item:hover {
  background: rgba(100, 160, 255, 0.15);
  color: white;
}

.font-item.active {
  background: rgba(0, 168, 255, 0.2);
  color: #00a8ff;
  font-weight: 500;
}

#font-done {
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid #00a8ff;
  color: #00a8ff;
  border-radius: var(--radius-sm);
  font-family: var(--font-brand);
  font-size: 11px;
  letter-spacing: 0.05em;
  transition: all var(--transition-fast);
}

#font-done:hover {
  background: #00a8ff;
  color: white;
}

/* ── TEXT EDITOR ───────────────────────────────────────────── */

#text-editor {
  position: absolute;
  z-index: 100;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.15);
  outline: none;
  padding: 4px;
  margin: -5px; /* Offset the padding/border so it hugs the text */
  resize: none;
  color: white;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.2;
  font-family: var(--font-brand);
  transform-origin: left top;
  caret-color: #00a8ff;
  box-shadow: 0 0 15px rgba(0,0,0,0.4);
}

/* Layout Picker */
#layout-picker {
  position: absolute;
  top: 100px;
  left: 64px;
  background: rgba(11, 11, 15, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  min-width: 200px;
  box-shadow: var(--shadow-panel);
  animation: menuAppear 0.15s ease;
  z-index: 1000;
}

.layout-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layout-item {
  background: none;
  border: none;
  padding: 10px;
  text-align: left;
  border-radius: var(--radius-md);
  color: white;
  transition: background 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.layout-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.layout-name {
  font-family: var(--font-brand);
  font-size: 13px;
  font-weight: 500;
  display: block;
}

.layout-desc {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
  display: block;
  margin-top: 2px;
}

#layout-done {
  margin-top: 16px;
  width: 100%;
  padding: 8px;
  background: rgba(0, 168, 255, 0.1);
  border: 1px solid rgba(0, 168, 255, 0.3);
  border-radius: var(--radius-sm);
  color: #00a8ff;
  font-family: var(--font-brand);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
}

#layout-done:hover {
  background: rgba(0, 168, 255, 0.2);
}


/* ── LASSO OVERLAY ────────────────────────────────────────── */

/* Higher specificity than #stage-wrap canvas (which sets position: relative) */
#stage-wrap > canvas#lasso-overlay,
#lasso-overlay {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  inset: 0 !important;
  z-index: 9999 !important;
  cursor: crosshair !important;
  pointer-events: auto !important;
  background: transparent;
  display: block !important;
  touch-action: none;
}

/* ── CROP INVERT TOGGLE ───────────────────────────────────── */

.crop-invert-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  font-family: var(--font-brand);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}
.crop-invert-toggle:hover { color: rgba(255, 255, 255, 0.9); }
.crop-invert-toggle input { cursor: pointer; accent-color: #00a8ff; }
.crop-invert-toggle input:checked + span { color: #00a8ff; }

/* ── COLOR PANEL ──────────────────────────────────────────── */

#color-panel {
  position: fixed;
  right: 14px;
  top: 0;
  bottom: var(--bottom-safe);
  margin: auto 0;
  height: fit-content;
  z-index: var(--z-stack-ui);
  width: 234px;
  padding: 12px 12px 10px;
  background: rgba(11, 11, 15, 0.95);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  animation: stackSlideIn 0.16s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cp-row {
  display: grid;
  grid-template-columns: 70px 1fr 32px;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-family: var(--font-brand);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
  letter-spacing: 0.02em;
}
.cp-row label { cursor: default; }
.cp-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  height: 3px;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.cp-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00a8ff;
  border: 2px solid #0c1020;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(0, 168, 255, 0.55);
}
.cp-row input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00a8ff;
  border: 2px solid #0c1020;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(0, 168, 255, 0.55);
}
.cp-val {
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: right;
  color: rgba(255, 255, 255, 0.50);
}

.cp-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 2px;
}
.cp-preset {
  padding: 6px 6px;
  font-size: 10.5px;
  background: transparent;
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.70);
  cursor: pointer;
  font-family: var(--font-brand);
  letter-spacing: 0.04em;
  transition: all var(--transition-fast);
}
.cp-preset:hover {
  border-color: var(--color-accent);
  color: #ffffff;
  background: rgba(100, 160, 255, 0.10);
}
.cp-preset:active { transform: scale(0.96); }

.cp-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.cp-cancel {
  flex: 1;
  padding: 7px 10px;
  font-family: var(--font-brand);
  font-size: 11px;
  letter-spacing: 0.05em;
  background: transparent;
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.cp-cancel:hover {
  border-color: var(--color-border-strong);
  color: rgba(255, 255, 255, 0.85);
}
.cp-actions .edit-close {
  flex: 1;
  margin-top: 0 !important;
}
/* -- HELP & BUG REPORT STYLES ------------------------------ */

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: 0.5px solid rgba(255, 255, 255, 0.5);
  color: rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-brand);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 1);
  color: rgba(255, 255, 255, 1);
  transform: scale(1.05);
}

#welcome-modal {
  position: fixed;
  inset: 0;
  z-index: 10100;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#help-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.help-card {
  background: rgba(16, 16, 22, 0.98);
  border: 0.5px solid var(--color-border-medium);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: min(460px, calc(100vw - 40px));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.9);
}

.help-header {
  font-family: var(--font-brand);
  font-size: 10px;
  color: var(--color-accent);
  letter-spacing: 0.2em;
  margin-bottom: 24px;
  text-align: center;
}

.help-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 32px;
}

.help-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-field label {
  font-family: var(--font-brand);
  font-size: 11px;
  color: var(--color-text-secondary);
  text-transform: lowercase;
  letter-spacing: 0.05em;
}

#help-comment {
  width: 100%;
  height: 120px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  color: white;
  font-family: var(--font-ui);
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
}

#help-comment:focus {
  border-color: var(--color-accent);
}

#help-user {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--color-border-strong);
  padding: 8px 0;
  color: white;
  font-family: var(--font-ui);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease;
}

#help-user:focus {
  border-bottom-color: var(--color-accent);
}

#help-user::placeholder {
  color: rgba(255, 255, 255, 0.25);
  font-style: italic;
  /* Simulated dither look via text-shadow */
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
  transition: opacity 0.2s ease;
}

#help-user:focus::placeholder {
  opacity: 0;
}

.help-actions {
  display: flex;
  gap: 12px;
}

/* -- NEW HELP MENU STYLES -- */
.help-menu-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.help-menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text-primary);
  font-family: var(--font-brand);
  font-size: 15px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.help-menu-btn:hover {
  background: rgba(100, 160, 255, 0.08);
  border-color: var(--color-accent-border);
  transform: translateX(5px);
}

.help-menu-btn .icon {
  font-size: 20px;
  width: 24px;
  text-align: center;
}

.help-menu-btn .btn-text {
  flex: 1;
}

.help-menu-btn .chevron {
  opacity: 0.3;
  font-size: 12px;
}

/* -- FEATURES LIST STYLES -- */
.features-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 12px;
  margin: 10px 0 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--color-accent-border) transparent;
}

.features-list::-webkit-scrollbar {
  width: 4px;
}
.features-list::-webkit-scrollbar-thumb {
  background: var(--color-accent-border);
  border-radius: 4px;
}

.feature-item {
  display: flex;
  gap: 16px;
}

.feature-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: rgba(100, 160, 255, 0.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feature-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feature-title {
  font-family: var(--font-brand);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-accent);
  letter-spacing: 0.01em;
}

.feature-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.help-back-btn {
  margin-bottom: 20px;
  background: transparent;
  border: none;
  color: var(--color-accent);
  font-family: var(--font-brand);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.help-back-btn:hover {
  opacity: 1;
}

/* -- ONBOARDING TOOLTIP STYLES --------------------------- */

.tooltip-bubble {
  position: fixed;
  z-index: 10000;
  background: rgba(16, 16, 22, 0.98);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  width: min(280px, calc(100vw - 40px));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: auto;
  animation: ttAppear 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes ttAppear {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.tooltip-bubble.shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* Special case for centered tooltip */
.tooltip-bubble[style*="translate(-50%, -50%)"].shake {
  animation: shakeCenter 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

.tt-header {
  font-family: var(--font-brand);
  font-size: 10px;
  color: var(--color-accent);
  letter-spacing: 0.15em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.tt-body {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.tt-actions {
  display: flex;
  justify-content: flex-end;
}

.tt-next {
  background: var(--color-accent-dim);
  border: 1px solid var(--color-accent-border);
  border-radius: var(--radius-sm);
  color: var(--color-accent);
  padding: 6px 14px;
  font-family: var(--font-brand);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tt-next:hover {
  background: rgba(100, 160, 255, 0.25);
  transform: translateX(2px);
}

.tt-image {
  width: 100%;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  border: 1px solid var(--color-border-medium);
}

/* -- ONBOARDING WELCOME OVERLAY ------------------------- */

#onboarding-welcome {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.1); /* Dark tint */
  backdrop-filter: blur(8px);     /* Glass effect */
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 1s ease;
}

.onboarding-welcome-text {
  font-family: var(--font-brand);
  font-size: clamp(24px, 5vw, 42px);
  color: white;
  letter-spacing: 0.1em;
  opacity: 0;
  animation: welcomeFadeIn 1.5s ease forwards;
}

@keyframes welcomeFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

#onboarding-welcome {
  flex-direction: column;
  gap: 16px;
  cursor: pointer;
}

#welcome-continue-hint {
  font-family: var(--font-brand);
  font-size: 11px;
  font-style: italic;
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 0.1em;
  opacity: 0;
  animation: welcomeFadeIn 1s ease 1s forwards;
}

/* -- FORM HARDENING ---------------------------------- */

.help-field input.error, .help-field textarea.error {
  border-color: #ff4d4d !important;
  background: rgba(255, 77, 77, 0.05);
}

.shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

#help-error-msg {
  color: #ff4d4d;
  font-size: 11px;
  margin-top: 8px;
  text-align: center;
  font-family: var(--font-brand);
  opacity: 0;
  transition: opacity 0.2s ease;
}

#help-error-msg.visible {
  opacity: 1;
}

/* -- HELP SUCCESS ANIMATION ---------------------------- */

#help-success-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  min-height: 250px;
}

.success-icon {
  width: 80px;
  height: 80px;
  margin-bottom: 24px;
}

.success-circle {
  stroke: #00a8ff;
  stroke-width: 2;
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-linecap: round;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.success-check {
  transform-origin: 50% 50%;
  stroke: #00a8ff;
  stroke-width: 4;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

.success-msg {
  font-family: var(--font-brand);
  font-size: 18px;
  color: white;
  text-align: center;
  animation: welcomeFadeIn 0.5s ease 0.5s both;
}

@keyframes stroke {
  100% { stroke-dashoffset: 0; }
}

.help-recipient-info {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 12px;
  text-align: center;
  font-family: var(--font-brand);
  letter-spacing: 0.5px;
}


/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE SYSTEM — Boarderless
   Breakpoints (device-width, not pixel-count):
     xs  : < 400px   — small phones (SE, older Androids)
     sm  : 400–600px — standard phones (iPhone 14, Pixel)
     md  : 600–900px — large phones, phablets, portrait tablet
     lg  : 900–1400px — landscape tablet, small laptop
     xl  : > 1400px  — large desktop, 4K monitors
   Strategy:
     - Base styles = "sm" (the modal center of gravity)
     - xs   = shrink everything
     - md+  = grow and re-position panels
     - lg+  = full desktop layout
     - xl   = spacious desktop, larger hit-targets
   Collision avoidance:
     Panels (edit-ui, stack-ui, color-panel, font-picker, layout-picker)
     share a right-side column on desktop and move to bottom-anchored
     sheets on mobile. JS handles runtime conflict resolution when
     multiple panels are simultaneously visible (see initPanelCollision).
   ═══════════════════════════════════════════════════════════════ */

/* ── EDIT ICON (SVG inline icons in edit-btn) ────────────────── */

.edit-icon {
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity var(--transition-fast);
}
.edit-btn:hover .edit-icon { opacity: 1; }

/* ── XS — tiny phones (< 400px) ─────────────────────────────── */

@media (max-width: 399px) {
  /* Tool palette: shrink buttons */
  .tool-btn { width: 30px; height: 30px; }
  #tool-stroke-slider { height: 60px; }
  #tool-palette { gap: 4px; padding: 6px; left: 8px; }

  /* Gallery */
  .g-thumb, #add-btn { width: 52px; height: 52px; }
  #gallery { height: 82px; bottom: 38px; }
  :root { --bottom-safe: 120px; }
  #bottom-bar { height: 38px; }

  /* Edit panel: compress */
  #edit-ui { min-width: 96px; padding: 7px 6px; right: 8px; }
  .edit-btn { font-size: 10px; padding: 6px 7px; gap: 5px; }
  .edit-label { font-size: 8px; }

  /* Stack UI */
  #stack-ui { right: 8px; padding: 7px 6px; }
  .stack-btn { width: 30px; height: 30px; font-size: 15px; }

  /* Color panel: full-width bottom sheet */
  #color-panel {
    right: 0; left: 0; top: auto;
    bottom: 120px;
    transform: none;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-left: none; border-right: none; border-bottom: none;
    max-height: 55vh;
    overflow-y: auto;
  }

  /* Font picker: full-width bottom sheet */
  #font-picker {
    left: 0; right: 0; top: auto;
    bottom: 120px;
    transform: none;
    min-width: unset;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 60vh;
    overflow-y: auto;
  }

  /* Top controls */
  #top-left-controls { top: 8px; left: 8px; }
  #top-right-controls { top: 8px; right: 8px; }
  .accent-btn { padding: 6px 10px; font-size: 11px; }
  .history-btn { width: 26px; height: 26px; }

  /* Hint */
  #hint { width: 80%; padding: 16px; top: 35%; }
  #hint p { font-size: 13px; }
  #hint span { font-size: 10px; }
}

/* ── SM — standard phones (400–599px) ───────────────────────── */

@media (min-width: 400px) and (max-width: 599px) {
  /* Tool palette */
  .tool-btn { width: 33px; height: 33px; }
  #tool-stroke-slider { height: 70px; }

  /* Color panel: bottom sheet */
  #color-panel {
    right: 0; left: 0; top: auto;
    bottom: 150px;
    transform: none;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-left: none; border-right: none; border-bottom: none;
    max-height: 52vh;
    overflow-y: auto;
  }

  /* Font picker: bottom sheet */
  #font-picker {
    left: 0; right: 0; top: auto;
    bottom: 150px;
    transform: none;
    min-width: unset;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 58vh;
    overflow-y: auto;
  }

  /* Layout picker: bottom sheet */
  #layout-picker {
    left: 0; right: 0; top: auto;
    bottom: 150px;
    position: fixed;
    transform: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 55vh;
    overflow-y: auto;
  }
}

/* ── MD — large phones / phablets / portrait tablet (600–899px) */

@media (min-width: 600px) and (max-width: 899px) {
  .tool-btn { width: 38px; height: 38px; }

  /* Panels shift left away from right edge to avoid edit-ui */
  #stack-ui { right: 24px; }
  #edit-ui  { right: 24px; }

  #color-panel,
  #font-picker,
  #layout-picker {
    position: fixed;
    top: auto;
    bottom: var(--bottom-safe);
    left: 14px;
    right: 14px;
    width: auto;
    height: auto;
    max-height: 50vh;
    overflow-y: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border: 0.5px solid var(--color-accent-border);
    transform: none;
    margin: 0;
  }
}

/* ── LG — landscape tablet / small laptop (900–1399px) ────────── */

@media (min-width: 900px) {
  /* More breathing room for all panels */
  #tool-palette { left: 20px; gap: 8px; padding: 10px; }
  .tool-btn { width: 40px; height: 40px; }

  #edit-ui  { right: 20px; min-width: 130px; }
  #stack-ui { right: 20px; }
  #color-panel { right: 20px; width: 250px; }

  #font-picker  { left: 120px; }
  #layout-picker { left: 120px; }

  #top-left-controls  { top: 18px; left: 18px; }
  #top-right-controls { top: 18px; right: 18px; }
}

/* ── XL — large desktop / 4K (≥ 1400px) ──────────────────────── */

@media (min-width: 1400px) {
  /* Upscale the whole UI proportionally */
  .tool-btn { width: 46px; height: 46px; }
  #tool-palette { left: 28px; gap: 10px; padding: 12px; }

  .edit-btn { font-size: 14px; padding: 10px 13px; }
  #edit-ui  { right: 28px; min-width: 148px; padding: 13px 10px; }
  #stack-ui { right: 28px; }
  .stack-btn { width: 42px; height: 42px; font-size: 22px; }

  #color-panel { right: 28px; width: 270px; }
  #font-picker  { left: 132px; }
  #layout-picker { left: 132px; }

  .g-thumb, #add-btn { width: 80px; height: 80px; }
  #gallery { height: 116px; }
  :root { --bottom-safe: 160px; }
  .gallery-label { font-size: 10px; }

  #top-left-controls  { top: 22px; left: 28px; }
  #top-right-controls { top: 22px; right: 28px; }
  .accent-btn { padding: 10px 20px; font-size: 14px; }
  .history-btn { width: 34px; height: 34px; }

  #hint p { font-size: 18px; }
  #hint span { font-size: 13px; }

  .ctx-item { font-size: 14px; padding: 11px 13px; }
  #ctx-menu, #stage-ctx-menu { min-width: 180px; }
}

/* ── PANEL COLLISION CONTAINMENT ─────────────────────────────── */
/* When both edit-ui and stack-ui are visible on narrow screens,
   JS adds .panel-shift-left to stack-ui to avoid overlap.
   On desktop they naturally fit — this only fires on mobile. */

#stack-ui.panel-shift-left {
  right: auto;
  left: 60px;
}

/* color-panel overlaps edit-ui on phone — JS adds .panel-below
   to push it into a bottom-sheet position regardless of breakpoint */
#color-panel.panel-below,
#font-picker.panel-below,
#layout-picker.panel-below {
  right: 0; left: 0; top: auto;
  bottom: 150px;
  transform: none;
  width: min(100%, 500px);
  margin: 0 auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-left: none; border-right: none; border-bottom: none;
}

/* ── Frame Style Panel ──────────────────────────────────────────── */
#frame-style-panel {
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--z-stack-ui);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 10px;
  background: rgba(11, 11, 15, 0.93);
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  min-width: 160px;
}

.frame-style-header {
  font-family: var(--font-brand);
  font-size: 9px;
  color: rgba(100, 160, 255, 0.42);
  letter-spacing: 0.14em;
  text-align: center;
  margin-bottom: 2px;
}

.frame-style-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.frame-style-label {
  font-size: 11px;
  color: var(--color-text-muted, rgba(255,255,255,0.55));
  min-width: 36px;
  flex-shrink: 0;
}

#frame-color-input {
  width: 36px;
  height: 28px;
  padding: 0;
  border: 0.5px solid var(--color-accent-border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

#frame-thickness-input {
  flex: 1;
  accent-color: var(--color-accent);
  min-width: 0;
}

#frame-thickness-val {
  font-size: 11px;
  color: var(--color-accent);
  min-width: 20px;
  text-align: right;
}

/* Mobile: use same positioning rules as stack-ui */
@media (max-width: 599px) {
  #frame-style-panel {
    right: 8px;
    padding: 9px 8px;
    min-width: 140px;
  }
}
@media (min-width: 900px) {
  #frame-style-panel {
    right: 24px;
  }
}
@media (min-width: 1400px) {
  #frame-style-panel {
    right: 28px;
  }
}
