:root {
  --color-heading: #151211;
  --color-body: #2c2827;
  --color-muted: #787270;
  --color-bubble: #7ABAFF;
  --color-border: #ddd;
  --color-surface: #fff;
  --color-accent: #4a9ae8;
  --color-whisker: #8f8a88;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--color-surface);
  color: var(--color-body);
}

/* Page-specific overrides (replaces inline <style> blocks) */
html:has(body.page-chart),
body.page-chart { height: auto; overflow: visible; }
body.page-chart #chart-container { height: auto; }

.page-wordcloud #bubble-chart { width: 820px; margin: 0 auto; }

#chart-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

#controls {
  padding: 12px 24px 0;
  flex-shrink: 0;
}

#chart-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#chart-scroll::-webkit-scrollbar {
  display: none;
}

#bubble-chart {
  width: 820px;
  height: 580px;
}

#explore-hint {
  display: none;
  align-items: left;
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 24px 12px;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--color-muted);
}

@media (min-width: 961px) {
  #chart-scroll {
    overflow: hidden;
  }
  #bubble-chart {
    width: 100%;
    height: 100%;
  }
}

@media (max-width: 960px) {
  #explore-hint {
    display: flex;
  }
  #tooltip {
    display: none !important;
  }
}

/* Word cloud iframe is always <960px; keep tooltip visible */
.page-wordcloud #tooltip {
  display: block !important;
}

svg text {
  font-family: 'DM Sans', sans-serif;
}

/* Tooltip */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 100;
  max-width: 280px;
}
#tooltip .tt-name {
  font-weight: 700;
  font-size: 12px;
  color: var(--color-heading);
  margin-bottom: 4px;
}
#tooltip .tt-row {
  color: var(--color-muted);
}
#tooltip .tt-value {
  font-weight: 700;
  color: var(--color-heading);
}

/* Overlay backdrop — hidden on desktop, visible on mobile */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  display: none;
}
#overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Detail panel — desktop/tablet: side panel */
#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  border-radius: 0;
  box-shadow: none;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
  z-index: 200;
  overflow-y: auto;
  padding: 24px;
}
#detail-panel.open {
  transform: translateX(0);
  box-shadow: -4px 0 24px rgba(0,0,0,0.08);
}
#detail-panel .panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
#detail-panel .panel-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-heading);
}
#detail-panel .panel-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--color-muted);
  padding: 0 4px;
  line-height: 1;
}
#detail-panel .panel-close:hover { color: var(--color-heading); }
#detail-panel .panel-stats {
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 20px;
}
#detail-panel .cat-group {
  margin-bottom: 16px;
}
#detail-panel .cat-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-bubble);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--color-bubble);
}
#detail-panel .cat-group-stats {
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 6px;
}
#detail-panel .cat-group ul {
  list-style: none;
  padding: 0;
}
#detail-panel .cat-group li {
  font-size: 12px;
  line-height: 1.5;
  padding: 4px 0;
  color: var(--color-body);
  border-bottom: 1px solid #f0f0f0;
}
#detail-panel .cat-group li:last-child {
  border-bottom: none;
}

/* Y-axis category labels clickable */
.y-axis .tick text {
  cursor: pointer;
  transition: fill 0.2s ease, font-weight 0.2s ease;
}
.y-axis .tick text:hover {
  fill: var(--color-accent);
}

/* Legend */
.legend text {
  font-size: 14px;
  fill: var(--color-muted);
}
.legend-title {
  font-size: 16px;
  font-weight: 500;
  fill: var(--color-muted);
}

/* Toggle buttons */
#toggle-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

/* Color legend */
#color-legend {
  display: none;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 4px 16px;
  margin-bottom: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#color-legend::-webkit-scrollbar {
  display: none;
}
#color-legend.visible {
  display: flex;
}
@media (min-width: 600px) {
  #color-legend {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-body);
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  transition: background 0.15s ease, opacity 0.2s ease;
}
.legend-item:hover {
  background: #f5f5f5;
}
.legend-item.dimmed {
  opacity: 0.5;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-label {
  line-height: 1;
}
.toggle-btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 16px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-body);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.toggle-btn:hover {
  border-color: #aaa;
  background: #f5f5f5;
}
.toggle-btn.active {
  background: var(--color-heading);
  color: var(--color-surface);
  border-color: var(--color-heading);
}

/* ── Responsive ── */

/* Tablet — scrollable chart, side panel stays */
@media (max-width: 768px) {
  #chart-container {
    padding: 0 16px;
    margin: 24px auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #chart svg {
    min-width: 700px;
    width: 700px;
    height: auto;
  }
}

/* Phone — centered popup modal */
@media (max-width: 480px) {
  #chart-container {
    padding: 0 12px;
    margin: 16px auto;
  }

  #chart svg {
    min-width: 600px;
    width: 600px;
  }

  #tooltip {
    max-width: 200px;
    font-size: 10px;
    padding: 8px 10px;
  }

  /* Show overlay on mobile */
  #overlay {
    display: block;
  }

  /* Switch to centered modal */
  #detail-panel {
    top: 50%;
    left: 50%;
    right: auto;
    width: 90%;
    max-width: 520px;
    height: auto;
    max-height: 80vh;
    border-left: none;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    padding: 24px;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #detail-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
  }

  #detail-panel .panel-title {
    font-size: 16px;
  }

  #detail-panel .cat-group li {
    font-size: 10px;
  }
}
