:root {
  --bg: #ffffff;
  --panel: #f7f8fa;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #666f7a;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --viewer-bg: #ffffff;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1b1f26;
    --border: #2c323b;
    --text: #e8eaed;
    --muted: #9aa3ae;
    --accent: #5b8dff;
    --accent-text: #0d1117;
    --danger: #ff6b5b;
    --viewer-bg: #14171c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h1 { font-size: 17px; margin: 0 0 4px; letter-spacing: -0.01em; }
.sub { margin: 0; color: var(--muted); font-size: 12.5px; }

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.counter { font-family: var(--mono); font-weight: 400; text-transform: none; }
.counter.over { color: var(--danger); font-weight: 700; }

textarea {
  width: 100%;
  height: 170px;
  padding: 10px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  word-break: break-all;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

textarea:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.examples { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 4px 9px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--accent); }

.primary {
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.primary:disabled { opacity: 0.55; cursor: progress; }

.secondary {
  display: block;
  padding: 9px;
  text-align: center;
  text-decoration: none;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.secondary:hover { border-color: var(--accent); }

.status { margin: 0; font-size: 12.5px; color: var(--muted); min-height: 1.2em; }
.status.error { color: var(--danger); }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 12px; }

.provider-badge {
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.provider-badge strong { display: block; font-size: 13px; }
.provider-badge a { color: var(--accent); }
.provider-badge .note { color: var(--muted); font-size: 11.5px; }

.metric { display: flex; justify-content: space-between; align-items: baseline; }
.metric-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted);
}
.metric-value { font-family: var(--mono); font-size: 26px; font-weight: 600; }

.bands {
  display: flex;
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--border);
}
.bands span { height: 100%; }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 10px;
  font-size: 11px;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; flex: none; }

/* Confidence swatches live here rather than as inline style attributes,
   so the Content-Security-Policy needs no 'unsafe-inline'. */
.sw-very-high { background: #0053D6; }
.sw-confident { background: #65CBF3; }
.sw-low       { background: #FFDB13; }
.sw-very-low  { background: #FF7D45; }

.chart-wrap { display: flex; flex-direction: column; gap: 5px; }
#chart {
  width: 100%;
  height: 70px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.hint { font-size: 11px; color: var(--muted); font-family: var(--mono); }

footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
footer p { margin: 0; font-size: 11.5px; color: var(--muted); }
footer a { color: var(--accent); }

/* ---------- Stage ---------- */
.stage { position: relative; background: var(--viewer-bg); }
#viewer { position: absolute; inset: 0; }

.controls {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.controls select, .toggle {
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .stage { height: 65vh; }
}
