:root {
  --bg-app: #0f1115;
  --bg-panel: #16181d;
  --bg-panel-hover: #1e2128;
  --bg-canvas: #090a0c;

  --border-light: #2a2e38;
  --border-focus: #3e4451;

  --text-main: #e2e4e9;
  --text-muted: #8b949e;
  --text-primary: #58a6ff;

  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-bg: rgba(88, 166, 255, 0.1);
  --accent-ring: rgba(88, 166, 255, 0.5);
  --danger: #f85149;
  --danger-bg: rgba(248, 81, 73, 0.1);

  --xml-text: #a5d6ff;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);

  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Fira Code", "JetBrains Mono", "Courier New", monospace;
}

[data-theme="light"] {
  --bg-app: #f0f1f3;
  --bg-panel: #ffffff;
  --bg-panel-hover: #ebedf0;
  --bg-canvas: #e4e6ea;

  --border-light: #d0d4dc;
  --border-focus: #a8aeb8;

  --text-main: #1a1d23;
  --text-muted: #4a5260;
  --text-primary: #0969da;

  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-bg: rgba(9, 105, 218, 0.1);
  --accent-ring: rgba(9, 105, 218, 0.5);
  --danger: #cf222e;
  --danger-bg: rgba(207, 34, 46, 0.1);

  --xml-text: #0550ae;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* Light theme component overrides */
[data-theme="light"] .channel-swatch {
  border: 1px solid rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .channel-swatch.transparent {
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  border-color: #aaa;
}

[data-theme="light"] .canvas-status-pill {
  background-color: rgba(255, 255, 255, 0.9);
  color: var(--text-muted);
}

[data-theme="light"] .canvas-wrapper.default-bg {
  background-image: radial-gradient(var(--border-light) 1px, transparent 1px);
}

[data-theme="light"] .preview-checkered {
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
}

[data-theme="light"] .channel-key {
  background: var(--bg-app);
}

[data-theme="light"] .qud-color-btn {
  border-color: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .canvas-grid-container {
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .btn-primary {
  border-color: rgba(9, 105, 218, 0.4);
}

[data-theme="light"] .btn-primary:hover {
  border-color: var(--accent);
  background-color: rgba(9, 105, 218, 0.15);
}

[data-theme="light"] .btn-danger {
  border-color: rgba(207, 34, 46, 0.3);
}

[data-theme="light"] .btn-danger:hover {
  border-color: var(--danger);
  background-color: rgba(207, 34, 46, 0.15);
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-focus);
}

/* Layout Shell */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.header {
  height: 56px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.header-title-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  width: 12px;
  height: 12px;
  background-color: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-main);
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Core Buttons */
button {
  all: unset;
  box-sizing: border-box;
  font-family: var(--font-ui);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--border-light);
  background-color: var(--bg-panel);
  color: var(--text-main);
}

.btn:hover {
  background-color: var(--bg-panel-hover);
  border-color: var(--border-focus);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

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

.btn-primary {
  background-color: var(--accent-bg);
  color: var(--accent);
  border-color: rgba(88, 166, 255, 0.4);
}

.btn-primary:hover {
  background-color: rgba(88, 166, 255, 0.2);
  border-color: var(--accent);
}

.btn-danger {
  background-color: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.3);
}

.btn-danger:hover {
  background-color: rgba(248, 81, 73, 0.2);
  border-color: var(--danger);
}

/* App Main Layout */
.main-area {
  display: flex;
  flex: 1;
  min-height: 0;
  /* Important for flex overflow */
}

/* Sidebars */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar.right {
  border-right: none;
  border-left: 1px solid var(--border-light);
  width: 320px;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Sidebar Select */
.sidebar-select {
  background: var(--bg-app);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: var(--font-ui);
  outline: none;
  cursor: pointer;
}

.sidebar-select:focus-visible {
  border-color: var(--accent);
}

/* Tool & Channel Buttons */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: 6px;
  background-color: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s ease;
}

.tool-btn:hover {
  background-color: var(--bg-panel-hover);
  color: var(--text-main);
}

.tool-btn.active {
  background-color: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

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

.tool-shortcut {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  background: var(--bg-app);
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--border-light);
  margin-left: 4px;
}

.channel-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: all 0.1s ease;
}

.channel-btn:hover:not(.active) {
  background-color: var(--bg-panel-hover);
}

.channel-btn.active {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--border-focus);
  color: var(--text-main);
}

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

.channel-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.channel-swatch.transparent {
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%),
    linear-gradient(-45deg, #333 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333 75%),
    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  border-color: #555;
}

.channel-key {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-app);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
}

/* Brush Size */
.brush-size-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.brush-size-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.1s ease;
}

.brush-size-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.brush-size-btn:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 1px;
}

/* Undo Count Badge */
.undo-count {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 16px;
  text-align: center;
}

/* Form Controls */
.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-label {
  font-size: 12px;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  background-color: var(--bg-app);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color 0.15s ease;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.input-group {
  margin-bottom: 12px;
}

.input-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Custom Grid for Colors */
.qud-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
  gap: 4px;
  margin-bottom: 6px;
}

.qud-color-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.qud-color-btn:hover {
  transform: scale(1.1);
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.qud-color-btn.active {
  border: 2px solid white;
  transform: scale(1.1);
  z-index: 10;
  box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 4px var(--accent);
}

.qud-color-btn:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 1px;
}

.qud-color-desc {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Canvas Area */
.canvas-wrapper {
  flex: 1;
  background-color: var(--bg-canvas);
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.canvas-bg-dark {
  background-color: #000;
}

.canvas-bg-gray {
  background-color: #1e1e1e;
}

.canvas-bg-light {
  background-color: #cccccc;
}

.canvas-bg-white {
  background-color: #ffffff;
}

.canvas-grid-container {
  position: relative;
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(255, 255, 255, 0.05);
  background-color: #000;
  /* Fallback for transparency */
  touch-action: none;
}

/* Dynamic dot grid for regular background */
.canvas-wrapper.default-bg {
  background-image: radial-gradient(var(--border-light) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: -10px -10px;
}

.canvas-status-pill {
  position: absolute;
  top: 16px;
  left: 16px;
  background-color: rgba(22, 24, 29, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-light);
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.canvas-status-value {
  color: var(--text-main);
}

/* Coordinate Display */
.coord-display {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  min-width: 70px;
  text-align: right;
}

/* Hover Cell Overlay */
.hover-cell {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--accent);
  opacity: 0.6;
  z-index: 50;
}

/* Overlay / Reference Layer */
.reference-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  image-rendering: pixelated;
}

/* Line/Rect Preview Overlay */
.preview-pixel {
  position: absolute;
  pointer-events: none;
  z-index: 40;
}

/* Selection Overlay */
.selection-outline {
  position: absolute;
  border: 2px dashed var(--accent);
  pointer-events: none;
  z-index: 60;
  animation: marchingAnts 0.5s linear infinite;
}

@keyframes marchingAnts {
  from { border-color: var(--accent); }
  to { border-color: transparent; }
}

/* Previews */
.previews-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-card {
  background-color: var(--bg-app);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Checkered background for transparency in previews */
.preview-checkered {
  background-image:
    linear-gradient(45deg, #1a1a1a 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1a 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1a 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  border: 1px solid var(--border-light);
}

/* XML Output */
.xml-output {
  background-color: var(--bg-app);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--xml-text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  animation: toastIn 0.2s ease;
  pointer-events: none;
}

.toast.fade-out {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Guide Overlay */
.guide-overlay {
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
  padding: 24px;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
  margin-bottom: 16px;
}

.guide-card {
  background-color: var(--bg-app);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
}

.guide-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.code-badge {
  background-color: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-main);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal-panel {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  max-width: 600px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

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

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== MOBILE-ONLY COMPONENTS (hidden on desktop) ===== */
.mobile-bottom-bar,
.mobile-floating-actions,
.mobile-drawer-backdrop {
  display: none;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {

  /* Hide desktop sidebars */
  .sidebar {
    display: none !important;
  }

  .app-container {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .header {
    height: auto;
    padding: 8px 12px;
    flex-shrink: 0;
  }

  .header-title {
    font-size: 14px;
  }

  .header-subtitle {
    display: none;
  }

  .header-actions {
    gap: 4px;
  }

  .header-actions .btn {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  input[type="text"],
  select {
    font-size: 16px !important;
  }

  .main-area {
    flex: 1;
    min-height: 0;
    flex-direction: column;
  }

  .canvas-wrapper {
    flex: 1;
    padding: 12px;
    padding-bottom: 120px;
    /* space for bottom bar with 7 tools */
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .canvas-status-pill {
    display: none;
  }

  .guide-overlay {
    padding: 12px;
    max-height: 50vh;
    overflow-y: auto;
  }

  .guide-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .modal-panel {
    width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
  }

  .modal-body > div {
    flex-direction: column !important;
  }

  .toast {
    bottom: 140px;
  }

  /* ---- Mobile Bottom Bar ---- */
  .mobile-bottom-bar {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 500;
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border-light);
    padding: 6px 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .mobile-channels {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .mobile-channels::-webkit-scrollbar {
    display: none;
  }

  .mobile-channel-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 16px;
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font-ui);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.1s ease;
  }

  .mobile-channel-pill.active {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
  }

  .mobile-ch-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
  }

  [data-theme="light"] .mobile-ch-dot {
    border-color: rgba(0, 0, 0, 0.2);
  }

  .mobile-tools {
    display: flex;
    gap: 4px;
  }

  .mobile-tool {
    flex: 1;
    padding: 6px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font-ui);
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: all 0.1s ease;
  }

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

  .mobile-brush-size {
    display: flex;
    gap: 4px;
    padding: 0 8px;
  }

  /* ---- Floating Undo/Redo ---- */
  .mobile-floating-actions {
    display: flex;
    position: fixed;
    top: 52px;
    right: 8px;
    z-index: 400;
    gap: 4px;
  }

  .mobile-fab {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.1s ease;
  }

  .mobile-fab:disabled {
    opacity: 0.3;
    pointer-events: none;
  }

  .mobile-fab:active {
    transform: scale(0.9);
  }

  /* ---- Slide-Up Drawer ---- */
  .mobile-drawer-backdrop {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 600;
    background: rgba(0, 0, 0, 0.4);
    align-items: flex-end;
    animation: fadeIn 0.15s ease;
  }

  .mobile-drawer {
    width: 100%;
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background-color: var(--bg-panel);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    border-top: 1px solid var(--border-light);
    animation: drawerSlideUp 0.25s ease;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .mobile-drawer .sidebar-section {
    padding: 12px 16px;
  }

  .mobile-drawer-handle {
    padding: 10px 0 6px;
    cursor: pointer;
  }

  @keyframes drawerSlideUp {
    from {
      transform: translateY(100%);
    }

    to {
      transform: translateY(0);
    }
  }

  .mobile-drawer .qud-color-grid {
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  }
}

@media (max-width: 480px) {
  .header-title {
    font-size: 13px;
  }

  .mobile-channel-pill {
    padding: 3px 8px;
    font-size: 10px;
  }
}
