/* === Variables & Base === */
:root {
  color-scheme: light;
  --bg: #F3F4F6;
  --surface: #F9FAFB;
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-ring: rgba(79, 70, 229, 0.2);
  --accent: #F59E0B;
  --ink: #111827;
  --muted: #6B7280;
  --border: #E5E7EB;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

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

html {
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--primary-dark);
}

button,
input,
select {
  font: inherit;
}

button,
summary {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--primary-ring);
  outline-offset: 3px;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
}

/* === Header (shared: main page + generated pages) === */
.site-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand:hover {
  color: var(--primary-dark);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px 20px;
  font-size: 14px;
  font-weight: 700;
}

.header-nav a {
  color: var(--muted);
  text-decoration: none;
}

.header-nav a:hover {
  color: var(--primary-dark);
}

/* === Main page: input section === */
.input-section {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 24px 28px;
  text-align: center;
}

.hero-title {
  margin: 0 0 8px;
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.hero-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 17px;
}

#unscramble-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
}

.input-row {
  position: relative;
}

.input-row input {
  width: 100%;
  height: 52px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0 44px 0 16px;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.input-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms ease, background 150ms ease;
}

.input-clear:hover {
  color: var(--ink);
  background: var(--border);
}

.input-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.input-row input::placeholder {
  color: #9CA3AF;
}

.button-row {
  display: flex;
  gap: 10px;
}

.unscramble-btn {
  flex: 1;
  height: 52px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background 180ms ease, transform 180ms ease;
}

.unscramble-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.unscramble-btn:active {
  transform: translateY(0);
}

/* Options toggle */
.options-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  background: none;
  border: 1.5px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 0 18px;
  border-radius: 12px;
  white-space: nowrap;
  transition: color 180ms ease, border-color 180ms ease;
}

.options-toggle:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.toggle-arrow {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 180ms ease;
  flex-shrink: 0;
}

.options-toggle[aria-expanded="true"] .toggle-arrow {
  transform: rotate(-135deg) translateY(-2px);
}

/* Options panel */
.options-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: left;
}

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

.option-label span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.option-label input,
.option-label select {
  width: 100%;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  min-height: unset;
}

.option-label input:focus,
.option-label select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.reset-options {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0 0;
  text-decoration: underline;
}

.reset-options:hover {
  color: var(--primary);
}

/* === Main page: results === */
#results {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 24px 56px;
}

.empty-state {
  text-align: center;
  padding: 32px 0;
  color: var(--muted);
}

.empty-state a {
  color: var(--primary);
}

.results-summary {
  margin: 0 0 24px;
  font-size: 18px;
  color: var(--ink);
}

.results-summary span {
  color: var(--muted);
}

.results-query {
  color: var(--ink);
}

.word-group {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  background: #fff;
}

.group-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #374151;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}


.chip-row {
  display: flex;
  flex-wrap: wrap;
  column-gap: 8px;
  row-gap: 2px;
}

/* === Word chip (shared: main page chips + generated page best-words) === */
.word-chip {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  padding: 4px 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.02em;
  text-transform: lowercase;
  cursor: default;
}

.word-chip:hover {
  color: var(--primary);
}

.word-chip > span {
  font-size: 11px;
  font-weight: 600;
  color: #9CA3AF;
}

.results-cap-note {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.clear-link {
  display: block;
  margin: 20px auto 0;
  padding: 8px 20px;
  width: fit-content;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  background: none;
  text-decoration: none;
  transition: border-color 150ms ease, color 150ms ease;
}

.clear-link:hover {
  border-color: #9CA3AF;
  color: var(--ink);
}

/* === Footer === */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.site-footer a {
  color: var(--muted);
  text-decoration: underline;
}

/* === Generated pages: shared layout tokens === */
.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  max-width: 700px;
  font-size: clamp(32px, 5vw, 56px);
}

h2 {
  font-size: 26px;
}

h3 {
  font-size: 19px;
}


/* Generated pages: hero section (two-column grid) */
.hero-section {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(340px, 1.15fr);
  gap: 28px;
  align-items: end;
  padding: 44px 24px 34px;
  max-width: 1160px;
  margin: 0 auto;
}

.generated-page {
  padding-top: 20px;
}

.generated-intro {
  max-width: 780px;
  margin: 12px 0 22px;
  color: var(--muted);
  font-size: 18px;
}

.related-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.related-links a {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-weight: 800;
  text-decoration: none;
}

/* Generated pages: tool form */
.tool-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 18px 50px rgba(79, 70, 229, 0.07);
}

.field-label,
.advanced-filters label span {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.letter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  color: var(--ink);
  background: #fff;
}

input::placeholder {
  color: #9CA3AF;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 700;
  transition: transform 180ms ease, background 180ms ease;
}

.primary-button {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.28);
}

.primary-button:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.secondary-button {
  color: var(--primary);
  background: #EEF2FF;
}

.secondary-button:hover {
  background: #E0E7FF;
}

.field-note {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.advanced-filters {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.advanced-filters summary {
  color: var(--primary);
  font-weight: 700;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 15px;
}

/* Generated pages: results area */
.results-section {
  width: min(1160px, calc(100% - 48px));
  margin: 0 auto;
  padding: 18px 0 44px;
}

.best-words {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 20px;
  margin-bottom: 14px;
}

.word-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 12px;
}

.result-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 20px;
  margin-bottom: 14px;
}

.group-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.group-heading span {
  color: var(--muted);
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 500px;
  border-collapse: collapse;
  font-size: 15px;
}

th,
td {
  border-top: 1px solid var(--border);
  padding: 10px;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td:not(:first-child),
th:not(:first-child) {
  text-align: right;
}


/* === Ad slot === */
.ad-slot {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 24px;
  text-align: center;
}

.ad-label {
  display: none;
}


/* === Info section === */
.info-section {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

.info-section h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin: 36px 0 10px;
  letter-spacing: -0.02em;
}

.info-section h2:first-child {
  margin-top: 0;
}

.info-section p,
.info-section ul {
  color: var(--muted);
  margin: 0 0 14px;
  line-height: 1.75;
}

.info-section ul {
  padding-left: 20px;
}

.info-section li {
  margin-bottom: 6px;
}

.info-section code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.9em;
  color: var(--primary);
}

/* === Responsive === */
@media (max-width: 960px) {
  .hero-section {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .input-section {
    padding: 28px 16px 20px;
  }

  #results {
    padding: 4px 16px 40px;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }

  .site-header {
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
  }

  .letter-row {
    grid-template-columns: 1fr;
  }
}

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