:root {
  --bg0: #f3efe6;
  --bg1: #e7e1d4;
  --ink: #1c2430;
  --muted: #5c6674;
  --line: #c9c0b0;
  --panel: rgba(255, 252, 246, 0.92);
  --accent: #0f6b5c;
  --accent-soft: #d7ebe6;
  --danger: #9b3b2e;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --font: "DM Sans", sans-serif;
  --display: "IBM Plex Serif", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff9ee 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #dcece8 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.75);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.lang-toggle,
.tabs,
.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.lang-btn,
.tab,
.toggle {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.lang-btn.active,
.tab.active,
.toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toggle:not(.active) {
  opacity: 0.55;
}

.toggle.year-toggle,
.toggle.year-toggle.active {
  background: var(--year-color, #888);
  border-color: var(--year-color, #888);
  color: #fff;
}

.toggle.bucket-toggle,
.toggle.bucket-toggle.active {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.toggle.bucket-toggle .marker-glyph {
  width: 12px;
  height: 12px;
  margin: 0;
  flex-shrink: 0;
  color: var(--ink);
  border-color: rgba(28, 36, 48, 0.45);
}

.toggle.bucket-toggle .marker-glyph.sym-diamond {
  width: 10px;
  height: 10px;
  margin: 0;
}

.toggle.bucket-toggle .marker-glyph.sym-triangle-up {
  width: 0;
  height: 0;
  margin: 0;
  border-left-width: 6px;
  border-right-width: 6px;
  border-bottom-width: 11px;
}

.toggle.bucket-toggle .marker-glyph.sym-x {
  width: 12px;
  height: 12px;
}

.toggle.bucket-toggle .marker-glyph.sym-x::before,
.toggle.bucket-toggle .marker-glyph.sym-x::after {
  height: 12px;
}

.toggle.bucket-toggle .marker-glyph.sym-star {
  width: 13px;
  height: 13px;
  margin: 0;
}

main {
  flex: 1;
  min-height: 0;
  position: relative;
}

.panel {
  display: none;
  height: 100%;
  min-height: 0;
}

.panel.active {
  display: flex;
  flex-direction: column;
}

#panel-chart {
  position: relative;
  padding: 0.6rem 1rem 0.75rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  margin-bottom: 0.4rem;
  flex-shrink: 0;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.chart {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

/* Keep Plotly point-picking for clicks; hide its hover UI entirely. */
.chart .hoverlayer {
  display: none !important;
}

.marker-stack {
  position: absolute;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-height: min(70vh, 420px);
  overflow-y: auto;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.marker-stack.hidden {
  display: none;
}

.marker-stack-item {
  position: relative;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

.marker-stack-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.marker-glyph {
  display: block;
  width: 14px;
  height: 14px;
  margin: 4px auto;
  box-sizing: border-box;
  border: 1.5px solid rgba(28, 36, 48, 0.4);
  background: currentColor;
}

.marker-glyph.sym-circle {
  border-radius: 50%;
}

.marker-glyph.sym-square {
  border-radius: 2px;
}

.marker-glyph.sym-diamond {
  width: 12px;
  height: 12px;
  margin: 5px auto;
  border-radius: 1px;
  transform: rotate(45deg);
}

.marker-glyph.sym-triangle-up {
  width: 0;
  height: 0;
  margin: 3px auto 0;
  border: none;
  background: transparent;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 14px solid currentColor;
  filter: drop-shadow(0 0 0.4px rgba(28, 36, 48, 0.45));
}

.marker-glyph.sym-x {
  width: 14px;
  height: 14px;
  border: none;
  background: transparent;
  position: relative;
}

.marker-glyph.sym-x::before,
.marker-glyph.sym-x::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 2.5px;
  height: 14px;
  margin-left: -1.25px;
  background: currentColor;
  border-radius: 1px;
}

.marker-glyph.sym-x::before {
  transform: rotate(45deg);
}

.marker-glyph.sym-x::after {
  transform: rotate(-45deg);
}

.marker-glyph.sym-star {
  width: 16px;
  height: 16px;
  margin: 3px auto;
  border: none;
  background: currentColor;
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
}

.hover-card {
  position: absolute;
  z-index: 20;
  width: min(360px, calc(100vw - 2rem));
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf8;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.hover-card.hidden {
  display: none;
}

.hover-author {
  font-weight: 700;
  font-size: 0.92rem;
}

.hover-title {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.hover-point {
  margin: 0.65rem 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.hover-link {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.82rem;
  text-decoration: none;
}

.hover-link:hover {
  background: var(--accent);
  color: #fff;
}

#panel-defs {
  padding: 0.75rem 1rem 1rem;
  overflow: auto;
}

.defs-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.65rem;
  align-items: stretch;
}

.defs-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.defs-card h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 0.98rem;
  line-height: 1.25;
}

.defs-card .question {
  margin: 0.4rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.level-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}

.level-table th,
.level-table td {
  border-top: 1px solid var(--line);
  padding: 0.28rem 0.2rem;
  vertical-align: top;
  text-align: left;
}

.level-table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.level-table .lvl {
  font-weight: 700;
  white-space: nowrap;
  width: 1.8rem;
}

.level-table .cat {
  font-weight: 600;
  width: 34%;
}

#panel-articles {
  padding: 0.6rem 1rem 0.75rem;
  gap: 0.5rem;
}

.articles-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: flex-end;
  flex-shrink: 0;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.articles-search {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.65rem;
  width: 100%;
  min-width: 0;
}

.articles-filters .filter-group {
  align-items: flex-start;
  flex-direction: column;
  gap: 0.3rem;
}

.articles-search-group {
  flex: 1;
  min-width: 14rem;
}

.ms-wrap {
  position: relative;
  min-width: 12rem;
}

.articles-ms[data-filter-key="types"] .ms-wrap {
  min-width: 16rem;
}

.ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  text-align: left;
}

.ms-trigger::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  flex-shrink: 0;
  margin-top: -0.15rem;
}

.ms-trigger[aria-expanded="true"] {
  border-color: var(--accent);
}

.ms-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.ms-panel[hidden] {
  display: none;
}

.ms-option {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.3;
  cursor: pointer;
}

.ms-option:hover {
  background: rgba(15, 107, 92, 0.08);
}

.ms-option input {
  margin: 0.15rem 0 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.articles-grid-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.articles-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.articles-table th,
.articles-table td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.articles-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff9ef;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.articles-table tbody tr:hover {
  background: rgba(15, 107, 92, 0.05);
}

.articles-clip {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.articles-url {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}

.articles-url:hover {
  text-decoration: underline;
}

.articles-actions {
  white-space: nowrap;
}

.articles-btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  margin-right: 0.3rem;
}

.articles-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.articles-btn-secondary {
  background: #fffdf8;
  color: var(--ink);
  border-color: var(--line);
}

.articles-btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.articles-empty {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem !important;
}

.articles-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.articles-page-numbers {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.articles-page-num {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.articles-page-num:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.articles-page-num.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: default;
}

.articles-page-ellipsis {
  min-width: 1.25rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.articles-page-meta {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  min-width: 8rem;
  text-align: center;
}

.article-details {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(720px, calc(100vw - 2rem));
  width: 100%;
}

.article-details::backdrop {
  background: rgba(28, 36, 48, 0.45);
}

.article-details-panel {
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-height: min(85vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.article-details-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.article-details-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  line-height: 1.3;
}

.article-details-body {
  margin: 0;
  padding: 0.85rem 1rem 1.1rem;
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(7rem, 11rem) 1fr;
  gap: 0.45rem 0.75rem;
  font-size: 0.84rem;
}

.article-details-body dt {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.article-details-body dd {
  margin: 0;
  line-height: 1.4;
  word-break: break-word;
}

.article-details-body a {
  color: var(--accent);
}

@media (max-width: 1200px) {
  .defs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .defs-grid {
    grid-template-columns: 1fr;
  }

  #panel-chart {
    min-height: 80vh;
  }

  .chart {
    min-height: 60vh;
  }

  .article-details-body {
    grid-template-columns: 1fr;
  }

  .articles-clip {
    max-width: 10rem;
  }
}
