/* ==========================================================================
   Context — design system
   Everything is offline: system font stacks only, no external requests.
   ========================================================================== */

:root {
  /* Type */
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
                "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  /* Light palette — warm paper, deep teal accent */
  --bg:          #f4f3ef;
  --bg-alt:      #eceae4;
  --surface:     #ffffff;
  --surface-2:   #faf9f6;
  --ink:         #17191c;
  --ink-2:       #414750;
  --muted:       #757c86;
  --line:        #e0ddd6;
  --line-strong: #cbc7bd;
  --accent:      #1e5d53;
  --accent-soft: #e3efec;
  --accent-ink:  #ffffff;
  --network-label-halo: rgba(0, 0, 0, .28);
  --warm:        #a8551f;
  --warm-soft:   #f7e9dd;
  --danger:      #9d2f2f;
  --ok:          #2b6a4a;
  --shadow-sm: 0 1px 2px rgba(20,22,26,.06), 0 1px 3px rgba(20,22,26,.05);
  --shadow-md: 0 2px 4px rgba(20,22,26,.05), 0 8px 24px rgba(20,22,26,.08);
  --radius: 10px;
  --radius-sm: 6px;

  /* Categorical series — checked for distinguishability in both themes */
  --s1: #1e5d53; --s2: #a8551f; --s3: #3f5b8c; --s4: #7a4b78;
  --s5: #55702c; --s6: #99632a; --s7: #2f6f7d; --s8: #8c3f4a;
}

[data-theme="dark"] {
  --bg:          #121417;
  --bg-alt:      #171a1e;
  --surface:     #1b1e23;
  --surface-2:   #21252b;
  --ink:         #e9e7e2;
  --ink-2:       #c3c7ce;
  --muted:       #8a919c;
  --line:        #2b3037;
  --line-strong: #3b424b;
  --accent:      #58b7a4;
  --accent-soft: #17322e;
  --accent-ink:  #0d1211;
  --network-label-halo: rgba(255, 255, 255, .34);
  --warm:        #d99257;
  --warm-soft:   #33241a;
  --danger:      #e08585;
  --ok:          #6fc39a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 2px 4px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.45);

  --s1: #58b7a4; --s2: #d99257; --s3: #7f9ede; --s4: #c08fc0;
  --s5: #9fc064; --s6: #d9b061; --s7: #6fbccb; --s8: #dd8b96;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }

a { color: var(--accent); }

/* --- App shell ----------------------------------------------------------- */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 56px; flex: 0 0 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .mark {
  font-family: var(--font-serif); font-size: 19px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.02em;
}
.brand .mark em { font-style: normal; color: var(--accent); }
.brand .sub { font-size: 12px; color: var(--muted); letter-spacing: .02em; }

.topbar .spacer { flex: 1; }

.corpus-chip {
  display: none; align-items: center; gap: 10px;
  padding: 5px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface-2);
  font-size: 12.5px; color: var(--ink-2);
}
.corpus-chip.on { display: inline-flex; }
.corpus-chip b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.corpus-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

.layout { display: flex; flex: 1; min-height: 0; }

/* --- Sidebar ------------------------------------------------------------- */

.sidebar {
  width: 320px; flex: 0 0 320px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 18px 40px;
}
.sidebar::-webkit-scrollbar, .main::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.sidebar::-webkit-scrollbar-thumb, .main::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 6px;
  border: 3px solid var(--surface);
}

.panel + .panel { margin-top: 22px; }
.panel-title {
  font-size: 11px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}
.panel-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Drop zone */
.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 20px 14px; text-align: center;
  background: var(--surface-2);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.hot { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-icon { font-size: 20px; opacity: .5; }
.dropzone .dz-main { font-size: 13.5px; font-weight: 600; margin-top: 4px; }
.dropzone .dz-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.filelist { list-style: none; margin: 10px 0 0; padding: 0; }
.filelist li {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; padding: 5px 8px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
}
.filelist li + li { margin-top: 5px; }
.filelist .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .fmeta { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.filelist .fx {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px;
}
.filelist .fx:hover { color: var(--danger); }

/* Form controls */
.field { margin-bottom: 12px; }
.field label, .lbl {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--ink-2); margin-bottom: 5px;
}
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.45; }

.language-status {
  margin: -2px 0 10px; padding: 8px 9px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-2);
  font-size: 11.5px; line-height: 1.45;
}
.language-status strong { color: var(--accent); font-weight: 700; }

.structured-panel {
  padding: 13px; border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
  border-radius: var(--radius); background: color-mix(in srgb, var(--accent-soft) 42%, var(--surface));
}
.structure-summary {
  margin-bottom: 12px; padding: 9px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-2); font-size: 12px; line-height: 1.45;
}
.structure-summary b { color: var(--ink); }
.dataset-citation { display: inline-block; margin-top: 5px; font-size: 11px; color: var(--muted); }
.dataset-citation a { color: var(--accent); }
.dataset-notice { display: inline-block; margin-top: 6px; font-size: 10.5px; color: var(--muted); line-height: 1.45; }
.quran-controls {
  margin: 10px 0; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
.quran-controls[hidden] { display: none; }
.structure-status { margin-top: 8px; }
.structure-status.busy { color: var(--accent); font-weight: 600; }
.filelist .fname[data-structured="true"] { cursor: pointer; color: var(--accent); font-weight: 600; }

.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; margin-left: 6px; padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font: 800 10px/1 var(--font-sans); vertical-align: 2px; cursor: help;
}
.info-dot:hover, .info-dot:focus, .info-dot[aria-expanded="true"] {
  outline: none; background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

input[type="text"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: 7px 10px;
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 90px; font-size: 13px; line-height: 1.5; }
select { appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 28px;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.check input { margin: 3px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.check span { color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; font-family: inherit; font-size: 13.5px; font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  width: 100%; padding: 10px 14px; font-size: 14px;
}
.btn-primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; font-weight: 500; }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }

.icon-btn {
  width: 32px; height: 32px; padding: 0; display: inline-flex;
  align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.linkrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip-btn {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface-2);
  color: var(--ink-2); cursor: pointer; font-family: inherit;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.demo-chip { border-color: color-mix(in srgb, var(--accent) 38%, var(--line)); }

.demo-guide {
  display: grid; grid-template-columns: minmax(230px, .72fr) minmax(420px, 1.28fr);
  gap: 20px; padding: 20px; margin: 0 0 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  border-radius: calc(var(--radius) + 3px);
  background:
    radial-gradient(circle at 0 0, color-mix(in srgb, var(--accent) 16%, transparent), transparent 46%),
    linear-gradient(135deg, var(--surface), var(--surface-2));
  box-shadow: var(--shadow-sm);
}
.demo-guide[hidden] { display: none; }
.demo-copy { align-self: center; }
.demo-kicker { color: var(--accent); font-size: 10.5px; font-weight: 750; letter-spacing: .13em; }
.demo-copy h3 { margin: 7px 0 7px; font-size: 21px; line-height: 1.18; max-width: 24ch; }
.demo-copy p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.55; max-width: 48ch; }
.demo-copy .demo-source { margin-top: 7px; font-size: 11px; }
.demo-source a { color: var(--accent); font-weight: 600; }
.demo-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.demo-actions button {
  min-width: 0; text-align: left; padding: 10px 11px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--ink);
  font: inherit; transition: border-color .14s, transform .14s, background .14s;
}
.demo-actions button:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.demo-guide[dir="rtl"] { text-align: right; }
.demo-guide[dir="rtl"] .demo-copy h3 { max-width: 28ch; }
.demo-guide[dir="rtl"] .demo-actions button { text-align: right; }
.arabic-demo #targetWord, .arabic-demo #concQuery, .arabic-demo #collQuery,
.arabic-demo #netQuery, .arabic-demo #dispQuery, .arabic-demo #trendTerms { direction: rtl; text-align: right; }
.arabic-demo .fname, .arabic-demo td.term { direction: rtl; text-align: right; }
.demo-actions span { display: block; font-size: 12.5px; font-weight: 650; }
.demo-actions small { display: block; margin-top: 2px; color: var(--muted); font-size: 10.5px; line-height: 1.35; }
.report-btn { white-space: nowrap; }
.section-label { font-size: 13px; margin: 0 0 9px; color: var(--ink-2); }
.lab-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 18px 20px; margin: 2px 0 16px; border: 1px solid color-mix(in srgb, var(--warm) 42%, var(--line));
  border-radius: var(--radius); background: linear-gradient(135deg, color-mix(in srgb, var(--warm) 10%, var(--surface)), var(--surface));
}
.lab-banner h3 { margin: 5px 0 3px; font-size: 20px; }
.lab-banner p { margin: 0; color: var(--muted); font-size: 12.5px; }
.lab-banner .field { min-width: 210px; margin: 0; }
.explore-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 18px; }
.trend-heatmap { overflow-x: auto; padding-bottom: 4px; }
.hm-grid { display: grid; grid-template-columns: minmax(170px, 1.7fr) repeat(var(--hm-cols), minmax(70px, .7fr)); gap: 4px; min-width: 620px; align-items: stretch; }
.hm-grid > b { text-align: center; padding: 6px 4px; font-size: 11px; color: var(--ink-2); }
.hm-doc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 7px 8px; font-size: 11px; color: var(--muted); }
.hm-cell { display: flex; align-items: center; justify-content: center; min-height: 31px; border-radius: 4px;
  background: color-mix(in srgb, var(--accent) calc(var(--heat) * 100%), var(--surface-2)); color: var(--ink); font-size: 11px; font-weight: 650; }
.diff-head, .diff-row { display: grid; grid-template-columns: minmax(180px,1fr) minmax(110px,.45fr) minmax(180px,1fr); align-items: center; gap: 10px; }
.diff-head { color: var(--muted); font-size: 10.5px; text-align: center; margin-bottom: 7px; text-transform: uppercase; letter-spacing: .06em; }
.diff-row { min-height: 29px; border-top: 1px solid var(--line); }
.diff-row strong { font-size: 11.5px; text-align: center; overflow: hidden; text-overflow: ellipsis; }
.diff-side { height: 18px; position: relative; display: flex; align-items: center; font-size: 9.5px; color: var(--muted); }
.diff-side i { position: absolute; top: 2px; bottom: 2px; min-width: 1px; border-radius: 3px; opacity: .76; }
.diff-side span { position: relative; z-index: 1; }
.diff-side.ref { justify-content: flex-end; text-align: right; }.diff-side.ref i { right: 0; background: var(--warm); }.diff-side.ref span { padding-right: 5px; }
.diff-side.study { justify-content: flex-start; }.diff-side.study i { left: 0; background: var(--accent); }.diff-side.study span { padding-left: 5px; }
.cql-builder { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }.cql-builder .field { flex: 1; min-width: 260px; margin: 0; }
.cql-examples { display: flex; flex-wrap: wrap; gap: 5px; padding-bottom: 2px; }
.annotation-results { margin-top: 12px; max-height: 620px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.ann-row { display: grid; grid-template-columns: minmax(340px,1fr) 100px minmax(170px,.55fr); gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); align-items: center; }
.ann-row:last-child { border-bottom: 0; }.ann-row input { padding: 6px 7px; font-size: 11.5px; }
.ann-kwic { min-width: 0; font-family: var(--font-mono); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ann-kwic mark { color: var(--accent); background: var(--accent-soft); font-weight: 750; padding: 2px 3px; }.ann-kwic small { display: block; color: var(--muted); font-family: var(--font-sans); margin-top: 3px; }

/* --- Main area ----------------------------------------------------------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tabs {
  display: flex; gap: 2px; padding: 0 20px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--line);
  flex: 0 0 auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; font-family: inherit; font-size: 13.5px;
  color: var(--muted); padding: 11px 13px; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab[disabled] { opacity: .38; cursor: not-allowed; }

.views { flex: 1; overflow-y: auto; padding: 22px 24px 60px; }
.view { display: none; max-width: 1180px; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 16px; }
.view-head h2 { font-size: 21px; }
.view-head p { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; max-width: 68ch; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  margin-bottom: 18px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.card-head h3 { font-size: 15px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

/* Stat grid */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
         background: var(--surface); border-radius: var(--radius); overflow: hidden;
         border: 1px solid var(--line); }
/* Borders on the cells rather than a gap, so a partly-filled last row does not
   leave a block of divider colour showing through. */
.stat { background: var(--surface); padding: 13px 15px;
        border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat .k { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums;
           letter-spacing: -.02em; margin-top: 3px; font-family: var(--font-serif); }
.stat .n { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.stat.accent .v { color: var(--accent); }

/* Tables */
.table-wrap { overflow: auto; max-height: 620px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); text-align: left;
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
  padding: 9px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--accent); }
table.data th .arrow { opacity: .35; margin-left: 3px; font-size: 9px; }
table.data th.sorted .arrow { opacity: 1; color: var(--accent); }
table.data td { padding: 7px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.term { font-weight: 600; }
table.data td.mono { font-family: var(--font-mono); font-size: 12px; }
table.data .idx { color: var(--muted); font-variant-numeric: tabular-nums; width: 42px; }

/* In-cell bar */
.cellbar { position: relative; min-width: 90px; }
.cellbar .fill {
  position: absolute; left: 0; top: 3px; bottom: 3px;
  background: var(--accent-soft); border-radius: 2px; z-index: 0;
}
.cellbar .fill.neg { background: var(--warm-soft); }
.cellbar span { position: relative; z-index: 1; padding-left: 6px; font-variant-numeric: tabular-nums; }

.sig { font-size: 10.5px; padding: 1px 5px; border-radius: 3px; background: var(--accent-soft);
       color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.sig.none { background: var(--bg-alt); color: var(--muted); }
.tag-neg { color: var(--warm); }

/* KWIC */
.kwic { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 12.5px; }
.kwic td { padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.kwic tr:hover { background: var(--accent-soft); }
.kwic .kl { text-align: right; direction: rtl; max-width: 44%; overflow: hidden;
            text-overflow: ellipsis; color: var(--ink-2); }
.kwic .kl > span { direction: ltr; unicode-bidi: embed; }
.kwic .kn { text-align: center; font-weight: 700; color: var(--accent); padding: 4px 10px;
            background: var(--accent-soft); }
.kwic .kr { max-width: 44%; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.kwic .kdoc { color: var(--muted); font-size: 11px; text-align: right; }

/* Charts */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font-sans); fill: var(--muted); font-size: 11px; }
.chart .axis line, .chart .axis path { stroke: var(--line); }
.chart .grid line { stroke: var(--line); stroke-dasharray: 2 3; }
.chart .bar { fill: var(--accent); }
.chart .bar.neg { fill: var(--warm); }
.chart .bar:hover { filter: brightness(1.15); }
.chart .label { fill: var(--ink-2); font-size: 11.5px; }
.chart .dot { stroke: var(--surface); stroke-width: 1.2; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 5px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 100;
  background: var(--ink); color: var(--bg);
  padding: 6px 9px; border-radius: 5px; font-size: 12px; line-height: 1.4;
  box-shadow: var(--shadow-md); opacity: 0; transition: opacity .1s;
  max-width: 260px;
}
.tooltip.on { opacity: 1; }
.tooltip b { color: #fff; }
[data-theme="dark"] .tooltip { background: #2f343c; color: var(--ink); }

/* Word cloud */
#cloudCanvas { display: block; margin: 0 auto; max-width: 100%; }

/* Dispersion strip */
.dispersion-strip { position: relative; height: 44px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.dispersion-strip i { position: absolute; top: 6px; bottom: 6px; width: 2px;
  background: var(--accent); opacity: .75; }

/* Topics */
.topic-card { border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; background: var(--surface); }
.topic-card { cursor: pointer; transition: border-color .15s, transform .15s; }
.topic-card:hover, .topic-card.selected { border-color: var(--accent); transform: translateY(-1px); }
.topic-evidence { border-left: 3px solid var(--accent); padding: 8px 10px; margin: 9px 0; background: var(--surface-2); border-radius: 0 7px 7px 0; font-size: 12.5px; line-height: 1.5; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.topic-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.topic-head .tnum { font-size: 11px; font-weight: 700; color: var(--accent-ink);
  background: var(--accent); border-radius: 4px; padding: 1px 6px; }
.topic-head .tshare { margin-left: auto; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; }
.term-bar { display: flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 12.5px; }
.term-bar .tw { width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-bar .tt { flex: 1; height: 6px; background: var(--bg-alt); border-radius: 3px; overflow: hidden; }
.term-bar .tt i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* Visual Lab */
.visual-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.visual-grid .card { margin: 0; min-width: 0; }
.visual-grid .span-2 { grid-column: span 2; }
.visual-hero { border-color: color-mix(in srgb, var(--accent) 34%, var(--line)); }
.visual-callout { font-size: 13px; color: var(--muted); line-height: 1.55; }
.visual-callout b { color: var(--ink); }
.visual-tall { min-height: 420px; }
.rhythm-detail { margin-top: 12px; padding: 11px 13px; min-height: 48px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.rhythm-detail b { color: var(--ink); margin-right: 8px; }
.rhythm-detail span { color: var(--muted); font-size: 11px; }
.rhythm-detail p { color: var(--ink-2); margin: 6px 0 0; }
.cloud-canvas { display: block; width: 100%; height: 260px; max-width: 100%; }
.empty.compact { min-height: 140px; padding: 35px 18px; }
.empty.compact p { margin: 0; }

/* Misc */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .big { font-size: 30px; opacity: .35; }
.empty h3 { font-size: 17px; color: var(--ink-2); margin: 10px 0 5px; }
.empty p { font-size: 13.5px; max-width: 46ch; margin: 0 auto; }

.note {
  font-size: 12.5px; color: var(--ink-2); background: var(--surface-2);
  border-left: 3px solid var(--line-strong); padding: 9px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 12px 0 0; line-height: 1.5;
}
.note.warn { border-left-color: var(--warm); background: var(--warm-soft); }
.note b { color: var(--ink); }

.inline-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.inline-controls label { font-size: 12px; color: var(--muted); font-weight: 600; }
.inline-controls input[type="text"], .inline-controls input[type="search"] { width: 190px; }
.inline-controls input[type="number"] { width: 74px; }
.inline-controls select { width: auto; min-width: 120px; }

/* Integrated analysis extensions. JavaScript remains lazy-loaded for speed. */
.extension-launch { display: flex; align-items: center; justify-content: space-between; gap: 18px;
  margin: 16px 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(120deg, var(--surface), var(--accent-soft)); }
.extension-launch b { display: block; color: var(--ink); font-size: 13px; }
.extension-launch span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.extension-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.context-extension { margin: 16px 0 26px; scroll-margin-top: 24px; }
.context-extension[hidden] { display: none; }
.context-extension > .card:first-child, .context-extension > .wb-grid > .card { margin-top: 0; }
.wb-grid { display: grid; grid-template-columns: minmax(270px, .75fr) minmax(0, 1.75fr); gap: 16px; }
.wb-grid.equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wb-controls .field { margin-bottom: 11px; }
.wb-controls textarea { min-height: 96px; resize: vertical; }
.wb-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.wb-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: 8px; margin: 12px 0; }
.wb-metric { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.wb-metric b { display: block; font-size: 17px; color: var(--ink); }
.wb-metric span { font-size: 11px; color: var(--muted); }
.wb-chart { min-height: 270px; }
.wb-boxplot { min-height: 115px; margin: 4px 0 18px; }
.wb-boxplot svg { width: 100%; height: auto; overflow: visible; }
.wb-code { font: 12px/1.5 var(--font-mono); direction: ltr; text-align: left; white-space: pre-wrap;
  padding: 10px 12px; border-radius: 7px; background: var(--bg-alt); color: var(--ink-2); }
.wb-highlight { background: color-mix(in srgb, var(--warm) 35%, transparent); color: var(--ink); border-radius: 2px; padding: 0 1px; }
.wb-reader { font-size: 15px; line-height: 1.75; max-height: 520px; overflow: auto; white-space: pre-wrap;
  padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.wb-reader mark { background: color-mix(in srgb, var(--warm) 30%, transparent); color: var(--ink); border-radius: 3px; padding: 1px 2px; }
.wb-reader mark.active { outline: 2px solid var(--warm); outline-offset: 2px; }
.wb-token-tag { display: inline-block; margin-inline: 3px; padding: 0 3px; border: 1px solid var(--line);
  border-radius: 3px; color: var(--muted); background: var(--surface-2); font: 9px/1.5 var(--font-mono); vertical-align: .15em; }
.wb-report-frame { width: 100%; min-height: 680px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.wb-report-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 12px; }
.wb-colloc-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(310px, .75fr); gap: 16px; }
.wb-mini-bars { display: grid; gap: 6px; }
.wb-mini-bar { display: grid; grid-template-columns: minmax(90px, 1fr) 4fr auto; gap: 8px; align-items: center; font-size: 12px; }
.wb-mini-bar i { display: block; height: 8px; border-radius: 4px; background: var(--accent); }
.wb-mini-bar b { font-variant-numeric: tabular-nums; font-weight: 600; }
.wb-table-note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }

@media (max-width: 1050px) {
  .wb-grid, .wb-grid.equal, .wb-colloc-layout { grid-template-columns: 1fr; }
}

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.3);
  display: none; align-items: center; justify-content: center; z-index: 200;
  backdrop-filter: blur(2px);
}
.overlay.on { display: flex; }
.overlay .box {
  background: var(--surface); border-radius: var(--radius); padding: 24px 30px;
  box-shadow: var(--shadow-md); text-align: center; min-width: 260px;
}
.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay .box p { margin: 0; font-size: 13.5px; color: var(--ink-2); }

.modal { position: fixed; inset: 0; z-index: 210; display: none; }
.modal.on { display: block; }
.modal .scrim { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.modal .sheet {
  position: relative; margin: 6vh auto; max-width: 620px; max-height: 88vh;
  overflow: auto; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 24px 26px;
}
.modal h2 { font-size: 19px; margin-bottom: 6px; }
.modal h4 { font-size: 13.5px; margin: 18px 0 4px; font-family: var(--font-sans); font-weight: 700; }
.modal p, .modal li { font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.modal code { font-family: var(--font-mono); font-size: 12px; background: var(--bg-alt);
  padding: 1px 5px; border-radius: 3px; }
.extension-modal { z-index: 220; }
.extension-modal .sheet { max-width: min(1180px, 94vw); margin: 3vh auto; max-height: 94vh; padding: 26px; }
.extension-close { position: sticky; z-index: 2; top: 0; float: right; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink);
  font: 24px/1 var(--font-sans); cursor: pointer; box-shadow: var(--shadow-sm); }
.extension-modal .context-extension { clear: both; margin: 6px 0 0; }

@media (max-width: 900px) {
  .extension-launch { align-items: stretch; flex-direction: column; }
  .extension-actions { justify-content: flex-start; }
  .visual-grid { grid-template-columns: 1fr; }
  .visual-grid .span-2 { grid-column: span 1; }
  .demo-guide { grid-template-columns: 1fr; }
  .explore-grid { grid-template-columns: 1fr; }
  .lab-banner { align-items: stretch; flex-direction: column; }
  .ann-row { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; max-height: 46vh; border-right: 0;
             border-bottom: 1px solid var(--line); }
  .views { padding: 16px; }
  .stat .v { font-size: 19px; }
}
