/* ============================================================================
   Judge Explorer — academic, theme-adaptive (follows device light/dark).
   Direction colors: blue = left, red = right (US convention).
   ========================================================================== */

:root {
  /* light theme (default) */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e0e3e8;
  --border-strong: #cdd2da;
  --text: #1b1f24;
  --text-soft: #5a6472;
  --text-faint: #8a94a3;
  --accent: #3b5bdb;
  --accent-soft: #e7ecfb;
  --left: #2563eb;
  --left-soft: #e3edfd;
  --right: #dc2626;
  --right-soft: #fce4e4;
  --good: #16a34a;
  --good-soft: #e3f4ea;
  --warn: #d97706;
  --warn-soft: #fbeed9;
  --bad: #dc2626;
  --bad-soft: #fce4e4;
  --purple: #7c3aed;
  --purple-soft: #efe7fc;
  --slate: #64748b;
  --slate-soft: #eaedf1;
  --shadow: 0 1px 2px rgba(20,28,40,.06), 0 2px 8px rgba(20,28,40,.05);
  --shadow-lg: 0 8px 30px rgba(20,28,40,.14);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1f242d;
    --border: #2a313c;
    --border-strong: #3a434f;
    --text: #e6e9ee;
    --text-soft: #a7b0bd;
    --text-faint: #707a88;
    --accent: #6f8bf5;
    --accent-soft: #1d2540;
    --left: #5b8cf0;
    --left-soft: #16233f;
    --right: #f06868;
    --right-soft: #3a1c1f;
    --good: #4ade80;
    --good-soft: #14301f;
    --warn: #f0b455;
    --warn-soft: #38290f;
    --bad: #f06868;
    --bad-soft: #3a1c1f;
    --purple: #a888f5;
    --purple-soft: #271a3e;
    --slate: #94a3b8;
    --slate-soft: #232a33;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.25);
    --shadow-lg: 0 10px 36px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #171b22; --surface-2: #1f242d; --border: #2a313c;
  --border-strong: #3a434f; --text: #e6e9ee; --text-soft: #a7b0bd; --text-faint: #707a88;
  --accent: #6f8bf5; --accent-soft: #1d2540; --left: #5b8cf0; --left-soft: #16233f;
  --right: #f06868; --right-soft: #3a1c1f; --good: #4ade80; --good-soft: #14301f;
  --warn: #f0b455; --warn-soft: #38290f; --bad: #f06868; --bad-soft: #3a1c1f;
  --purple: #a888f5; --purple-soft: #271a3e; --slate: #94a3b8; --slate-soft: #232a33;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.25);
  --shadow-lg: 0 10px 36px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ----------------------------- header ----------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand-title { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--text-faint); }
.tabs { display: flex; gap: 4px; margin-left: 8px; background: var(--surface-2);
  padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tab {
  border: 0; background: transparent; color: var(--text-soft);
  padding: 7px 16px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.tab[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab:hover { color: var(--text); }
.header-actions { margin-left: auto; display: flex; gap: 8px; }
.ghost-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  padding: 7px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.ghost-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* ----------------------------- layout ----------------------------- */
main { display: block; }
.view { display: grid; grid-template-columns: 290px 1fr; gap: 0; align-items: start; }
.view.view-single { display: block; }
.controls {
  position: sticky; top: 57px; align-self: start;
  height: calc(100vh - 57px); overflow-y: auto;
  padding: 18px 16px 60px; border-right: 1px solid var(--border);
  background: var(--surface);
}
.content { padding: 20px 24px 80px; min-width: 0; }

/* ----------------------------- control groups ----------------------------- */
.cgroup { margin-bottom: 20px; }
.cgroup > label, .clabel {
  display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-faint); margin-bottom: 8px;
}
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px;
  border-radius: 9px; border: 1px solid var(--border); }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--text-soft);
  padding: 8px 6px; border-radius: 6px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button.dir-left[aria-pressed="true"] { color: var(--left); }
.seg button.dir-right[aria-pressed="true"] { color: var(--right); }

select.input {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit;
}
input.search {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit;
}
input.search::placeholder { color: var(--text-faint); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all .12s; user-select: none;
}
.chip:hover { border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.config[aria-pressed="true"].dir-left { background: var(--left-soft); border-color: var(--left); color: var(--left); }
.chip.config[aria-pressed="true"].dir-right { background: var(--right-soft); border-color: var(--right); color: var(--right); }
.chip.config[aria-pressed="true"].dir-none { background: var(--slate-soft); border-color: var(--slate); color: var(--text); }
.chip-count { font-size: 10.5px; color: var(--text-faint); font-weight: 600; }

.reset-link { background: none; border: 0; color: var(--accent); font-size: 12px;
  cursor: pointer; padding: 0; font-weight: 600; }

/* ----------------------------- stats ----------------------------- */
.stats-wrap { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 18px; }
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); font-weight: 700; }
.stat-card .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-card .delta { font-size: 11.5px; font-weight: 600; margin-top: 2px; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--text-faint); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.panel-head h3 { margin: 0; font-size: 14px; font-weight: 700; }
.panel-note { font-size: 11.5px; color: var(--text-faint); }
.panels-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }

/* ----------------------------- results bar ----------------------------- */
.results-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.results-count { font-size: 13px; color: var(--text-soft); }
.results-count b { color: var(--text); }
.results-bar .spacer { flex: 1; }
.mini-select { padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 12.5px; }

/* ----------------------------- cards ----------------------------- */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.card-id { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.card-ans { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.card-ans b { color: var(--text); }
.card-top .spacer { flex: 1; }
.conf { display: inline-flex; gap: 1px; color: var(--warn); font-size: 12px; }
.card-body { padding: 14px 16px; }
.field-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); font-weight: 700; margin: 0 0 5px; }
.prompt-text { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; max-height: 160px; overflow: auto; margin-bottom: 12px; }
.response-text { font-size: 13px; white-space: pre-wrap; line-height: 1.55;
  border-left: 3px solid var(--border-strong); padding: 2px 0 2px 12px; margin-bottom: 6px; }
.response-text.clamped { max-height: 92px; overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent); }
.toggle-more { background: none; border: 0; color: var(--accent); font-size: 12px;
  font-weight: 600; cursor: pointer; padding: 2px 0; }
.judge-box { margin-top: 12px; background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: 10px 12px; }
.judge-box .field-label { color: var(--accent); }
.judge-reason { font-size: 12.5px; color: var(--text); }
.judge-quote { font-style: italic; color: var(--text-soft); font-size: 12.5px;
  border-left: 2px solid var(--accent); padding-left: 8px; margin-top: 6px; }

/* label chips on cards */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid transparent; }
.tag .dot { width: 7px; height: 7px; border-radius: 50%; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.purple { background: var(--purple-soft); color: var(--purple); }
.tag.slate { background: var(--slate-soft); color: var(--text-soft); }
.tag.left { background: var(--left-soft); color: var(--left); }
.tag.right { background: var(--right-soft); color: var(--right); }
.tag.neutral { background: var(--surface-2); color: var(--text-soft); border-color: var(--border); }

.empty { text-align: center; color: var(--text-faint); padding: 60px 20px; font-size: 14px; }
.copy-btn { background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-faint); font-size: 11px; cursor: pointer; padding: 3px 8px; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ----------------------------- strength explorer ----------------------------- */
.readout-wrap { display: grid; grid-template-columns: repeat(2, 1fr) repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.gauge { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); }
.gauge .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); font-weight: 700; }
.gauge .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.gauge .bar { height: 6px; border-radius: 4px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.gauge .bar > span { display: block; height: 100%; border-radius: 4px; transition: width .25s ease; }

.slider-wrap { margin: 6px 0 2px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.slider-val { font-family: var(--mono); font-size: 15px; font-weight: 700; }
.slider-val .unit { color: var(--text-faint); }
input[type=range].strength {
  width: 100%; -webkit-appearance: none; appearance: none; height: 6px; border-radius: 4px;
  background: var(--surface-2); outline: none; border: 1px solid var(--border);
}
input[type=range].strength::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 3px solid var(--surface); box-shadow: var(--shadow);
}
input[type=range].strength::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent); cursor: pointer;
  border: 3px solid var(--surface);
}
.ticks { display: flex; justify-content: space-between; margin-top: 6px; }
.tick { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); position: relative; }
.tick.deployed { color: var(--accent); font-weight: 700; }
.tick.cliff { color: var(--bad); font-weight: 700; }
.legend-hint { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 11.5px; color: var(--text-soft); }
.legend-hint span { display: inline-flex; align-items: center; gap: 6px; }
.legend-hint i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }

.responses-panel .resp-item { border-bottom: 1px solid var(--border); padding: 12px 0; }
.responses-panel .resp-item:last-child { border-bottom: 0; }
.resp-q { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.resp-a { font-size: 12.5px; color: var(--text-soft); white-space: pre-wrap; line-height: 1.5; }
.resp-scores { display: flex; gap: 8px; margin-top: 6px; }

/* ----------------------------- drawer ----------------------------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw; z-index: 60;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  padding: 20px 22px; overflow-y: auto; transform: translateX(0);
}
.drawer.hidden { display: block !important; transform: translateX(100%); pointer-events: none;
  transition: transform .25s ease; }
.drawer:not(.hidden) { transition: transform .25s ease; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { font-family: var(--serif); margin: 0; font-size: 20px; }
.drawer-intro { color: var(--text-soft); font-size: 12.5px; }
.gloss-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.gloss-term { font-weight: 700; font-size: 13.5px; }
.gloss-def { font-size: 12.5px; color: var(--text-soft); margin-top: 3px; }
.gloss-src { font-size: 11px; color: var(--text-faint); margin-top: 4px; font-style: italic; }
.scrim { position: fixed; inset: 0; background: rgba(10,14,20,.4); z-index: 55; }
.scrim.hidden { display: none; }

.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text-soft); font-size: 15px; z-index: 80;
}
.loading.hidden { display: none; }

.note-banner { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px; }

/* ----------------------------- findings tour ----------------------------- */
.tour-content { max-width: 960px; margin: 0 auto; padding: 38px 28px 90px; }
.tour-hero h1 { font-family: var(--serif); font-size: 28px; font-weight: 650; line-height: 1.25;
  margin: 0 0 14px; letter-spacing: .2px; }
.tour-hero .lede { font-size: 14.5px; color: var(--text-soft); line-height: 1.65; max-width: 76ch; margin: 0 0 10px; }
.tour-hero .lede b { color: var(--text); }

.tour-map { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0 8px; }
.map-card {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; font-family: inherit; color: inherit;
  transition: border-color .15s, transform .15s;
}
.map-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.map-title { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; color: var(--accent); }
.map-body { font-size: 12px; color: var(--text-soft); line-height: 1.5; }

.two-source {
  margin: 16px 0 8px; padding: 12px 16px; font-size: 13px; line-height: 1.6; color: var(--text-soft);
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: var(--radius-sm);
}
.two-source b { color: var(--text); }

.rq-head { margin: 40px 0 14px; }
.rq-kicker { display: flex; align-items: baseline; justify-content: space-between; }
.rq-kicker span:first-child { font-size: 11.5px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .8px; color: var(--accent); }
.sec-badge { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.rq-head h2 { font-family: var(--serif); font-size: 21px; margin: 6px 0 8px; font-weight: 650; }
.rq-intro { font-size: 13px; color: var(--text-soft); line-height: 1.6; margin: 0; max-width: 80ch; }

.finding {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.finding-head { display: flex; align-items: center; gap: 10px; }
.fnum {
  flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font-size: 11.5px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center;
}
.finding-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.fbadge { text-transform: uppercase; letter-spacing: .5px; font-size: 10px; }
.finding-body { font-size: 13.5px; color: var(--text-soft); line-height: 1.65; margin: 8px 0 0 32px; max-width: 82ch; }
.finding-body b { color: var(--text); }
.finding-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 2px 32px; }
.link-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft);
  color: var(--accent); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 650;
  cursor: pointer; font-family: inherit; transition: border-color .15s, transform .15s;
}
.link-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.link-arrow { font-weight: 800; }
.tour-footer { margin-top: 36px; font-size: 12px; color: var(--text-faint); line-height: 1.6; max-width: 86ch; }

/* ----------------------------- small companions ----------------------------- */
.bench-blurb { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; margin: 8px 2px 0; }

mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 1px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--warn) 35%, transparent); }

button.card-id { background: none; border: 0; padding: 0; cursor: pointer;
  font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
button.card-id:hover { color: var(--accent); text-decoration: underline; }

.slider-side { display: inline-flex; align-items: center; gap: 8px; }
.play-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--accent);
  width: 26px; height: 26px; border-radius: 50%; font-size: 11px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.play-btn:hover { border-color: var(--accent); }

#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 10px);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 100;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.card.flash { animation: cardflash 1.6s ease 1; }
@keyframes cardflash {
  0% { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: var(--shadow); }
}

/* ----------------------------- responsive ----------------------------- */
@media (max-width: 900px) {
  .view { grid-template-columns: 1fr; }
  .view.view-single { display: block; }
  .controls { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .panels-row { grid-template-columns: 1fr; }
  .readout-wrap { grid-template-columns: repeat(2, 1fr); }
  .app-header { flex-wrap: wrap; }
  .tour-map { grid-template-columns: 1fr; }
  .tour-content { padding: 26px 18px 70px; }
  .finding-body, .finding-links { margin-left: 0; }
}
