:root {
  --bg: #f5f0eb;
  --surface: #faf7f2;
  --ink: #1a1410;
  --ink-light: #3d3329;
  --ink-faint: #6b5d50;
  --accent: #6b4c2a;
  --moss: #4a6340;
  --clay: #8c5a30;
  --stone: #c4b8a8;
}

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

/* ── Canvas toggle (view background) ────────── */
.canvas-toggle {
  position: fixed;
  z-index: 50;
  bottom: 1.2rem;
  right: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(212, 205, 196, 0.5);
  background: rgba(234, 213, 182, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink-light);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.canvas-toggle:hover {
  background: rgba(234, 213, 182, 0.85);
  color: var(--ink);
  transform: scale(1.1);
}

body.canvas-mode .canvas-toggle {
  background: rgba(26, 20, 16, 0.6);
  color: rgba(234, 213, 182, 0.9);
  border-color: rgba(234, 213, 182, 0.3);
}

/* Panels: fade-in when returning (no slide back) */
.left-col,
#graph-panel {
  transition: opacity 0.4s ease-out;
}

/* Panels: slide-out when entering canvas mode */
body.canvas-mode .left-col {
  transform: translateX(calc(-100% - 2rem));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.6s ease;
}

body.canvas-mode #graph-panel {
  transform: translateX(calc(100% + 2rem));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.6s ease;
}

/* ── Loading screen ────────────────────────── */
.loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.8s ease;
}

.is-reveal .loader {
  opacity: 0;
  pointer-events: none;
}

.loader__icon {
  animation: spin 3s linear infinite;
}

.loader__arc {
  stroke-dasharray: 60 200;
  animation: arc-draw 1.8s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes arc-draw {
  0% { stroke-dashoffset: 60; }
  50% { stroke-dashoffset: -60; }
  100% { stroke-dashoffset: -180; }
}

/* ── Staggered reveal ────────────────────────── */
.is-loading .hero__name,
.is-loading .hero__tagline,
.is-loading .hero__intro,
.is-loading #chat-panel,
.is-loading #graph-panel {
  opacity: 0;
  transform: translateY(12px);
}

.hero__name,
.hero__tagline,
.hero__intro,
#chat-panel,
#graph-panel {
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.is-reveal .hero__name     { transition-delay: 0.3s; }
.is-reveal .hero__tagline  { transition-delay: 0.8s; }
.is-reveal .hero__intro    { transition-delay: 1.3s; }
.is-reveal #chat-panel     { transition-delay: 2.2s; }
.is-reveal #graph-panel    { transition-delay: 2.6s; }

/* Clear reveal delays after initial load so they don't interfere with canvas toggle */
.is-loaded .hero__name,
.is-loaded .hero__tagline,
.is-loaded .hero__intro,
.is-loaded #chat-panel,
.is-loaded #graph-panel { transition-delay: 0s; }

body {
  font-family: "Noto Sans JP", -apple-system, sans-serif;
  font-weight: 400;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  background-image: url('background.svg');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-attachment: fixed;
  overflow: hidden;
  height: 100vh;
}

/* Layout */
main {
  display: flex;
  height: 100vh;
  position: relative;
  z-index: 1;
  gap: 1rem;
  padding: 1rem;
}

/* Site credit */
.site-credit {
  position: fixed;
  bottom: 0.6rem;
  right: 3.2rem;
  z-index: 2;
  font-size: 0.68rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.site-credit a {
  color: var(--accent);
  text-decoration: none;
}

.site-credit a:hover { text-decoration: underline; }

.site-credit__heart { font-style: normal; }

body.canvas-mode .site-credit { color: rgba(234, 213, 182, 0.6); }
body.canvas-mode .site-credit a { color: rgba(234, 213, 182, 0.8); }

.left-col {
  flex: 0 0 30%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

/* Hero header — top-left clear zone */
.hero {
  flex-shrink: 0;
  padding: 1rem 1.2rem;
  font-family: "Cormorant Garamond", "Georgia", serif;
  background: rgba(234, 213, 182, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
}

.hero__name {
  font-weight: 700;
  font-size: 2.2rem;
  letter-spacing: 0.03em;
  color: var(--ink);
  text-shadow: 0 1px 10px rgba(245, 240, 235, 0.8);
  line-height: 1.2;
}

.hero__tagline {
  font-family: "Noto Sans JP", -apple-system, sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 0.3rem;
  text-shadow: 0 1px 6px rgba(245, 240, 235, 0.7);
}

.hero__intro {
  font-weight: 600;
  font-size: 1.05rem;
  font-style: italic;
  color: var(--ink-light);
  margin-top: 0.6rem;
  line-height: 1.55;
  text-shadow: 0 1px 8px rgba(245, 240, 235, 0.8);
}

/* ── Mobile: tablets & small laptops ────────── */
@media (max-width: 768px) {
  body {
    overflow: hidden;
    height: 100dvh;
    height: 100vh; /* fallback for older browsers */
    height: 100dvh;
  }

  main {
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
    height: 100dvh;
    padding: 0.75rem;
    gap: 0;
    overflow: hidden;
  }

  .left-col {
    flex: 1;
    min-height: 0;
    gap: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Close the gap between hero and chat — merge into one visual block */
  .hero {
    padding: 0.8rem 1rem;
    border-radius: 12px 12px 0 0;
    background: rgba(234, 213, 182, 0.82);
  }

  #chat-panel {
    flex: 1;
    min-height: 0;
    padding: 0.8rem 1rem;
    border-radius: 0 0 12px 12px;
    border-top: 1px solid rgba(212, 205, 196, 0.3);
    background: rgba(250, 247, 242, 0.78);
    overflow-y: auto;
  }

  #graph-panel {
    min-height: 0;
    max-height: 40dvh;
    margin-top: 0.75rem;
    background: rgba(250, 247, 242, 0.78);
    overflow-y: auto;
  }

  /* Collapse graph container until data arrives */
  #graph-container {
    flex: 0;
  }

  .graph-empty {
    position: static;
    transform: none;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }

  /* JS sets .graph-empty display:none when data arrives */
  #graph-panel:not(:has(.graph-empty)) #graph-container {
    flex: 1;
    min-height: 30vh;
  }

  .hero__name {
    font-size: 1.8rem;
  }

  /* Larger tap targets */
  .canvas-toggle {
    width: 44px;
    height: 44px;
    bottom: 0.8rem;
    right: 0.8rem;
  }

  .jd-btn {
    width: 44px;
    height: 44px;
  }

  .viz-toggle__btn {
    padding: 0.55rem 0.8rem;
    font-size: 0.85rem;
  }

  .filter-pill {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
  }

  /* Site credit — reposition to avoid overlap */
  .site-credit {
    position: relative;
    bottom: auto;
    right: auto;
    text-align: center;
    padding: 0.8rem 0;
    font-size: 0.72rem;
  }

  /* Canvas mode — slide left col down, not left */
  body.canvas-mode .left-col {
    transform: translateY(-100%);
  }

  body.canvas-mode #graph-panel {
    transform: translateY(100%);
  }

  /* JD accordion tap targets */
  .jd-req-acc {
    padding: 0.7rem 0;
    gap: 0.6rem;
  }

  .jd-req-acc__arrow {
    font-size: 0.75rem;
  }

  .jd-req-acc__name {
    font-size: 0.88rem;
  }

  .jd-conf {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
  }

  .jd-evidence__link {
    font-size: 0.78rem;
  }

  .jd-evidence__ctx {
    font-size: 0.75rem;
  }

  /* Tooltip readability */
  .viz-tooltip {
    max-width: min(280px, 85vw);
    font-size: 0.8rem;
  }

  .tip-link {
    font-size: 0.75rem;
  }

  .tip-prof {
    font-size: 0.7rem;
  }

  /* Reference modal */
  .ref-filter__btn {
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
  }

  .ref-item__link {
    font-size: 0.85rem;
  }

  .ref-item__dates {
    font-size: 0.75rem;
  }
}

/* ── Mobile: phones ────────────────────────── */
@media (max-width: 480px) {
  main {
    padding: 0.5rem;
  }

  .hero {
    padding: 0.6rem 0.8rem;
  }

  .hero__name {
    font-size: 1.5rem;
  }

  .hero__tagline {
    font-size: 0.72rem;
  }

  .hero__intro {
    font-size: 0.88rem;
    line-height: 1.5;
  }

  #chat-panel {
    padding: 0.6rem 0.8rem;
  }

  #chat-input {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  #graph-panel {
    margin-top: 0.5rem;
  }

  /* Tap targets — full 48px minimum */
  .canvas-toggle {
    width: 48px;
    height: 48px;
  }

  .jd-btn {
    width: 48px;
    height: 48px;
  }

  /* Messages */
  .msg {
    margin-bottom: 1rem;
  }

  .msg-assistant pre {
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
  }

  /* Legend wrapping */
  .legend {
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    font-size: 0.78rem;
  }

  /* JD modal */
  .jd-modal__panel {
    padding: 1.2rem 1rem 1rem;
  }

  .jd-results__pct {
    font-size: 2rem;
  }

  .jd-drop {
    padding: 1rem;
  }

  .jd-text {
    font-size: 16px; /* prevents iOS zoom */
  }

  /* Reference modal */
  .ref-modal__header {
    padding: 1rem 1rem 0.6rem;
  }

  .ref-modal__body {
    padding: 0.5rem 1rem 1rem;
  }

  /* Status tracker */
  .msg-status {
    font-size: 0.78rem;
  }
}

/* Chat panel */
#chat-panel {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.5rem;
  overflow: hidden;
  background: rgba(250, 247, 242, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 12px;
  border: 1px solid rgba(212, 205, 196, 0.45);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 1rem;
}

.msg { margin-bottom: 1.2rem; max-width: 100%; }
.msg-user { color: var(--ink); font-weight: 400; }
.msg-user::before { content: "› "; color: var(--accent); }

.msg-assistant {
  color: var(--ink-light);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-assistant code {
  background: var(--surface);
  padding: 0.1em 0.35em;
  border-radius: 2px;
  font-size: 0.88em;
  color: var(--moss);
}

.msg-assistant pre {
  background: var(--surface);
  padding: 0.8rem 1rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  border-left: 2px solid var(--stone);
  line-height: 1.5;
}

.msg-assistant pre code { background: none; padding: 0; color: var(--ink); }

#chat-form {
  display: flex;
  align-items: end;
  gap: 0.5rem;
  border-top: 1px solid rgba(212, 205, 196, 0.4);
  padding-top: 1rem;
  background: transparent;
}

#chat-input {
  flex: 1;
  border: none;
  border-bottom: 1px solid var(--stone);
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  padding: 0.5rem 0;
  outline: none;
}

#chat-input::placeholder { color: var(--ink-light); }
#chat-input:focus { border-bottom-color: var(--accent); }

.jd-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--stone);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-faint);
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: 0.35rem;
}

.jd-btn:hover { color: var(--accent); border-color: var(--accent); }

/* Loading dots */
.loading span {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ink-faint);
  margin-right: 4px;
  animation: pulse 1.4s ease-in-out infinite;
}
.loading span:nth-child(2) { animation-delay: 0.2s; }
.loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* Graph panel */
#graph-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: rgba(250, 247, 242, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 12px;
  border: 1px solid rgba(212, 205, 196, 0.45);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}

#graph-container { flex: 1; min-height: 0; }

.graph-empty {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--ink-light);
  font-size: 0.95rem;
  text-shadow: 0 1px 6px rgba(245, 240, 235, 0.8);
}

.legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ink);
  text-shadow: 0 1px 6px rgba(245, 240, 235, 0.8);
}

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 3px;
  vertical-align: middle;
}

.legend-note { color: var(--ink-light); }



.msg-assistant blockquote {
  font-style: italic;
  color: var(--ink-faint);
  border-left: 2px solid var(--stone);
  padding-left: 0.8rem;
  margin: 0.3rem 0;
}

/* Markdown inline */
.msg-assistant strong { color: var(--ink); font-weight: 400; }
.msg-assistant em { font-style: italic; }

/* Viz toggle bar */
.viz-toggle {
  display: flex;
  gap: 0;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(212, 205, 196, 0.4);
}

.viz-toggle__btn {
  flex: 1;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--stone);
  border-right: none;
  background: var(--surface);
  color: var(--ink-light);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.viz-toggle__btn:last-child { border-right: 1px solid var(--stone); border-radius: 0 3px 3px 0; }
.viz-toggle__btn:first-child { border-radius: 3px 0 0 3px; }
.viz-toggle__btn--active { background: var(--bg); color: var(--ink); }
.viz-toggle__btn:hover:not(.viz-toggle__btn--active) { background: var(--bg); }

/* Domain filter bar */
.graph-filter {
  display: none;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  border-bottom: 1px solid rgba(212, 205, 196, 0.4);
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--stone);
  border-radius: 10px;
  background: transparent;
  color: var(--ink-light);
  font-family: inherit;
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.filter-pill:hover:not(.filter-pill--active) { background: var(--bg); }
.filter-pill--active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.filter-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-pill--active .filter-dot { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4); }

/* D3 SVG */
#viz-svg { width: 100%; height: 100%; }

.treemap-leaf { cursor: pointer; transition: opacity 0.15s; }
.treemap-label { pointer-events: none; font-family: inherit; }
.treemap-group-label { pointer-events: none; font-family: inherit; }

.bar-row rect { cursor: pointer; transition: opacity 0.15s; }
.bar-row text { font-family: inherit; }

.viz-tooltip {
  position: absolute;
  padding: 0.6rem 0.8rem;
  background: rgba(250, 247, 242, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(212, 205, 196, 0.45);
  border-radius: 10px;
  font-size: 0.75rem;
  color: var(--ink);
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  font-family: inherit;
  max-width: 280px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}
.viz-tooltip--visible { opacity: 1; }

.tip-prof {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tip-prof--extensive { background: #5a7a4f22; color: #4a6a3f; }
.tip-prof--moderate { background: #8b735522; color: #7a6345; }
.tip-prof--minimal { background: #9e989022; color: #8a8280; }

.tip-count { margin-top: 0.25rem; color: var(--ink-light); }
.tip-status { margin-top: 0.25rem; font-style: italic; color: var(--ink-faint); }
.tip-status--gap { color: #b05a4f; }

.tip-links {
  margin-top: 0.4rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--stone);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.tip-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.68rem;
  word-break: break-all;
  line-height: 1.4;
}
.tip-link:hover { text-decoration: underline; }

.tip-lock { font-size: 0.6rem; }

.tip-private {
  font-size: 0.62rem;
  font-style: italic;
  color: var(--ink-faint);
  margin-top: 0.3rem;
  line-height: 1.4;
}

/* Status tracker */
.msg-status {
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin-bottom: 0.8rem;
  padding: 0.5rem 0 0.5rem 0.8rem;
  border-left: 2px solid var(--stone);
}

.status-steps {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.status-step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  opacity: 0.5;
  transition: opacity 0.3s;
}

.status-step--active {
  opacity: 1;
  color: var(--ink-light);
}

.status-step--active .status-icon {
  color: var(--accent);
  animation: blink 1.4s ease-in-out infinite;
}

.status-step--done { opacity: 0.7; }
.status-step--done .status-icon { color: var(--moss); }

.status-elapsed {
  font-size: 0.75rem;
  color: var(--ink-faint);
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.msg-status--done {
  border-left: none;
  padding-left: 0;
  margin-bottom: 0.5rem;
}

.status-summary {
  font-size: 0.75rem;
  color: var(--ink-faint);
}

@keyframes blink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ── Rate-limit Modal ────────────────────────────── */

.rate-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
}

.rate-modal--open { display: flex; align-items: center; justify-content: center; }

.rate-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 44, 44, 0.35);
  backdrop-filter: blur(2px);
}

.rate-modal__panel {
  position: relative;
  width: min(400px, 85vw);
  background: rgba(250, 247, 242, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(212, 205, 196, 0.45);
  border-radius: 14px;
  padding: 2rem 2rem 1.5rem;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.04);
}

.rate-modal__title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--ink);
  margin-bottom: 0.6rem;
}

.rate-modal__text {
  font-size: 0.88rem;
  color: var(--ink-light);
  line-height: 1.6;
  margin-bottom: 0.4rem;
}

.rate-modal__timer {
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin-bottom: 1.2rem;
}

.rate-modal__btn {
  padding: 0.5rem 1.8rem;
  border: 1px solid var(--stone);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.rate-modal__btn:hover { background: var(--bg); }

/* ── Reference Index Modal ────────────────────────── */

.ref-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
}

.ref-modal--open { display: flex; align-items: center; justify-content: center; }

.ref-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 44, 44, 0.35);
  backdrop-filter: blur(2px);
}

.ref-modal__panel {
  position: relative;
  width: min(640px, 90vw);
  max-height: 80vh;
  background: rgba(250, 247, 242, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(212, 205, 196, 0.45);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.ref-modal__close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--ink-faint);
  cursor: pointer;
  line-height: 1;
  z-index: 1;
}
.ref-modal__close:hover { color: var(--ink); }

.ref-modal__header {
  padding: 1.2rem 1.4rem 0.8rem;
  border-bottom: 1px solid var(--stone);
  flex-shrink: 0;
}

.ref-modal__header h2 {
  font-weight: 400;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  margin-bottom: 0.2rem;
}

.ref-modal__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.ref-modal__path {
  font-size: 0.78rem;
  color: var(--ink-light);
}

.ref-modal__stats {
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* Repo filter */
.ref-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.ref-filter__btn {
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--stone);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink-light);
  font-family: inherit;
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.ref-filter__btn:hover:not(.ref-filter__btn--active) { background: var(--bg); }
.ref-filter__btn--active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ref-modal__loading {
  font-size: 0.82rem;
  color: var(--ink-faint);
  font-style: italic;
}

.ref-modal__empty {
  padding: 2rem 1.4rem;
  color: var(--ink-faint);
  text-align: center;
}

.ref-modal__body {
  overflow-y: auto;
  padding: 0.6rem 1.4rem 1.2rem;
  flex: 1;
  min-height: 0;
}

/* Repo group */
.ref-repo { margin-bottom: 1rem; }
.ref-repo:last-child { margin-bottom: 0; }

.ref-repo__name {
  font-weight: 400;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--stone);
}

.ref-repo__name a {
  color: var(--accent);
  text-decoration: none;
}
.ref-repo__name a:hover { text-decoration: underline; }

/* Individual reference */
.ref-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid #ebe6df;
}
.ref-item:last-child { border-bottom: none; }

.ref-item__file {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ref-item__link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  word-break: break-all;
}
.ref-item__link:hover { text-decoration: underline; }

.ref-item__line {
  font-size: 0.7rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.ref-item__lang {
  font-size: 0.65rem;
  color: var(--moss);
  background: #7a8b6f15;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
}

.ref-item__name {
  font-size: 0.75rem;
  color: var(--ink-light);
  margin-top: 0.15rem;
  font-family: monospace;
}

.ref-item__context {
  font-size: 0.75rem;
  color: var(--ink-light);
  margin-top: 0.2rem;
  line-height: 1.5;
}

.ref-item__dates {
  font-size: 0.68rem;
  color: var(--ink-faint);
  margin-top: 0.15rem;
}

.ref-repo__lock { font-size: 0.72rem; vertical-align: middle; }

.ref-private-note {
  margin-top: 1rem;
  padding: 0.7rem 0.9rem;
  background: rgba(107, 76, 42, 0.06);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--ink-light);
  line-height: 1.55;
}

.ref-private-note a {
  color: var(--accent);
  text-decoration: none;
}

.ref-private-note a:hover { text-decoration: underline; }

/* ── JD Match Modal ──────────────────────────────── */

.jd-modal { display: none; position: fixed; inset: 0; z-index: 100; }
.jd-modal--open { display: flex; align-items: center; justify-content: center; }

.jd-modal__backdrop { position: absolute; inset: 0; background: rgba(44, 44, 44, 0.35); backdrop-filter: blur(2px); }

.jd-modal__panel {
  position: relative; width: min(560px, 90vw); max-height: 85vh; overflow-y: auto;
  background: rgba(250, 247, 242, 0.88); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(212, 205, 196, 0.45); border-radius: 14px;
  padding: 1.6rem 1.8rem 1.4rem;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.04);
}

.jd-modal__close { position: absolute; top: 0.6rem; right: 0.8rem; background: none; border: none; font-size: 1.4rem; color: var(--ink-faint); cursor: pointer; line-height: 1; }
.jd-modal__close:hover { color: var(--ink); }

.jd-modal__title { font-family: "Cormorant Garamond", Georgia, serif; font-weight: 600; font-size: 1.2rem; color: var(--ink); margin-bottom: 0.2rem; }
.jd-modal__subtitle { font-size: 0.82rem; color: var(--ink-light); margin-bottom: 1rem; }

/* Drop zone */
.jd-drop { border: 2px dashed var(--stone); border-radius: 10px; padding: 1.4rem; text-align: center; cursor: pointer; transition: border-color 0.2s, background 0.2s; margin-bottom: 0.8rem; }
.jd-drop:hover, .jd-drop--over { border-color: var(--accent); background: rgba(107, 76, 42, 0.04); }
.jd-drop__label { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; color: var(--ink-faint); font-size: 0.82rem; }
.jd-drop__label svg { color: var(--stone); }
.jd-drop__browse { font-size: 0.72rem; color: var(--accent); }
.jd-drop__file { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.jd-drop__filename { font-size: 0.85rem; color: var(--ink); }
.jd-drop__clear { background: none; border: none; font-size: 1.1rem; color: var(--ink-faint); cursor: pointer; line-height: 1; }
.jd-drop__clear:hover { color: var(--ink); }

.jd-text { width: 100%; border: 1px solid var(--stone); border-radius: 8px; background: transparent; font-family: inherit; font-size: 0.85rem; color: var(--ink); padding: 0.6rem 0.8rem; resize: vertical; outline: none; transition: border-color 0.15s; margin-bottom: 1rem; }
.jd-text:focus { border-color: var(--accent); }
.jd-text::placeholder { color: var(--ink-faint); }

.jd-modal__analyze { display: block; width: 100%; padding: 0.6rem; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; font-family: inherit; font-size: 0.88rem; cursor: pointer; transition: opacity 0.15s; }
.jd-modal__analyze:hover:not(:disabled) { opacity: 0.9; }
.jd-modal__analyze:disabled { opacity: 0.45; cursor: default; }

/* Da Vinci loading spinner */
.jd-loading__inner { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; padding: 1.5rem 0; }
.jd-spinner { animation: spin 3s linear infinite; }
.jd-spinner__arc { stroke-dasharray: 60 200; animation: arc-draw 1.8s ease-in-out infinite; }
.jd-loading__text { font-size: 0.85rem; color: var(--ink-light); }
.jd-loading__timer { font-size: 0.78rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* Results */
.jd-results { margin-top: 1.2rem; }
.jd-results__header { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.5rem; }
.jd-results__pct { font-family: "Cormorant Garamond", Georgia, serif; font-size: 2.4rem; font-weight: 600; color: var(--ink); line-height: 1; }
.jd-results__label { font-size: 0.85rem; color: var(--ink-faint); }
.jd-results__summary { font-size: 0.85rem; color: var(--ink-light); line-height: 1.55; margin-bottom: 0.6rem; }
.jd-results__error { color: #b05a4f; font-size: 0.85rem; }

.jd-results__reqs { display: flex; flex-direction: column; }

/* Each requirement is an accordion row */
.jd-req-acc {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.5rem 0; border: none; border-bottom: 1px solid #ebe6df;
  background: none; cursor: pointer; font-family: inherit; text-align: left;
}
.jd-req-acc:last-of-type { border-bottom: none; }
.jd-req-acc__arrow { font-size: 0.6rem; color: var(--ink-faint); transition: transform 0.2s; flex-shrink: 0; }
.jd-req-acc--open .jd-req-acc__arrow { transform: rotate(90deg); }
.jd-req-acc__name { flex: 1; font-size: 0.82rem; color: var(--ink); }
.jd-req-acc__count { font-size: 0.65rem; color: var(--ink-faint); white-space: nowrap; }

.jd-req-acc__body { padding: 0.3rem 0 0.5rem 1rem; border-bottom: 1px solid #ebe6df; }

.jd-conf { flex-shrink: 0; font-size: 0.68rem; font-weight: 400; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.15rem 0.45rem; border-radius: 3px; }
.jd-conf--strong { background: #5a7a4f22; color: #4a6a3f; }
.jd-conf--partial { background: #8b735522; color: #7a6345; }
.jd-conf--none { background: #9e989022; color: #8a8280; }

.jd-evidence { padding: 0.4rem 0 0.2rem 0.8rem; border-left: 2px solid var(--stone); margin-top: 0.3rem; display: flex; flex-direction: column; gap: 0.35rem; }
.jd-evidence__item { font-size: 0.75rem; }
.jd-evidence__link { color: var(--accent); text-decoration: none; font-size: 0.72rem; word-break: break-all; }
.jd-evidence__link:hover { text-decoration: underline; }
.jd-evidence__ctx { font-size: 0.7rem; color: var(--ink-light); line-height: 1.45; margin-top: 0.1rem; }
