/* ============================================================
   AKAM COLLAGE — Design System
   Warm, creative palette for image collage work
   By Akam Systems
   ============================================================ */

:root {
  /* ── Warm Neutral Palette (unified) ── */
  --bg: #FEFCFA;
  --canvas-bg: #EDE8E3;
  --surface: #F5F0EB;
  --text: #292118;
  --text-muted: #7A6C60;
  --accent: #E16B3A;
  --accent-hover: #C9552A;
  --accent-glow: rgba(225, 107, 58, 0.25);
  --accent-subtle: rgba(225, 107, 58, 0.12);
  --success: #4ADE80;
  --danger: #dc2626;
  --border: #E0D8D0;

  /* Panel surfaces (warm tones) */
  --sidebar-bg: #F5F0EB;
  --sidebar-surface: #FEFCFA;
  --sidebar-hover: #EDE8E3;
  --sidebar-active: #E0D8D0;
  --sidebar-border: #E0D8D0;

  /* Header (warm dark — keeps contrast for branding) */
  --header-bg: #292118;
  --header-border: #1F1914;
  --header-text: #F5F0EB;
  --header-text-muted: #B8AFA5;

  /* Status bar */
  --status-bg: #F5F0EB;
  --status-border: #E0D8D0;

  /* Panel (unified with sidebar — no split personality) */
  --panel-bg: #FEFCFA;
  --panel-surface: #FFFFFF;
  --panel-border: #E0D8D0;
  --panel-hover: #F5F0EB;
  --panel-header-bg: #EDE8E3;

  /* Legacy aliases (for code that still references old names) */
  --text-dark: #292118;
  --text-dark-muted: #6B5D50; /* darkened to meet WCAG AA on light surfaces */

  /* Shared */
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 6px;
  --radius-sm: 4px;
  --header-height: clamp(49px, 7.2vh, 62px);
  --tabbar-h: 56px; /* mobile bottom tab bar height */
}

/* ─── Dark theme tokens (chrome only) — toggle wired in a later phase ─── */
:root[data-theme="dark"] {
  --bg: #1E1915;
  --surface: #292118;
  --border: #443A30;
  --text: #F5F0EB;
  --text-muted: #B8A896;
  --canvas-bg: #16120E;
  --text-dark: #F5F0EB;
  --text-dark-muted: #B8A896;

  --sidebar-bg: #292118;
  --sidebar-surface: #1E1915;
  --sidebar-hover: #332B23;
  --sidebar-active: #443A30;
  --sidebar-border: #443A30;

  --status-bg: #292118;
  --status-border: #443A30;

  --panel-bg: #1E1915;
  --panel-surface: #292118;
  --panel-border: #443A30;
  --panel-hover: #332B23;
  --panel-header-bg: #332B23;
}

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

body {
  background: var(--bg);
  color: var(--text-dark);
  font-family: var(--font);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
}

/* ─── Top Header (dark) ─── */
.top-header {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: clamp(3px, 0.5vh, 5px) clamp(8px, 1.3vw, 16px);
  min-height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  z-index: 10;
  gap: 3px clamp(5px, 0.8vw, 10px);
  overflow: visible;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 10px);
  flex-shrink: 0;
}

.app-logo {
  width: clamp(22px, 3.5vw, 28px);
  height: clamp(22px, 3.5vw, 28px);
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

.app-title {
  margin: 0; /* reset <h1> default block margins — this sits inline in the header */
  font-size: clamp(14px, 2.1vw, 20px);
  font-weight: 700;
  color: var(--header-text);
  letter-spacing: 0.4px;
  white-space: nowrap;
  text-transform: uppercase;
  margin-right: 4px;
  padding-right: 8px;
  border-right: 1px solid rgba(255,255,255,0.08);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: clamp(2px, 0.4vw, 4px);
  margin-left: auto;
  flex: 1 1 auto;
  min-width: 0; /* allow the toolbar to shrink below 360px instead of overflowing */
}

.header-divider {
  width: 1px;
  height: 29px;
  background: rgba(255,255,255,0.1);
  margin: 0 8px;
  flex-shrink: 0;
}

/* Tool buttons (header — dark context) */
.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: clamp(5px, 0.8vh, 8px) clamp(10px, 1.6vw, 16px);
  min-height: clamp(36px, 5.2vh, 44px);
  font-family: var(--font);
  font-size: clamp(13px, 2vw, 17px);
  font-weight: 600;
  color: var(--header-text-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-text);
}

.tool-btn:active {
  transform: scale(0.97);
}

.tool-btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tool-btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.btn-icon svg {
  width: clamp(16px, 2.3vw, 21px);
  height: clamp(16px, 2.3vw, 21px);
}

/* Tool button text labels — always hidden (icon-only toolbar, text via tooltips) */
.tool-label {
  display: none;
}

/* Export group */
.export-group {
  display: flex;
  align-items: center;
}

.export-select {
  background: rgba(255, 255, 255, 0.08);
  color: var(--header-text-muted);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: clamp(5px, 0.8vh, 8px) clamp(8px, 1vw, 10px);
  min-height: clamp(36px, 5.2vh, 44px);
  font-family: var(--font);
  font-size: clamp(12px, 1.7vw, 14px);
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.export-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.export-group .tool-btn--primary {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

/* ─── Side Panel ─── */
.side-panel {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  width: clamp(240px, 26vw, 380px);
  min-width: 0;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  overflow: hidden;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ─── Accordion (right-side control panel) ─── */
.acc {
  border-bottom: 1px solid var(--panel-border);
}

.acc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: clamp(8px, 1.2vh, 12px) clamp(10px, 1.4vw, 14px);
  border: none;
  background: var(--panel-header-bg);
  font-family: var(--font);
  font-size: clamp(12px, 1.4vw, 14px);
  font-weight: 700;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.acc-header:hover {
  background: var(--panel-hover);
}

.acc-header:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.acc-chevron {
  display: inline-flex;
  align-items: center;
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-left: 8px;
}

.acc-chevron svg {
  display: block;
}

.acc-header[aria-expanded="true"] .acc-chevron {
  transform: rotate(180deg);
}

.acc-body {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 0.8vh, 10px);
  padding: clamp(8px, 1.2vw, 14px);
  max-height: calc(100vh - var(--header-height) - 44px);
  overflow-y: auto;
}

.acc-body[hidden] {
  display: none;
}

/* ─── Thumbnail grid (masks / patterns / cell shapes) ─── */
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}

.thumb-grid .thumb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 4px;
  background: var(--sidebar-surface);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}

.thumb-grid .thumb-btn:hover {
  background: var(--sidebar-hover);
  color: var(--text);
  border-color: var(--sidebar-hover);
}

.thumb-grid .thumb-btn[aria-checked="true"],
.thumb-grid .thumb-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.thumb-grid .thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 2px;
  pointer-events: none;
}

.thumb-grid-heading {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  margin: 6px 0 -2px;
}

.thumb-grid-heading:first-child {
  margin-top: 0;
}

/* ─── Plain sidebar action buttons (accordion bodies) ─── */
.sidebar-btn {
  background: transparent;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  padding: clamp(6px, 0.9vh, 10px) clamp(8px, 1.1vw, 12px);
  min-height: 40px;
  font-family: var(--font);
  font-size: clamp(12px, 1.6vw, 14px);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all 0.12s ease;
}

.sidebar-btn:hover {
  background: var(--panel-hover);
}

.sidebar-btn[aria-pressed="true"] {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.panel-btn-row .sidebar-btn {
  flex: 1;
}

.panel-section-label {
  font-size: clamp(9px, 1.1vw, 11px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dark-muted);
  margin-top: clamp(4px, 0.8vh, 8px);
}

.panel-hint {
  font-size: clamp(10px, 1.2vw, 12px);
  color: var(--text-muted);
  margin: -2px 0 4px;
}

/* Sub-group heading within a merged accordion section (e.g. "Frame" inside
   Canvas, "Walls" inside Cell walls) — visually separates the group with a
   divider above it. */
.panel-subgroup {
  margin-top: clamp(10px, 1.6vh, 16px);
  padding-top: clamp(8px, 1.2vh, 12px);
  border-top: 1px solid var(--panel-border);
}

.panel-btn-row {
  display: flex;
  gap: clamp(3px, 0.5vw, 6px);
}

/* ─── Layers list (Edit image section) ─── */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: clamp(6px, 1vh, 10px);
  padding-right: 2px;
}

.layer-list:empty::after {
  content: 'No cells yet.';
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 2px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: var(--sidebar-surface);
  cursor: pointer;
  transition: all 0.12s ease;
}

.layer-row:hover {
  background: var(--sidebar-hover);
}

.layer-row[aria-selected="true"] {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.layer-thumb {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--sidebar-hover);
}

.layer-thumb-placeholder {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
}

.layer-label {
  font-size: 13px;
  font-weight: 500;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-order-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.layer-order-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Segmented toggle (e.g. Cell edges: Straight / Rounded) ─── */
.segmented {
  display: flex;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segmented-btn {
  flex: 1;
  background: var(--sidebar-surface);
  border: none;
  padding: clamp(8px, 1.1vh, 12px) clamp(8px, 1.1vw, 12px);
  min-height: 40px;
  font-family: var(--font);
  font-size: clamp(12px, 1.6vw, 14px);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all 0.12s ease;
}

.segmented-btn + .segmented-btn {
  border-left: 1px solid var(--sidebar-border);
}

.segmented-btn:hover {
  background: var(--sidebar-hover);
}

.segmented-btn[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  border-color: var(--accent);
}

.segmented-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ─── Panel toggle (mobile sheet handle) ─── */
.panel-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border: 2px solid var(--accent);
  border-radius: 24px;
  background: var(--panel-surface, #fff);
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  z-index: 70;
  cursor: pointer;
}

.panel-toggle::before {
  content: '';
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.custom-artboard-fields {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.custom-artboard-fields input[type="number"] {
  flex: 1;
  min-width: 0;
}

/* ─── Sidebar Dropdowns ─── */
.sidebar-dropdown {
  width: 100%;
  min-height: clamp(29px, 3.9vh, 36px);
  padding: clamp(3px, 0.5vh, 5px) clamp(5px, 0.7vw, 8px);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: clamp(10px, 1.6vw, 13px);
  font-weight: 500;
  color: var(--text);
  background: var(--sidebar-surface);
  cursor: pointer;
}

.sidebar-dropdown:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ─── Canvas ─── */
#canvasContainer {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
  background: var(--canvas-bg);
  min-width: 0;
  min-height: 0;
  box-shadow: inset 1px 1px 4px rgba(0,0,0,0.06), inset -1px 0 4px rgba(0,0,0,0.03);
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ─── Status Bar (dark) ─── */
.status-bar {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(6px, 1vw, 16px);
  background: var(--status-bg);
  border-top: 1px solid var(--status-border);
  min-height: clamp(22px, 3vh, 28px);
}

.status-project-name {
  font-size: clamp(9px, 1.4vw, 12px);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.status-divider {
  width: 1px;
  height: 14px;
  background: var(--status-border);
  margin: 0 10px;
  flex-shrink: 0;
}

#statusText {
  font-size: clamp(9px, 1.4vw, 12px);
  font-weight: 500;
  color: var(--text-muted);
  flex: 1;
  font-family: var(--font-mono);
}

/* Zoom controls */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: clamp(2px, 0.4vw, 4px);
  font-size: clamp(9px, 1.4vw, 12px);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.zoom-btn {
  background: transparent;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  width: clamp(20px, 2.5vh, 24px);
  height: clamp(20px, 2.5vh, 24px);
  font-size: clamp(11px, 1.6vw, 14px);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
}

.zoom-btn:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

/* ─── Accessibility ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  /* Bottom sheet: instant show/hide, no slide animation */
  .side-panel {
    transition: none !important;
  }
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── Scrollbar styling ─── */
.panel-body::-webkit-scrollbar {
  width: 6px;
}

.panel-body::-webkit-scrollbar-track {
  background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 3px;
}

.panel-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Export Preview Dialog ─── */
#previewDialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--panel-bg);
  box-shadow: 0 25px 60px rgba(0,0,0,0.3), 0 0 0 1px rgba(0,0,0,0.08);
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  overflow: hidden;
}

#previewDialog::backdrop {
  background: rgba(0,0,0,0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.preview-dialog-content {
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}

.preview-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--panel-border);
}

.preview-dialog-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
}

.preview-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-dark-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background 0.12s ease, color 0.12s ease;
}

.preview-close-btn:hover {
  background: var(--panel-hover);
  color: var(--text-dark);
}

.preview-canvas-wrap {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--canvas-bg);
  min-height: 200px;
}

.preview-canvas-wrap canvas {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  background: #fff;
  object-fit: contain;
}

.preview-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--panel-border);
}

.preview-info-item {
  font-size: 12px;
  color: var(--text-dark-muted);
  font-family: var(--font-mono);
}

.preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--panel-border);
}

.preview-btn {
  padding: 8px 20px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel-surface);
  color: var(--text-dark);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.preview-btn:hover {
  background: var(--panel-hover);
}

.preview-btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.preview-btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ─── Progress Overlay ─── */
.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.progress-overlay p {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.progress-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Fullscreen Toggle Button ─── */
.fullscreen-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: clamp(5px, 0.8vh, 8px) clamp(10px, 1.6vw, 16px);
  min-height: clamp(36px, 5.2vh, 44px);
  font-size: clamp(18px, 2.6vw, 23px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
}

.fullscreen-btn:hover {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 8px var(--accent-glow);
}

.fullscreen-btn:active {
  transform: scale(0.95);
}

/* ─── Fullscreen mode — side panel hidden, header enlarged ─── */
.fullscreen-mode {
  --header-height: 62px;
  grid-template-columns: 1fr;
}

.fullscreen-mode #canvasContainer {
  grid-column: 1;
}

.fullscreen-mode .side-panel {
  display: none;
}

/* Fullscreen header — larger, more prominent */
.fullscreen-mode .top-header {
  height: 62px;
  padding: 0 21px;
  gap: 10px;
}

.fullscreen-mode .tool-btn {
  padding: 8px 18px;
  min-height: 44px;
  font-size: 17px;
  gap: 8px;
}

.fullscreen-mode .btn-icon svg {
  width: 21px;
  height: 21px;
}

.fullscreen-mode .app-title {
  font-size: 20px;
}

.fullscreen-mode .export-select {
  min-height: 44px;
  font-size: 14px;
  padding: 5px 10px;
}

.fullscreen-mode .fullscreen-btn {
  min-height: 44px;
  font-size: 23px;
  padding: 8px 16px;
}

.fullscreen-mode .header-divider {
  height: 31px;
  margin: 0 10px;
}


/* ============================================================
   RESPONSIVE: Laptops and larger (≥ 1024px)
   25% larger font sizes and controls for comfortable desktop use
   ============================================================ */
@media (min-width: 1024px) {

  /* Section labels */
  .panel-section-label {
    font-size: clamp(11px, 1.3vw, 14px);
  }

  /* Dropdowns */
  .sidebar-dropdown {
    min-height: clamp(34px, 4.6vh, 42px);
    font-size: clamp(13px, 1.8vw, 16px);
  }

  /* Status bar text */
  #statusText {
    font-size: clamp(11px, 1.6vw, 14px);
  }

  .status-project-name {
    font-size: clamp(11px, 1.6vw, 14px);
  }

  /* Zoom controls */
  .zoom-controls {
    font-size: clamp(11px, 1.6vw, 14px);
  }

  .zoom-btn {
    width: clamp(24px, 3vh, 28px);
    height: clamp(24px, 3vh, 28px);
    font-size: clamp(13px, 1.8vw, 16px);
  }

  /* Header tool buttons */
  .tool-btn {
    font-size: clamp(13px, 1.8vw, 16px);
    padding: clamp(5px, 0.8vh, 8px) clamp(10px, 1.5vw, 16px);
    min-height: clamp(34px, 4.8vh, 42px);
  }

  .btn-icon svg {
    width: clamp(16px, 2vw, 20px);
    height: clamp(16px, 2vw, 20px);
  }

  /* Export select */
  .export-select {
    font-size: clamp(12px, 1.5vw, 14px);
    min-height: clamp(34px, 4.8vh, 42px);
  }
}

/* ============================================================
   RESPONSIVE: Small screens (≤ 768px)
   Side panel hidden, bottom tab bar shown, larger touch targets
   ============================================================ */
@media (max-width: 768px) {

  /* ── Grid becomes single-column; side panel becomes a fixed bottom sheet ── */
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  /* Canvas takes full width */
  #canvasContainer {
    grid-column: 1;
  }

  /* Side panel becomes a bottom sheet overlay */
  .side-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 55vh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 50;
    border-left: none;
    border-top: 1px solid var(--panel-border);
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
  }

  .side-panel.side-panel--open {
    transform: translateY(0);
  }

  /* Mobile sheet handle — hidden on desktop, shown here */
  .panel-toggle {
    display: flex;
  }

  /* ── Larger elements for touch ── */

  .sidebar-dropdown {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 17px;
  }

  .sidebar-btn {
    min-height: 44px;
  }

  .fullscreen-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Status bar: condense */
  .status-bar {
    gap: 4px;
  }

  #statusText {
    display: none;
  }

  .status-divider {
    display: none;
  }

  /* Touch targets — meet the 44px minimum on mobile */
  .tool-btn {
    min-height: 44px;
  }

  .zoom-btn {
    width: 44px;
    height: 44px;
  }

  .acc-header {
    min-height: 48px;
  }
}

/* ============================================================
   TEMPLATE GALLERY — first-open / "New" splash overlay
   ============================================================ */
.template-gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 4vw, 40px);
  background: rgba(20, 15, 10, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}

.template-gallery-overlay[hidden] {
  display: none;
}

.template-gallery-inner {
  width: 100%;
  max-width: 980px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.06);
  padding: clamp(20px, 3vw, 32px);
}

.template-gallery-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(16px, 2.5vw, 24px);
}

.template-gallery-title {
  font-family: var(--font);
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.template-gallery-subtitle {
  margin-top: 4px;
  font-family: var(--font);
  font-size: clamp(13px, 1.6vw, 15px);
  color: var(--text-muted);
}

.template-gallery-close {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.template-gallery-close:hover {
  background: var(--panel-hover);
  color: var(--text);
  border-color: var(--border);
}

.template-gallery-grid {
  display: grid;
  /* Fixed 3 columns so each template type reads as its own row
     (Squares 2/4/6, then Polygonal 2/4/6, then Mosaic 6/9/12). */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.template-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.template-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  border-color: var(--accent);
}

.template-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.template-card-preview {
  width: 100%;
  background: var(--canvas-bg);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.template-card-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.template-card-name {
  margin-top: 10px;
  padding: 0 12px;
  font-family: var(--font);
  font-size: clamp(14px, 1.8vw, 16px);
  font-weight: 600;
  color: var(--text);
}

.template-card-subtitle {
  margin: 2px 0 12px;
  padding: 0 12px;
  font-family: var(--font);
  font-size: clamp(12px, 1.5vw, 13px);
  color: var(--text-muted);
}

.template-gallery-footer {
  display: flex;
  justify-content: center;
  margin-top: clamp(16px, 2.5vw, 24px);
}

.template-blank-link {
  min-height: 44px;
  padding: 10px 20px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.template-blank-link:hover {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

@media (max-width: 768px) {
  .template-gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .template-card {
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  .template-gallery-grid {
    grid-template-columns: 1fr;
  }
}


/* ── Right-click context menu ── */
.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 168px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.context-menu[hidden] { display: none; }
.context-menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 8px 12px;
  min-height: 36px;
  border-radius: 5px;
  cursor: pointer;
}
.context-menu-item:hover,
.context-menu-item:focus-visible {
  background: var(--accent);
  color: #fff;
  outline: none;
}
.context-menu-item[hidden] { display: none; }
.context-menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}
.context-menu-sep[hidden] { display: none; }

/* ── Context-menu submenu (Change shape) ── */
.context-has-submenu {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  position: relative;
  cursor: default;
}
.context-submenu {
  position: absolute;
  left: 100%;
  top: -5px;
  margin-left: 3px;
  min-width: 148px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
  gap: 1px;
  z-index: 1001;
}
.context-has-submenu:hover > .context-submenu,
.context-has-submenu:focus-within > .context-submenu { display: flex; }

/* ── Cell count: stepped slider (snaps to knobs) + dots + custom box ── */
.cell-slider-wrap { margin-bottom: 12px; }
.cell-slider-track-wrap { position: relative; }
.cell-slider { width: 100%; display: block; accent-color: var(--accent); position: relative; z-index: 1; }
/* Dots on the track, one per knob, aligned above the number labels. */
.cell-slider-dots {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  padding: 0 8px; /* ~half the native thumb, so end dots sit under the thumb travel */
  pointer-events: none;
}
.cell-slider-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
}
.cell-slider-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  padding: 0 2px; /* nudge end labels under the thumb's travel */
}
.cell-slider-tick {
  flex: 1;
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  user-select: none;
}
.cell-slider-tick:first-child { text-align: left; }
.cell-slider-tick:last-child { text-align: right; }
.cell-count-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-input-label {
  font-size: 12px;
  color: var(--text-muted);
}
.cell-count-row input[type="number"] {
  width: 56px;
  flex: none;
  padding: 5px 6px;
  font: inherit;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  -moz-appearance: textfield;
  appearance: textfield;
}
/* Hide the native browser spinners — we provide our own ▲/▼ steppers. */
.cell-count-row input[type="number"]::-webkit-outer-spin-button,
.cell-count-row input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.count-steppers {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.count-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 20px;
  padding: 0;
  font-size: 9px;
  line-height: 1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}
.count-stepper:hover:not(:disabled) { background: var(--sidebar-hover); }
.count-stepper:active:not(:disabled) { transform: scale(0.9); }
.count-stepper:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.count-stepper:disabled { opacity: 0.4; cursor: default; }
