/* ============================================================
   世界文学探索マップ — Atlas of World Literature
   Design reference: Francis Galton, "Isochronic Passage Chart
   for Travellers" (1881) — 19th century scholarly cartography:
   parchment ground, pastel washes, serif labels, graticule,
   cartouche legend. Fused with modern interactions.
   ============================================================ */

:root {
  /* parchment ground */
  --paper: #f2ead6;
  --paper-deep: #e9dfc6;
  --paper-panel: #f6f0e0;
  --ink: #3d3129;
  --ink-soft: #6b5d4f;
  --ink-faint: #97897a;
  --ocean: #cfd8cd;
  --ocean-deep: #bfcabf;
  --land-empty: #e6ddc6;
  --graticule: rgba(61, 49, 41, 0.14);
  --border-line: #b3a586;
  --accent: #7a4a2b;
  --accent-deep: #5f3a20;
  --gold: #b08642;
  --shadow-soft: 0 2px 10px rgba(61, 49, 41, 0.18);
  --shadow-deep: 0 8px 30px rgba(61, 49, 41, 0.30);
  --serif-en: "EB Garamond", "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --serif-ja: "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Yu Mincho", YuMincho, "Noto Serif JP", serif;
  --serif: var(--serif-en), var(--serif-ja);
}

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

html, body { height: 100%; }

body {
  font-family: var(--serif);
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(255, 252, 240, 0.55), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(180, 160, 120, 0.22), transparent 60%),
    repeating-linear-gradient(0deg, rgba(120, 100, 70, 0.025) 0 2px, transparent 2px 4px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------------- Header ---------------- */

.site-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 22px 8px;
  border-bottom: 1px solid var(--border-line);
  background:
    linear-gradient(180deg, rgba(246, 240, 224, 0.96), rgba(238, 229, 205, 0.96));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, var(--shadow-soft);
  z-index: 30;
  position: relative;
}

.brand { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }

.brand-title {
  font-size: 21px;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.brand-sub {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}

.header-ornament {
  flex: 1 1 auto;
  height: 1px;
  background: linear-gradient(90deg, var(--border-line), transparent 70%);
  position: relative;
}
.header-ornament::before {
  content: "❦";
  position: absolute;
  left: 12px;
  top: -9px;
  color: var(--gold);
  font-size: 14px;
  background: transparent;
}

.header-controls { display: flex; align-items: center; gap: 10px; }

/* view tabs (map / timeline) */
.view-tabs {
  display: flex;
  border: 1px solid var(--border-line);
  border-radius: 3px;
  overflow: hidden;
  background: var(--paper-panel);
  box-shadow: inset 0 1px 3px rgba(61, 49, 41, 0.12);
}
.view-tab {
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.08em;
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.view-tab + .view-tab { border-left: 1px solid var(--border-line); }
.view-tab.active {
  background: var(--accent);
  color: #f8f1de;
}
.view-tab:not(.active):hover { background: rgba(122, 74, 43, 0.10); }

/* language toggle */
.lang-toggle {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-line);
  border-radius: 3px;
  overflow: hidden;
  background: var(--paper-panel);
  font-size: 12px;
}
.lang-toggle button {
  font-family: var(--serif);
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  letter-spacing: 0.05em;
}
.lang-toggle button.active {
  background: var(--ink);
  color: #f8f1de;
}
.lang-toggle button:not(.active):hover { background: rgba(61, 49, 41, 0.08); }

/* ---------------- Filter bar ---------------- */

.filter-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 22px;
  background: rgba(233, 223, 198, 0.72);
  border-bottom: 1px solid var(--border-line);
  z-index: 25;
  position: relative;
}

.filter-group { display: flex; align-items: center; gap: 6px; }

.filter-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}

.genre-chips { display: flex; flex-wrap: wrap; gap: 4px; }

.chip {
  font-family: var(--serif);
  font-size: 12px;
  padding: 3px 10px 4px;
  border: 1px solid var(--border-line);
  border-radius: 20px;
  background: var(--paper-panel);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.chip .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(61, 49, 41, 0.35);
  flex: 0 0 auto;
}
.chip:hover { border-color: var(--ink-soft); }
.chip.active {
  background: var(--ink);
  color: #f4ecd8;
  border-color: var(--ink);
}
.chip.dim { opacity: 0.45; }

select.vintage, input[type="search"].vintage {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink);
  background: var(--paper-panel);
  border: 1px solid var(--border-line);
  border-radius: 3px;
  padding: 4px 8px;
  outline: none;
}
select.vintage:focus, input[type="search"].vintage:focus { border-color: var(--accent); }
input[type="search"].vintage { width: 150px; }

/* era dual slider */
.era-filter { display: flex; align-items: center; gap: 8px; }
.era-values {
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 132px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.era-slider-wrap { position: relative; width: 170px; height: 22px; }
.era-slider-wrap input[type="range"] {
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  height: 22px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  pointer-events: none;
  margin: 0;
}
.era-slider-wrap input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--border-line);
  border-radius: 2px;
}
.era-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  width: 13px; height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--paper-panel);
  border: 2px solid var(--accent);
  cursor: ew-resize;
}
.era-slider-wrap input[type="range"]::-moz-range-track {
  height: 3px; background: var(--border-line); border-radius: 2px;
}
.era-slider-wrap input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--paper-panel);
  border: 2px solid var(--accent);
  cursor: ew-resize;
}

.reset-btn {
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 4px 12px;
  border: 1px solid var(--border-line);
  border-radius: 3px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.reset-btn:hover { background: rgba(122, 74, 43, 0.10); color: var(--accent-deep); }

.result-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------------- Main stage ---------------- */

.stage {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.view-pane { position: absolute; inset: 0; display: none; }
.view-pane.active { display: block; }

/* ---------------- Map ---------------- */

#map-svg { width: 100%; height: 100%; display: block; cursor: grab; }
#map-svg.dragging { cursor: grabbing; }

.map-ocean { fill: var(--ocean); }
.map-ocean-pattern { fill: none; }

.graticule line {
  stroke: var(--graticule);
  stroke-width: 0.6;
}
.graticule text {
  font-size: 9px;
  fill: var(--ink-faint);
  font-family: var(--serif);
  letter-spacing: 0.05em;
}

.country-shape {
  fill: var(--land-empty);
  stroke: rgba(61, 49, 41, 0.45);
  stroke-width: 0.5;
  transition: fill 0.25s, opacity 0.25s;
}
.country-shape.has-works { cursor: pointer; }
.country-shape.has-works:hover {
  filter: brightness(0.94) saturate(1.25);
}
.country-shape.selected {
  stroke: var(--accent-deep);
  stroke-width: 1.6;
}
.country-shape.faded { opacity: 0.35; }

.country-label {
  font-family: var(--serif);
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(246, 240, 224, 0.85);
  stroke-width: 2.5px;
  stroke-linejoin: round;
}
.country-label .work-count { fill: var(--ink-soft); }

/* cartouche (legend) */
.cartouche {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 10;
  background:
    linear-gradient(180deg, rgba(248, 242, 226, 0.97), rgba(240, 231, 208, 0.97));
  border: 1px solid var(--ink-soft);
  outline: 3px double rgba(107, 93, 79, 0.55);
  outline-offset: 3px;
  padding: 12px 16px 12px;
  max-width: 300px;
  box-shadow: var(--shadow-deep);
}
.cartouche-title {
  font-size: 13px;
  letter-spacing: 0.16em;
  text-align: center;
  color: var(--ink);
  border-bottom: 1px solid var(--border-line);
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-variant: small-caps;
}
.cartouche-section + .cartouche-section { margin-top: 8px; }
.cartouche-heading {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.legend-grid { display: flex; flex-wrap: wrap; gap: 3px 10px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: nowrap;
}
.legend-swatch {
  width: 13px; height: 10px;
  border: 1px solid rgba(61, 49, 41, 0.4);
  flex: 0 0 auto;
}
.legend-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(61, 49, 41, 0.45);
  flex: 0 0 auto;
}

/* ---------------- Country works panel ---------------- */

.works-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 360px;
  max-width: 88vw;
  background:
    linear-gradient(180deg, rgba(248, 242, 226, 0.99), rgba(238, 229, 205, 0.99));
  border-left: 1px solid var(--ink-soft);
  box-shadow: -6px 0 24px rgba(61, 49, 41, 0.25);
  transform: translateX(105%);
  transition: transform 0.28s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.works-panel.open { transform: translateX(0); }

.works-panel-head {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border-line);
  position: relative;
}
.works-panel-country {
  font-size: 19px;
  letter-spacing: 0.05em;
  color: var(--ink);
}
.works-panel-meta {
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.panel-close {
  position: absolute;
  top: 10px; right: 12px;
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--serif);
  padding: 4px 6px;
  line-height: 1;
}
.panel-close:hover { color: var(--accent-deep); }

.works-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 14px 20px;
}

.work-card {
  border: 1px solid var(--border-line);
  background: var(--paper-panel);
  border-radius: 2px;
  padding: 9px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.work-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-soft);
}
.work-card-year {
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}
.work-card-title {
  font-size: 15px;
  color: var(--ink);
  margin: 1px 0;
  line-height: 1.35;
}
.work-card-author { font-size: 12px; color: var(--ink-soft); }
.work-card-genre {
  position: absolute;
  top: 9px; right: 10px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.work-card-genre .legend-dot { width: 7px; height: 7px; }

/* ---------------- Timeline view ---------------- */

#timeline-wrap {
  position: absolute;
  inset: 0;
  overflow: auto;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 252, 240, 0.5), transparent 60%);
}
.tl-inner { display: flex; width: max-content; min-height: 100%; }
.tl-gutter {
  position: sticky;
  left: 0;
  flex: 0 0 132px;
  z-index: 6;
  background: linear-gradient(90deg, var(--paper) 78%, rgba(242, 234, 214, 0));
}
.tl-gutter-label {
  position: absolute;
  left: 12px;
  font-size: 12px;
  letter-spacing: 0.10em;
  color: var(--ink-soft);
  font-variant: small-caps;
  white-space: nowrap;
}
#timeline-svg { display: block; }

.tl-axis line, .tl-axis path { stroke: var(--border-line); }
.tl-axis text {
  font-size: 11px;
  fill: var(--ink-soft);
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
}
.tl-grid-line { stroke: var(--graticule); stroke-dasharray: 2 4; }

.tl-region-label {
  font-size: 12px;
  fill: var(--ink-soft);
  font-family: var(--serif);
  letter-spacing: 0.12em;
  font-variant: small-caps;
}

.tl-work-dot { cursor: pointer; transition: r 0.12s; }
.tl-work-dot:hover { stroke: var(--accent-deep); stroke-width: 2; }
.tl-work-dot.faded { opacity: 0.15; pointer-events: none; }

.tl-work-label {
  font-size: 10px;
  fill: var(--ink-soft);
  font-family: var(--serif);
  pointer-events: none;
}

/* ---------------- Work detail modal ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(46, 36, 28, 0.45);
  backdrop-filter: blur(2px);
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop.open { display: flex; }

.work-modal {
  background:
    linear-gradient(180deg, #f8f2e2, #efe6cc);
  border: 1px solid var(--ink-soft);
  outline: 4px double rgba(107, 93, 79, 0.5);
  outline-offset: 4px;
  max-width: 620px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 26px 30px 24px;
  box-shadow: var(--shadow-deep);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 10px; right: 14px;
  border: none; background: transparent;
  font-size: 22px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--serif);
  line-height: 1;
}
.modal-close:hover { color: var(--accent-deep); }

.work-modal .wm-year {
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--gold);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.work-modal .wm-title {
  font-size: 26px;
  line-height: 1.25;
  color: var(--ink);
  margin: 4px 0 2px;
}
.work-modal .wm-orig {
  font-size: 14px;
  color: var(--ink-faint);
  font-style: italic;
}
.work-modal .wm-author {
  font-size: 15px;
  color: var(--ink-soft);
  margin: 8px 0 0;
}
.wm-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.wm-tag {
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border: 1px solid var(--border-line);
  border-radius: 20px;
  color: var(--ink-soft);
  background: rgba(255, 252, 240, 0.6);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.wm-desc {
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ink);
  margin: 10px 0 18px;
  text-align: justify;
}
.wm-sources-heading {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-top: 1px solid var(--border-line);
  padding-top: 12px;
  margin-bottom: 8px;
}
.wm-source-link {
  display: block;
  font-size: 13.5px;
  color: var(--accent-deep);
  text-decoration: none;
  padding: 5px 0 5px 18px;
  position: relative;
  border-bottom: 1px dashed rgba(179, 165, 134, 0.5);
}
.wm-source-link::before {
  content: "➤";
  position: absolute;
  left: 0;
  font-size: 10px;
  top: 9px;
  color: var(--gold);
}
.wm-source-link:hover { color: var(--accent); text-decoration: underline; }
.wm-source-host {
  font-size: 11px;
  color: var(--ink-faint);
  margin-left: 6px;
}

/* ---------------- Footer / about strip ---------------- */

.about-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 5px 22px;
  font-size: 11px;
  color: var(--ink-faint);
  border-top: 1px solid var(--border-line);
  background: rgba(233, 223, 198, 0.8);
  letter-spacing: 0.04em;
  z-index: 30;
}
.about-strip .spacer { flex: 1; }
.about-btn {
  font-family: var(--serif);
  font-size: 11px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  letter-spacing: 0.08em;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(122, 74, 43, 0.4);
}
.about-btn:hover { color: var(--accent-deep); }

/* about modal reuses work-modal shell */
.about-modal h2 {
  font-size: 19px;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  color: var(--ink);
}
.about-modal h3 {
  font-size: 13px;
  letter-spacing: 0.12em;
  margin: 16px 0 6px;
  color: var(--accent-deep);
  font-variant: small-caps;
}
.about-modal p, .about-modal li {
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--ink);
}
.about-modal ul { padding-left: 20px; }
.about-modal a { color: var(--accent-deep); }

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(233, 223, 198, 0.5); }
::-webkit-scrollbar-thumb {
  background: var(--border-line);
  border-radius: 5px;
  border: 2px solid var(--paper);
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* responsive */
@media (max-width: 900px) {
  .brand-sub { display: none; }
  .brand-title { font-size: 17px; }
  .works-panel { width: 320px; }
  .cartouche { max-width: 240px; padding: 10px 12px; }
  input[type="search"].vintage { width: 110px; }
}
@media (max-width: 640px) {
  .site-header { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .header-ornament { display: none; }
  .filter-bar { padding: 6px 12px; }
  .works-panel { width: 100vw; max-width: 100vw; }
  .cartouche { display: none; }
  .about-strip .hide-sm { display: none; }
}
