:root {
  --gap: 12px;
  --thumb-radius: 10px;
  --overlay-bg: rgba(0, 0, 0, 0.9);
  --chrome-bg: rgba(0, 0, 0, 0.5);
  --chrome-blur: 8px;
  --maxw: 1200px;
  --ink: #1b1f26;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: #0b0c10;
  color: #e8e8e8;
}

a {
  color: inherit;
  text-decoration: none;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.muted {
  color: #c9c9c9;
}

/* Breadcrumb */
.crumbs {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 6px 0 18px;
}

.crumbs .sep {
  opacity: 0.6;
}

.crumbs .crumb {
  padding: 4px 8px;
  border: 1px solid #2a2f3a;
  border-radius: 999px;
  background: #10131a;
}

/* Navigation buttons section */
.catalog-button-main {
  display: flex;
  margin-bottom: 24px;
}

.nav-buttons-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.navigation-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.nav-btn {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  border: 2px solid #4b90ff;
  background: rgba(75, 144, 255, 0.1);
  color: #4b90ff;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  line-height: 1;
}

.nav-btn:hover {
  background: rgba(75, 144, 255, 0.2);
  border-color: #6ba3ff;
  color: #6ba3ff;
}

.nav-btn:active {
  background: rgba(75, 144, 255, 0.3);
}

.btn {
  border: 1px solid #2a2f3a;
  background: #0f1116;
  color: #e8e8e8;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.btn:focus {
  outline: 2px solid #4b90ff;
  outline-offset: 2px;
}

/* Folders grid */
.folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--gap);
}

/* Folders row view */
.folders.row-view {
  display: flex;
  flex-direction: column;
  gap: 0px !important;
}

.folder {
  display: grid;
  grid-template-rows: 160px auto;
  gap: 8px;
  border: 1px solid var(--ink);
  background: #0f1116;
  border-radius: 12px;
  overflow: clip;
  box-shadow: 0 1px 0 #202736 inset, 0 1px 8px rgba(0, 0, 0, 0.25);
  text-align: left;
}

.folder.row-view {
  display: flex;
  align-items: center;
  padding: 1px 8px !important;
  border-radius: 1px;
  background: #0f1116;
  border: 1px solid var(--ink);
  transition: all 0.2s ease;
  margin: 0 !important;
  cursor: pointer;
  grid-template-rows: unset;
  gap: 10px;
}

.folder.row-view:hover {
  background: #151a22;
  border-color: #2a2f3a;
}

.folder .thumb {
  background: #0c0f15;
  display: grid;
  place-items: center;
  position: relative;
  padding: 12px;
}

.folder.row-view .thumb {
  flex-shrink: 0;
  width: 50px;
  height: 38px;
  padding: 4px;
  border-radius: 3px;
}

.folder .thumb img {
  display: block;
  width: 64%;
  height: auto;
  max-height: 120px;
  object-fit: contain;
  margin: auto;
}

.folder .meta {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ink);
  margin-top: 6px; /* Move folder name content lower */
}

.folder.row-view .meta {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding: 0;
  border-top: none;
}

/* Folder names: wrap + white text */
.folder .name {
  color: #ffffff;
  font-weight: 600;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.folder.row-view .name {
  font-size: 12px;
  font-weight: 500;
  color: #e8e8e8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  word-break: normal;
  overflow-wrap: normal;
}

.folder .count {
  color: #c9c9c9;
  font-size: 12px;
  white-space: nowrap;
}

.folder.row-view .count {
  font-size: 10px;
  color: #a0a0a0;
  white-space: nowrap;
  font-family: monospace;
  min-width: 70px;
  text-align: right;
}

/* Metadata display */
.metadata-info {
  font-size: 11px;
  color: #a0a0a0;
  margin-top: 4px;
  line-height: 1.3;
}

.metadata-info .metadata-row {
  display: flex;
  gap: 6px;
  margin-bottom: 2px;
  min-height: 14px;
  align-items: flex-start;
}

.metadata-info .metadata-label {
  font-weight: 500;
  color: #c0c0c0;
  min-width: 70px;
  flex-shrink: 0;
  padding-top: 1px;
}

.metadata-info .metadata-value {
  color: #e8e8e8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Special handling for long virus names */
.metadata-info .metadata-value.virus-name {
  white-space: normal;
  word-wrap: break-word;
  max-width: 200px;
  line-height: 1.2;
}

.folder.row-view .metadata-info {
  font-size: 10px;
  margin-top: 2px;
}

.folder.row-view .metadata-info .metadata-label {
  min-width: 55px;
  font-size: 9px;
}

.folder.row-view .metadata-info .metadata-value {
  font-size: 9px;
}

/* Lightbox metadata panel improvements */
.metadata-panel .metadata-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  align-items: flex-start;
}

.metadata-panel .metadata-label {
  min-width: 90px;
  flex-shrink: 0;
  font-weight: 500;
}

.metadata-panel .metadata-value {
  flex: 1;
  word-wrap: break-word;
}

.metadata-panel .metadata-value.virus-name {
  white-space: normal;
  line-height: 1.3;
}

/* Images grid (inside a folder) */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--gap);
}

.card {
  position: relative;
  overflow: clip;
  border-radius: 10px;
  border: 1px solid var(--ink);
  background: #0f1116;
  box-shadow: 0 1px 0 #202736 inset, 0 1px 8px rgba(0, 0, 0, 0.25);
}

.card button {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  background: #0f1116;
  cursor: zoom-in;
  display: block;
}

.card img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  filter: saturate(1.05);
  transition: transform 0.15s ease;
}

.card:hover img {
  transform: scale(1.02);
}

/* Image filenames: DO NOT wrap (truncate with ellipsis), but show tooltip on hover */
.caption {
  padding: 10px 12px;
  font-size: 13px;
  color: #cfd6e4;
  border-top: 1px solid var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: none;
  flex-direction: column;
  z-index: 9990;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Remove default focus outline on all lightbox buttons, show only for keyboard nav */
.lightbox button {
  outline: none;
}

.lightbox button:focus-visible {
  outline: 2px solid #4dabf7;
  outline-offset: 2px;
}

.lightbox img,
.lightbox .lb-title,
.lightbox .channel-slider label,
.lightbox .channel-slider span {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.lb-stage {
  position: relative;
  padding: 16px;
  width: 100%;
  height: auto;
  min-height: calc(100vh - 150px);
  margin-top: 0;
  padding-bottom: 60px;
  display: grid;
  place-items: center;
  flex: 1;
  overflow: hidden;
}

.lb-img {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 150px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 60px rgba(0, 0, 0, 0.6);
  user-select: none;
  pointer-events: auto;
  cursor: default;
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  /* Safe performance optimizations */
  image-rendering: auto;
}

.lb-img.zoomed {
  cursor: default;
  /* Keep size constraints for smooth transition */
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 150px);
}

.lb-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(var(--chrome-blur));
  backdrop-filter: blur(var(--chrome-blur));
  border-bottom: 1px solid #2a2f3a;
  padding: 12px 20px;
  font-size: 13px;
  z-index: 9995;
  box-sizing: border-box;
  max-height: auto;
  overflow: visible;
  transition: transform 0.3s ease;
}

.lb-top.hidden {
  transform: translateY(-100%);
  pointer-events: none;
  height: 0;
  overflow: hidden;
  padding: 0;
  min-height: 0;
}

/* Protective overlay for toolbar gap - prevents clicks from closing lightbox */
.toolbar-gap-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: none;
  pointer-events: none;
  z-index: 9994;
}

.lb-top.hidden ~ .toolbar-gap-overlay {
  display: block;
  pointer-events: auto;
}

/* Independent toolbar restore indicator button */
.toolbar-restore-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 32px;
  border: none;
  background: linear-gradient(to bottom, rgba(79, 172, 254, 0.95), rgba(79, 172, 254, 0.85));
  color: white;
  font-size: 16px;
  cursor: pointer;
  z-index: 9996;
  display: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 0;
  align-items: center;
  justify-content: center;
  border-radius: 0 0 4px 4px;
}

.toolbar-restore-indicator.visible {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

.toolbar-restore-indicator:hover {
  background: linear-gradient(to bottom, rgba(33, 150, 243, 1), rgba(33, 150, 243, 0.95));
}

.toolbar-restore-btn {
  display: none !important;
}

.toolbar-restore-btn.visible {
  display: inline-flex !important;
}

.lb-top-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-title-row {
  display: flex;
  align-items: center;
  min-height: 28px;
  flex-shrink: 0;
}

.lb-buttons-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.lb-buttons-row:first-child {
  align-items: center;
}

.lb-buttons-left {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.lb-buttons-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lb-title {
  font-weight: 500;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}

.swap-folder-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #4b90ff;
  background: rgba(75, 144, 255, 0.15);
  color: #4b90ff;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 32px;
  min-width: 80px;
  max-width: 140px;
  margin-left: 12px;
}

.swap-folder-btn:hover {
  background: rgba(75, 144, 255, 0.25);
  border-color: #6ba3ff;
  transform: translateY(-1px);
}

.swap-folder-btn:active {
  background: rgba(75, 144, 255, 0.35);
}

.swap-folder-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.iconbtn {
  border: 1px solid #2a2f3a;
  background: #0f1116;
  border-radius: 6px;
  padding: 6px 10px;
  color: #e8e8e8;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  min-height: 32px;
  min-width: 32px;
  transition: all 0.2s ease;
}

.iconbtn:hover {
  background: #1a1f2e;
  border-color: #3a3f4a;
  transform: translateY(-1px);
}

.iconbtn:hover {
  background: #1a1f2e;
  border-color: #3a3f4a;
  transform: translateY(-1px);
}

.iconbtn:focus {
  outline: 2px solid #4b90ff;
  outline-offset: 2px;
}

/* Close button - prominent red styling */
#lbClose {
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid #ff6b6b;
  color: #ff6b6b;
  font-weight: 700;
  font-size: 13px;
  min-width: 70px;
  padding: 6px 12px;
  outline: none;
}

#lbClose:hover {
  background: rgba(255, 107, 107, 0.25);
  border-color: #ff8b8b;
  color: #ff8b8b;
}

#lbClose:active {
  background: rgba(255, 107, 107, 0.35);
}

#lbClose:focus {
  outline: none;
}

#lbClose:focus-visible {
  outline: 2px solid #ff6b6b;
  outline-offset: 2px;
}

#lbHideToolbar {
  background: rgba(79, 172, 254, 0.15);
  border: 1px solid #4facfe;
  color: #4facfe;
  font-weight: 700;
  font-size: 16px;
  padding: 6px 12px;
  outline: none;
  transition: all 0.2s ease;
}

#lbHideToolbar:hover {
  background: rgba(79, 172, 254, 0.25);
  border-color: #6fbbfe;
}

#lbHideToolbar:focus {
  outline: none;
}

#lbHideToolbar:focus-visible {
  outline: 2px solid #4facfe;
  outline-offset: 2px;
}

.linkbtn {
  text-decoration: none;
  display: inline-block;
}

.metadata-toggle {
  background: #333;
  border: 1px solid #555;
  border-radius: 6px;
  color: white;
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
}

.metadata-toggle:hover {
  background: #444;
  transform: translateY(-1px);
}

.metadata-toggle.active {
  background: #4CAF50;
  border-color: #45a049;
  color: white;
}

.atlas-toggle {
  background: #333;
  border: 1px solid #555;
  border-radius: 6px;
  color: white;
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
}

.atlas-toggle:hover {
  background: #444;
  transform: translateY(-1px);
}

.atlas-toggle.active {
  background: #2196F3;
  border-color: #0b7dda;
  color: white;
}

.legend-toggle {
  background: #333;
  border: 1px solid #555;
  border-radius: 6px;
  color: white;
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
}

.legend-toggle:hover {
  background: #444;
  transform: translateY(-1px);
}

.legend-toggle.active {
  background: #9d6ec7;
  border-color: #8a5aa3;
  color: white;
}

.lb-nav {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.lb-prev,
.lb-next {
  position: relative;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(var(--chrome-blur));
  backdrop-filter: blur(var(--chrome-blur));
  border: 1px solid #2a2f3a;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  min-width: 32px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
}

.lb-prev:hover,
.lb-next:hover {
  background: #1a1f2e;
  border-color: #3a3f4a;
  transform: translateY(-1px);
}

.lb-prev {
  order: 1;
}

.lb-next {
  order: 3;
}

.lb-counter {
  position: relative;
  order: 2;
  font-size: 12px;
  color: #cfd6e4;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(var(--chrome-blur));
  backdrop-filter: blur(var(--chrome-blur));
  border-radius: 999px;
  padding: 4px 8px;
  border: 1px solid #2a2f3a;
  z-index: 2;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-bottom-controls {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: nowrap;
  z-index: 2;
  padding: 0 8px;
  max-width: calc(100vw - 32px);
}

.zoom-display {
  position: absolute;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 600;
  color: #4dabf7;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(var(--chrome-blur));
  backdrop-filter: blur(var(--chrome-blur));
  border-radius: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(0, 123, 255, 0.3);
  z-index: 9994;
  font-family: monospace;
  min-width: 60px;
  text-align: center;
  user-select: none;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
}

.zoom-display:hover {
  background: rgba(0, 123, 255, 0.2);
  border-color: rgba(0, 123, 255, 0.5);
  transform: translateX(-50%) translateY(-1px);
}

/* Metadata panel */
.metadata-panel {
  position: fixed;
  top: 120px;
  right: 20px;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(var(--chrome-blur));
  backdrop-filter: blur(var(--chrome-blur));
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 12px;
  font-size: 11px;
  color: #e8e8e8;
  z-index: 9993;
  min-width: 180px;
  max-width: 300px;
  max-height: calc(100vh - 140px);
  opacity: 0;
  transform: scale(0.95);
  transition: all 0.3s ease;
  pointer-events: none;
  overflow-y: auto;
}

.metadata-panel.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.metadata-panel h4 {
  margin: 0 0 8px 0;
  font-size: 12px;
  font-weight: 600;
  color: #4dabf7;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.panel-header h4 {
  margin: 0;
  flex: 1;
}

.panel-close-btn {
  border: none;
  background: transparent;
  color: #e8e8e8;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.panel-close-btn:hover {
  color: #ff6b6b;
  transform: scale(1.1);
}

.metadata-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  line-height: 1.3;
}

.metadata-label {
  color: #a0a0a0;
  font-weight: 500;
}

.metadata-value {
  color: #e8e8e8;
  font-family: monospace;
  font-weight: 400;
}

.metadata-value a {
  color: #87ceeb;
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.2s;
}

.metadata-value a:hover {
  color: #add8e6;
}

/* Brain Template Panel */
.brain-template-panel {
  position: fixed;
  left: 0;
  top: 140px;
  transform: scale(0.95);
  width: 250px;
  height: auto;
  max-height: calc(100vh - 200px);
  background: var(--chrome-bg);
  -webkit-backdrop-filter: blur(var(--chrome-blur));
  backdrop-filter: blur(var(--chrome-blur));
  border: 1px solid #2a2f3a;
  border-left: none;
  border-radius: 0 8px 8px 0;
  display: flex;
  flex-direction: column;
  z-index: 9991;
  transition: all 0.3s ease;
  opacity: 0;
  pointer-events: none;
  overflow-y: auto;
  padding: 12px;
}

.brain-template-panel.visible {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

.brain-template-toggle {
  flex-shrink: 0;
}

.brain-template-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  gap: 12px;
}

.brain-template-info {
  flex-shrink: 0;
}

.brain-template-info h4 {
  margin: 0 0 8px 0;
  font-size: 12px;
  font-weight: 600;
  color: #4dabf7;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
}

.brain-position-display {
  font-size: 10px;
  color: #a0a0a0;
  line-height: 1.4;
}

.brain-template-image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  min-height: 150px;
}

.brain-placeholder {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  object-fit: contain;
  display: block;
}

.channel-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 10px;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-wrap: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.rgb-toggle-group {
  display: none;
  gap: 4px;
  align-items: center;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}

.lb-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.channel-slider {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.channel-slider label {
  color: #e8e8e8;
  font-size: 10px;
  font-weight: 500;
  min-width: 24px;
  text-transform: uppercase;
  user-select: none;
}

.slider {
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  flex-shrink: 0;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: all 0.15s ease;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.red-slider::-webkit-slider-thumb {
  background: #ff6b6b;
}

.green-slider::-webkit-slider-thumb {
  background: #51cf66;
}

.blue-slider::-webkit-slider-thumb {
  background: #4dabf7;
}

.gain-slider::-webkit-slider-thumb {
  background: #ffd43b;
}

.red-slider {
  background: linear-gradient(to right, rgba(255, 107, 107, 0.3), #ff6b6b);
}

.green-slider {
  background: linear-gradient(to right, rgba(81, 207, 102, 0.3), #51cf66);
}

.blue-slider {
  background: linear-gradient(to right, rgba(77, 171, 247, 0.3), #4dabf7);
}

.gain-slider {
  background: linear-gradient(to right, rgba(255, 212, 59, 0.3), #ffd43b);
}

.channel-slider span {
  color: #e8e8e8;
  font-size: 9px;
  min-width: 28px;
  text-align: right;
  opacity: 0.8;
  font-weight: 500;
  user-select: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.channel-slider span:hover {
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

.channel-value-input {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #e8e8e8;
  font-size: 10px;
  font-weight: 500;
  text-align: right;
  padding: 2px 4px;
  border-radius: 3px;
  width: 50px;
  outline: none;
}

.channel-value-input:focus {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

.reset-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  transition: all 0.2s ease;
}

.reset-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.grayscale-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  transition: all 0.2s ease;
}

.grayscale-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.grayscale-btn.active {
  background: rgba(200, 200, 200, 0.3);
  border-color: rgba(200, 200, 200, 0.5);
  color: #ffffff;
}

.channel-btn {
  min-width: 32px;
  min-height: 32px;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.channel-btn[data-channel="red"] {
  background: #dc2626;
  border-color: #b91c1c;
  color: white;
}

.channel-btn[data-channel="red"]:hover {
  background: #ef4444;
  border-color: #dc2626;
  transform: scale(1.05);
}

.channel-btn[data-channel="green"] {
  background: #16a34a;
  border-color: #15803d;
  color: white;
}

.channel-btn[data-channel="green"]:hover {
  background: #22c55e;
  border-color: #16a34a;
  transform: scale(1.05);
}

.channel-btn[data-channel="blue"] {
  background: #2563eb;
  border-color: #1d4ed8;
  color: white;
}

.channel-btn[data-channel="blue"]:hover {
  background: #3b82f6;
  border-color: #2563eb;
  transform: scale(1.05);
}

.channel-btn.disabled {
  opacity: 0.4;
  background: #374151;
  border-color: #4b5563;
  cursor: not-allowed;
  transform: none;
}

.lb-img.filtered {
  transition: filter 0.2s ease;
}

/* View switcher button */
.view-switcher {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e8e8e8;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.view-switcher:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.view-switcher.active {
  background: rgba(77, 171, 247, 0.2);
  border-color: rgba(77, 171, 247, 0.4);
  color: #4dabf7;
}

/* Row-based detail view */
.gallery.row-view {
  display: flex;
  flex-direction: column;
  gap: 0px !important;
}

.card.row-view {
  display: flex;
  align-items: center;
  padding: 1px 8px !important;
  border-radius: 1px;
  background: #0f1116;
  border: 1px solid var(--ink);
  transition: all 0.2s ease;
  margin: 0 !important;
  cursor: pointer;
}

.card.row-view:hover {
  background: #151a22;
  border-color: #2a2f3a;
}

.card.row-view button {
  flex-shrink: 0;
  width: 50px;
  height: 38px;
  margin-right: 8px;
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer !important;
  pointer-events: none;
}

.card.row-view img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card.row-view .row-details {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.card.row-view .filename {
  font-size: 12px;
  font-weight: 500;
  color: #e8e8e8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.card.row-view .dimensions {
  font-size: 10px;
  color: #a0a0a0;
  white-space: nowrap;
  font-family: monospace;
}

.card.row-view .file-size {
  font-size: 10px;
  color: #a0a0a0;
  white-space: nowrap;
  font-family: monospace;
  min-width: 50px;
  text-align: right;
}

.card.row-view .last-modified {
  font-size: 10px;
  color: #a0a0a0;
  white-space: nowrap;
  min-width: 70px;
  text-align: right;
}

/* Folder Metadata Panel Styles */
.folder-metadata-panel {
  background: var(--card-bg);
  border: 1px solid var(--ink);
  border-radius: 12px;
  margin: 32px 0 40px 0; /* More space from subtitle above and images below */
  padding: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  max-width: 100%;
}

.metadata-header {
  background: linear-gradient(135deg, #2a2a2a 0%, #1e1e1e 100%);
  color: #ffffff;
  padding: 16px 20px;
  font-weight: 600;
  font-size: 16px;
  border-bottom: 1px solid var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.metadata-header::before {
  /*content: "🧬";*/
  font-size: 18px;
}

.metadata-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  background: var(--card-bg);
}

.metadata-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.metadata-row:last-child {
  border-bottom: none;
}

.metadata-label {
  font-weight: 500;
  color: #b0b8c8;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.metadata-value {
  color: #e8e8e8;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
  font-weight: 400;
}

/* Special styling for different value types */
.metadata-value.virus-name {
  color: #ffd700;
  font-weight: 500;
  font-size: 12px;
}

.metadata-value.date {
  color: #87ceeb;
  font-family: monospace;
  font-size: 12px;
}

.metadata-value.numeric {
  color: #98fb98;
  font-family: monospace;
  font-size: 12px;
}

.metadata-value.boolean {
  color: #ffa07a;
  font-weight: 500;
  text-transform: capitalize;
  font-size: 12px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .folder-metadata-panel {
    margin: 24px 0 32px 0;
  }
  
  .metadata-grid {
    padding: 16px;
    gap: 10px;
  }
  
  .metadata-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  
  .metadata-label {
    font-size: 12px;
    color: #9ca3af;
  }
  
  .metadata-value {
    font-size: 12px;
    margin-left: 12px;
  }
}

/* Channel Legend Styles */
.channel-legend {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 12px 16px;
  max-width: 300px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  pointer-events: none;
  display: block;
  opacity: 0;
  transform: scale(0.95);
  transition: all 0.3s ease;
}

.channel-legend.visible {
  display: block;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.channel-legend:not(.visible) {
  display: block;
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
}

.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.legend-title {
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  margin: 0;
  flex: 1;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.legend-item:last-child {
  margin-bottom: 0;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.red-color {
  background: #ff4444;
  box-shadow: 0 0 4px rgba(255, 68, 68, 0.4);
}

.red-color.disabled {
  background: #666666;
  box-shadow: 0 0 4px rgba(102, 102, 102, 0.2);
}

.green-color {
  background: #44ff44;
  box-shadow: 0 0 4px rgba(68, 255, 68, 0.4);
}

.green-color.disabled {
  background: #666666;
  box-shadow: 0 0 4px rgba(102, 102, 102, 0.2);
}

.blue-color {
  background: #4444ff;
  box-shadow: 0 0 4px rgba(68, 68, 255, 0.4);
}

.blue-color.disabled {
  background: #666666;
  box-shadow: 0 0 4px rgba(102, 102, 102, 0.2);
}

.legend-label {
  color: #e8e8e8;
  font-size: 12px;
  line-height: 1.3;
  word-break: break-word;
}

/* ========== MOBILE OPTIMIZATIONS ========== */
@media (max-width: 768px) {
  /* Reduce padding on mobile */
  .wrap {
    padding: 16px;
  }

  header {
    flex-wrap: wrap;
    gap: 8px;
  }

  h1 {
    font-size: 18px;
  }

  /* Make buttons touch-friendly */
  .btn, .iconbtn {
    min-height: 44px;
    padding: 10px 14px;
  }

  /* Breadcrumb adjustments */
  .crumbs {
    font-size: 12px;
  }

  .crumbs .crumb {
    padding: 6px 10px;
  }

  /* Folder grid - 2 columns on mobile */
  .folders {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  /* Image gallery - 2 columns on mobile */
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  /* Smaller folder cards */
  .folder {
    grid-template-rows: 100px auto;
  }

  .folder .thumb img {
    width: 50%;
    max-height: 80px;
  }

  .folder .meta {
    padding: 8px 10px;
    font-size: 11px;
  }

  .folder .name {
    font-size: 12px;
  }

  .folder .count {
    font-size: 10px;
  }

  /* Hide metadata in folder cards on mobile */
  .folder .metadata-info {
    display: none;
  }

  /* Row view adjustments for mobile */
  .folder.row-view .thumb {
    width: 40px;
    height: 32px;
  }

  .folder.row-view .name {
    font-size: 11px;
  }

  .folder.row-view .count {
    font-size: 9px;
    min-width: 60px;
  }

  /* Folder metadata panel - make scrollable */
  .folder-metadata-panel {
    margin: 16px 0 24px 0;
    max-height: 300px;
    overflow-y: auto;
  }

  .metadata-grid {
    padding: 12px;
  }

  /* ========== LIGHTBOX MOBILE OPTIMIZATIONS ========== */
  
  /* Lightbox container adjustments */
  .lightbox {
    flex-direction: column;
    overflow: auto;
  }

  /* Make top bar compact and stack properly */
  .lb-top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 8px 10px;
    height: auto;
    max-height: 80px;
    flex-wrap: wrap;
    gap: 6px;
    z-index: 9995;
    overflow: hidden;
  }

  .lb-top-content {
    gap: 6px;
    width: 100%;
    display: flex;
    flex-direction: column;
  }

  /* Stack the button rows vertically */
  .lb-buttons-row {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  /* Reduce title size */
  .lb-title {
    font-size: 12px;
    flex: 1 1 auto;
    margin-bottom: 0;
  }

  /* Move channel controls to collapse/hide on narrow screens */
  .channel-controls {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 6px 8px;
    order: 2;
    width: auto;
    overflow-x: auto;
    flex-shrink: 1;
    min-width: 0;
  }

  /* Make channel sliders compact on mobile */
  .channel-slider {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    min-width: 0;
  }

  .channel-slider label {
    font-size: 9px;
    min-width: auto;
    white-space: nowrap;
  }

  .slider {
    width: 30px;
    height: 2px;
    min-width: 30px;
  }

  .slider::-webkit-slider-thumb {
    width: 8px;
    height: 8px;
  }

  .channel-slider span {
    font-size: 9px;
    min-width: auto;
    white-space: nowrap;
  }

  .reset-btn {
    font-size: 9px !important;
    padding: 4px 6px !important;
    white-space: nowrap;
  }

  .grayscale-btn {
    font-size: 9px !important;
    padding: 4px 6px !important;
    white-space: nowrap;
  }

  /* Compact controls */
  .lb-controls {
    gap: 6px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
  }

  .lb-buttons-left {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  .metadata-toggle {
    font-size: 10px;
    padding: 4px 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  .atlas-toggle {
    font-size: 10px;
    padding: 4px 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  .legend-toggle {
    font-size: 10px;
    padding: 4px 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  .swap-folder-btn {
    font-size: 10px !important;
    padding: 4px 6px !important;
    min-width: auto !important;
    max-width: none !important;
    height: auto !important;
    white-space: nowrap !important;
  }

  .iconbtn {
    font-size: 11px;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  .linkbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
  }

  /* Adjust stage for mobile with proper padding for header */
  .lb-stage {
    position: relative;
    margin-top: 0;
    padding-top: 60px;
    padding-bottom: 60px;
    height: auto;
    min-height: calc(100vh - 120px);
    overflow-y: auto;
  }

  /* Image sizing for mobile */
  .lb-img {
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 180px);
  }

  .lb-img.zoomed {
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 180px);
  }

  /* Keep navigation at bottom with proper positioning */
  .lb-bottom-controls {
    position: fixed;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9994;
    gap: 12px;
    padding: 0 8px;
    max-width: calc(100vw - 32px);
  }

  /* Zoom display positioned above navigation on mobile */
  .zoom-display {
    position: fixed;
    bottom: calc(8px + 32px + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 9994;
  }

  .lb-prev, .lb-next {
    position: relative;
    padding: 8px 12px;
    font-size: 16px;
    background: var(--chrome-bg);
    -webkit-backdrop-filter: blur(var(--chrome-blur));
    backdrop-filter: blur(var(--chrome-blur));
    border: 1px solid #2a2f3a;
    border-radius: 999px;
    min-height: 32px;
    min-width: 32px;
  }

  .lb-counter {
    position: relative;
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Brain template as bottom drawer on mobile */
  .brain-template-panel {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    top: auto;
    width: 90vw;
    max-width: 400px;
    height: auto;
    max-height: 35vh;
    border-radius: 8px 8px 0 0;
    border-left: 1px solid #2a2f3a;
    border-right: 1px solid #2a2f3a;
    border-top: 1px solid #2a2f3a;
    z-index: 9995;
    transition: transform 0.3s ease;
    opacity: 0;
    pointer-events: none;
  }

  .brain-template-panel.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  /* Metadata panel as bottom drawer on mobile */
  .metadata-panel {
    position: fixed;
    bottom: calc(60px + 35vh + 8px);
    top: auto;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 30vh;
    border-radius: 8px;
    z-index: 9992;
    overflow-y: auto;
  }

  .metadata-panel.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Compact brain template content on mobile */
  .brain-template-content {
    padding: 8px;
    gap: 8px;
  }

  .brain-template-info h4 {
    font-size: 11px;
    margin-bottom: 4px;
  }

  .brain-position-display {
    font-size: 9px;
  }

  .brain-template-image {
    max-height: 120px;
  }

  /* Prevent header from taking too much space */
  .lb-top {
    max-height: 45vh;
  }

  /* Ensure stage has proper bounds */
  .lb-stage {
    padding-top: 50px;
    padding-bottom: 100px;
    min-height: calc(100vh - 100px);
  }

  /* Image sizing for small viewports */
  .lb-img {
    max-height: calc(100vh - 180px);
  }

  .lb-img.zoomed {
    max-height: calc(100vh - 180px);
  }

  /* ========== METADATA PANEL - MOBILE DRAWER ========== */
  
  /* Make metadata panel a bottom drawer on mobile */
  .metadata-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    border: 1px solid #2a2f3a;
    border-bottom: none;
    padding: 12px 16px 20px 16px;
    min-width: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    z-index: 9998;
  }

  .metadata-panel.visible {
    transform: translateY(0);
    opacity: 1;
  }

  /* Add handle indicator for drawer */
  .metadata-panel::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
  }

  .metadata-panel h4 {
    font-size: 11px;
    margin-top: 8px;
  }

  .metadata-row {
    font-size: 10px;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 6px;
  }

  .metadata-label {
    font-size: 9px;
    min-width: auto;
  }

  .metadata-value {
    font-size: 10px;
  }

  /* Hide biological metadata section on mobile to save space */
  #biologicalMetadata {
    display: none !important;
  }

  /* Image card captions */
  .caption {
    font-size: 11px;
    padding: 8px 10px;
  }

  /* Row view for images on mobile */
  .card.row-view button {
    width: 40px;
    height: 32px;
  }

  .card.row-view .filename {
    font-size: 11px;
  }

  .card.row-view .dimensions,
  .card.row-view .file-size,
  .card.row-view .last-modified {
    font-size: 9px;
  }

  /* View switcher */
  .view-switcher {
    font-size: 10px;
    padding: 6px 10px;
  }
}

/* Gesture hint for mobile */
.gesture-hint {
  display: none;
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 11px;
  text-align: center;
  z-index: 9999;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  max-width: 90vw;
  line-height: 1.3;
}

.gesture-hint.visible {
  opacity: 1;
}

/* Medium screens: 769px to 1024px */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Reduce padding on medium screens */
  .lb-top {
    padding: 8px 12px;
    max-height: none;
  }

  /* Stack some buttons on medium screens */
  .lb-buttons-row {
    gap: 6px;
    flex-wrap: wrap;
  }

  /* Keep close button on first row */
  .lb-buttons-row:first-child {
    justify-content: flex-start;
  }

  .lb-controls {
    flex-shrink: 0;
    min-width: fit-content;
  }

  /* Make channel controls wrap more gracefully */
  .channel-controls {
    flex-wrap: wrap;
  }

  /* Reduce slider sizes on medium */
  .channel-slider {
    gap: 2px;
  }

  .slider {
    width: 35px;
  }

  /* Reduce button sizes slightly */
  .swap-folder-btn {
    min-width: 120px !important;
    max-width: 140px !important;
    font-size: 11px !important;
  }

  /* Adjust metadata panel positioning */
  .metadata-panel {
    right: 10px;
    left: auto;
    width: calc(100vw - 40px);
    max-width: 250px;
    bottom: auto;
    top: 150px;
    max-height: calc(100vh - 170px);
  }

  .metadata-panel.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Keep brain template on side for medium screens */
  .brain-template-panel {
    position: fixed;
    left: 0;
    top: 140px;
    transform: translateX(-100%);
    bottom: auto;
    width: 200px;
    height: auto;
    max-height: calc(100vh - 200px);
    border-left: none;
    border-radius: 0 8px 8px 0;
  }

  .brain-template-panel.visible {
    transform: translateX(0);
  }

  /* Image sizing for medium */
  .lb-img {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 160px);
  }

  .lb-img.zoomed {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 160px);
  }

  /* Adjust stage for medium screens */
  .lb-stage {
    height: auto;
    min-height: calc(100vh - 140px);
    padding: 12px;
    padding-bottom: 60px;
  }
}

/* Large screens: 1025px and above */
@media (min-width: 1025px) {
  /* Ensure panels don't overlap */
  .lb-top {
    padding: 12px 20px;
  }

  /* Brain template panel positioned below toolbar */
  .brain-template-panel {
    position: fixed;
    left: 0;
    top: 140px;
    transform: translateX(-100%);
    width: 250px;
    height: auto;
    max-height: calc(100vh - 200px);
    border-left: none;
    border-radius: 0 8px 8px 0;
  }

  .brain-template-panel.visible {
    transform: translateX(0);
  }

  /* Metadata panel stays on right with proper spacing */
  .metadata-panel {
    right: 20px;
    left: auto;
    top: 120px;
    max-height: calc(100vh - 140px);
    width: auto;
  }

  /* Ensure image has room for all panels */
  .lb-img {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 150px);
  }

  .lb-img.zoomed {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 150px);
  }
}

/* Small screens: max-width 768px */
@media (max-width: 768px) {
  /* Switch to toggle buttons on small screens */
  .slider-group {
    display: none !important;
  }

  .rgb-toggle-group {
    display: flex !important;
    gap: 4px;
  }

  .channel-controls {
    gap: 6px;
    padding: 6px 8px;
  }

  .reset-btn {
    font-size: 9px !important;
    padding: 4px 6px !important;
  }

  .grayscale-btn {
    font-size: 9px !important;
    padding: 4px 6px !important;
  }

  .gesture-hint {
    display: block;
  }
}

/* Improve touch target sizes */
@media (hover: none) and (pointer: coarse) {
  /* Touch device specific styles */
  .btn, .iconbtn, .metadata-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  .lb-prev, .lb-next {
    min-width: 44px;
    min-height: 44px;
  }

  /* Prevent text selection on touch */
  .lightbox, .lb-img, .lb-top, .metadata-panel {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  /* Remove hover effects on touch devices */
  .card:hover img {
    transform: none;
  }

  .folder:hover {
    transform: none;
  }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
  /* Single column for very small screens */
  .folders:not(.row-view) {
    grid-template-columns: 1fr;
  }

  .gallery:not(.row-view) {
    grid-template-columns: 1fr;
  }

  /* Stack channel controls vertically */
  .channel-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .channel-slider {
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
  }

  .slider {
    flex: 1;
    width: auto;
    margin: 0 10px;
  }

  /* Hide some metadata fields to save space */
  .metadata-panel .metadata-row:nth-child(n+4) {
    display: none;
  }

  /* Compact navigation */
  .lb-prev, .lb-next {
    padding: 10px 12px;
    font-size: 16px;
  }

  /* Make gesture hint smaller */
  .gesture-hint {
    font-size: 10px;
    padding: 6px 12px;
  }
}

/* ========== README MODAL ========== */
.readme-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
  overflow: hidden;
}

.readme-modal.visible {
  display: flex;
}

.readme-modal-content {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.readme-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #333;
  background: rgba(0, 0, 0, 0.3);
  position: sticky;
  top: 0;
  flex-shrink: 0;
}

.readme-modal-header h2 {
  margin: 0;
  font-size: 22px;
  color: #ffffff;
}

.readme-modal-close {
  background: none;
  border: none;
  color: #ccc;
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.readme-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.readme-modal-body {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

.readme-section {
  margin-bottom: 24px;
}

.readme-section:last-child {
  margin-bottom: 0;
}

.readme-section h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: #4dabf7;
  font-weight: 600;
}

.readme-section ul {
  margin: 0;
  padding-left: 20px;
  list-style: none;
}

.readme-section li {
  margin-bottom: 8px;
  color: #e8e8e8;
  font-size: 14px;
  line-height: 1.5;
}

.readme-section li:last-child {
  margin-bottom: 0;
}

.readme-section strong {
  color: #fff;
  font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .readme-modal {
    padding: 10px;
  }

  .readme-modal-content {
    max-height: 95vh;
  }

  .readme-modal-header {
    padding: 16px;
  }

  .readme-modal-header h2 {
    font-size: 18px;
  }

  .readme-modal-body {
    padding: 16px;
  }

  .readme-section {
    margin-bottom: 16px;
  }

  .readme-section h3 {
    font-size: 14px;
  }

  .readme-section li {
    font-size: 13px;
  }
}
