/* Translation Explorer. Modules are hatch patterns (see explorer.js: CHAPTERS, hatchTile).
   Graph variants: a = cyan canvas with paper and orange tiles; b = paper canvas with ink tiles
   (?variant=a|b, or data-variant on the root). */

.explorer {
  --paper: #FCFBF7;
  --ink: #0A0A0A;
  --cyan: #0099C9;
  --cyan-press: #0085AF;
  --orange: #E56300;
  /* token aliases */
  --bg: var(--paper);
  --surface: var(--paper);
  --surface-subtle: var(--paper);
  --text: var(--ink);
  --text-muted: var(--ink);
  --text-subtle: var(--ink);
  --border: var(--ink);
  --border-strong: var(--ink);
  --accent: var(--cyan);
  --accent-deep: var(--cyan-press);
  --accent-soft: var(--paper);
  --font-sans: 'Geist', -apple-system, 'Segoe UI', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --control-btn-size: 34px;
  --rule: 2.5px;      /* container border */
  --rule-chip: 1.5px; /* chip border */

  max-width: 100%;
  margin: 0 auto;
  overflow: visible;
  padding-right: 8px;
  padding-bottom: 8px;
  color: var(--ink);
  font-family: var(--font-sans);
}

.explorer *,
.explorer *::before,
.explorer *::after { box-sizing: border-box; border-radius: 0 !important; box-shadow: none !important; }

.explorer :focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

body:has(.explorer:not(.explorer--figure)) { background: var(--paper); }

.container:has(.explorer) {
  max-width: 100%;
  padding: 0 var(--page-inset, 0);
  overflow-x: hidden;
}

/* mono microlabel */
.explorer .s-micro,
.explorer-header h1,
.explorer-controls .node-count,
.tab-switcher .tab-btn,
.list-header,
.detail-section h3,
.module-legend__note,
.legend-chip b {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
}

/* header */
.explorer-header { margin-bottom: 18px; max-width: 1464px; }
.explorer-header h1 { font-size: 15px; margin: 0 0 0.5rem; color: var(--ink); }
.explorer-description { color: var(--ink); font-size: 14px; line-height: 1.55; margin: 0 0 18px; max-width: 70ch; }

/* control bar */
.explorer-controls {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 12px; margin-bottom: 12px; max-width: 100%;
}
.explorer-controls > * { height: 36px; display: inline-flex; align-items: center; }

.tab-switcher { display: inline-flex; border: var(--rule) solid var(--ink); background: var(--paper); overflow: hidden; }
.tab-switcher .tab-btn {
  height: 100%; min-width: 90px; padding: 0 16px;
  border: 0; border-right: var(--rule) solid var(--ink);
  background: var(--paper); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.tab-switcher .tab-btn:last-child { border-right: 0; }
.tab-btn:hover { background: var(--cyan-press); color: var(--paper); }
.tab-btn.active { background: var(--cyan); color: var(--paper); }

.search-box { flex: 0 1 auto; width: 260px; max-width: 100%; border: var(--rule) solid var(--ink); background: var(--paper); }
.search-box input {
  width: 100%; height: 100%; padding: 0 12px; border: 0; background: transparent;
  color: var(--ink); font-family: var(--font-mono); font-size: 12.5px; letter-spacing: 0.02em; line-height: 1;
}
.search-box input::placeholder { color: var(--ink); }
.search-box input:focus { outline: none; }
.search-box:focus-within { border-color: var(--cyan); }

.explorer-controls .node-count { padding: 0 4px; margin-left: auto; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* main split */
.explorer-main { position: relative; display: flex; gap: 16px; height: calc(100vh - 260px); min-height: 540px; }
.explorer-content { flex: 1 1 0; min-width: 0; position: relative; overflow: hidden; border: var(--rule) solid var(--ink); background: var(--paper); }
.view-container { display: none; height: 100%; position: relative; }
.view-container.active { display: block; }

/* graph view */
#graph-view { position: relative; container-type: inline-size; background: var(--paper); }
.explorer[data-variant="a"] #graph-view { background: var(--cyan); }
#edge-canvas, #shadow-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#edge-canvas { z-index: 1; }
#shadow-canvas { z-index: 0; }
#cy { position: relative; width: 100%; height: 100%; z-index: 2; }

.graph-controls { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; z-index: 10; }
.zoom-controls { display: flex; gap: 0; border: var(--rule) solid var(--ink); background: var(--paper); }
.zoom-controls button {
  min-width: 36px; height: var(--control-btn-size); padding: 0 12px;
  border: 0; border-right: var(--rule) solid var(--ink); background: var(--paper); color: var(--ink);
  font-family: var(--font-mono); font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.zoom-controls button:last-child { border-right: 0; }
.graph-controls button:hover { background: var(--cyan-press); color: var(--paper); }
.graph-controls button.spinning { pointer-events: none; background: var(--cyan); color: var(--paper); }

.graph-hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: var(--paper); color: var(--ink); border: var(--rule-chip) solid var(--ink);
  padding: 6px 12px; font-family: var(--font-mono); font-size: 10.5px; line-height: 1.35; letter-spacing: 0.04em;
  pointer-events: none; max-width: min(360px, calc(100% - 28px)); text-align: center; text-wrap: balance; z-index: 10;
}

/* module legend */
.module-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin-top: 12px; padding: 10px 0 0;
}
.legend-chip { display: inline-flex; align-items: center; gap: 7px; color: var(--ink); }
.legend-chip i {
  display: inline-block; width: 18px; height: 18px; flex: none;
  border: var(--rule-chip) solid var(--ink);
  background-color: var(--paper); background-size: 8px 8px; background-repeat: repeat;
}
.explorer[data-variant="a"] .legend-chip i { background-color: var(--cyan); border-color: var(--ink); }
.legend-chip b { font-weight: 600; }
.module-legend__note { margin-left: auto; color: var(--ink); }
.module-legend__note span { display: inline-block; width: 18px; height: 18px; border: var(--rule-chip) solid var(--ink); vertical-align: middle; margin-right: 6px; }
.explorer[data-variant="a"] .module-legend__note span { background: var(--cyan); }
.module-legend__note span::after { content: ''; display: block; width: 8px; height: 8px; margin: 3px; background: var(--ink); }
.explorer[data-variant="a"] .module-legend__note span::after { background: var(--paper); }

/* list view */
#list-view {
  display: none; flex-direction: column; background: var(--paper);
  --list-grid-cols: minmax(120px, 1.6fr) minmax(90px, 1fr) minmax(120px, 1.4fr) minmax(54px, 0.55fr) minmax(72px, 0.7fr) minmax(80px, 0.8fr) minmax(72px, 0.7fr) minmax(80px, 0.8fr);
  --list-min-width: 738px;
}
#list-view.active { display: flex; }
.list-scroll { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-x: auto; overflow-y: hidden; }
.list-header, .list-row { display: grid; grid-template-columns: var(--list-grid-cols); align-items: center; gap: 4px; min-width: var(--list-min-width); }
.list-header { padding: 12px 16px; background: var(--ink); color: var(--paper); flex-shrink: 0; }
#list-content { flex: 1; overflow-y: auto; min-width: var(--list-min-width); }
.list-row { padding: 10px 16px; cursor: pointer; font-size: 13.5px; color: var(--ink); }
.list-row:hover { background: var(--cyan); color: var(--paper); }
.list-row:hover .name-cell, .list-row:hover .num-cell, .list-row:hover code { color: var(--paper); }
.list-cell { padding: 0 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-cell.sortable { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.list-cell-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-cell.sortable:hover { color: var(--cyan); }
.sort-indicator { flex-shrink: 0; display: inline-block; width: 10px; text-align: center; font-size: 11px; line-height: 1; color: var(--paper); }
.list-cell.sortable[data-active="true"] .sort-indicator { color: var(--cyan); font-weight: 700; }
.list-row .name-cell { color: var(--ink); font-weight: 500; }
.list-row .name-cell code, .list-cell code { font-family: var(--font-mono); font-size: 12.5px; letter-spacing: 0.02em; }
.list-row .num-cell { font-variant-numeric: tabular-nums; color: var(--ink); }
.list-row .num-cell.empty { color: var(--ink); }

/* difficulty badges */
.difficulty-badge {
  display: inline-block; padding: 2px 8px; border: var(--rule-chip) solid var(--ink);
  font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--paper); color: var(--ink);
}
.difficulty-medium { background: var(--cyan); color: var(--paper); }
.difficulty-hard { background: var(--ink); color: var(--paper); }
.difficulty-extreme { background: var(--ink); color: var(--paper); border-left: 6px solid var(--orange); }
.list-row:hover .difficulty-badge { border-color: var(--paper); }

/* detail panel */
.detail-panel { flex: 0 0 0; width: 0; background: var(--paper); border: 0 solid var(--ink); overflow: hidden; padding: 0; transition: flex 0.3s ease, width 0.3s ease, padding 0.3s ease; }
.detail-panel.open { flex: 1 1 0; width: 50%; padding: 22px; overflow-y: auto; border-width: var(--rule); }
.detail-header { position: relative; margin-bottom: 20px; }
.detail-top-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.detail-nav { display: flex; gap: 0; border: var(--rule-chip) solid var(--ink); }
.nav-btn, .close-btn {
  width: var(--control-btn-size); height: var(--control-btn-size);
  border: 0; background: var(--paper); color: var(--ink); cursor: pointer;
  font-family: var(--font-mono); font-size: 12px; display: flex; align-items: center; justify-content: center;
}
.nav-btn + .nav-btn { border-left: var(--rule-chip) solid var(--ink); }
.close-btn { border: var(--rule-chip) solid var(--ink); font-size: 16px; line-height: 1; margin-left: auto; }
.nav-btn:hover:not(:disabled), .close-btn:hover { background: var(--cyan-press); color: var(--paper); }
.nav-btn:disabled { cursor: not-allowed; color: var(--paper); background: var(--paper); background-image: repeating-linear-gradient(45deg, var(--ink) 0 1px, transparent 1px 5px); }

.solution-dd { position: relative; flex-shrink: 0; max-width: 240px; }
.solution-dd-trigger {
  display: inline-flex; align-items: center; gap: 10px; height: var(--control-btn-size); padding: 0 12px; max-width: 100%;
  border: var(--rule-chip) solid var(--ink); background: var(--paper); color: var(--ink);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; cursor: pointer;
}
.solution-dd-trigger:hover:not(:disabled) { background: var(--cyan-press); color: var(--paper); }
.solution-dd-trigger:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.solution-dd-trigger:disabled { cursor: not-allowed; border-style: dashed; }
.solution-dd-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.solution-dd-caret { flex-shrink: 0; }
.solution-dd[data-open="true"] .solution-dd-caret { transform: rotate(180deg); }
.solution-dd[data-single="true"] .solution-dd-caret { display: none; }
.solution-dd[data-single="true"] .solution-dd-trigger { cursor: default; pointer-events: none; padding-right: 12px; }
.solution-dd-menu {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 100%; margin: 0; padding: 0; list-style: none;
  background: var(--paper); border: var(--rule) solid var(--ink); z-index: 50; max-height: 280px; overflow-y: auto;
}
.solution-dd-option { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 12px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--ink); cursor: pointer; white-space: nowrap; }
.solution-dd-option:hover, .solution-dd-option[data-active="true"] { background: var(--cyan-press); color: var(--paper); }
.solution-dd-option[aria-selected="true"], .solution-dd-option[aria-selected="true"]:hover { background: var(--cyan); color: var(--paper); }
.solution-dd-option-check { width: 10px; flex-shrink: 0; display: inline-flex; justify-content: center; }

.detail-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.detail-title-row h2 { font-family: var(--font-sans); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.015em; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.detail-short-name { color: var(--ink); font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.02em; margin: 0; word-break: break-all; }
.detail-section { margin-bottom: 22px; }
.detail-section h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; color: var(--ink); }
.deps-list { display: flex; flex-wrap: wrap; gap: 6px; }
.dep-tag {
  padding: 4px 8px; background: var(--paper); border: var(--rule-chip) solid var(--ink); color: var(--ink);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.02em; cursor: pointer;
}
.dep-tag:hover { background: var(--cyan-press); border-color: var(--ink); color: var(--paper); }
.total-deps { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--ink); margin-top: 8px; }

.tab-btn:active, .graph-controls button:active, .nav-btn:active:not(:disabled), .close-btn:active, .pagination-btn:active:not(:disabled) { transform: scale(0.97); }
.list-row:active, .dep-tag:active { background: var(--cyan); color: var(--paper); }

/* code blocks */
.code-display {
  width: 100%; min-height: 180px; max-height: 460px; overflow: auto; padding: 12px 14px; margin: 0;
  border: var(--rule-chip) solid var(--ink); background: var(--paper); color: var(--ink);
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; letter-spacing: 0.02em; white-space: pre; resize: vertical;
}
.github-link { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; color: var(--cyan); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; margin-left: 8px; font-weight: 500; text-transform: none; }
.github-link:hover { color: var(--cyan-press); }
.highlight-line { display: inline-block; width: calc(100% + 1.75rem); margin: 0 -14px; padding: 0 14px; border-left: 4px solid var(--cyan); background: transparent; }

/* loading */
.page-loading {
  position: absolute; inset: 0; z-index: 40; background: var(--paper); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.page-loading.hidden { display: none; }
.loading-bars { display: flex; gap: 6px; }
.loading-bars span { display: block; width: 14px; height: 14px; background: var(--ink); animation: bp-blocks 0.9s steps(3, end) infinite; }
.loading-bars span:nth-child(2) { animation-delay: 0.3s; }
.loading-bars span:nth-child(3) { animation-delay: 0.6s; }
@keyframes bp-blocks { 0% { transform: translateY(0); } 50% { transform: translateY(-8px); } 100% { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .loading-bars span { animation: none; } }

/* pagination */
.list-pagination { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-top: var(--rule) solid var(--ink); background: var(--paper); position: sticky; bottom: 0; }
.pagination-pages { display: flex; align-items: center; gap: 4px; }
.pagination-btn { min-width: 32px; height: 32px; padding: 0 10px; border: var(--rule-chip) solid var(--ink); background: var(--paper); color: var(--ink); cursor: pointer; font-family: var(--font-mono); font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.pagination-btn:hover:not(:disabled):not(.active) { background: var(--cyan-press); color: var(--paper); }
.pagination-btn.active { background: var(--cyan); color: var(--paper); }
.pagination-btn:disabled { cursor: not-allowed; border-style: dashed; }
.pagination-btn.pagination-arrow { font-size: 16px; font-weight: 400; padding: 0 12px; }
.pagination-ellipsis { color: var(--ink); padding: 0 4px; font-size: 12px; }
.pagination-info { color: var(--ink); font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; margin-left: 8px; white-space: nowrap; }

/* medium widths */
@media (max-width: 900px) {
  .explorer { --control-btn-size: 44px; }
  #graph-view { touch-action: pan-x pan-y pinch-zoom; }
  .pagination-btn { min-width: 44px; height: 44px; }
}

/* phone */
@media (max-width: 600px) {
  .explorer-main { flex-direction: column; height: auto; max-height: none; overflow: visible; }
  .explorer-content { flex: none; min-height: 250px; overflow: hidden; height: 55vh; max-height: 55vh; }
  #list-view.active { height: 100%; max-height: 100%; overflow: hidden; display: flex; flex-direction: column; }
  #list-content { flex: 1; min-height: 280px; max-height: calc(60vh - 60px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .detail-panel.open { flex: none; width: 100%; max-width: 100%; height: auto; max-height: none; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .detail-panel.open::before { content: ''; display: block; width: 40px; height: 4px; background: var(--ink); margin: 0 auto 14px; }
  .code-display { min-height: 120px; max-height: 320px; -webkit-overflow-scrolling: touch; }
}
@supports (height: 100dvh) {
  @media (max-width: 600px) {
    .explorer-content { height: 55dvh; max-height: 55dvh; }
    html.embed-mode .explorer-content { height: clamp(360px, 96vw, 500px); max-height: 500px; }
    #list-content { max-height: calc(55dvh - 80px); }
  }
}

/* ?embed=1: the standalone page inside an iframe */
@media (max-width: 600px) {
  html.embed-mode .explorer { padding: 0 4px 8px 0; }
  html.embed-mode .explorer-header { margin-bottom: 10px; }
  html.embed-mode .explorer-header h1 { display: none; }
  html.embed-mode .explorer-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-bottom: 10px; }
  html.embed-mode .tab-switcher { grid-column: 1 / -1; display: flex; width: 100%; }
  html.embed-mode .tab-switcher .tab-btn { flex: 1 1 0; min-width: 0; height: 40px; }
  html.embed-mode .search-box { grid-column: 1 / 2; width: auto; min-width: 0; height: 40px; }
  html.embed-mode .search-box input { font-size: 16px; }
  html.embed-mode .explorer-controls .node-count { grid-column: 2 / 3; height: auto; margin-left: 0; padding-right: 0; font-size: 11px; align-self: center; }
  html.embed-mode .explorer-main { height: auto; min-height: 0; gap: 0; }
  html.embed-mode .explorer-content { height: clamp(360px, 96vw, 500px); max-height: 500px; min-height: 360px; }
  html.embed-mode .graph-controls { top: 6px; right: 6px; }
  html.embed-mode .zoom-controls button { min-width: 40px; height: 40px; }
  html.embed-mode .graph-hint { display: none; }
}

@media (max-width: 768px) {
  .explorer-header h1 { font-size: 14px; }
  .explorer-controls { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .tab-btn { height: 44px; min-width: 70px; padding: 0 12px; font-size: 11px; }
  .search-box { width: 100%; flex: 1; min-width: 140px; max-width: none; }
  .search-box input { height: 44px; font-size: 16px; }
  .graph-controls { top: 8px; right: 8px; }
  .zoom-controls button { min-width: 44px; height: 44px; }
  .code-display { font-size: 11.5px; min-height: 100px; max-height: 260px; }
}
@media (max-width: 480px) {
  .explorer-header h1 { font-size: 13px; }
  .list-header, .list-row { padding: 8px 12px; font-size: 12.5px; }
  .detail-panel.open { padding: 14px; }
  .detail-title-row h2 { font-size: 1rem; }
  .code-display { font-size: 11px; min-height: 90px; max-height: 220px; padding: 10px; }
  .module-legend { gap: 6px 12px; }
}

/* Figure mode: the explorer inside an article figure. Fixed height; the detail
   panel replaces the graph in place. */
.explorer--figure { padding: 0; margin: 0; }
.explorer--figure .explorer-header { margin-bottom: 10px; }
.explorer--figure .explorer-main { position: relative; height: 520px; min-height: 0; max-height: none; }
.explorer--figure .explorer-content { flex: 1 1 auto; min-width: 0; }
.explorer--figure .explorer-main .detail-panel { position: absolute; inset: 0; width: auto; flex: none; display: none; transition: none; border-width: var(--rule); }
.explorer--figure .explorer-main .detail-panel.open { display: block; width: auto; height: auto; max-height: none; padding: 18px 20px; overflow-y: auto; }
.explorer--figure .explorer-main .detail-panel.open::before { display: none; }
.explorer--figure .explorer-main.detail-open .explorer-content { visibility: hidden; }
.explorer--figure .module-legend { margin-top: 10px; }
@media (max-width: 600px) {
  .explorer--figure .explorer-main { height: 460px; min-height: 0; max-height: none; }
  .explorer--figure .explorer-content { height: 100%; max-height: none; }
  .explorer--figure .explorer-main .detail-panel.open { position: absolute; height: auto; max-height: none; }
}
