* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
/* Keep toolbar fixed; allow mosaic area to scroll */
html, body {
  /* Prevent the page itself from scrolling; the grid's main area should handle
     scrolling if ever needed. This also avoids 1px scrollbars from rounding. */
  overflow: hidden;
}

body {
  /* Constrain the CSS grid to the viewport to avoid tiny 1–2px overflows that
     cause an annoying vertical scrollbar. Prefer dvh when supported. */
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto; /* header, main, footer */
  background: radial-gradient(circle at top left, #1e293b, #020617 52%);
  color: #0f172a;
}
header { position: sticky; top: 0; z-index: 10; background: #fff; padding: 6px 2px 8px 2px; margin: 0px 0px 5px 0px;  border-bottom: 3px solid rgba(15,23,42,0.35);
 display: flex; align-items: center; gap: 10px; flex-wrap: wrap;   backdrop-filter: blur(10px);
}
.auth-controls { display: inline-flex; gap: 6px; align-items: center; }
.auth-controls .auth-primary { background: #2563eb; color: #fff; border-color: #1d4ed8; }
header {
  display: flex;
  justify-content: center;
}
header h1 {
  margin: 0 16px 0 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #0f172a; /* high contrast on light header bg */
}
header .toolbar {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15,23,42,0.93);
  box-shadow: 0 10px 30px rgba(15,23,42,0.75);
}
main {
  /* In a CSS grid, grid items default to min-height:auto, which can prevent the
     1fr row from shrinking and produce unwanted page scroll. */
  min-height: 0;
  overflow: auto;
  padding: 0;
  display: block;
}
.splash-backdrop { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 20vh; z-index: 900; background: #f1f5f9; }
.splash-backdrop[hidden] { display: none !important; }
.splash-backdrop .splash-title { color: #334155; font-size: 24px; font-weight: 600; letter-spacing: 0.3px; text-shadow: 0 1px 2px rgba(0,0,0,0.06); text-align: center; }
.mosaic-wrap { position: relative; width: max-content; min-height: max-content; margin: 0 auto;   border-radius: 22px;
  background: radial-gradient(circle at top, rgba(15,23,42,0.96), rgba(15,23,42,0.98));
  /* Use a centered glow instead of a big downward shadow, which looked like a grey overlay below the canvas. */
  box-shadow: 0 0 50px rgba(15,23,42,0.75);
}

/* Loading overlay shown during large chunked mosaic loads */
.load-overlay[hidden] { display: none !important; }
.load-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: rgba(2,6,23,0.60);
  backdrop-filter: blur(2px);
  z-index: 50;
  pointer-events: none;
}
.load-thumb {
  max-width: min(720px, 92vw);
  max-height: min(520px, 70vh);
  width: auto;
  height: auto;
  image-rendering: pixelated;
  border-radius: 12px;
  border: 1px solid rgba(148,163,184,0.5);
  box-shadow: 0 24px 60px rgba(15,23,42,0.85);
  background: #020617;
}
.load-card {
  max-width: min(720px, 92vw);
  background: rgba(15,23,42,0.92);
  border: 1px solid rgba(148,163,184,0.35);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 12px 30px rgba(15,23,42,0.75);
  text-align: center;
}
.load-title {
  color: #e5e7eb;
  font-size: 14px;
  font-weight: 700;
}
.load-sub {
  margin-top: 2px;
  color: #cbd5e1;
  font-size: 12px;
}
.load-progress {
  margin-top: 6px;
  color: #93c5fd;
  font-size: 12px;
}
.load-progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(15,23,42,0.9);
  border: 1px solid rgba(148,163,184,0.7);
  overflow: hidden;
}
.load-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  transition: width 120ms linear;
}
.load-progress-label {
  margin-top: 2px;
  font-size: 11px;
  color: #bfdbfe;
  text-align: center;
}
#mosaic {
  border: 1px solid #1e293b;
  image-rendering: pixelated;
  max-width: none;
  height: auto;
  display: block;
  background: #020617;
  /* Shadow is handled by .mosaic-wrap; keeping a second shadow here made the bottom look like an overlay. */
  box-shadow: none;
}
#overlay { position: absolute; left: 0; top: 0; image-rendering: pixelated; pointer-events: none; }
button { padding: 4px 10px; font-size: 12px; border-radius: 999px; border: 1px solid rgba(148,163,184,0.6); background:#0f172a; color:#e5e7eb; cursor:pointer; }
button:hover { background:#1e293b; }
/* Generic disabled state */
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.size-info { color: #94a3b8; font-size: 12px; }
.funds-info { color: #22c55e; font-size: 12px; margin-left: 8px; }
.tools { display: inline-flex; gap: 6px; margin-left: 8px; }
.tool-btn {
  border: 1px solid rgba(148,163,184,0.6);
  background: rgba(15,23,42,0.9);
  color: #e5e7eb;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 80ms ease;
}
.tool-btn .icon { display: inline-flex; width: 16px; height: 16px; }
.tool-btn .label { font-size: 12px; }
.tool-btn:hover { background: #111827; border-color: #60a5fa; }
.tool-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(96,165,250,0.9); }
.tool-btn.active {
  background: linear-gradient(135deg,#3b82f6,#22c55e);
  color: #0b1120;
  border-color: rgba(15,23,42,0.85);
  box-shadow: 0 6px 20px rgba(15,23,42,0.9);
  transform: translateY(-1px);
}
.tool-btn.active .icon { color: currentColor; }
.tool-btn.active .label { font-weight: 600; }
/* Playback combo control */
.playback-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Playback speed pills */
.playback-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.playback-speed-label {
  font-size: 11px;
  color: #94a3b8;
}

.speed-pills {
  display: inline-flex;
  background: rgba(15,23,42,0.85);
  border: 1px solid rgba(148,163,184,0.4);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}

.speed-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.speed-pill:hover {
  background: rgba(148,163,184,0.15);
}

.speed-pill.active {
  background: linear-gradient(135deg,#3b82f6,#22c55e);
  color: #020617;
  font-weight: 600;
}

/* Playback speed pills */
.playback-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.playback-speed-label {
  font-size: 11px;
  color: #94a3b8;
}

.speed-pills {
  display: inline-flex;
  background: rgba(15,23,42,0.85);
  border: 1px solid rgba(148,163,184,0.4);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}

.speed-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.speed-pill:hover {
  background: rgba(148,163,184,0.15);
}

.speed-pill.active {
  background: linear-gradient(135deg,#3b82f6,#22c55e);
  color: #020617;
  font-weight: 600;
}


/* Primary actions */
#commit {
  background: transparent;
  border-color: rgba(34,197,94,0.7);
  color: #bbf7d0;
}
#commit:hover {
  background: rgba(22,163,74,0.15);
  border-color: rgba(22,163,74,0.9);
}
#revert {
  background: transparent;
  border-color: rgba(248,113,113,0.6);
  color:#fecaca;
}

/* Commit preview status (confirm modal) */
.commit-status {
  font-weight: 600;
}
.commit-status.pending {
  color: #dc2626; /* red */
}
.commit-status.ready {
  color: #16a34a; /* green */
}

.commit-progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  margin: 10px 0 6px 0;
}
.commit-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  transition: width 120ms linear;
}
.commit-progress-label {
  font-size: 12px;
  color: #334155;
  margin: 0 0 6px 0;
  text-align: right;
}

#commitYes:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#uploadImage { background: rgba(15,23,42,0.85); }
/* When Upload is used as a tool (image tool active), make its active state
   look like the other tools and keep the label/icon clearly visible. */
#uploadImage.tool-btn.active {
  background: linear-gradient(135deg,#3b82f6,#22c55e);
  color: #0b1120;
  border-color: rgba(15,23,42,0.85);
  box-shadow: 0 6px 20px rgba(15,23,42,0.9);
  transform: translateY(-1px);
}
.toolbar .spacer { flex: 1 1 auto; }
/* In view-only mode (no auth), hide the Upload button entirely as a safety net */
body.view-only #uploadImage { display: none !important; }
/* In view-only mode, hide pixel change footer text */
body.view-only #pixelChangeInfo { display: none !important; }
/* In edit mode, make pixel-change info more prominent */
body:not(.view-only) #pixelChangeInfo {
  color: #f9fafb;
  font-weight: 600;
}

#mosaic.cursor-pen { cursor: crosshair; }
#mosaic.cursor-eraser { cursor: crosshair; }
#mosaic.cursor-dropper { cursor: copy; }
#mosaic.cursor-line { cursor: crosshair; }
#mosaic.cursor-rect, #mosaic.cursor-oval { cursor: crosshair; }
#mosaic.cursor-select, #mosaic.cursor-lasso { cursor: crosshair; }
#mosaic.cursor-text { cursor: text; }
#mosaic.cursor-lock { cursor: crosshair; }

/* Image mini toolbar */
.mini-toolbar[hidden] { display: none; }
.mini-toolbar { position: absolute; left: 0; top: 0; display: inline-flex; gap: 6px; background: #fff; border: 1px solid #cbd5e1; border-radius: 4px; padding: 4px 6px; box-shadow: 0 6px 18px rgba(0,0,0,0.15); z-index: 2; pointer-events: auto; }
.mini-toolbar button { padding: 4px 8px; font-size: 12px; }

/* Modal/panel styles (non-dimming, draggable) */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: transparent; display: block; z-index: 1000; pointer-events: none; }
.modal {
  position: absolute;
  top: 64px;          /* was 16px – drop it below the header/toolbar */
  right: 16px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 12px;
  min-width: 360px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  pointer-events: auto;
}
.modal h2 {
  margin: 0 0 6px 0;
  font-size: 16px;
  cursor: grab;      /* was: move */
  user-select: none;
  padding-right: 18px;
}
.modal.panel-dragging h2 {
  cursor: grabbing;
}
body.panel-dragging {
  user-select: none;
}
.modal .modal-close { position: absolute; top: 4px; right: 6px; border: none; background: transparent; padding: 0; font-size: 14px; line-height: 1; cursor: pointer; color: #64748b; }
.modal .modal-close:hover { color: #0f172a; }
.modal .modal-close:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.modal .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.modal .row label { display: flex; gap: 6px; align-items: center; }
.modal .row.erase-options { flex-direction: column; align-items: flex-start; }
.modal .row.erase-options label { width: 100%; justify-content: space-between; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* Tool panel Apply/Cancel should be compact (pen/line overlays) */
#toolPendingActions {
  gap: 6px;
  margin-top: 10px;
}
#toolPendingActions button {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 10px;
}

/* Centered, larger, embellished auth panel */
#authPanel.modal-backdrop { background: rgba(15, 23, 42, 0.35); backdrop-filter: blur(1px); }
#authPanel .modal {
  top: 50%; right: auto; left: 50%; transform: translate(-50%, -50%);
  min-width: 440px; max-width: 560px;
  padding: 18px 20px;
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
}
#resetPanel .modal {
  top: 50%; right: auto; left: 50%; transform: translate(-50%, -50%);
  min-width: 420px; max-width: 520px;
  padding: 18px 20px;
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
}
#adminChangeModal .modal {
  top: 50%; right: auto; left: 50%; transform: translate(-50%, -50%);
  min-width: 360px; max-width: 520px;
}
#authPanel .modal h2 {
  margin: 0 0 10px 0;
  font-size: 20px;
  letter-spacing: 0.2px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}
#authPanel .modal .row label { gap: 8px; }
#authPanel input[type="email"], #authPanel input[type="password"] {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}
#authPanel .actions { margin-top: 14px; }
#authPanel .auth-subtext { margin: 10px 0 0 0; color: #64748b; font-size: 12px; }

/* Lock timer bar at bottom of page */
.lock-timer {
  position: fixed;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  background: #0f172a;
  color: #e5e7eb;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: 0 4px 12px rgba(15,23,42,0.6);
  z-index: 2000;
}
.lock-timer[hidden] { display: none; }

/* Global busy overlay shown while large pixel batches are pushed down to the base canvas */
.busy-overlay[hidden] { display: none; }
.busy-overlay {
  position: fixed;
  inset: 0;
  /* Strong dimming tint so the overlay is clearly visible over the dark
     mosaic background. */
  background: rgba(15,23,42,0.75);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  pointer-events: auto;
}

/* Keep the commit confirm modal above the busy overlay so we can show progress
   while the rest of the UI is blocked. */
#commitConfirm.modal-backdrop {
  z-index: 10000;
}

/* Insufficient-funds modal must be above the commit panel (which can still be
   open when billing hold fails). */
#addFundsModal.modal-backdrop {
  z-index: 11000;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(1px);
  pointer-events: auto;
}
#addFundsModal .modal {
  top: 50%;
  right: auto;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
}
.busy-overlay .busy-panel {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(15,23,42,0.96);
  color: #e5e7eb;
  box-shadow: 0 18px 40px rgba(15,23,42,0.9);
}
.busy-overlay .busy-text {
  font-size: 13px;
}
.busy-spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(148,163,184,0.6);
  border-top-color: #60a5fa;
  animation: busy-spin 0.8s linear infinite;
}
@keyframes busy-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Transient notice for very large pushdowns (non-interactive, auto-hides) */
.pushdown-hint[hidden] { display: none; }
.pushdown-hint {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15,23,42,0.96);
  color: #e5e7eb;
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(15,23,42,0.75);
  z-index: 3200;
  pointer-events: none;
}

/* Higher-visibility warning variant (used for protected/no-overwrite alerts) */
.pushdown-hint.warn {
  background: #f59e0b;          /* orange */
  color: #0b1220;               /* near-black */
  border: 1px solid rgba(11,18,32,0.85);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 14px;
  box-shadow: 0 12px 36px rgba(15,23,42,0.55);
}


#guestViewNotice.modal-backdrop {
  z-index: 10500;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}
#guestViewNotice .modal {
  top: 50%;
  right: auto;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 380px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 18px 20px;
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.22), 0 2px 8px rgba(0,0,0,0.08);
}
#guestViewNotice .modal h2 {
  margin: 0 0 10px 0;
  font-size: 20px;
  letter-spacing: 0.2px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
  cursor: default;
}
#guestViewNotice .actions {
  margin-top: 16px;
  justify-content: flex-end;
}


#editorHelpModal.modal-backdrop {
  z-index: 10480;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}
#editorHelpModal .modal {
  top: 50%;
  right: auto;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(860px, calc(100vw - 32px));
  min-width: 320px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 18px 20px 16px;
  border-radius: 12px;
  box-shadow: 0 18px 42px rgba(0,0,0,0.24), 0 2px 8px rgba(0,0,0,0.08);
}
#editorHelpModal .modal h2 {
  margin: 0 0 10px 0;
  font-size: 22px;
  letter-spacing: 0.2px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
  cursor: default;
}
.editor-help-intro {
  color: #334155;
  line-height: 1.55;
  margin-bottom: 12px;
}
.editor-help-intro p {
  margin: 0 0 10px 0;
}
.editor-help-guest-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}
.editor-help-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 14px 0;
}
.editor-help-tab {
  border-radius: 999px;
  background: #e2e8f0;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  padding: 6px 12px;
  font-size: 12px;
}
.editor-help-tab:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}
.editor-help-tab.active {
  background: linear-gradient(135deg,#3b82f6,#22c55e);
  color: #0b1120;
  border-color: rgba(15,23,42,0.85);
  font-weight: 700;
}
.editor-help-panels {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  padding: 14px 16px;
}
.editor-help-panel h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
  color: #0f172a;
}
.editor-help-panel p,
.editor-help-panel li {
  color: #334155;
  line-height: 1.6;
  font-size: 14px;
}
.editor-help-panel ul,
.editor-help-panel ol {
  margin: 0 0 10px 18px;
  padding: 0;
}
.editor-help-panel p:last-child {
  margin-bottom: 0;
}
#editorHelpModal .actions {
  margin-top: 14px;
  justify-content: flex-end;
}



/* Enhanced resize handles */
.resize-handle {
    width: 16px;
    height: 16px;
    background: #ffffff;
    border: 2px solid #0f172a;
    border-radius: 3px;
    position: absolute;
    z-index: 20;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.resize-handle::before {
    content: '';
    position: absolute;
    inset: -8px;
}
.resize-handle.nw { cursor: nwse-resize; }
.resize-handle.ne { cursor: nesw-resize; }
.resize-handle.sw { cursor: nesw-resize; }
.resize-handle.se { cursor: nwse-resize; }
.resize-handle:hover {
    transform: scale(1.15);
}



/* Cursor fixes for resize handles */
.resize-handle {
    cursor: pointer;
}
.resize-handle.nw,
.resize-handle.se {
    cursor: nwse-resize;
}
.resize-handle.ne,
.resize-handle.sw {
    cursor: nesw-resize;
}
/* ensure hitbox does not block cursor */
.resize-handle::before {
    pointer-events: none;
}


/* Keep the container cursor in sync while hovering image resize corners. */
.mosaic-wrap {
  cursor: inherit;
}



/* Desktop editor layout: reserve a right-side dock for active tool panels */
body.editor-side-panel-open main {
  padding-right: 372px;
  transition: padding-right 160ms ease;
}
main {
  transition: padding-right 160ms ease;
}

/* Make the header and toolbar handle tighter widths more gracefully */
header {
  justify-content: flex-start;
  padding-left: 10px;
  padding-right: 10px;
}
header .toolbar {
  flex: 1 1 720px;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 6px 8px;
  border-radius: 22px;
  padding: 8px 10px;
}
.tools {
  flex-wrap: wrap;
  margin-left: 0;
  max-width: 100%;
}
.tool-btn {
  flex: 0 0 auto;
}
.toolbar > * {
  min-width: 0;
}

/* Convert the tool panels into a vertical dock on larger screens */
@media (min-width: 1180px) {
  #toolPanel,
  #textPanel,
  #imagePanel {
    position: fixed;
    top: 84px;
    right: 0;
    bottom: 10px;
    left: auto;
    width: 360px;
    background: transparent;
    z-index: 1200;
    pointer-events: none;
  }
  #toolPanel .modal,
  #textPanel .modal,
  #imagePanel .modal {
    position: absolute !important;
    top: 0 !important;
    right: 16px !important;
    left: auto !important;
    bottom: 0 !important;
    transform: none !important;
    width: 340px !important;
    min-width: 0 !important;
    max-width: 340px !important;
    max-height: calc(100vh - 110px) !important;
    overflow: auto;
    border-radius: 18px;
    padding: 14px 14px 12px;
    box-shadow: 0 16px 40px rgba(2, 6, 23, 0.30), 0 3px 10px rgba(2, 6, 23, 0.16);
  }
  #toolPanel .modal .row,
  #textPanel .modal .row,
  #imagePanel .modal .row {
    flex-direction: column;
    align-items: stretch;
  }
  #toolPanel .modal .row label,
  #textPanel .modal .row label,
  #imagePanel .modal .row label {
    justify-content: space-between;
  }
  #toolPanel .modal input[type="range"],
  #textPanel .modal input[type="range"],
  #imagePanel .modal input[type="range"],
  #toolPanel .modal select,
  #textPanel .modal select,
  #imagePanel .modal select {
    width: 100%;
  }
  #toolPanel .modal .actions,
  #textPanel .modal .actions,
  #imagePanel .modal .actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  #toolPanel .modal .modal-close,
  #textPanel .modal .modal-close,
  #imagePanel .modal .modal-close {
    display: none;
  }
  #toolPanel .modal h2,
  #textPanel .modal h2,
  #imagePanel .modal h2 {
    cursor: default;
    font-size: 18px;
    margin-bottom: 10px;
    padding-right: 0;
  }
}

/* Medium widths: tighten toolbar and hide some labels before it gets cramped */
@media (max-width: 1279px) {
  .tool-btn .label {
    font-size: 11px;
  }
  header h1 {
    margin-right: 8px;
  }
}

/* Smaller editor widths: make the toolbar horizontally scrollable and use compact panels */
@media (max-width: 1179px) {
  body.editor-side-panel-open main {
    padding-right: 0;
  }
  header {
    gap: 8px;
  }
  header .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tools {
    flex-wrap: nowrap;
  }
  #toolPanel,
  #textPanel,
  #imagePanel {
    z-index: 1200;
  }
  #toolPanel .modal,
  #textPanel .modal,
  #imagePanel .modal {
    width: min(420px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
    min-width: 0 !important;
    top: 84px !important;
    right: 12px !important;
    left: auto !important;
    bottom: auto !important;
    max-height: calc(100vh - 120px) !important;
    overflow: auto;
  }
}

/* Very narrow screens: focus on icons and keep panels full-width near the bottom */
@media (max-width: 760px) {
  .tool-btn {
    padding: 4px 8px;
  }
  .tool-btn .label {
    display: none;
  }
  header h1 {
    font-size: 14px;
    margin-right: 4px;
  }
  #toolPanel .modal,
  #textPanel .modal,
  #imagePanel .modal {
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
  }
}



/* Desktop editor layout: reserve a narrower right-side dock for active tool panels */
body.editor-side-panel-open main {
  padding-right: clamp(220px, 18vw, 280px);
  transition: padding-right 160ms ease;
}
main {
  transition: padding-right 160ms ease;
}

/* Make the header and toolbar handle tighter widths more gracefully */
header {
  justify-content: flex-start;
  padding-left: 10px;
  padding-right: 10px;
}
header .toolbar {
  flex: 1 1 720px;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 6px 8px;
  border-radius: 22px;
  padding: 8px 10px;
}
.tools {
  flex-wrap: wrap;
  margin-left: 0;
  max-width: 100%;
}
.tool-btn {
  flex: 0 0 auto;
}
.toolbar > * {
  min-width: 0;
}

/* Convert the tool panels into a vertical dock on larger screens */
@media (min-width: 1180px) {
  #toolPanel,
  #textPanel,
  #imagePanel {
    position: fixed;
    top: 84px;
    right: 0;
    bottom: 10px;
    left: auto;
    width: clamp(220px, 18vw, 280px);
    background: transparent;
    z-index: 1200;
    pointer-events: none;
  }
  #toolPanel .modal,
  #textPanel .modal,
  #imagePanel .modal {
    position: absolute !important;
    top: 0 !important;
    right: 12px !important;
    left: auto !important;
    bottom: 0 !important;
    transform: none !important;
    width: clamp(208px, 17vw, 268px) !important;
    min-width: 0 !important;
    max-width: clamp(208px, 17vw, 268px) !important;
    max-height: calc(100vh - 110px) !important;
    overflow: auto;
    border-radius: 18px;
    padding: 12px 12px 10px;
    box-shadow: 0 16px 40px rgba(2, 6, 23, 0.30), 0 3px 10px rgba(2, 6, 23, 0.16);
  }
  #toolPanel .modal h2,
  #textPanel .modal h2,
  #imagePanel .modal h2 {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    margin: -12px -12px 10px -12px;
    padding: 12px 36px 10px 12px;
    border-bottom: 1px solid #e2e8f0;
  }
  #toolPanel .modal .modal-close,
  #textPanel .modal .modal-close,
  #imagePanel .modal .modal-close {
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
  }
  #toolPanel .modal .row,
  #textPanel .modal .row,
  #imagePanel .modal .row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-top: 6px;
  }
  #toolPanel .modal .row label,
  #textPanel .modal .row label,
  #imagePanel .modal .row label {
    justify-content: space-between;
    gap: 8px;
  }
  #toolPanel .modal input[type="color"],
  #textPanel .modal input[type="color"],
  #imagePanel .modal input[type="color"] {
    width: 46px;
    min-width: 46px;
    height: 28px;
    padding: 0;
  }
  #toolPanel .modal input[type="range"],
  #textPanel .modal input[type="range"],
  #imagePanel .modal input[type="range"],
  #toolPanel .modal select,
  #textPanel .modal select,
  #imagePanel .modal select {
    width: 100%;
    max-width: 100%;
  }
  #toolPanel .modal input[type="number"],
  #textPanel .modal input[type="number"],
  #imagePanel .modal input[type="number"] {
    width: 72px;
    max-width: 72px;
  }
  #toolPanel .modal .actions,
  #textPanel .modal .actions,
  #imagePanel .modal .actions {
    justify-content: stretch;
  }
  #toolPanel .modal .actions > *,
  #textPanel .modal .actions > *,
  #imagePanel .modal .actions > * {
    flex: 1 1 auto;
  }
}

/* On medium widths, keep panels floating but let toolbar scroll instead of crowding */
@media (max-width: 1179px) {
  header .toolbar {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: thin;
  }
  .tools {
    flex-wrap: nowrap;
  }
}

/* On tighter screens, reduce label footprint to avoid toolbar collisions */
@media (max-width: 920px) {
  .tool-btn .label {
    display: none;
  }
  header .toolbar {
    gap: 6px;
    padding: 8px;
  }
}


/* Tighter docked panel control layout */
#toolPanel .modal label,
#textPanel .modal label,
#imagePanel .modal label {
  font-size: 13px;
}
#toolPanel .modal .row + .row,
#textPanel .modal .row + .row,
#imagePanel .modal .row + .row {
  margin-top: 4px;
}



/* Dock spacing polish */
@media (min-width: 1180px) {
  #toolPanel,
  #textPanel,
  #imagePanel {
    top: 108px !important;
    bottom: auto !important;
    min-height: 0 !important;
    height: auto !important;
  }

  #toolPanel .modal,
  #textPanel .modal,
  #imagePanel .modal {
    top: 0 !important;
    bottom: auto !important;
    max-height: calc(100vh - 156px) !important;
    min-height: 260px !important;
    height: auto !important;
    padding: 16px 14px 14px !important;
  }

  #toolPanel .modal h2,
  #textPanel .modal h2,
  #imagePanel .modal h2 {
    margin: -16px -14px 16px -14px !important;
    padding: 14px 40px 14px 14px !important;
  }

  #toolPanel .modal .modal-close,
  #textPanel .modal .modal-close,
  #imagePanel .modal .modal-close {
    top: 12px !important;
    right: 10px !important;
  }

  #toolPanel .modal .row,
  #textPanel .modal .row,
  #imagePanel .modal .row {
    gap: 8px !important;
    margin-top: 10px !important;
  }

  #toolPanel .modal .row:first-of-type,
  #textPanel .modal .row:first-of-type,
  #imagePanel .modal .row:first-of-type {
    margin-top: 2px !important;
  }

  #toolPanel .modal label,
  #textPanel .modal label,
  #imagePanel .modal label {
    margin-bottom: 2px !important;
  }

  #toolPanel .modal .actions,
  #textPanel .modal .actions,
  #imagePanel .modal .actions {
    margin-top: 14px !important;
  }
}



/* Dock tighten pass */
@media (min-width: 1180px) {
  body.editor-side-panel-open main {
    padding-right: clamp(190px, 16vw, 242px) !important;
  }

  #toolPanel,
  #textPanel,
  #imagePanel {
    width: clamp(196px, 16vw, 248px) !important;
  }

  #toolPanel .modal,
  #textPanel .modal,
  #imagePanel .modal {
    right: 8px !important;
    width: clamp(188px, 15.5vw, 236px) !important;
    max-width: clamp(188px, 15.5vw, 236px) !important;
    padding: 10px 10px 12px !important;
  }

  #toolPanel .modal h2,
  #textPanel .modal h2,
  #imagePanel .modal h2 {
    margin: -10px -10px 10px -10px !important;
    padding: 10px 36px 8px 12px !important;
  }

  #toolPanel .modal .row:first-of-type,
  #textPanel .modal .row:first-of-type,
  #imagePanel .modal .row:first-of-type {
    margin-top: 8px !important;
  }

  #toolPanel .modal .row,
  #textPanel .modal .row,
  #imagePanel .modal .row {
    gap: 6px !important;
    margin-top: 8px !important;
  }

  #toolPanel .modal input[type="color"],
  #textPanel .modal input[type="color"],
  #imagePanel .modal input[type="color"] {
    margin-top: 2px !important;
  }
}



/* Server-update notification banner */
.server-update-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 12px 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: rgba(120, 53, 15, 0.14);
  color: #fde68a;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.16);
  position: relative;
  z-index: 25;
}

@media (min-width: 1180px) {
  body.editor-side-panel-open .server-update-banner {
    margin-right: calc(clamp(190px, 16vw, 242px) + 18px) !important;
  }
}
.server-update-banner[hidden] {
  display: none !important;
}
.server-update-banner__content {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  line-height: 1.45;
  min-width: 0;
}
.server-update-banner__content strong {
  color: #fef3c7;
  white-space: nowrap;
}
.server-update-banner__content span {
  color: #fde68a;
}
.server-update-banner__actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
}
.server-update-banner__actions button {
  border: 1px solid rgba(251, 191, 36, 0.55);
  background: rgba(30, 41, 59, 0.72);
  color: #fef3c7;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}
.server-update-banner__actions button.secondary {
  background: transparent;
  border-color: rgba(148, 163, 184, 0.45);
  color: #e2e8f0;
}
.server-update-banner__actions button:hover {
  filter: brightness(1.08);
}
@media (max-width: 920px) {
  .server-update-banner {
    flex-direction: column;
    align-items: stretch;
  }
  .server-update-banner__actions {
    width: 100%;
    justify-content: flex-end;
  }
}




/* Hide toolbar contents until auth + page state are initialized to avoid the
   login/tools flicker before we know the real session state. */
body.app-loading header .toolbar {
  visibility: hidden;
}
body.app-loading #toolPanel,
body.app-loading #textPanel,
body.app-loading #imagePanel {
  display: none !important;
}




/* Temporary lock-zone warning */
.lock-warning-toast {
  position: fixed;
  left: 50%;
  top: 92px;
  transform: translateX(-50%);
  z-index: 1700;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(91, 33, 182, 0.94);
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 10px 28px rgba(2,6,23,0.28);
  font-weight: 600;
  line-height: 1.35;
  pointer-events: none;
  opacity: 1;
  transition: opacity 160ms ease, transform 160ms ease;
}
.lock-warning-toast[hidden] {
  display: none !important;
}
.lock-warning-toast.is-hiding {
  opacity: 0;
  transform: translateX(-50%) translateY(-8px);
}
@media (max-width: 920px) {
  .lock-warning-toast {
    top: 82px;
    max-width: calc(100vw - 24px);
    text-align: center;
  }
}




/* Single help button next to hamburger */
.toolbar-sep {
  display: none !important;
}
#editorHelpOpen {
  min-width: 24px !important;
  width: 24px !important;
  height: 24px !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-weight: 700 !important;
  font-size: 13px !important;
  line-height: 1 !important;
}
#editorHelpOpen .icon,
#editorHelpOpen .label,
#editorHelpOpen::before,
#editorHelpOpen::after {
  display: none !important;
  content: none !important;
}



/* Help spacing tweak */
.editor-help-panel p + p {
  margin-top: 12px; /* more space from paragraph above */
}

.editor-help-panel p.help-subtext {
  margin-top: 14px;
  margin-bottom: 6px; /* tighter to buttons below */
}



/* Help spacing tweak v2 */
.editor-help-panel .help-subtext {
  display: block;
  margin-top: 14px;
  margin-bottom: 2px !important;
}
.editor-help-nav {
  margin-top: 8px !important;
}



/* Guest help banner */
.editor-help-guest-banner {
  margin: 12px 0 16px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.18);
  border: 1px solid rgba(37, 99, 235, 0.35);
  color: #dbeafe;
  font-weight: 500;
}
.editor-help-guest-banner strong {
  display: block;
  font-weight: 700;
  margin-bottom: 4px;
}
