/* ============================================
   AUTUMN COLOR PALETTE FOR EXPLORER
   ============================================ */
.explorer {
  --autumn-brown-dark: #8D3123;
  --autumn-brown: #964B00;
  --autumn-brown-russet: #80461B;
  --autumn-orange-tawny: #CD5700;
  --autumn-orange-burnt: #CC5404;
  --autumn-orange: #FFA500;
  --autumn-orange-cinnamon: #D27D2D;
  --autumn-tan: #D2B48C;
  --autumn-tan-peach: #FFDAB9;
  --autumn-neutral-bark: #5C4033;
  --autumn-neutral-mushroom: #A89F91;
  --autumn-neutral-wheat: #C9B896;
  
  /* Primary text brown - matches SVG node titles */
  --autumn-text-brown: #5D4037;
  
  /* Control button size - used for zoom, nav, and close buttons */
  --control-btn-size: 32px;
}

/* Override the container width for explorer page */
.container:has(.explorer) {
  max-width: 100%;
  padding: 0 2rem;
  box-sizing: border-box;
  overflow-x: hidden;
}

.explorer {
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.explorer-header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.explorer-subtitle {
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.explorer-description {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.explorer-controls {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 0.5rem;
  gap: 0.75rem;
  flex-wrap: wrap;
  max-width: 100%;
  box-sizing: border-box;
}

.tab-switcher {
  display: flex;
  gap: 0;
  align-items: stretch;
}

.tab-switcher .tab-btn {
  border-radius: 0;
}

.tab-switcher .tab-btn:first-child {
  border-radius: var(--border-radius) 0 0 var(--border-radius);
}

.tab-switcher .tab-btn:last-child {
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  border-left: none;
}

.tab-btn {
  height: 38px;
  min-width: 70px;
  padding: 0 1rem;
  border: 1px solid var(--autumn-tan);
  background: var(--background);
  color: var(--autumn-text-brown);
  cursor: pointer;
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1;
  box-sizing: border-box;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab-btn:hover {
  border-color: var(--autumn-orange-cinnamon);
  background: var(--autumn-tan-peach);
}

.tab-btn.active {
  background: var(--autumn-brown-russet);
  color: white;
  border-color: var(--autumn-brown-russet);
}

.search-box {
  flex: 0 1 auto;
  width: 220px;
  max-width: 100%;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1;
  box-sizing: border-box;
}

.search-box input:focus {
  outline: none;
  border-color: var(--autumn-orange-cinnamon);
}

/* Main split layout */
.explorer-main {
  display: flex;
  gap: 1rem;
  height: calc(100vh - 200px);
  min-height: 500px;
}

.explorer-content {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: white;
  position: relative;
  overflow: hidden;
  transition: flex 0.3s ease;
}

.explorer-main.detail-open .explorer-content {
  flex: 1;
}

.view-container {
  display: none;
  height: 100%;
  position: relative;
}

.view-container.active {
  display: block;
}

/* Graph View */
#graph-view {
  position: relative;
}

#edge-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#cy {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.graph-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.375rem;
  z-index: 10;
  background: white;
  padding: 0.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border-color);
}

/* Button group for zoom controls */
.graph-controls .zoom-group {
  display: flex;
  gap: 0;
}

.graph-controls .zoom-group button {
  border-radius: 0;
  border-right-width: 0;
}

.graph-controls .zoom-group button:first-child {
  border-radius: var(--border-radius) 0 0 var(--border-radius);
}

.graph-controls .zoom-group button:last-child {
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  border-right-width: 1px;
}

.zoom-controls {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
}

.zoom-controls button {
  min-width: 36px;
  height: 32px;
  padding: 0 12px;
  font-weight: 500;
  font-size: 0.875rem;
}

.graph-controls button {
  width: var(--control-btn-size);
  height: var(--control-btn-size);
  border: 1px solid var(--autumn-tan);
  background: white;
  color: var(--autumn-text-brown);
  cursor: pointer;
  border-radius: var(--border-radius);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.graph-controls button:hover {
  border-color: var(--autumn-orange-cinnamon);
}


.graph-controls button.spinning {
  animation: pulse 0.6s ease-in-out infinite;
}

#load-more {
  width: auto;
  padding: 0 12px;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 500;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.85); opacity: 0.7; }
}

.controls-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  flex-shrink: 0;
}

.layout-btn {
  width: auto !important;
  padding: 0 10px !important;
  font-size: 0.75rem !important;
  font-weight: 500 !important;
}

.layout-btn.active {
  background: var(--autumn-brown-russet) !important;
  color: white;
  border-color: var(--autumn-brown-russet) !important;
}

.node-count {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--autumn-text-brown);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  align-self: center;
}

.graph-hint {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(92, 64, 51, 0.85);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  font-size: 0.75rem;
  pointer-events: none;
  z-index: 10;
}

/* List View */
#list-view {
  display: none;
  flex-direction: column;
}

#list-view.active {
  display: flex;
}

.list-header {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0.75rem 1rem;
  background: var(--gray-100);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.list-cell {
  padding: 0 0.5rem;
}

.list-cell.sortable {
  cursor: pointer;
}

.list-cell.sortable:hover {
  color: var(--autumn-orange-cinnamon);
}

#list-content {
  flex: 1;
  overflow-y: auto;
}

.list-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  font-size: 0.875rem;
}

.list-row:hover {
  background: var(--autumn-tan-peach);
}

.list-row .list-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row .name-cell {
  color: var(--autumn-brown-russet);
}

/* Difficulty badges */
.difficulty-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
}

/* Detail Panel - Side by side */
.detail-panel {
  flex: 0 0 0;
  width: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  transition: flex 0.3s ease, width 0.3s ease, padding 0.3s ease;
  padding: 0;
}

.detail-panel.open {
  flex: 1;
  width: auto;
  padding: 1.5rem;
  overflow-y: auto;
}

.detail-header {
  position: relative;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.detail-top-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.detail-nav {
  display: flex;
  gap: 0.25rem;
}

.nav-btn {
  width: var(--control-btn-size);
  height: var(--control-btn-size);
  border: 1px solid var(--autumn-tan);
  background: white;
  color: var(--autumn-text-brown);
  cursor: pointer;
  border-radius: var(--border-radius);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:hover:not(:disabled) {
  border-color: var(--autumn-orange-cinnamon);
}

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

.solution-select-small {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--autumn-tan);
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  background: white;
  color: var(--autumn-text-brown);
  flex-shrink: 0;
  max-width: 180px;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
  color-scheme: light;
}

.solution-select-small:hover:not(:disabled):not(.single-option) {
  border-color: var(--autumn-orange-cinnamon);
}

.solution-select-small:focus {
  outline: none;
  border-color: var(--autumn-orange-cinnamon);
}

.solution-select-small:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.solution-select-small.single-option {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
  cursor: default;
  padding-right: 0.5rem;  /* Remove extra padding for arrow */
}

.close-btn {
  width: var(--control-btn-size);
  height: var(--control-btn-size);
  border: 1px solid var(--autumn-tan);
  background: white;
  cursor: pointer;
  border-radius: var(--border-radius);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--autumn-text-brown);
  line-height: 1;
}

.close-btn:hover {
  border-color: var(--autumn-orange-cinnamon);
  color: var(--autumn-text-brown);
}

.detail-title-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.detail-title-row h2 {
  font-size: 1.125rem;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-short-name {
  color: var(--text-light);
  font-size: 0.8rem;
  margin: 0;
  word-break: break-all;
}

.detail-section {
  margin-bottom: 1.25rem;
}

.detail-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
}

.deps-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dep-tag {
  padding: 0.25rem 0.5rem;
  background: var(--autumn-tan-peach);
  border-radius: var(--border-radius);
  font-size: 0.7rem;
  cursor: pointer;
  color: var(--autumn-brown-russet);
}

.dep-tag:hover {
  background: var(--autumn-tan);
}

.total-deps {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.5rem;
}

.code-display {
  width: 100%;
  min-height: 180px;
  max-height: 400px;
  overflow: auto;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.75rem;
  background: var(--gray-100);
  white-space: pre;
  margin: 0;
  box-sizing: border-box;
}

.github-link {
  font-size: 0.7rem;
  color: var(--text-light);
  text-decoration: none;
  margin-left: 0.5rem;
  font-weight: normal;
  text-transform: none;
}

.github-link:hover {
  color: var(--autumn-orange-cinnamon);
}

/* Code highlighting */
.highlight-line {
  display: block;
  background: rgba(210, 125, 45, 0.15);
  margin: 0 -0.75rem;
  padding: 0 0.75rem;
  border-left: 3px solid var(--autumn-orange-cinnamon);
}

/* Side-by-side source panels */
.source-split {
  display: flex;
  gap: 1rem;
}

.source-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.source-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-light);
}

.book-iframe {
  flex: 1;
  /* min-height: 250px; */
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: white;
}

.book-unavailable {
  flex: 1;
  min-height: 250px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 0.875rem;
  padding: 1rem;
  text-align: center;
}

/* Page-level loading overlay */
.page-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 99999;
  color: #666;
  font-size: 1rem;
  transition: opacity 0.3s ease;
}

.page-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--autumn-tan);
  border-top-color: var(--autumn-orange-cinnamon);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Resize handle between panels */
.resize-handle {
  width: 12px;
  background: var(--gray-100);
  cursor: col-resize;
  border-radius: 6px;
  transition: background 0.2s;
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
}

.resize-handle-grip {
  width: 4px;
  height: 40px;
  background: var(--gray-300);
  border-radius: 2px;
  transition: background 0.2s;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--autumn-tan-peach);
  border-color: var(--autumn-orange-cinnamon);
}

.resize-handle:hover .resize-handle-grip,
.resize-handle.dragging .resize-handle-grip {
  background: var(--autumn-orange-cinnamon);
}

.explorer-main.detail-open .resize-handle {
  display: flex;
}

/* Resizable code displays */
.code-display {
  resize: vertical;
  overflow: auto;
}

/* Vertical source split (stacked) */
.source-split {
  flex-direction: column;
  gap: 1rem;
}

.source-panel {
  flex: none;
}

.source-panel .code-display {
  height: 180px;
  min-height: 100px;
  max-height: 500px;
}

/* Book container with resize handle */
.book-container {
  display: flex;
  flex-direction: column;
}

.book-iframe {
  height: 350px;
  min-height: 350px;
  max-height: 600px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: white;
}

.book-resize-handle {
  height: 8px;
  background: var(--gray-100);
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-resize-handle::after {
  content: '';
  width: 40px;
  height: 3px;
  background: var(--gray-300);
  border-radius: 2px;
}

.book-resize-handle:hover {
  background: var(--autumn-tan-peach);
}

.book-resize-handle:hover::after {
  background: var(--autumn-orange-cinnamon);
}

.book-unavailable {
  height: 150px;
  min-height: 100px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 0.875rem;
  padding: 1rem;
  text-align: center;
}

/* Lean translation and ISO proof code boxes */
.detail-section .code-display {
  height: 200px;
  min-height: 120px;
  max-height: 600px;
}

/* Mobile responsive
   NOTE: Always test on BOTH iPhone Safari and Android Chrome!
   See CONTRIBUTING.md for mobile testing guidelines.
*/
@media (max-width: 900px) {
  .explorer-main {
    flex-direction: column;
    /* Fallback for older browsers */
    height: calc(100vh - 180px);
    max-height: calc(100vh - 180px);
    overflow: hidden;
  }

  .explorer-content {
    flex: 1;
    min-height: 250px;
    /* Fallback for older browsers */
    height: 50vh;
    max-height: 50vh;
    overflow: hidden;
  }

  #list-view.active {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #list-content {
    /* Fallback for older browsers */
    flex: 1;
    max-height: calc(50vh - 80px);
    overflow-y: auto;
  }

  .detail-panel.open {
    flex: none;
    height: auto;
    overflow-y: auto;
  }

  .code-display {
    min-height: 120px;
    max-height: 300px;
  }

  .source-split {
    flex-direction: column;
  }

  .book-iframe {
    min-height: 300px;
  }
}

/* Modern viewport units (dvh) for browsers that support it */
@supports (height: 100dvh) {
  @media (max-width: 900px) {
    .explorer-main {
      height: calc(100dvh - 180px);
      max-height: calc(100dvh - 180px);
    }

    .explorer-content {
      height: 50dvh;
      max-height: 50dvh;
    }

    #list-content {
      max-height: calc(50dvh - 80px);
    }

  }
}

@media (max-width: 768px) {
  /* Match navbar padding on mobile for alignment */
  .container:has(.explorer) {
    padding: 0 var(--padding-16);
  }

  .explorer-controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .search-box {
    width: 180px;
  }

  .list-header,
  .list-row {
    grid-template-columns: 1fr 0.6fr 0.5fr;
  }

  /* Hide module column on mobile, keep difficulty */
  .list-header .list-cell:nth-child(3),
  .list-row .list-cell:nth-child(3) {
    display: none;
  }

  .explorer-content {
    /* Fallback for older browsers */
    height: 45vh;
    max-height: 45vh;
    min-height: 200px;
  }

  #list-content {
    /* Fallback for older browsers */
    max-height: calc(45vh - 80px);
  }
}

/* Modern viewport units for small mobile */
@supports (height: 100dvh) {
  @media (max-width: 768px) {
    .explorer-content {
      height: 45dvh;
      max-height: 45dvh;
    }

    #list-content {
      max-height: calc(45dvh - 80px);
    }
  }
}

/* Mobile List Pagination */
.list-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--gray-100);
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.pagination-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.625rem;
  border: 1px solid var(--autumn-tan);
  background: white;
  color: var(--autumn-text-brown);
  cursor: pointer;
  border-radius: var(--border-radius);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.pagination-btn:hover:not(:disabled):not(.active) {
  background: var(--autumn-tan-peach);
  border-color: var(--autumn-orange-cinnamon);
}

.pagination-btn.active {
  background: var(--autumn-brown-russet);
  color: white;
  border-color: var(--autumn-brown-russet);
}

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

.pagination-btn.pagination-nav {
  padding: 0 0.625rem;
  font-weight: 500;
}

.pagination-ellipsis {
  color: var(--text-light);
  padding: 0 0.25rem;
  font-size: 0.875rem;
}

.pagination-info {
  color: var(--text-light);
  font-size: 0.75rem;
  margin-left: 0.5rem;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .list-pagination {
    gap: 0.375rem;
    padding: 0.75rem 0.5rem;
  }

  .pagination-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 0.5rem;
    font-size: 0.8125rem;
  }

  .pagination-btn.pagination-nav {
    padding: 0 0.5rem;
  }

  .pagination-info {
    width: 100%;
    text-align: center;
    margin-left: 0;
    margin-top: 0.25rem;
  }
}
