:root {
  --bg:       oklch(0.975 0.007 75);
  --bg2:      oklch(0.955 0.007 75);
  --bg3:      oklch(0.930 0.008 75);
  --line:     oklch(0.875 0.006 75);
  --text:     oklch(0.14  0.012 250);
  --text-dim: oklch(0.46  0.010 250);
  --text-sub: oklch(0.52  0.010 250);
  --accent:   oklch(0.34  0.08  162);
  --accent-l: oklch(0.34  0.08  162 / 0.09);
  --danger:   oklch(0.55  0.18  25);
  --f-sans:   system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-mono:   "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --pad:      max(16px, 3vw);
  --r:        6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:       oklch(0.10  0.010 200);
    --bg2:      oklch(0.135 0.010 200);
    --bg3:      oklch(0.165 0.010 200);
    --line:     oklch(0.24  0.008 200);
    --text:     oklch(0.93  0.005 75);
    --text-dim: oklch(0.66  0.008 200);
    --text-sub: oklch(0.60  0.008 200);
    --accent:   oklch(0.72  0.14  162);
    --accent-l: oklch(0.72  0.14  162 / 0.10);
    --danger:   oklch(0.72  0.18  25);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
::selection { background: var(--accent); color: var(--bg); }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* ─── HEADER ─────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--line);
  padding: 11px var(--pad);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  opacity: 0.8;
}
.header-back:hover { opacity: 1; text-decoration: none; color: var(--text); }
.header-back svg { width: 16px; height: 16px; flex-shrink: 0; }
.header-sep { color: var(--line); font-size: 16px; user-select: none; }
.header-title { font-size: 13px; font-weight: 600; color: var(--text); }

/* ─── SPLIT LAYOUT ───────────────────────────────────────────── */
.app {
  display: flex;
  min-height: calc(100dvh - 46px);
}
.panel {
  flex: 1;
  min-width: 0;
  padding: 28px var(--pad);
  overflow-y: auto;
}
.panel--detect { border-right: none; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .panel--detect { border-right: none; }
  .panel { padding: 20px var(--pad); }
  .panel-divider {
    position: relative;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .panel-divider::before {
    content: '';
    position: absolute;
    left: 0; right: 0;
    top: 50%;
    height: 1px;
    background: var(--line);
  }
  .panel-divider__label {
    position: relative;
    z-index: 1;
    background: var(--bg);
    padding: 0 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-sub);
  }
}
@media (min-width: 761px) {
  .panel-divider { display: none; }
}

/* ─── PANEL HEADING ──────────────────────────────────────────── */
.panel-head {
  margin-bottom: 22px;
}
.panel-head h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.panel-head p {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ─── DROP ZONE (detect) ─────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover,
.drop-zone.over { border-color: var(--accent); background: var(--accent-l); }
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.drop-zone__icon { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--text-dim); }
.drop-zone__main { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.drop-zone__sub { font-size: 12px; color: var(--text-sub); margin-top: 3px; }

/* ─── DETECT PREVIEW ─────────────────────────────────────────── */
.detect-preview {
  display: none;
  margin-top: 18px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg3);
  position: relative;
}
.detect-preview.show { display: block; }
.detect-preview img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  display: block;
}
.detect-preview__name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg2);
  padding: 4px 10px;
  border-top: 1px solid var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── SCORE SECTION ──────────────────────────────────────────── */
.score-section {
  display: none;
  margin-top: 22px;
}
.score-section.show { display: block; }

.score-row-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
}
.score-lbl {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.score-lbl-ai   { color: oklch(0.50 0.20 25); }
.score-lbl-real { color: oklch(0.44 0.16 145); }
@media (prefers-color-scheme: dark) {
  .score-lbl-ai   { color: oklch(0.72 0.20 25); }
  .score-lbl-real { color: oklch(0.70 0.16 145); }
}

.score-track {
  position: relative;
  height: 28px;
  border-radius: 14px;
  overflow: visible;
  background: linear-gradient(to right,
    oklch(0.50 0.22 22),
    oklch(0.72 0.18 75),
    oklch(0.48 0.18 145)
  );
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.15);
}
@media (prefers-color-scheme: dark) {
  .score-track {
    background: linear-gradient(to right,
      oklch(0.42 0.22 22),
      oklch(0.65 0.20 75),
      oklch(0.42 0.20 145)
    );
  }
}

.score-needle {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 6px;
  border-radius: 3px;
  background: white;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.25), 0 3px 10px rgba(0,0,0,0.35);
  transform: translateX(-50%);
  left: 50%;
  transition: left 0.85s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: left;
}
@keyframes needle-scan {
  0%   { left: 6%; }
  50%  { left: 94%; }
  100% { left: 6%; }
}
.score-needle.scanning {
  transition: none;
  animation: needle-scan 1.1s ease-in-out infinite;
}

/* ─── VERDICT ────────────────────────────────────────────────── */
.verdict-wrap {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border: 1.5px solid transparent;
}
.verdict-badge.ai {
  background: oklch(0.50 0.20 25 / 0.10);
  color: oklch(0.40 0.20 25);
  border-color: oklch(0.50 0.20 25 / 0.22);
}
.verdict-badge.real {
  background: oklch(0.44 0.16 145 / 0.10);
  color: oklch(0.34 0.16 145);
  border-color: oklch(0.44 0.16 145 / 0.22);
}
.verdict-badge.uncertain {
  background: oklch(0.72 0.15 75 / 0.10);
  color: oklch(0.50 0.14 75);
  border-color: oklch(0.72 0.15 75 / 0.25);
}
@media (prefers-color-scheme: dark) {
  .verdict-badge.ai {
    background: oklch(0.50 0.22 25 / 0.16);
    color: oklch(0.78 0.20 25);
    border-color: oklch(0.55 0.22 25 / 0.4);
  }
  .verdict-badge.real {
    background: oklch(0.44 0.18 145 / 0.16);
    color: oklch(0.72 0.16 145);
    border-color: oklch(0.48 0.18 145 / 0.4);
  }
  .verdict-badge.uncertain {
    background: oklch(0.65 0.18 75 / 0.14);
    color: oklch(0.80 0.16 75);
    border-color: oklch(0.65 0.18 75 / 0.35);
  }
}
.verdict-pct {
  font-size: 13px;
  color: var(--text-dim);
}
.compress-note {
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border-radius: 7px;
  background: oklch(0.72 0.13 75 / 0.08);
  border: 1px solid oklch(0.72 0.13 75 / 0.28);
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.55;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.compress-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  background: oklch(0.72 0.13 75 / 0.18);
  border: 1px solid oklch(0.72 0.13 75 / 0.35);
  color: oklch(0.48 0.12 75);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
@media (prefers-color-scheme: dark) {
  .compress-note {
    background: oklch(0.65 0.14 75 / 0.10);
    border-color: oklch(0.65 0.14 75 / 0.30);
  }
  .compress-badge {
    background: oklch(0.65 0.14 75 / 0.20);
    border-color: oklch(0.65 0.14 75 / 0.40);
    color: oklch(0.82 0.13 75);
  }
}

/* ─── META CHIPS ─────────────────────────────────────────────── */
.score-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg3);
  color: var(--text-sub);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.warn {
  background: oklch(0.72 0.16 75 / 0.10);
  color: oklch(0.52 0.14 75);
  border-color: oklch(0.72 0.16 75 / 0.25);
}
@media (prefers-color-scheme: dark) {
  .chip.warn { color: oklch(0.78 0.16 75); }
}

/* ─── DIAGNOSTICS ────────────────────────────────────────────── */
.diagnostics {
  display: none;
  margin-top: 18px;
}
.diagnostics.show { display: block; }
.diag-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.diag-card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg2);
  padding: 10px;
  min-width: 0;
}
.diag-card--wide { grid-column: auto; }
.diag-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.diag-card__head span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}
.diag-card__head code {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--text-sub);
  white-space: nowrap;
}
.diag-map {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background:
    linear-gradient(45deg, var(--bg3) 25%, transparent 25%),
    linear-gradient(-45deg, var(--bg3) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--bg3) 75%),
    linear-gradient(-45deg, transparent 75%, var(--bg3) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  border-radius: 4px;
  border: 1px solid var(--line);
  image-rendering: pixelated;
}
.diag-bars {
  height: 116px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 8px 6px 18px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--bg);
  overflow: hidden;
}
.diag-bars--hist { gap: 1px; }
.diag-bar {
  flex: 1 1 0;
  min-width: 2px;
  height: calc(var(--v) * 1%);
  min-height: 1px;
  border-radius: 2px 2px 0 0;
  background: oklch(0.50 0.11 162);
  opacity: 0.92;
  position: relative;
}
.diag-bars--hist .diag-bar { background: oklch(0.55 0.06 250); }
.diag-bar[data-label]::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: -16px;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-sub);
  font-family: var(--f-mono);
}
.diag-meter-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.diag-meter-list.compact {
  margin-top: 10px;
  gap: 6px;
}
.diag-meter {
  display: grid;
  grid-template-columns: minmax(86px, 0.9fr) minmax(110px, 1.4fr) 46px;
  align-items: center;
  gap: 8px;
}
.diag-meter__name {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diag-meter__track {
  height: 7px;
  border-radius: 4px;
  background: var(--bg3);
  border: 1px solid var(--line);
  overflow: hidden;
}
.diag-meter__fill {
  display: block;
  height: 100%;
  width: calc(var(--v) * 1%);
  border-radius: inherit;
  background: oklch(0.52 0.15 162);
}
.diag-meter__fill.warn { background: oklch(0.70 0.16 75); }
.diag-meter__fill.hot  { background: oklch(0.58 0.20 25); }
.diag-meter__value {
  font-size: 10px;
  font-family: var(--f-mono);
  color: var(--text-sub);
  text-align: right;
  white-space: nowrap;
}
@media (max-width: 520px) {
  .diag-grid { grid-template-columns: 1fr; }
  .diag-card--wide { grid-column: auto; }
  .diag-meter { grid-template-columns: 1fr; gap: 4px; }
  .diag-meter__value { text-align: left; }
}

/* ─── HEURISTIC ACCORDION ────────────────────────────────────── */
.accordion {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg2);
  cursor: pointer;
  user-select: none;
  gap: 8px;
}
.accordion-header:hover { background: var(--bg3); }
.accordion-arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.2s;
  color: var(--text-sub);
}
.accordion-header.open .accordion-arrow { transform: rotate(180deg); }
.accordion-body {
  display: none;
  padding: 12px 14px;
  background: var(--bg);
}
.accordion-body.open { display: block; }
.accordion-body ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.accordion-body li {
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 18px;
  position: relative;
  line-height: 1.5;
}
.accordion-body li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 11px;
  top: 1px;
}
.accordion-body .empty {
  font-size: 12px;
  color: var(--text-sub);
  padding-left: 0;
}
.accordion-body .empty::before { display: none; }

/* ─── TRAIN SECTION LABELS ───────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-sub);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

/* ─── CONFIG STATUS ──────────────────────────────────────────── */
.config-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--bg2);
  margin-bottom: 20px;
  line-height: 1.4;
}
.config-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.config-dot.ok   { background: oklch(0.52 0.18 145); }
.config-dot.warn { background: oklch(0.72 0.18 75); }
.config-dot.none { background: var(--line); }

/* ─── SAMPLES COUNTER ────────────────────────────────────────── */
.samples-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.s-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text-dim);
}
.s-chip.ai-chip   { border-color: oklch(0.50 0.20 25 / 0.35); }
.s-chip.real-chip { border-color: oklch(0.44 0.16 145 / 0.35); }

/* ─── TRAIN UPLOAD ───────────────────────────────────────────── */
.train-upload {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 10px;
}
.train-upload:hover,
.train-upload.over { border-color: var(--accent); background: var(--accent-l); }
.train-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.train-upload__text { font-size: 13px; color: var(--text-dim); }

.train-preview { display: none; margin-bottom: 12px; }
.train-preview.show { display: flex; gap: 10px; align-items: flex-start; }
.train-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg3);
  flex-shrink: 0;
}
.train-preview__info { min-width: 0; }
.train-preview__name {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}
.train-preview__status { font-size: 11px; color: var(--text-sub); }

/* ─── BUTTONS ────────────────────────────────────────────────── */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row + .btn-row { margin-top: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover:not(:disabled) { background: var(--bg3); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-ai {
  background: oklch(0.50 0.20 25 / 0.08);
  border-color: oklch(0.50 0.20 25 / 0.28);
  color: oklch(0.38 0.20 25);
}
.btn-ai:hover:not(:disabled) { background: oklch(0.50 0.20 25 / 0.15); }

.btn-real {
  background: oklch(0.44 0.16 145 / 0.08);
  border-color: oklch(0.44 0.16 145 / 0.28);
  color: oklch(0.32 0.16 145);
}
.btn-real:hover:not(:disabled) { background: oklch(0.44 0.16 145 / 0.15); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg2); }

@media (prefers-color-scheme: dark) {
  .btn-ai {
    background: oklch(0.50 0.22 25 / 0.12);
    border-color: oklch(0.55 0.22 25 / 0.36);
    color: oklch(0.78 0.20 25);
  }
  .btn-real {
    background: oklch(0.44 0.18 145 / 0.12);
    border-color: oklch(0.48 0.18 145 / 0.36);
    color: oklch(0.72 0.16 145);
  }
}

/* ─── FILE INPUT SHIM ────────────────────────────────────────── */
.file-btn-wrap {
  position: relative;
  display: inline-flex;
}
.file-btn-wrap input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

/* ─── TIP BOX ────────────────────────────────────────────────── */
.tip {
  font-size: 12px;
  color: var(--text-sub);
  background: var(--bg2);
  border-radius: var(--r);
  padding: 10px 14px;
  border: 1px solid var(--line);
  margin-top: 14px;
  line-height: 1.55;
}
.tip code {
  font-family: var(--f-mono);
  font-size: 11px;
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-dim);
  word-break: break-all;
}

/* ─── BULK UPLOAD ────────────────────────────────────────────── */
.bulk-row { margin-top: 8px; }

.bulk-progress {
  display: none;
  margin-top: 10px;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--r);
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.bulk-progress.show { display: block; }

.bulk-bar-wrap {
  margin-top: 6px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.bulk-bar {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.15s;
}

/* ─── TRAIN SECTIONS SPACING ─────────────────────────────────── */
.train-block { margin-bottom: 26px; }
.train-block:last-child { margin-bottom: 0; }

/* ─── DISCLAIMER ─────────────────────────────────────────────── */
.notice {
  margin-top: 28px;
  padding: 12px 14px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.65;
}
.notice p { margin: 0 0 6px; }
.notice ul { margin: 0; padding-left: 18px; }
.notice li { margin-bottom: 4px; }
.notice li:last-child { margin-bottom: 0; }
.notice strong { color: var(--text); font-weight: 600; }

/* ─── HIDDEN CANVASES ────────────────────────────────────────── */
canvas { display: none; }
