/* Browser demo page. Tokens and shared components come from site.css.
   Class names marked (js) are toggled or created by assets/js/demo.js. */

:root {
  --c0: #2459e0;
  --c1: #d98f00;
  --c2: #0b8f7c;
  --c3: #d9482b;
  --hl: rgba(255, 217, 61, 0.55);
}
@media (prefers-color-scheme: dark) {
  :root {
    --c0: #8fadff;
    --c1: #ffd93d;
    --c2: #4cd4bf;
    --c3: #ff8b6b;
    --hl: rgba(255, 217, 61, 0.28);
  }
}

.demo-main { padding-block: clamp(2.5rem, 5vw, 4.5rem) clamp(4rem, 8vw, 7rem); }
.demo-head h1 { font-size: clamp(2.4rem, 1.2rem + 4.2vw, 4.75rem); margin-top: clamp(1.25rem, 2.5vw, 2rem); }
.demo-head .lead { margin-top: 1.25rem; }
.demo-step { margin-top: clamp(2.25rem, 4vw, 3.5rem); }

/* ── Book picker ──────────────────────────────────────── */
.demo-book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.book-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.8rem;
  min-height: 96px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background-color 0.15s, color 0.15s;
}
.book-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.book-card.selected { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.book-card.selected::after {
  content: "";
  position: absolute;
  top: 0.8rem; right: 0.8rem;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--mark);
}
.book-card-title { font: 700 1.05rem/1.25 var(--f-display); letter-spacing: -0.01em; word-spacing: 0.06em; }
.book-card-author { font: 500 0.7rem/1.3 var(--f-mono); letter-spacing: 0.05em; text-transform: uppercase; color: var(--fg-3); }
.book-card.selected .book-card-author { color: inherit; opacity: 0.78; }
.book-card-custom { display: flex; flex-direction: column; justify-content: space-between; gap: 0.8rem; height: 100%; }
.book-card-custom-icon svg { width: 22px; height: 22px; }

.custom-text-container {          /* (js) .visible */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.5s ease, opacity 0.35s, margin 0.35s;
}
.custom-text-container.visible { max-height: 320px; opacity: 1; margin-top: 0.75rem; }
.custom-textarea {
  display: block;
  width: 100%;
  min-height: 200px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font: 400 1rem/1.6 var(--f-body);
  resize: vertical;
}
.custom-textarea::placeholder { color: var(--fg-3); opacity: 1; }

/* ── Model note, start button, progress ───────────────── */
.model-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-top: clamp(1.5rem, 3vw, 2.25rem);
  color: var(--fg-2);
  font-size: 0.9375rem;
}
.model-info-badge {
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font: 500 0.68rem/1 var(--f-mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--fg);
  white-space: nowrap;
}
.demo-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; margin-top: 1.25rem; min-height: 48px; }
#startBtn.loading { cursor: progress; }                 /* (js) .loading */
#startBtn:disabled { opacity: 0.75; }
.btn-spinner { display: none; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }
#startBtn.loading .btn-spinner { display: inline-block; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-text { min-height: 1.4em; font: 400 0.8125rem/1.4 var(--f-mono); color: var(--fg-3); }
.status-text.active { color: var(--fg); }                /* (js) .active */
.progress-bar-container {                                /* (js) .visible */
  flex-basis: 100%;
  max-width: 420px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.25s;
}
.progress-bar-container.visible { opacity: 1; }
.progress-bar-fill { width: 0; height: 100%; background: var(--accent-fill); transition: width 0.35s ease; }

/* ── Search ───────────────────────────────────────────── */
.demo-search-area {                                      /* (js) .visible */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.6s ease, opacity 0.45s;
}
.demo-search-area.visible { max-height: 4000px; opacity: 1; overflow: visible; margin-top: clamp(2.25rem, 4vw, 3.5rem); }

.search-input-wrapper { position: relative; margin-top: 1.25rem; }
.search-icon { position: absolute; left: 1.1rem; top: 50%; width: 22px; height: 22px; translate: 0 -50%; color: var(--fg-3); pointer-events: none; }
.search-input {
  width: 100%;
  min-height: 68px;
  padding: 0 1.25rem 0 3.4rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font: 600 clamp(1.15rem, 1rem + 0.8vw, 1.6rem)/1.2 var(--f-display);
  letter-spacing: -0.02em;
}
.search-input::placeholder { color: var(--fg-3); opacity: 1; font-weight: 500; }
.search-input:focus { outline: 3px solid var(--accent); outline-offset: 2px; }

.suggestion-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.9rem; }
.suggestion-chip {
  min-height: 40px;
  padding: 0.4rem 0.95rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font: 500 0.9rem/1.2 var(--f-body);
  text-align: left;
  transition: background-color 0.15s, color 0.15s;
}
.suggestion-chip:hover { background: var(--mark); border-color: var(--mark); color: var(--on-mark); }

/* Keyword vs meaning */
.showdown-panel { display: none; margin-top: 1.5rem; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); overflow: hidden; }
.showdown-panel.visible { display: block; }                /* (js) .visible */
.showdown-header, .meaning-map-header, .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line-strong);
  min-height: 46px;
}
.showdown-title, .meaning-map-title, .panel-label, .results-label {
  font: 500 0.72rem/1.3 var(--f-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.showdown-query, .meaning-map-meta, .panel-meta, .results-count { font: 400 0.75rem/1.3 var(--f-mono); color: var(--fg-3); }
.showdown-query { max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.showdown-grid { display: grid; grid-template-columns: 1fr 1fr; }
.showdown-column + .showdown-column { border-left: 1px solid var(--line); }
.showdown-column-label { padding: 0.7rem 1rem 0.4rem; font: 500 0.68rem/1.3 var(--f-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.showdown-item {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}
.showdown-item:hover { background: var(--bg-2); }
.showdown-item-source { display: block; font: 500 0.68rem/1.3 var(--f-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-3); }
.showdown-item-text { display: -webkit-box; margin-top: 0.25rem; font-size: 0.875rem; line-height: 1.5; color: var(--fg-2); -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Meaning map */
.meaning-map { margin-top: 1rem; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); overflow: hidden; }
.meaning-map-plot {
  position: relative;
  height: 240px;
  background-color: var(--bg-2);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px;
}
.map-node {
  position: absolute;
  z-index: 1;
  width: 10px; height: 10px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fg-3);
  transform: translate(-50%, -50%);
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.map-node::after { content: ""; position: absolute; inset: -9px; }   /* larger tap target */
.map-node[data-cluster="0"] { background: var(--c0); }
.map-node[data-cluster="1"] { background: var(--c1); }
.map-node[data-cluster="2"] { background: var(--c2); }
.map-node[data-cluster="3"] { background: var(--c3); }
.map-node:hover { transform: translate(-50%, -50%) scale(1.5); }
.map-node.cluster-muted { opacity: 0.22; }                 /* (js) */
.map-node.cluster-active { transform: translate(-50%, -50%) scale(1.3); z-index: 2; }
.map-node.top-hit { transform: translate(-50%, -50%) scale(1.7); z-index: 3; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg); }
.map-query-pulse {
  position: absolute;
  z-index: 4;
  width: 16px; height: 16px;
  border: 2px solid var(--fg);
  border-radius: 50%;
  background: var(--mark);
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}
.map-query-pulse.active { opacity: 1; }                    /* (js) */
@media (prefers-reduced-motion: no-preference) {
  .map-query-pulse.active { animation: pulse 1.4s ease-out infinite; }
  @keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 217, 61, 0.7); } 100% { box-shadow: 0 0 0 20px rgba(255, 217, 61, 0); } }
}

/* ── Results and full text ────────────────────────────── */
.panel-tabs { display: none; }
.panel-tab {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: transparent;
  color: var(--fg-2);
  font: 500 0.75rem/1 var(--f-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.panel-tab.active { background: var(--fg); color: var(--bg); }  /* (js) */

.split-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: min(640px, calc(100vh - 220px));
  min-height: 420px;
  margin-top: 1rem;
}
.panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); overflow: hidden; }
.panel-header { flex: none; }
.panel-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.panel-book .panel-scroll { padding: 0.5rem 1rem 1rem; }
.results-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; }

.book-section-header { margin: 1.25rem 0 0.4rem; font: 500 0.68rem/1.3 var(--f-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.book-section-header:first-child { margin-top: 0.5rem; }
.book-chunk {                                              /* (js) .highlighted .highlight-flash */
  margin: 0 -0.6rem;
  padding: 0.55rem 0.6rem;
  border-radius: 3px;
  color: var(--fg-2);
  font-size: 0.95rem;
  line-height: 1.75;
  cursor: pointer;
  transition: background-color 0.15s;
}
.book-chunk:hover { background: var(--bg-2); }
.book-chunk.highlighted { background: var(--hl); color: var(--fg); }
@media (prefers-reduced-motion: no-preference) {
  .book-chunk.highlight-flash { animation: flash 1.6s ease-out; }
  @keyframes flash { from { background: var(--mark); } }
}

.results-grid { display: flex; flex-direction: column; }
.result-card {                                             /* (js) .active */
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background-color 0.15s;
}
@media (prefers-reduced-motion: no-preference) {
  .result-card { animation: resultIn 0.4s ease both; }
  @keyframes resultIn { from { opacity: 0; transform: translateY(8px); } }
}
.result-card:hover { background: var(--bg-2); }
.result-card.active { background: var(--hl); box-shadow: inset 3px 0 0 var(--fg); }
.result-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.5rem; }
.result-card-actions { display: inline-flex; align-items: center; gap: 0.75rem; }
.result-source { font: 500 0.7rem/1.3 var(--f-mono); letter-spacing: 0.07em; text-transform: uppercase; color: var(--fg-3); }
.result-score { white-space: nowrap; padding: 0.2rem 0.5rem; border: 1px solid currentColor; border-radius: 999px; font: 500 0.7rem/1 var(--f-mono); }
.result-score.high { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.result-score.medium { color: var(--fg); }
.result-score.low { color: var(--fg-3); }
.result-similar-btn {
  min-height: 32px;
  white-space: nowrap;
  padding: 0 0.2rem;
  border: 0;
  background: none;
  color: var(--accent);
  font: 600 0.8125rem/1 var(--f-body);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
.result-similar-btn:hover { color: var(--fg); }
.result-text { display: -webkit-box; font-size: 0.9375rem; line-height: 1.6; color: var(--fg-2); -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.result-card.active .result-text { -webkit-line-clamp: unset; color: var(--fg); }

.results-empty { padding: 3rem 1.25rem; text-align: center; color: var(--fg-3); font-size: 0.9375rem; }
.results-empty-icon { width: 40px; height: 40px; margin: 0 auto 1rem; opacity: 0.6; }
.search-loading { display: none; align-items: center; justify-content: center; gap: 0.5rem; padding: 2rem; }
.search-loading.visible { display: flex; }                  /* (js) */
.search-loading-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg); }
@media (prefers-reduced-motion: no-preference) {
  .search-loading-dot { animation: dots 1.2s ease-in-out infinite; }
  .search-loading-dot:nth-child(2) { animation-delay: 0.15s; }
  .search-loading-dot:nth-child(3) { animation-delay: 0.3s; }
  @keyframes dots { 0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
}

/* ── Small screens ────────────────────────────────────── */
@media (max-width: 860px) {
  .demo-book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* demo.js switches to its one-panel-at-a-time mode at 768px, so the layout must match. */
@media (max-width: 768px) {
  .showdown-grid { grid-template-columns: 1fr; }
  .showdown-column + .showdown-column { border-left: 0; border-top: 1px solid var(--line-strong); }
  .showdown-query { max-width: 50%; }
  .panel-tabs { display: flex; gap: 0.5rem; margin-top: 1rem; }
  .split-panel { grid-template-columns: 1fr; height: auto; min-height: 0; margin-top: 0.75rem; }
  .panel-book { display: none; height: 520px; }               /* (js) .panel-visible / .panel-hidden */
  .panel-book.panel-visible { display: flex; }
  .panel-results { min-height: 360px; }
  .panel-results.panel-hidden { display: none; }
  .panel-results .panel-scroll { max-height: 70vh; }
  .meaning-map-plot { height: 200px; }
}
@media (max-width: 480px) {
  .book-card { min-height: 88px; padding: 0.85rem; }
  .book-card-title { font-size: 0.98rem; }
  .meaning-map-header { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
}
