@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Syne:wght@400;700;800&display=swap');

/* ─── Tokens ──────────────────────────────────────────── */
:root {
  --bg:             #0a0a0b;
  --surface:        #212128;
  --surface-raised: #37373c;
  --border:         #1e1e24;
  --border-bright:  #2e2e3a;
  --text:           #ffffff;
  --text-dim:       #d6d6de;
  --text-dimmer:    #a4a4aa;
  --accent:         #00e5ff;
  --accent-dim:     rgba(0,229,255,0.07);
  --accent-glow:    rgba(0,229,255,0.25);
  --green:          #39ff7a;
  --warn:           #ff6b35;
  --warn-dim:       rgba(255,107,53,0.12);
  --radius:         4px;
  --mono:           'JetBrains Mono', 'Fira Code', monospace;
  --display:        'Syne', sans-serif;
}

/* ─── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* CRT scan-line overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.10) 2px, rgba(0,0,0,0.10) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ─── Header ──────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 36px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,11,0.96);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.4px;
  color: var(--text);
}
.logo span { color: var(--accent); }

.header-right { display: flex; align-items: center; gap: 12px; }

.badge {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  color: var(--text-dim);
  border: 1px solid var(--border-bright);
  padding: 3px 9px;
  border-radius: 2px;
  text-transform: uppercase;
}

.key-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.key-btn:hover { border-color: var(--accent); color: var(--accent); }
.key-btn.has-key { border-color: rgba(57,255,122,0.4); color: var(--green); }
.key-btn svg { flex-shrink: 0; }

/* ─── Layout ──────────────────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 36px 80px;
  align-items: start;
}

/* ─── Panel ───────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.panel-hint {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dimmer);
  letter-spacing: 0.5px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-accent { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.dot-green  { background: var(--green);  box-shadow: 0 0 6px rgba(57,255,122,0.35); }

.panel-body { padding: 20px; }

/* ─── Form elements ───────────────────────────────────── */
/* ─── Analysis target toggle ──────────────────────────────────────────── */
.target-toggle-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.target-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}

.target-btn {
  flex: 1;
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: 2px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.target-btn:hover { color: var(--text); }
.target-btn.active {
  background: var(--accent);
  color: #000;
  font-weight: 500;
}

.target-badge {
  display: inline-block;
  font-size: 9px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #000;
  background: var(--accent);
  border-radius: 2px;
  padding: 2px 5px;
  margin-left: 5px;
  vertical-align: middle;
}

/* ─── Field label ─────────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.optional { color: var(--text-dimmer); font-size: 9px; }

textarea {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.8;
  padding: 14px;
  resize: vertical;
  outline: none;
  transition: border-color 0.18s;
  min-height: 200px;
}
textarea[rows="3"] { min-height: unset; }
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--text-dimmer); }

/* ─── Method selector ─────────────────────────────────── */
.method-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.method-group { display: flex; gap: 6px; flex: 1; }

.method-btn {
  flex: 1;
  padding: 7px 4px;
  background: transparent;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.method-btn:hover { border-color: var(--accent); color: var(--accent); }
.method-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.method-desc {
  margin-top: 10px;
  font-size: 11px;
  line-height: 1.7;
  color: var(--text-dim);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 13px;
}
.method-desc code {
  background: rgba(0,229,255,0.1);
  color: var(--accent);
  border-radius: 2px;
  padding: 1px 4px;
  font-size: 10.5px;
}

/* ─── Error banner ────────────────────────────────────── */
.error-banner {
  display: none;
  margin-top: 14px;
  padding: 11px 14px;
  background: var(--warn-dim);
  border: 1px solid rgba(255,107,53,0.3);
  border-radius: var(--radius);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--warn);
}
.error-banner.show { display: block; }

/* ─── Run button ──────────────────────────────────────── */
.run-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
}
.run-btn:hover:not(:disabled) {
  background: #33eeff;
  box-shadow: 0 0 22px var(--accent-glow);
}
.run-btn:disabled {
  background: var(--border-bright);
  color: var(--text-dimmer);
  cursor: not-allowed;
}
.kbd-hint {
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0.5;
  margin-left: auto;
}

.spinner {
  display: none;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(0,0,0,0.25);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
.run-btn.loading .spinner { display: block; }
.run-btn.loading .kbd-hint { display: none; }

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

/* ─── Output column ───────────────────────────────────── */
.output-col { display: flex; flex-direction: column; gap: 18px; }

/* ─── Progress ────────────────────────────────────────── */
.progress-wrap {
  display: none;
  height: 2px;
  background: var(--border);
  overflow: hidden;
}
.progress-wrap.active { display: block; }
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  transition: width 0.35s ease;
}

.phase-log {
  display: none;
  padding: 8px 18px;
  font-size: 10px;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  min-height: 30px;
}
.phase-log.active { display: block; }

/* ─── Saliency text ───────────────────────────────────── */
.saliency-text {
  padding: 20px;
  font-size: 13px;
  line-height: 2.2;
  font-family: var(--mono);
  word-break: break-word;
}

.phrase {
  border-radius: 3px;
  padding: 1px 3px;
  display: inline;
  cursor: default;
  position: relative;
  transition: filter 0.15s;
}
.phrase:hover { filter: brightness(1.35); }

/* Score tooltip */
.phrase::after {
  content: attr(data-tip);
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #16161e;
  border: 1px solid var(--border-bright);
  color: var(--accent);
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 20;
}
.phrase:hover::after { opacity: 1; }

/* ─── Empty state ─────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 52px 24px;
  gap: 14px;
  text-align: center;
}
.empty-icon {
  width: 46px;
  height: 46px;
  border: 2px solid var(--border-bright);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-dimmer);
}
.empty-state p {
  font-size: 11.5px;
  color: var(--text-dimmer);
  line-height: 1.8;
  max-width: 260px;
}

/* ─── Legend ──────────────────────────────────────────── */
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.legend-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-right: 4px;
}
.legend-low, .legend-high {
  font-size: 10px;
  color: var(--text-dimmer);
}
.legend-bar {
  flex: 1;
  height: 9px;
  border-radius: 3px;
  background: linear-gradient(to right,
    rgba(15,40,80,0.55),
    rgba(20,80,160,0.65),
    rgba(200,140,0,0.75),
    rgba(240,80,0,0.85),
    rgba(255,30,0,1)
  );
}

/* ─── Stats ───────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.stat-value {
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  color: var(--accent);
}
.stat-value--sm {
  font-size: 12px;
  line-height: 1.4;
  padding-top: 2px;
  word-break: break-word;
}

/* ─── Model output ────────────────────────────────────── */
.model-response {
  padding: 18px 20px;
  font-size: 12px;
  line-height: 1.85;
  color: #c0c0d4;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-bright) transparent;
}

/* ─── Modal ───────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
}
.modal-backdrop.open { display: block; }

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 94vw);
  background: var(--surface-raised);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  z-index: 201;
  overflow: hidden;
}
.modal.open { display: block; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 2px;
  transition: color 0.1s;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 22px 20px; display: flex; flex-direction: column; gap: 16px; }

.modal-desc {
  font-size: 12px;
  line-height: 1.75;
  color: var(--text-dim);
}
.modal-desc strong { color: var(--text); }

.modal-steps {
  font-size: 11.5px;
  line-height: 2;
  color: var(--text-dim);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.modal-steps span { color: var(--accent); }
.modal-steps a { color: var(--accent); text-decoration: none; }
.modal-steps a:hover { text-decoration: underline; }

#keyInput {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 10px 13px;
  outline: none;
  transition: border-color 0.18s;
  letter-spacing: 1px;
}
#keyInput:focus { border-color: var(--accent); }
#keyInput::placeholder { letter-spacing: 0; }

.key-error {
  font-size: 11px;
  color: var(--warn);
  min-height: 16px;
}

/* ─── Provider tabs ───────────────────────────────────────────────────── */
.provider-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

.provider-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.14s;
}
.provider-tab:hover { border-color: var(--accent); }
.provider-tab.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.provider-tab-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-dim);
  transition: color 0.14s;
}
.provider-tab.active .provider-tab-label { color: var(--accent); }

.provider-tab-sub {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.5px;
  color: var(--text-dimmer);
}

/* ─── Modal actions ───────────────────────────────────────────────────── */
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.btn-primary {
  padding: 9px 20px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.14s;
}
.btn-primary:hover { background: #33eeff; box-shadow: 0 0 16px var(--accent-glow); }

.btn-secondary {
  padding: 9px 16px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.14s;
}
.btn-secondary:hover { border-color: var(--warn); color: var(--warn); }

/* ─── Animations ──────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}
.fade-in { animation: fadeUp 0.28s ease forwards; }

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    padding: 20px 18px 60px;
    gap: 20px;
  }
  header { padding: 14px 18px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .stats-row .stat-card:last-child { grid-column: 1 / -1; }
}
