:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #14171f;
  --text-muted: #5b6270;
  --border: #e3e6ee;
  --accent: #4f46e5;
  --accent-contrast: #ffffff;
  --accent-soft: #eef0ff;
  --required-bg: #fff4e6;
  --required-border: #eeae63;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --text: #eef0f5;
    --text-muted: #9aa1b2;
    --border: #2a2e3a;
    --accent: #818cf8;
    --accent-contrast: #0f1117;
    --accent-soft: #1e2030;
    --required-bg: rgba(255, 171, 61, .14);
    --required-border: rgba(255, 176, 74, .55);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 20px;
}

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

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 14px;
}
.brand {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.brand-logo {
  display: block;
  height: clamp(34px, 9vw, 44px);
  width: auto;
  border-radius: 6px;
}
.site-nav {
  display: flex;
  gap: 16px;
}
.site-nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: .95rem;
}

/* Main */
main.wrap {
  padding-top: 32px;
  padding-bottom: 48px;
}

.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { font-size: 2rem; margin: 0 0 8px; }
.lead {
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto 24px;
}

/* Letter count selector */
.letter-count {
  display: inline-flex;
  gap: 4px;
  background: var(--accent-soft);
  padding: 4px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.letter-count__option {
  position: relative;
  display: block;
}
.letter-count__option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.letter-count__option span {
  display: block;
  min-width: 34px;
  padding: 6px 4px;
  text-align: center;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.letter-count__option input:checked + span {
  background: var(--accent);
  color: var(--accent-contrast);
}
.letter-count__option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Letter boxes */
.letter-boxes {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 8px;
  margin-bottom: 18px;
  /* Sized so all 9 boxes plus their gaps always fit in one row, even on
     narrow portrait phones - see .wrap padding (40px) and the 8px column
     gap x 8 gaps (64px) subtracted below, with a small safety margin. */
  --box-w: clamp(24px, calc((100vw - 112px) / 9), 46px);
}
.letter-cell {
  position: relative;
}
.letter-cell--hidden {
  display: none;
}
/* Visual gap between the pinned "required" group and the rest of the row */
.letter-cell.required + .letter-cell:not(.required) {
  margin-left: 16px;
}
.letter-box {
  display: block;
  width: var(--box-w);
  height: calc(var(--box-w) * 1.2);
  font-size: calc(var(--box-w) * 0.42);
  text-align: center;
  text-transform: uppercase;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s ease, transform .1s ease, background-color .15s ease;
}
.letter-box:focus {
  outline: none;
  border-color: var(--accent);
  transform: translateY(-1px);
}
.letter-box:disabled {
  display: none;
}

/* Required-letter tick: a small mark tucked in the tile's corner so it adds
   no extra height - important for short/landscape viewports. */
.required-toggle {
  position: absolute;
  bottom: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.required-toggle::before {
  /* enlarges the tap target well past the visible mark, without growing it visually */
  content: "";
  position: absolute;
  inset: -8px;
}
.required-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.required-toggle__mark {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  pointer-events: none;
  transition: background-color .15s ease, border-color .15s ease;
}
.required-toggle__mark::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 3px;
  width: 7px;
  height: 4px;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
  opacity: 0;
  transition: opacity .1s ease;
}
.required-radio:checked ~ .required-toggle__mark {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.required-radio:checked ~ .required-toggle__mark::after {
  opacity: 1;
}
.required-radio:focus-visible ~ .required-toggle__mark {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.letter-cell.required .letter-box {
  background: var(--required-bg);
  border-color: var(--required-border);
}

.hint {
  text-align: center;
  color: var(--text-muted);
  font-size: .82rem;
  margin: 0 0 16px;
}

.form-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius);
  padding: 11px 22px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s ease, transform .1s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { opacity: .92; }
.btn--ghost { background: var(--accent-soft); color: var(--accent); }
.btn--ghost:hover { opacity: .85; }

.status {
  text-align: center;
  min-height: 1.2em;
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: 10px;
}

/* Results */
.results { margin-top: 8px; }
.results-summary {
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-muted);
}
.result-group { margin-bottom: 18px; }
.group-title {
  font-weight: 700;
  margin-bottom: 8px;
}
.group-title .count { color: var(--text-muted); font-weight: 400; }
.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: .9rem;
  box-shadow: var(--shadow);
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
}

/* Ads */
.ad-slot {
  margin: 24px 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* About / FAQ */
.about, .faq {
  max-width: 640px;
  margin: 40px auto 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.about h2, .faq h2 { font-size: 1.2rem; margin-bottom: 10px; }
.about ul { padding-left: 20px; margin: 10px 0; }
.about li { margin-bottom: 6px; }
.faq-item { margin-bottom: 16px; }
.faq-item h3 { font-size: 1rem; margin: 0 0 4px; }
.faq-item p { margin: 0; color: var(--text-muted); }

/* Word list hub (/words/) */
.hub-group { margin: 24px 0; }
.hub-group h2 { font-size: 1rem; margin-bottom: 8px; }
.hub-links { display: flex; flex-wrap: wrap; gap: 6px; }
.hub-links a {
  display: inline-block;
  min-width: 30px;
  text-align: center;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: .85rem;
}
.hub-links a:hover { opacity: .85; }

/* Word list page (/words/<n>-letter-words-with-<letter>) */
.breadcrumb { font-size: .85rem; color: var(--text-muted); margin: 0 0 8px; }
.breadcrumb a { color: var(--text-muted); }
.word-list {
  margin: 20px 0;
  line-height: 2;
}
.word-list .w {
  color: var(--text);
}
.word-list .w::after { content: ", "; color: var(--text-muted); }
.word-list .w:last-child::after { content: ""; }

.crosslinks { margin-top: 32px; border-top: 1px solid var(--border); padding-top: 20px; }
.crosslinks-group { margin-bottom: 16px; }
.crosslinks-group h2 { font-size: .9rem; color: var(--text-muted); margin-bottom: 8px; }
.crosslinks-row { display: flex; flex-wrap: wrap; gap: 6px; }
.crosslinks-row a, .crosslinks-row .current {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: .8rem;
  text-decoration: none;
}
.crosslinks-row a { background: var(--accent-soft); color: var(--accent); }
.crosslinks-row .current { background: var(--accent); color: var(--accent-contrast); font-weight: 600; }

/* Legal pages */
.legal { max-width: 700px; margin: 0 auto; }
.legal h1 { margin-top: 0; }
.legal h2 { margin-top: 28px; font-size: 1.15rem; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .85rem;
}
.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 18px 20px;
}
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
}
.link-btn:hover { color: var(--accent); }

/* Cookie banner */
.cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  z-index: 1000;
}
.cookie-banner__text {
  flex: 1 1 260px;
  font-size: .85rem;
  color: var(--text-muted);
}
.cookie-banner__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.6rem; }
}

/* Short / landscape phones: reclaim vertical space so the tool and its
   results stay usable without excessive scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  main.wrap { padding-top: 16px; padding-bottom: 24px; }
  .hero { margin-bottom: 16px; }
  .hero h1 { font-size: 1.3rem; margin-bottom: 4px; }
  .lead { margin-bottom: 14px; font-size: .85rem; }
  .letter-box { height: clamp(32px, 9vh, 44px); }
  .letter-count { margin-bottom: 10px; }
  .letter-boxes { margin-bottom: 12px; }
  .cookie-banner { padding: 10px 14px; }
}
