:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #14162b;
  --ink-soft: #4a4f6a;
  --line: #d7dceb;
  --brand: #2b2b6b;
  --brand-ink: #ffffff;
  --accent: #0b6e4f;
  --error: #b3261e;
  --error-bg: #fdeceb;
  --warn: #8a5a00;
  --warn-bg: #fff5e0;
  --ok: #0b6e4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 43, 0.06), 0 8px 24px rgba(20, 22, 43, 0.06);
  --focus: #0b57d0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101223;
    --surface: #181b30;
    --ink: #f2f4ff;
    --ink-soft: #b9c0dc;
    --line: #2c3150;
    --brand: #8f9bff;
    --brand-ink: #101223;
    --accent: #5fe0b0;
    --error: #ff9c94;
    --error-bg: #3a1a19;
    --warn: #ffcf7a;
    --warn-bg: #33280f;
    --ok: #5fe0b0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --focus: #8fb6ff;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.6 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: max(1rem, 16px);
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.4rem;
}

h1 { font-size: clamp(1.35rem, 2.4vw, 1.7rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

p { margin: 0 0 0.85rem; }

a {
  color: inherit;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:hover { color: var(--accent); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
  background: color-mix(in srgb, var(--line) 45%, transparent);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--brand);
  color: var(--brand-ink);
  padding: 0.75rem 1.25rem;
  z-index: 100;
  border-radius: 0 0 10px 0;
  font-weight: 600;
}

.skip-link:focus {
  left: 0;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem clamp(1rem, 4vw, 2.5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.logo {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
  letter-spacing: 0.03em;
  flex: none;
}

.tagline {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  max-width: 46ch;
}

.privacy {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ok);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) clamp(1rem, 4vw, 2.5rem) 3rem;
  display: grid;
  gap: 1.15rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 2.5vw, 1.6rem);
  box-shadow: var(--shadow);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 0.75rem;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
}

input[type="file"],
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: color-mix(in srgb, var(--bg) 65%, var(--surface));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
}

input[type="file"] {
  cursor: pointer;
  padding: 0.5rem;
}

input[type="file"]::file-selector-button {
  font: inherit;
  font-weight: 600;
  margin-right: 0.75rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 6rem;
}

textarea:focus,
input[type="file"]:focus {
  border-color: var(--focus);
}

.row {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.7rem;
}

.row.wrap {
  flex-wrap: wrap;
}

button {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--brand);
  color: var(--brand-ink);
}

button.primary:hover {
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

button.ghost:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 0.86rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.status {
  margin: 1rem 0 0;
  padding: 0.7rem 0.95rem;
  border-radius: 10px;
  border-left: 4px solid var(--line);
  background: color-mix(in srgb, var(--bg) 70%, var(--surface));
  font-size: 0.94rem;
}

.status[data-kind="ok"] { border-color: var(--ok); }
.status[data-kind="error"] { border-color: var(--error); color: var(--error); background: var(--error-bg); }
.status[data-kind="info"] { border-color: var(--brand); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.8rem;
  margin: 0.9rem 0;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 55%, var(--surface));
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.score-track {
  height: 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 70%, transparent);
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.score-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.4s ease;
}

.score-bar[data-level="mid"] { background: var(--warn); }
.score-bar[data-level="bad"] { background: var(--error); }

.table-wrap {
  overflow-x: auto;
  margin-top: 0.6rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  white-space: nowrap;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}

td em {
  color: var(--ink-soft);
  font-style: normal;
  display: block;
  font-size: 0.86em;
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.error { background: var(--error-bg); color: var(--error); }
.badge.warning { background: var(--warn-bg); color: var(--warn); }

.gaps {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.gap {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: color-mix(in srgb, var(--bg) 45%, var(--surface));
}

.gap header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.gap textarea {
  min-height: 4.2rem;
}

.gap-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-top: 0.5rem;
}

.gap-actions button {
  padding: 0.35rem 0.8rem;
  font-size: 0.88rem;
}

.counter {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.audio-result {
  margin-top: 0.8rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px dashed var(--line);
  font-size: 0.9rem;
}

.inline-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  margin: 0.5rem 0 0;
}

.inline-list li {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
}

.prose ul {
  padding-left: 1.2rem;
  display: grid;
  gap: 0.45rem;
}

footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 1.4rem clamp(1rem, 4vw, 2.5rem);
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

footer p {
  margin: 0.2rem 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

@media (max-width: 560px) {
  .topbar { padding: 0.9rem 1rem; }
  .logo { width: 40px; height: 40px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 1.25rem; }
}

@media print {
  .topbar, footer, button, .skip-link, input[type="file"] { display: none; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
}
