/* ==========================================================================
   AI 文本质量评测 — design tokens
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f6f7f9;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #eef2ff 0%, transparent 60%),
             radial-gradient(900px 500px at 100% 0%, #fdf2f8 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e7ec;
  --border-strong: #d3d8e0;

  --text: #14161a;
  --text-2: #4a5058;
  --text-3: #7d848e;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;

  --bad: #c0392b;
  --bad-bg: #fdecea;
  --minor: #d97706;
  --minor-bg: #fef3c7;
  --mediocre: #b7950b;
  --mediocre-bg: #fdf6d8;
  --ok: #2e8a4c;
  --ok-bg: #e8f6ec;
  --good: #1c7a63;
  --good-bg: #dff5ef;
  --skip: #55606e;
  --skip-bg: #eceff3;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px -6px rgba(16, 24, 40, 0.12), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 20px 48px -24px rgba(16, 24, 40, 0.28);

  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1116;
    --bg-grad: radial-gradient(1200px 600px at 15% -10%, #1b1f33 0%, transparent 60%),
               radial-gradient(900px 500px at 100% 0%, #2a1a2b 0%, transparent 55%);
    --surface: #171a21;
    --surface-2: #1d212a;
    --border: #2a2f3a;
    --border-strong: #3a4150;

    --text: #f0f2f5;
    --text-2: #b3bac6;
    --text-3: #838b99;

    --accent: #8b87ff;
    --accent-hover: #a5a1ff;
    --accent-soft: #232338;

    --bad: #ff8a80;
    --bad-bg: #3a1f1c;
    --minor: #ffbf5f;
    --minor-bg: #3a2c14;
    --mediocre: #e8cf6a;
    --mediocre-bg: #35301a;
    --ok: #6fd48f;
    --ok-bg: #16301f;
    --good: #6ed7bd;
    --good-bg: #123028;
    --skip: #9aa4b2;
    --skip-bg: #242931;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 16px -6px rgba(0, 0, 0, 0.6), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 48px -24px rgba(0, 0, 0, 0.8);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

button, select, textarea { font: inherit; color: inherit; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* The header is sticky, so anchor targets need clearance or their first line
   renders underneath it. */
#input,
#overallCard,
#detailSection { scroll-margin-top: 84px; }

.hidden { display: none !important; }

/* ==========================================================================
   Top bar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 34px; height: 34px; flex: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #9333ea);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 9px;
  border-radius: 4px;
  background: #fff;
  opacity: 0.92;
  clip-path: polygon(0 0, 100% 0, 100% 34%, 0 34%, 0 48%, 100% 48%, 100% 82%, 0 82%, 0 96%, 100% 96%, 100% 100%, 0 100%);
}

.brand-text h1 { font-size: 17px; line-height: 1.25; }
.brand-text p { margin: 1px 0 0; font-size: 12px; color: var(--text-3); }

.select-wrap {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 4px 4px 8px;
}
/* Lay the picker's label inline with its button: two stacked rows add header
   height for no benefit, and the label is context rather than a control. */
.select-wrap .picker { display: flex; align-items: center; gap: 7px; min-width: 0; }
.select-wrap .picker-label { flex: none; }
.select-wrap .picker-button { flex: 1 1 auto; min-width: 0; padding: 5px 7px; }

/*
 * Dropdown (.picker) — custom replacement for <select>.
 *
 * The native select popup is painted by the OS/browser and ignores page CSS, so
 * in dark mode Chrome showed near-white option text on a white list. This control
 * is plain DOM themed by the same tokens, so it renders identically everywhere.
 */
.picker { position: relative; display: inline-block; min-width: 0; }

.picker-label { font-size: 12px; color: var(--text-3); font-weight: 600; white-space: nowrap; }

.picker-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.picker-button:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.picker-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.picker-value { display: inline-flex; align-items: baseline; gap: 7px; min-width: 0; flex: 1 1 auto; }
.picker-value-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-value-meta { color: var(--text-3); font-weight: 500; font-size: 12px; white-space: nowrap; }

.picker-caret {
  flex: none;
  width: 12px; height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237d848e' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  transition: transform 0.15s ease;
}
.picker.is-open .picker-caret { transform: rotate(180deg); }

.picker-panel {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  right: 0;
  min-width: 100%;
  /*
   * A percentage min-width cannot exceed the anchor, so a narrow trigger (the
   * toolbar's 最大长度/批大小 controls are ~60px) would force the hint text to
   * wrap one character per line. A real minimum, clamped to the viewport, keeps
   * option labels on one line.
   */
  width: max-content;
  min-width: min(240px, calc(100vw - 24px));
  max-width: min(380px, calc(100vw - 24px));
  max-height: min(60vh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.picker-panel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.picker-group + .picker-group { margin-top: 4px; border-top: 1px solid var(--border); padding-top: 4px; }
.picker-group-title {
  padding: 7px 10px 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-3);
}

.picker-option {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.picker-option.is-active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.picker-option.is-selected { color: var(--accent); font-weight: 650; }

.picker-option-main { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.picker-option-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-option-meta { flex: none; color: var(--text-3); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.picker-option-hint { color: var(--text-3); font-size: 11.5px; font-weight: 400; }

/* Compact "field" variant used by the toolbar (分句 / 最大长度 / 批大小). */
.picker.is-field { width: 100%; }
.picker.is-field .picker-button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
}

.badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 650;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge-loading { color: var(--minor); }
.badge-loading .dot { animation: pulse 1.2s ease-in-out infinite; }
.badge-ready { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); background: var(--ok-bg); }
.badge-error { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); background: var(--bad-bg); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Model facts. Scrolling content, deliberately outside the sticky header — it is
   reference detail, not navigation, and pinning it was costing 30% of a phone
   screen. */
.model-meta {
  display: flex;
  align-items: center;
  gap: 6px 16px;
  flex-wrap: wrap;
  padding: 2px 4px 0;
  font-size: 12px;
  color: var(--text-3);
}
.model-meta[hidden] { display: none; }
.model-meta b { color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Layout
   ========================================================================== */

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 22px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { font-size: 15.5px; }

.head-stats { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Input
   ========================================================================== */

textarea#inputText {
  width: 100%;
  min-height: 210px;
  max-height: 60vh;
  resize: vertical;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 15px;
  line-height: 1.75;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea#inputText:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  background: var(--surface);
}

.toolbar {
  margin-top: 14px;
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 14px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 9px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 11.5px; font-weight: 600; color: var(--text-3); letter-spacing: 0.02em; }

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 620;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.06s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); }
.btn-small { padding: 6px 13px; font-size: 13px; }

.btn.is-busy { position: relative; color: transparent; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress { margin-top: 15px; }
.progress-track {
  height: 6px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #9333ea);
  transition: width 0.18s ease;
}
.progress-text { margin-top: 6px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.cancel-wrap { margin-top: 10px; }

.alert {
  margin-top: 14px;
  border: 1px solid color-mix(in srgb, var(--bad) 40%, var(--border));
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  white-space: pre-wrap;
  font-family: var(--mono);
  max-height: 220px;
  overflow: auto;
}

/* Non-fatal notices (degraded backend) use the warning palette. */
.alert.is-warn {
  border-color: color-mix(in srgb, var(--minor) 45%, var(--border));
  background: var(--minor-bg);
  color: var(--minor);
}

/* ==========================================================================
   Overall result
   ========================================================================== */

.latency { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.overall-grid {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(320px, 2fr);
  gap: 18px;
  align-items: stretch;
}

.verdict {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 18px;
  display: flex; flex-direction: column; justify-content: center; gap: 8px;
  border-left: 5px solid var(--tone, var(--text-3));
}
.verdict-chip {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--tone, var(--text));
  line-height: 1.2;
}
.verdict-sub { font-size: 12.5px; color: var(--text-3); }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}
.metric {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 12px 10px;
  text-align: center;
}
.metric-value { font-size: 19px; font-weight: 680; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.metric-label { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

.footnote { margin: 14px 0 0; font-size: 12.5px; color: var(--text-3); }

/* ==========================================================================
   Distribution bars
   ========================================================================== */

.dist { margin-top: 18px; display: flex; flex-direction: column; gap: 7px; }
.dist-title {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--text-3); text-transform: uppercase; margin-bottom: 2px;
}

.bar-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.bar-label { color: var(--text-2); text-align: right; font-weight: 600; overflow-wrap: anywhere; }
/* `display: block` is required: both are <span>, and an inline box ignores
   width/height, which is what made the bars render empty. */
.bar-track {
  display: block;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: 999px;
  background: var(--tone, var(--text-3));
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-value { font-variant-numeric: tabular-nums; color: var(--text-3); font-size: 12px; }

/* ==========================================================================
   Sentence list
   ========================================================================== */

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; margin: 6px 2px 12px; flex-wrap: wrap;
}
.section-head h2 { font-size: 15.5px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-3); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; background: var(--tone); display: inline-block; }

.sentence-list { display: flex; flex-direction: column; gap: 12px; }

.sentence-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tone, var(--text-3));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.sentence-card[open] { box-shadow: var(--shadow); }

.sentence-summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 18px;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 14px;
  align-items: center;
}
.sentence-summary::-webkit-details-marker { display: none; }
.sentence-summary:hover { background: var(--surface-2); }
.sentence-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.sentence-index {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.sentence-text {
  min-width: 0;
  font-size: 14.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.sentence-card[open] .sentence-text { white-space: pre-wrap; }
.sentence-card:not([open]) .sentence-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  /* Generous line-height so the badness tint on the second line is not clipped
     by the ellipsis box. */
  line-height: 1.85;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 650;
  padding: 5px 11px; border-radius: 999px;
  background: var(--tone-bg, var(--surface-2));
  color: var(--tone, var(--text-2));
  border: 1px solid color-mix(in srgb, var(--tone) 28%, transparent);
  white-space: nowrap;
}

.sentence-body {
  padding: 4px 18px 18px;
  border-top: 1px solid var(--border);
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sentence-facts {
  display: flex; gap: 8px 20px; flex-wrap: wrap;
  padding-top: 14px;
  font-size: 12.5px; color: var(--text-3);
}
.sentence-facts b { color: var(--text-2); font-weight: 650; font-variant-numeric: tabular-nums; }
.warn { color: var(--minor); font-weight: 600; }

/* ==========================================================================
   Inline token tint (quality-token family)
   ========================================================================== */

/*
 * The sentence itself carries the badness gradient, so a collapsed card is
 * already informative. The tint is applied inline per token (`rgba(...)`) and
 * these rules only handle shape and legibility, never colour, so the gradient
 * cannot be overridden by a theme.
 */
.sentence-text mark.bad-token {
  color: inherit;
  border-radius: 3px;
  padding: 1px 0;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.token-summary {
  margin-top: 10px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-3);
}
.token-summary b { color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Empty state / footer
   ========================================================================== */

.empty {
  text-align: center;
  padding: 52px 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-3);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.empty-icon { font-size: 32px; color: var(--border-strong); margin-bottom: 8px; }
.empty p { margin: 4px 0; }
.muted { color: var(--text-3); font-size: 13px; }

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 22px 40px;
  display: flex; justify-content: space-between; gap: 14px 20px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-3);
}
.footer-links { display: inline-flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.footer a { color: var(--text-2); text-decoration: none; border-bottom: 1px solid var(--border-strong); }
.footer a:hover { color: var(--accent); border-bottom-color: currentColor; }
.footer a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* Inline button that reads as a link, for footer actions. */
.link-button {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--text-2);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  cursor: pointer;
}
.link-button:hover { color: var(--accent); border-bottom-color: currentColor; }
.link-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ==========================================================================
   Responsive — mobile first in effect: every block below is a narrow-screen
   override, ordered widest-first so later rules win.
   ========================================================================== */

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

  /* One header row: let the brand shrink so the picker and badge don't wrap onto
     a second line (at 768px the badge alone wrapped, doubling header height). */
  .topbar-inner { flex-wrap: nowrap; gap: 10px; }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand-text { min-width: 0; }
  .brand-text p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .select-wrap { flex: 0 1 auto; }
  #modelBadge { flex: none; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }

  .shell { padding: 16px 12px 40px; gap: 14px; }
  .topbar-inner { padding: 8px 12px; gap: 10px; flex-wrap: nowrap; }
  .model-meta { padding: 0 2px; gap: 5px 12px; font-size: 11.5px; }
  .card { padding: 15px 14px; border-radius: 12px; }

  .brand-mark { width: 30px; height: 30px; }
  .brand-text h1 { font-size: 15.5px; }
  .brand-text p { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /*
   * Keep the header a single short row: brand on the left, compact model picker
   * on the right. `flex-wrap: nowrap` plus a shrinking brand stops the picker
   * from being pushed onto its own full-width line.
   */
  .brand { flex: 1 1 auto; min-width: 0; }
  .select-wrap { flex: 0 1 auto; max-width: 58%; padding: 3px 3px 3px 6px; }
  /* The name is what identifies the model; ρ/size are secondary and still visible
     in the dropdown and the facts line below. Truncating the name instead
     produced "6L 蒸…", which identifies nothing. */
  .select-wrap .picker-value-meta { display: none; }

  /* The badge only earns its space while something is happening. */
  .badge { flex: none; font-size: 11.5px; padding: 5px 10px; }
  .topbar .badge-ready { display: none; }

  /*
   * Loading/error states collapse to their dot. The full text cannot fit beside
   * the picker without wrapping to a second row (which doubled header height),
   * and truncating it to "6L 蒸…" identifies nothing. The text stays in the DOM,
   * clipped rather than removed, so assistive tech and the hover title still
   * announce it; the error detail is shown in full in the alert below.
   */
  .topbar .badge { padding: 7px; gap: 0; }
  #modelBadgeText {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  textarea#inputText { min-height: 150px; padding: 12px; font-size: 15px; }

  /* Toolbar becomes a two-up grid instead of a ragged wrap. */
  .toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .toolbar-left { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .toolbar-right { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }
  .btn { padding: 11px 14px; font-size: 14px; }
  .btn-small { padding: 8px 12px; }

  /* The panel is anchored to its own control, so keep it inside the viewport. */

  .overall-grid { gap: 12px; }
  .verdict { padding: 14px; }
  .verdict-chip { font-size: 22px; }
  .metrics { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .metric { padding: 10px 6px; }
  .metric-value { font-size: 16px; }
  .metric-label { font-size: 10.5px; }

  /* Short labels so the bar tracks keep usable width on phones. */
  .bar-row { grid-template-columns: minmax(44px, 62px) minmax(0, 1fr) 46px; gap: 8px; font-size: 12px; }
  .bar-track { height: 10px; }
  .bar-value { font-size: 11px; }

  .section-head { margin-bottom: 10px; }
  .sentence-card { border-radius: 12px; }
  .sentence-summary { grid-template-columns: 20px minmax(0, 1fr); gap: 8px; padding: 11px 12px; }
  .sentence-summary .chip { grid-column: 2; justify-self: start; margin-top: 2px; }
  .sentence-text { font-size: 14px; }
  .sentence-body { padding: 2px 12px 14px; gap: 11px; }
  .sentence-facts { gap: 6px 14px; padding-top: 11px; font-size: 12px; }

  .empty { padding: 34px 16px; }
  .empty-icon { font-size: 26px; }
  .footer { padding: 0 12px 28px; font-size: 11.5px; }
}

/* Only very narrow phones drop to a single column; 390px-class screens keep the
   two-up toolbar so the form stays short. */
@media (max-width: 360px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .toolbar-left { grid-template-columns: 1fr; }
  .toolbar-right { grid-template-columns: 1fr 1fr; }
  .toolbar-right .btn-primary { grid-column: span 2; }
  .bar-row { grid-template-columns: 44px minmax(0, 1fr) 42px; }
}

/* Coarse pointers get bigger hit targets regardless of width. */
@media (pointer: coarse) {
  .sentence-summary { padding-top: 13px; padding-bottom: 13px; }
  .btn { min-height: 42px; }
  .btn-small { min-height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
