:root {
  --bg-primary: #0e0e10;
  --bg-secondary: #18181b;
  --bg-tertiary: #27272a;
  --bg-hover: #3f3f46;
  --border: #3f3f46;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #c9a96e;
  --accent-hover: #d4b87e;
  --accent-dim: rgba(201, 169, 110, 0.15);
  --sidebar-width: 280px;
  --header-bar: 52px;
  --header-height: calc(var(--header-bar) + env(safe-area-inset-top, 0px));
  --radius: 8px;
  --radius-sm: 4px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* No-JS crawlable fallback */
.noscript-fallback {
  max-width: 40rem;
  margin: 2rem auto;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  line-height: 1.65;
}
.noscript-fallback h1 {
  color: var(--text-primary);
  font-size: 1.35rem;
  margin-bottom: 1rem;
}
.noscript-fallback p {
  margin-bottom: 1rem;
}

/* Header — fixed so it stays visible during mobile zoom / pan */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  min-height: var(--header-height);
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: 0;
  box-sizing: border-box;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.header-left h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-center {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-right {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Buttons */
.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 8px;
}
.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Main Layout */
#app-main {
  display: flex;
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  min-height: 0;
  box-sizing: border-box;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}
#sidebar::-webkit-scrollbar {
  width: 5px;
}
#sidebar::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}
#sidebar.closed {
  display: none;
}

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

.sidebar-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Gallery */
.gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.gallery-item:hover {
  border-color: var(--text-muted);
  transform: scale(1.02);
}
.gallery-item.active {
  border-color: var(--accent);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item .gallery-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 4px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  font-size: 9px;
  font-weight: 500;
  color: #fff;
  text-align: center;
  line-height: 1.3;
  padding-top: 14px;
}

/* Filters */
.filter-group {
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.filter-group label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.filter-group input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}
.filter-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-secondary);
}
.filter-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-secondary);
}

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

.filter-value {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Nav controls */
.nav-controls {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.zoom-display {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* About */
.about-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.6;
}
.about-text.credits {
  font-size: 11px;
  color: var(--text-muted);
}

/* Viewer */
#viewer-container {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

#osd-viewer {
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
}

/* Loading overlay */
#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-primary);
  z-index: 10;
  opacity: 1;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
#loading-overlay.hidden {
  opacity: 0;
}
#loading-overlay span {
  font-size: 13px;
  color: var(--text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Minimap */
#minimap {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  height: 120px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Fullscreen */
#viewer-container:fullscreen {
  background: var(--bg-primary);
}
#viewer-container:fullscreen #osd-viewer {
  width: 100vw;
  height: 100vh;
}

/* OSD overrides */
.openseadragon-canvas {
  outline: none !important;
}
.navigator .displayregion {
  border: 2px solid var(--accent) !important;
  background: rgba(201, 169, 110, 0.1) !important;
}

/* Responsive: sidebar overlay on narrow viewports */
@media (max-width: 768px) {
  :root {
    --sidebar-width: min(100vw, 300px);
  }
  .header-left h1 {
    font-size: 14px;
  }
  .subtitle {
    display: none;
  }
  #app-main {
    position: relative;
  }
  #sidebar {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1500;
    width: var(--sidebar-width);
    min-width: unset;
    max-width: 100%;
    height: 100%;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.45);
    border-right: 1px solid var(--border);
  }
  #sidebar.closed {
    display: none;
  }
  #viewer-container {
    flex: 1;
    min-width: 0;
    width: 100%;
  }
  #minimap {
    width: 120px;
    height: 90px;
    bottom: 10px;
    right: 10px;
  }
}
