@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-serif-4-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1c2030;
  --muted: #5b6275;
  --border: #dde1ec;
  --field: #ffffff;
  --field-border: #c3c9da;
  --accent: #4a3fd0;
  --accent-text: #ffffff;
  --accent-soft: #ecebfb;
  --ok: #14783a;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --warn-soft: #fff4d6;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14161f;
    --surface: #1d2030;
    --text: #eceef7;
    --muted: #a3a9bf;
    --border: #2f3348;
    --field: #272b40;
    --field-border: #434968;
    --accent: #9d95ff;
    --accent-text: #14161f;
    --accent-soft: #2a2850;
    --ok: #5fd08a;
    --bad: #ff8a80;
    --bad-soft: #3a1f24;
    --warn-soft: #3a3118;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161f;
  --surface: #1d2030;
  --text: #eceef7;
  --muted: #a3a9bf;
  --border: #2f3348;
  --field: #272b40;
  --field-border: #434968;
  --accent: #9d95ff;
  --accent-text: #14161f;
  --accent-soft: #2a2850;
  --ok: #5fd08a;
  --bad: #ff8a80;
  --bad-soft: #3a1f24;
  --warn-soft: #3a3118;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.55 "Source Serif 4", Georgia, "Times New Roman", serif;
}

[hidden] { display: none !important; }

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

.layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
}

.brand-icon { display: flex; color: var(--accent); }
.brand-icon svg { width: 26px; height: 26px; }

#menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

#menu svg,
.theme svg {
  flex: none;
  width: 20px;
  height: 20px;
}

#menu a:hover { background: var(--accent-soft); }
#menu a[data-tool="rhymes"] svg { color: #8b5cf6; }
#menu a[data-tool="search"] svg { color: #3b82f6; }
#menu a[data-tool="pattern"] svg { color: #f59e0b; }
#menu a[data-tool="letter"] svg { color: #10b981; }
#menu a[data-tool="length"] svg { color: #ec4899; }
#menu a[data-tool="random"] svg { color: #ef4444; }
#menu a[data-tool="definition"] svg { color: #06b6d4; }
#menu a[data-tool="exists"] svg { color: #22c55e; }
#menu a[aria-current="page"] svg { color: inherit; }

.theme {
  display: flex;
  gap: 4px;
  margin: 0 8px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.theme button {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}

.theme button:hover { color: var(--text); }
.theme button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

#menu a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: auto 8px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state="ok"] .dot { background: var(--ok); }
.status[data-state="problem"] .dot { background: var(--bad); }

main {
  width: 100%;
  max-width: 1100px;
  padding: 32px 24px 64px;
}

h1 { margin: 0 0 4px; font-size: 2rem; font-weight: 700; letter-spacing: -0.01em; }
.help { margin: 0 0 20px; color: var(--muted); }

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  background: var(--bad-soft);
}

.banner p { margin: 0; }

.fields {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.field {
  display: flex;
  flex: 1 1 220px;
  flex-direction: column;
  gap: 6px;
}

.label { font-weight: 600; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#form { max-width: 760px; }
.hint { color: var(--muted); font-size: 0.9rem; }

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--field-border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  font: inherit;
}

button {
  font: inherit;
  cursor: pointer;
}

.word {
  color: var(--accent);
  text-decoration: none;
}

.word:hover { text-decoration: underline; }

.filters { margin-top: 20px; }
.filters summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.filters-body { display: grid; gap: 16px; margin-top: 12px; }

.filters fieldset { margin: 0; padding: 0; border: 0; }
.filters legend { margin-bottom: 8px; padding: 0; }

.options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 24px;
}

.check { display: flex; align-items: center; gap: 10px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.actions { margin-top: 20px; }

.primary,
.secondary,
.banner button {
  display: inline-flex;
  align-items: center;
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 600;
}

.primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
}

a.secondary { text-decoration: none; }

.small { padding: 6px 14px; font-size: 0.95rem; }

.secondary,
.banner button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

button:disabled { opacity: 0.6; cursor: wait; }

.result { margin-top: 24px; }

.message {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--warn-soft);
}

.message.error { background: var(--bad-soft); }

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

.summary p { margin: 0; font-weight: 600; }

.words {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 1.05rem;
  line-height: 1.9;
}

.words li { display: inline; }
.words li:not(:last-child)::after { content: ", "; color: var(--muted); }

.narrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
}

.back { margin-bottom: 16px; }

.toggle[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.toggle[aria-pressed="true"]::before { content: "✓ "; white-space: pre; }

.group + .group { margin-top: 24px; }
.group-title { margin: 0 0 8px; font-size: 1.15rem; }

.more { margin-top: 20px; }

.big-word {
  margin: 0 0 16px;
  font-size: 2.6rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.senses { padding-left: 24px; }
.senses li { margin-bottom: 10px; }
.category { color: var(--muted); font-style: italic; }
.source { color: var(--muted); font-size: 0.9rem; }

.checks { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }

.check-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.check-row .mark { font-weight: 700; }
.check-row.yes .mark { color: var(--ok); }
.check-row.no .mark { color: var(--bad); }

.tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.85rem;
}

.spinner {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: middle;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    flex-flow: row wrap;
    align-items: center;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand { flex: 1; }
  .options { grid-template-columns: 1fr; }
  .theme { order: 1; margin: 0; }
  .theme button { padding: 6px 10px; }
  .status { order: 2; margin: 0; }

  #menu {
    order: 3;
    flex: 1 0 100%;
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  #menu a { flex: 0 0 auto; }
  main { padding: 20px 16px 48px; }
}
