:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --blue-line: #93c5fd;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --purple: #7c3aed;
  --purple-soft: #ede9fe;
  --slate: #1e293b;
  --slate-dark: #0f172a;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  --radius: 18px;
  --toolbar-height: 58px;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

.app-toolbar {
  min-height: var(--toolbar-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 24px;
  border-bottom: 1px solid rgba(203, 213, 225, 0.75);
  background: rgba(248, 250, 252, 0.96);
}

.language-menu {
  position: relative;
  z-index: 30;
}

.language-trigger {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 164px;
  justify-content: space-between;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 11px;
  background: #fff;
  color: var(--ink);
  box-shadow: none;
  transition: border-color 160ms ease, background 160ms ease;
}

.language-trigger:hover {
  border-color: var(--blue-line);
  background: #f8fafc;
}

.language-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.language-trigger strong {
  font-size: 13px;
}

.language-caret {
  color: var(--muted);
  font-size: 11px;
}

.language-options {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 150px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.18);
}

.language-options button {
  width: 100%;
  border: 0;
  background: #fff;
  color: var(--ink);
  padding: 10px 13px;
  text-align: left;
  font-weight: 700;
}

.language-options button:hover,
.language-options button.is-active {
  background: var(--blue-soft);
  color: #1d4ed8;
}

.researcher-panel {
  background: var(--slate-dark);
  color: #fff;
  padding: 18px 24px;
}

.researcher-panel__inner {
  max-width: 1180px;
  margin: 0 auto;
}

.researcher-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.32);
}

.eyebrow {
  margin: 0 0 4px;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.researcher-panel h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.ghost-button,
.mini-button {
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.3);
  color: #cbd5e1;
  border-radius: 8px;
  padding: 8px 11px;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.ghost-button:hover,
.mini-button:hover {
  border-color: rgba(255, 255, 255, 0.7);
  color: #fff;
  background: rgba(30, 41, 59, 0.9);
}

.researcher-grid {
  display: grid;
  grid-template-columns: minmax(160px, 0.65fr) minmax(220px, 0.8fr) minmax(280px, 1.1fr) minmax(320px, 1.25fr);
  gap: 22px;
  padding-top: 18px;
}

.researcher-block {
  min-width: 0;
}

.control-title {
  margin: 0 0 10px;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 700;
}

.control-note {
  margin: 8px 0 0;
  color: #94a3b8;
  font-size: 12px;
}

.segmented-control {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segment-button {
  min-width: 74px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: #1e293b;
  color: #dbeafe;
  border-radius: 8px;
  padding: 8px 12px;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.segment-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: #60a5fa;
}

.segment-button.is-active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.segment-button[data-ai-reliability="correct"].is-active {
  background: var(--green);
  border-color: var(--green);
}

.segment-button[data-ai-reliability="wrong"].is-active {
  background: var(--red);
  border-color: var(--red);
}

.segment-button:disabled {
  opacity: 0.45;
}

.researcher-block--logs {
  display: flex;
  flex-direction: column;
}

.researcher-block--current {
  min-width: 0;
}

.debug-list {
  display: grid;
  gap: 6px;
  max-height: 132px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid rgba(51, 65, 85, 0.9);
  border-radius: 10px;
  background: #020617;
  color: #cbd5e1;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.35;
}

.debug-line {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
}

.debug-line span {
  color: #64748b;
}

.debug-line strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #e2e8f0;
  font-weight: 600;
}

.logs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mini-button {
  padding: 6px 9px;
  font-size: 12px;
}

.log-stream {
  min-height: 96px;
  max-height: 128px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid rgba(51, 65, 85, 0.9);
  border-radius: 10px;
  background: #020617;
  color: #86efac;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
}

.log-line + .log-line {
  margin-top: 7px;
}

.log-empty {
  color: #64748b;
  font-style: italic;
}

.show-researcher-button {
  position: fixed;
  top: calc(var(--toolbar-height) + 12px);
  right: 12px;
  z-index: 20;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  opacity: 0.35;
  transition: opacity 160ms ease;
}

.show-researcher-button:hover {
  opacity: 1;
}

.onboarding-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 34px 24px;
}

.study-panel {
  width: min(1120px, 100%);
  max-height: calc(100vh - var(--toolbar-height) - 86px);
  overflow-y: auto;
  padding: 34px;
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.study-panel__head {
  max-width: 760px;
  margin-bottom: 24px;
}

.study-panel__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.study-panel__head h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
}

.study-panel__head p:not(.eyebrow) {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.reference-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.reference-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.reference-item h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.reference-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.reference-attribution {
  overflow-wrap: anywhere;
}

.reference-attribution a {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.reference-attribution a:hover {
  color: var(--ink);
}

.reference-item audio,
.practice-audio-block audio {
  width: 100%;
}

.study-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
}

.secondary-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  padding: 0 14px;
  white-space: nowrap;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.secondary-button:hover {
  border-color: #94a3b8;
  background: var(--surface-soft);
  color: var(--ink);
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(360px, 1.1fr);
  gap: 28px;
}

.practice-audio-block {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.candidate-list--practice {
  flex: 0 0 auto;
  margin-top: 0;
}

.practice-feedback {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: #475569;
  font-weight: 700;
}

.practice-feedback.is-correct {
  border-color: #86efac;
  background: var(--green-soft);
  color: #047857;
}

.practice-feedback.is-wrong {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.participant-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 34px 24px;
}

.experiment-frame {
  width: min(1120px, 100%);
  height: min(680px, calc(100vh - var(--toolbar-height) - 112px));
  min-height: 590px;
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(370px, 0.94fr);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.audio-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 30px;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
}

.trial-meta,
.site-strip,
.trial-design-note,
.confidence-head,
.decision-head {
  display: flex;
  align-items: center;
}

.trial-meta {
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
}

.phase-status {
  min-width: 110px;
  text-align: right;
  font-weight: 700;
  color: var(--blue);
}

.site-strip {
  gap: 10px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 14px;
}

.site-strip span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}

.site-strip strong {
  color: var(--ink);
}

.spectrogram-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 280px;
  margin-top: 18px;
}

.spectrogram {
  width: 100%;
  height: 285px;
  display: grid;
  grid-template-columns: repeat(64, 1fr);
  align-items: end;
  gap: 2px;
  overflow: hidden;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(241, 245, 249, 0.72)),
    repeating-linear-gradient(0deg, rgba(148, 163, 184, 0.15), rgba(148, 163, 184, 0.15) 1px, transparent 1px, transparent 36px),
    #eef2f7;
}

.spectrogram--image {
  display: block;
  padding: 0;
  background: #0f172a;
}

.spectrogram-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.spectrogram-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: #94a3b8;
  font-weight: 700;
}

.spectrogram-bar {
  min-height: 14px;
  border-radius: 4px 4px 1px 1px;
  background: linear-gradient(180deg, #60a5fa, #1d4ed8);
  opacity: 0.82;
  transform-origin: bottom;
  transition: height 320ms ease, opacity 180ms ease;
}

.spectrogram.is-muted .spectrogram-bar {
  opacity: 0.25;
}

.scan-line {
  position: absolute;
  top: 50%;
  bottom: auto;
  left: 18px;
  width: 2px;
  height: 285px;
  transform: translateY(-50%);
  background: rgba(239, 68, 68, 0.62);
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.48);
  transition: left 50ms linear;
}

.audio-controller {
  display: block;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.native-audio {
  width: 100%;
  min-width: 0;
}

.audio-controller:not(.is-enabled) .native-audio {
  opacity: 0.52;
  pointer-events: none;
}

.trial-design-note {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.trial-design-note span {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.decision-pane {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 30px;
  background: #fff;
}

.state-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px;
  text-align: center;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.state-overlay.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay-icon {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
}

.overlay-icon svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.state-overlay h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.state-overlay p {
  max-width: 390px;
  margin: 0 0 28px;
  color: var(--muted);
  line-height: 1.65;
}

.primary-button,
.submit-button {
  border: 0;
  border-radius: 12px;
  padding: 13px 24px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
  transition: background 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.primary-button:hover,
.submit-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #1d4ed8;
}

.decision-head {
  align-items: flex-start;
  flex-direction: column;
  gap: 10px;
}

.step-indicator {
  display: flex;
  gap: 8px;
}

.phase-pill {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}

.phase-pill.is-active {
  border-color: var(--blue-line);
  background: var(--blue-soft);
  color: #1d4ed8;
}

.decision-head h2 {
  margin: 0;
  font-size: 20px;
}

.decision-head p {
  margin: 0;
  min-height: 42px;
  color: var(--muted);
  line-height: 1.55;
}

.candidate-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  margin-top: 22px;
}

.candidate-button {
  position: relative;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: #334155;
  padding: 14px 16px;
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.candidate-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: #f8fafc;
}

.candidate-button.is-selected {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.45);
  color: #1e3a8a;
}

.candidate-name {
  font-weight: 700;
  line-height: 1.2;
}

.candidate-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.ai-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid #c4b5fd;
  border-radius: 8px;
  background: var(--purple-soft);
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
}

.ai-badge svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

.confidence-panel {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.confidence-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.confidence-head p {
  margin: 0;
  color: #475569;
  font-size: 14px;
  font-weight: 700;
}

.confidence-head strong {
  color: var(--blue);
  font-size: 14px;
}

.confidence-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.confidence-button {
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #475569;
  font-weight: 800;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.confidence-button span {
  display: block;
  min-height: 12px;
  margin-bottom: 3px;
  color: inherit;
  opacity: 0.58;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.confidence-button.is-selected {
  border-color: var(--slate);
  background: var(--slate);
  color: #fff;
}

.submit-zone {
  margin-top: 18px;
}

.submit-button {
  width: 100%;
  background: var(--slate);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.submit-button.is-final {
  background: var(--blue);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
}

.submit-button:disabled {
  opacity: 0.46;
  box-shadow: none;
}

@media (max-width: 980px) {
  .researcher-grid {
    grid-template-columns: 1fr;
  }

  .participant-stage {
    align-items: start;
    padding: 18px;
  }

  .onboarding-stage {
    align-items: start;
    padding: 18px;
  }

  .study-panel {
    max-height: none;
    padding: 24px;
  }

  .study-panel__top {
    display: grid;
    gap: 14px;
  }

  .study-panel__head {
    margin-bottom: 0;
  }

  .secondary-button {
    justify-self: start;
  }

  .reference-list,
  .practice-layout {
    grid-template-columns: 1fr;
  }

  .experiment-frame {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .audio-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .spectrogram-wrap {
    min-height: 220px;
  }

  .spectrogram,
  .scan-line {
    height: 220px;
  }

  .decision-pane {
    min-height: 620px;
  }
}

@media (max-width: 620px) {
  .researcher-panel,
  .audio-pane,
  .decision-pane {
    padding: 20px;
  }

  .researcher-panel__head {
    flex-direction: column;
  }

  .candidate-button {
    align-items: flex-start;
    flex-direction: column;
  }

  .confidence-grid {
    gap: 6px;
  }
}
