/* stats.tech-book.net shared article styles.
 *
 * Loaded via `<link rel="stylesheet" href="/_shared/article.css">` from each
 * article's index.html. Per-article overrides (accent color etc.) belong in
 * a small `<style>` block inside the article's <head>.
 *
 * Site-wide design: dark UI, map raster stays light (GSI 淡色 is designed
 * for light backgrounds; darkening it kills layer legibility).
 */

:root {
  /* Per-article overrides expected: --accent, --accent-soft */
  --accent: #4fc3f7;
  --accent-soft: #81d4fa;
  --fg: #ececec;
  --muted: #b0b0b0;
  --bg: #15171a;
  --card-bg: rgba(28, 30, 33, 0.95);
  --border: #2c2f33;
  --code-bg: #25282c;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* === Sticky TOC bar (top) === */
.toc-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--card-bg); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  font-family: -apple-system, sans-serif; font-size: 12px;
  display: flex; align-items: center; gap: 4px; padding: 6px 12px;
}
.toc-bar .toc-title {
  font-weight: 600; color: var(--accent); white-space: nowrap;
  padding-right: 10px; margin-right: 4px; border-right: 1px solid var(--border);
  flex-shrink: 0; text-decoration: none;
}
.toc-bar .toc-items {
  display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none;
}
.toc-bar .toc-items::-webkit-scrollbar { display: none; }
.toc-bar .toc-item {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 4px 9px; border-radius: 14px; cursor: pointer;
  font-size: 12px; white-space: nowrap; font-family: -apple-system, sans-serif;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.toc-bar .toc-item:hover { background: var(--code-bg); color: var(--fg); }
.toc-bar .toc-item.active { background: var(--accent); color: #15171a; border-color: var(--accent); }
.toc-bar .toc-item .toc-num { opacity: 0.6; margin-right: 4px; font-variant-numeric: tabular-nums; }
.toc-bar .toc-item.active .toc-num { opacity: 0.85; }
.toc-bar .play-toggle {
  background: none; border: 1px solid var(--border); color: var(--fg);
  padding: 2px 8px; border-radius: 4px; cursor: pointer; font-size: 13px;
  flex-shrink: 0; margin-left: 6px;
  font-family: -apple-system, sans-serif;
}
.toc-bar .play-toggle:hover { background: var(--code-bg); }
.toc-bar .play-toggle.on {
  background: var(--accent); color: #15171a; border-color: var(--accent);
}

/* Breadcrumb strip above the TOC bar — gives every article an exit door
   to its parent (city hub → prefecture hub → /jp/ → /). */
.crumb-strip {
  position: fixed; top: 32px; left: 0; right: 0; z-index: 998;
  background: rgba(21,23,26,0.92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  font-family: -apple-system, sans-serif; font-size: 11px;
  color: var(--muted); padding: 4px 12px;
  white-space: nowrap; overflow-x: auto; scrollbar-width: none;
}
.crumb-strip::-webkit-scrollbar { display: none; }
.crumb-strip a { color: var(--muted); text-decoration: none; }
.crumb-strip a:hover { color: var(--accent); text-decoration: underline; }
.crumb-strip .sep { margin: 0 6px; opacity: 0.5; }
.crumb-strip .current { color: var(--fg); }
.crumb-strip .search-link {
  float: right; color: var(--accent); padding-left: 12px;
  border-left: 1px solid var(--border); margin-left: 12px;
}
@media (max-width: 640px) {
  .toc-bar { font-size: 11px; padding: 5px 8px; }
  .toc-bar .toc-title { font-size: 11px; padding-right: 6px; margin-right: 2px; }
  .toc-bar .toc-item { padding: 3px 7px; font-size: 11px; }
  .toc-bar .toc-item .toc-label { display: none; }
  .toc-bar .toc-item .toc-num { margin-right: 0; opacity: 1; }
}

/* === Progress bar (under crumb strip + TOC) === */
.progress-bar {
  position: fixed; top: 56px; left: 0; right: 0;
  height: 3px; background: transparent; z-index: 999; pointer-events: none;
}
.progress-bar .progress-fill {
  height: 100%; width: 0%; background: var(--accent); transition: width 0.1s linear;
}

/* === Intro / Outro === */
.intro, .outro { max-width: 720px; margin: 0 auto; padding: 4rem 1.5rem 4rem; }
.intro h1 {
  font-size: clamp(1.7rem, 4.5vw, 2.6rem); line-height: 1.3;
  margin: 0 0 1.5rem; letter-spacing: -0.02em;
}
.intro h1 strong { color: var(--accent); }
.intro .subhead {
  color: var(--muted); font-size: 0.95rem; margin-bottom: 2rem;
  font-family: -apple-system, sans-serif;
}
.intro .lede { font-size: 1.15rem; color: var(--fg); }
.intro .lede strong { color: var(--accent); }
.intro .byline {
  font-family: -apple-system, sans-serif; font-size: 0.85rem;
  color: var(--muted); border-top: 1px solid var(--border);
  padding-top: 1rem; margin-top: 2rem;
}
.outro h2, .outro h3 { margin: 2rem 0 0.6rem; }
.outro code { background: var(--code-bg); padding: 0 0.3rem; border-radius: 3px; font-size: 0.85em; }
.outro .footer {
  margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border);
  font-size: 0.85rem; color: var(--muted); font-family: -apple-system, sans-serif;
}

/* === Scrollytelling — sticky map + step cards === */
#scrolly { position: relative; }
#scrolly .sticky {
  position: sticky; top: 0; width: 100%; height: 100vh; z-index: 0;
}
#map { position: absolute; inset: 0; }

/* Optional FX canvas overlay (e.g. particle animations on top of the map).
   The article can drop `<canvas id="fx">` into `.sticky` and resize it
   from JS — without these rules the canvas would sit in normal flow,
   pushed below the map. */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

.overlay {
  position: absolute; bottom: 20px; left: 20px;
  max-width: 340px; background: var(--card-bg);
  padding: 10px 14px; border-radius: 6px;
  font-size: 13px; font-family: -apple-system, sans-serif; line-height: 1.5;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  opacity: 0; transition: opacity 0.3s ease; pointer-events: none; z-index: 10;
}
.overlay.visible { opacity: 1; }
.overlay h3 { font-size: 13px; margin: 0 0 4px; color: var(--accent); }
.overlay .row { display: flex; justify-content: space-between; padding: 1px 0; gap: 12px; }
.overlay .row .label { color: var(--fg); }
.overlay .row .val { font-variant-numeric: tabular-nums; color: var(--muted); }
.overlay .legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle; border: 1px solid rgba(0,0,0,0.25);
}

.step {
  position: relative; margin: 0 auto; max-width: 560px; padding: 0 1.5rem;
  margin-top: 60vh; margin-bottom: 60vh; z-index: 1;
}
.step .card {
  background: var(--card-bg); color: var(--fg);
  padding: 1.5rem 1.75rem; border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  font-size: 1.02rem; backdrop-filter: blur(4px);
  position: relative;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.step .card h2 {
  font-family: "Hiragino Mincho ProN", serif;
  font-size: 1.4rem; line-height: 1.4; margin: 0 0 0.8rem;
  letter-spacing: -0.01em; color: var(--fg);
}
.step .card p { margin: 0.8rem 0; }
.step .card strong { color: var(--accent); }
.step .card .num {
  font-variant-numeric: tabular-nums; font-weight: 700;
  font-size: 1.1em; color: var(--accent);
}

/* === Scroll affordances === */
.scroll-hint {
  display: flex; flex-direction: column; align-items: center;
  margin: 2.4rem auto 0;
  font-family: -apple-system, sans-serif;
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
  width: fit-content;
  cursor: pointer; user-select: none;
  transition: opacity 0.5s ease;
}
.scroll-hint .label { font-size: 0.85rem; font-weight: 600; letter-spacing: 0.08em; }
.scroll-hint .arrow {
  font-size: 2rem; line-height: 1; margin-top: 2px;
  animation: bounce 1.2s ease-in-out infinite;
}
.scroll-hint.faded { opacity: 0.18; animation: none; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(8px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

.step-counter {
  position: absolute; top: 50px; right: 16px;
  font-family: -apple-system, sans-serif; font-size: 11px;
  font-weight: 600; color: var(--accent);
  background: var(--card-bg);
  padding: 3px 9px; border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  opacity: 0; transition: opacity 0.3s; z-index: 10;
}
.step-counter.visible { opacity: 1; }

.scroll-floating {
  position: absolute; bottom: 20px; right: 20px; z-index: 11;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 12px; border-radius: 18px;
  font-family: -apple-system, sans-serif;
  color: #15171a; background: var(--accent);
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  opacity: 0; transition: opacity 0.4s; pointer-events: none;
}
.scroll-floating.visible { opacity: 0.92; animation: pulse 2s ease-in-out infinite; }
.scroll-floating .arrow { font-size: 14px; line-height: 1; animation: bounce 1.2s ease-in-out infinite; }

/* === Card hide / restore === */
body.cards-hidden .step .card,
body.cards-hidden .overlay {
  opacity: 0; transform: translateY(-8px); pointer-events: none;
}
.card-hide {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer;
  font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  font-family: -apple-system, sans-serif;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.card-hide:hover { background: var(--accent); color: #15171a; border-color: var(--accent); }
.restore-cards {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: none;
  background: var(--accent); color: #15171a; border: none;
  padding: 10px 18px; border-radius: 22px;
  font-family: -apple-system, sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  animation: pulse 2s ease-in-out infinite;
}
body.cards-hidden .restore-cards { display: inline-block; }

/* === Fullscreen map toggle === */
.map-fs-hint {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%) translateY(-6px);
  z-index: 1002;
  background: rgba(28, 30, 33, 0.92);
  color: var(--accent);
  padding: 11px 20px; border-radius: 22px;
  font-family: -apple-system, sans-serif;
  font-size: 13px; font-weight: 600; letter-spacing: 0.04em;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: none;
  opacity: 0; transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
}
.map-fs-hint.visible {
  opacity: 1; transform: translate(-50%, -50%);
}
.map-fullscreen-btn {
  position: absolute; top: 50px; left: 16px; z-index: 12;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--card-bg); color: var(--accent);
  border: 1px solid var(--border);
  font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  font-family: -apple-system, sans-serif;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.map-fullscreen-btn:hover {
  background: var(--accent); color: #15171a; border-color: var(--accent);
}
body.map-fullscreen #scrolly .sticky {
  position: fixed; top: 0; left: 0; right: 0;
  height: 100vh; height: 100dvh; z-index: 1000;
}
body.map-fullscreen .map-fullscreen-btn { z-index: 1001; }
body.map-fullscreen .toc-bar,
body.map-fullscreen .crumb-strip,
body.map-fullscreen .progress-bar,
body.map-fullscreen .step .card,
body.map-fullscreen .step-counter,
body.map-fullscreen .scroll-floating,
body.map-fullscreen .restore-cards {
  opacity: 0 !important; pointer-events: none !important; visibility: hidden;
}
body.map-fullscreen { overflow: hidden; }

/* === Autoplay mode === */
body.autoplay .step .card,
body.autoplay .overlay {
  opacity: 0 !important;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
body.autoplay #scrolly .sticky {
  position: fixed; top: 0; left: 0; right: 0; height: 100vh; z-index: 50;
}
body.autoplay .intro, body.autoplay .outro, body.autoplay .step {
  visibility: hidden;
}

/* ---- 関連書籍 (related-books.js が render) -------------------------- */
.related-books-section {
  margin-top: 2.2rem;
}
.related-books-section h3 {
  font-family: -apple-system, sans-serif;
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}
.related-books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 0.6rem;
}
.related-book {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  font-family: -apple-system, sans-serif;
}
.related-book:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--accent, #60a5fa);
  transform: translateY(-1px);
}
.related-book__cover {
  flex: 0 0 64px;
  width: 64px;
  height: 90px;
  object-fit: cover;
  border-radius: 3px;
  background: rgba(255,255,255,0.04);
}
.related-book__body { flex: 1 1 auto; min-width: 0; }
.related-book__title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 0.15rem;
}
.related-book__author {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.related-book__why {
  font-size: 0.78rem;
  line-height: 1.55;
  margin: 0;
  color: var(--muted);
}
.related-books-note {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.6rem;
  font-family: -apple-system, sans-serif;
}
