:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5b6472;
  --accent: #2f6fed;
  --border: #d7dce5;
  --heading-red: #d93025;
  --heading-blue: #1a56db;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
}

.page {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.page__header {
  margin-bottom: 20px;
}

.page__header h1 {
  margin: 0 0 8px;
  width: fit-content;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1.2;
  color: var(--heading-red);
}

@supports (background-clip: text) or (-webkit-background-clip: text) {
  .page__header h1 {
    background-image: linear-gradient(
      90deg,
      var(--heading-red),
      var(--heading-blue)
    );
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

.page__lead {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.editor__label,
.results__title,
.top__title {
  display: block;
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
}

.editor__input {
  display: block;
  width: 100%;
  min-height: 220px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  resize: vertical;
}

.editor__input:focus-visible,
.top__limit input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.results {
  margin-top: 24px;
}

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

.stats__item {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
}

.stats__label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats__value {
  margin: 4px 0 0;
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.top {
  margin-top: 24px;
}

.top__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 8px;
}

.top__header .top__title {
  margin: 0;
}

.top__limit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.top__limit input {
  width: 5.5rem;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  font: inherit;
}

.top__list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.top__list:empty {
  display: none;
}

.top__item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  min-width: 0;
}

.top__item + .top__item {
  border-top: 1px solid var(--border);
}

.top__word {
  min-width: 0;
  overflow-wrap: anywhere;
}

.top__count {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.top__empty {
  margin: 0;
  padding: 14px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
}

.top__empty[hidden] {
  display: none;
}

@media (max-width: 420px) {
  .page {
    padding: 18px 14px 32px;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .stats__item {
    padding: 10px 6px;
  }

  .stats__value {
    font-size: 1.4rem;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1b212b;
    --text: #e8ebf0;
    --muted: #a3adbb;
    --accent: #7aa2ff;
    --border: #2d3746;
    --heading-red: #ff6b5e;
    --heading-blue: #7aa2ff;
  }
}
