:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f0f0f6;
  --text: #16161d;
  --muted: #5d5d6e;
  --border: #e2e2ea;
  --accent: #4f46e5;
  --accent-2: #4338ca;
  --accent-soft: #eef0ff;
  --tile: #fdf3d8;
  --tile-edge: #e6cf8f;
  --tile-text: #3d2f08;
  --ring: 0 0 0 3px rgba(79, 70, 229, .35);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 16, 29, .05), 0 4px 16px rgba(16, 16, 29, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f14; --surface: #191920; --surface-2: #22222b; --text: #ececf1; --muted: #a0a0b2;
    --border: #2e2e3a; --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #23243d;
    --tile: #3a3220; --tile-edge: #5a4c2a; --tile-text: #f7e7bd; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f14; --surface: #191920; --surface-2: #22222b; --text: #ececf1; --muted: #a0a0b2;
  --border: #2e2e3a; --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #23243d;
  --tile: #3a3220; --tile-edge: #5a4c2a; --tile-text: #f7e7bd; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
kbd {
  font: 600 .8em ui-monospace, SFMono-Regular, Menlo, monospace; padding: .1em .4em;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface);
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: none; box-shadow: var(--ring); }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand-tiles { display: flex; gap: 2px; }
.brand-tiles span {
  display: grid; place-items: center; width: 24px; height: 26px; border-radius: 5px; font-size: .8rem;
  background: var(--tile); color: var(--tile-text); box-shadow: inset 0 -2px 0 var(--tile-edge);
}
.nav { display: flex; align-items: center; gap: 18px; }
.nav a { color: var(--muted); text-decoration: none; font-size: .95rem; }
.nav a:hover { color: var(--text); }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 1.3rem; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
@media (max-width: 520px) { .nav a { display: none; } }

/* Hero / search */
.hero { padding: 36px 0 20px; text-align: center; }
.hero h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.lede { color: var(--muted); margin: 0 auto 22px; max-width: 560px; }
.search { max-width: 680px; margin: 0 auto; }
.search-box {
  position: relative; display: flex; gap: 8px; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.search-box:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.search-box input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font-size: 1.3rem; font-weight: 600; letter-spacing: .08em; padding: 10px 40px 10px 12px; text-transform: uppercase;
}
.search-box input::placeholder { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); font-size: 1.05rem; }
.search-box input:focus { outline: none; box-shadow: none; }
.clear-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: var(--surface-2); color: var(--muted); font-size: 1.2rem; cursor: pointer; line-height: 1;
}
.btn-primary {
  border: 0; border-radius: 11px; background: var(--accent); color: #fff;
  font-weight: 700; font-size: 1rem; cursor: pointer; padding: 12px 28px;
}
.search-actions { display: flex; justify-content: flex-start; margin-top: 10px; }
:root[data-theme="dark"] .btn-primary { color: #0f0f14; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0f0f14; } }
.btn-primary:hover { background: var(--accent-2); }
@media (max-width: 520px) { .search-actions .btn-primary { width: 100%; } }

.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 44px; margin: 14px 0 4px; }
.tile {
  display: grid; place-items: center; position: relative; width: 38px; height: 42px; border-radius: 7px;
  background: var(--tile); color: var(--tile-text); font-weight: 800; font-size: 1.15rem;
  box-shadow: inset 0 -3px 0 var(--tile-edge); text-transform: uppercase; animation: pop .14s ease-out;
}
.tile sub { position: absolute; right: 4px; bottom: 3px; font-size: .55rem; font-weight: 700; }
.tile.blank { color: transparent; }
.tile.blank::before { content: "?"; color: var(--tile-text); opacity: .45; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

/* Example diagrams on the homepage: racks, answers and game boards drawn with tiles */
.ex { margin: 10px 0 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.ex-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ex-row + .ex-row { margin-top: 10px; }
.ex-label { min-width: 74px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ex-tiles { display: flex; flex-wrap: wrap; gap: 4px; }
.ex-tiles + .ex-tiles { margin-left: 8px; }
.ex-pts { font-size: .78rem; font-weight: 700; color: var(--muted); }
.ex .tile { width: 30px; height: 34px; font-size: .95rem; border-radius: 6px; animation: none; }
.ex .tile sub { right: 3px; bottom: 2px; font-size: .5rem; }
.ex .tile.hit { box-shadow: inset 0 -3px 0 var(--accent); outline: 2px solid var(--accent); outline-offset: -2px; }
.ex .tile.wild { text-decoration: underline 2px var(--accent); text-underline-offset: 3px; }
.ex .tile.ghost { background: none; box-shadow: none; border: 2px dashed var(--border); color: var(--muted); }
/* Wordle-style feedback squares */
.ex .tile.w-hit { background: #3f8f55; color: #fff; box-shadow: none; }
.ex .tile.w-near { background: #c49a1c; color: #1f1800; box-shadow: none; }
.ex .tile.w-miss { background: #7c7c88; color: #fff; box-shadow: none; }
/* Crossword answer squares */
.ex .tile.cw { background: var(--surface); color: var(--text); box-shadow: none; border: 2px solid var(--text); border-radius: 2px; }
.ex .tile.cw.cw-blank { color: transparent; }
/* Letter wheel (Wordscapes / Text Twist) */
.ex-wheel { position: relative; width: 112px; height: 112px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); flex: none; }
.ex-wheel .tile { position: absolute; left: 41px; top: 39px; transform: rotate(calc(var(--i) * 60deg)) translateY(-38px) rotate(calc(var(--i) * -60deg)); }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 10px; }

.filters { text-align: left; margin-top: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.filters summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: .95rem; list-style-position: inside; }
.filter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 4px 14px 14px; }
.filter-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); font-weight: 600; }
.filter-grid input[type=text], .filter-grid select {
  font: inherit; font-size: 1rem; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; text-transform: lowercase; width: 100%;
}
.filter-grid .check { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); }
.filter-grid .check input { width: 18px; height: 18px; accent-color: var(--accent); }
@media (max-width: 620px) { .filter-grid { grid-template-columns: 1fr 1fr; } }

/* Layout */
.layout { max-width: 860px; padding-bottom: 40px; } /* single column; Auto ads place themselves */


/* Results */
.results { min-height: 160px; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.empty-title { font-weight: 700; color: var(--text); font-size: 1.1rem; margin: 0 0 6px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-transform: uppercase; }

.summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; }
.summary h2 { font-size: 1.15rem; margin: 0; }
.summary h2 span { color: var(--muted); font-weight: 500; }
.sort { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.sort button { border: 0; background: none; color: var(--muted); padding: 6px 12px; border-radius: 7px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.sort button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.hidden-note { margin: -4px 0 12px; font-size: .85rem; color: var(--muted); }
.hidden-note .link-btn { text-transform: none; }
.empty .hidden-note { margin: 10px 0 0; }
.jump { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: thin; }
.jump a {
  flex: none; text-decoration: none; font-size: .85rem; font-weight: 600; padding: 5px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.jump a:hover { border-color: var(--accent); color: var(--accent); }

.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 16px; margin-bottom: 14px; scroll-margin-top: 12px; }
.group h3 { margin: 0 0 10px; font-size: 1rem; display: flex; align-items: baseline; gap: 8px; }
.group h3 small { color: var(--muted); font-weight: 500; }
.words { display: flex; flex-wrap: wrap; gap: 8px; }
.word {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px 7px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-weight: 600;
  font-size: .98rem; cursor: pointer; text-transform: lowercase; transition: border-color .1s, transform .1s;
}
.word:hover { border-color: var(--accent); }
.word:active { transform: scale(.97); }
.word u { text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.word .pts { font-size: .7rem; font-weight: 700; color: var(--muted); background: var(--surface-2); border-radius: 5px; padding: 1px 5px; }
.more-btn { margin-top: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--accent); font: inherit; font-weight: 600; font-size: .9rem; border-radius: 9px; padding: 7px 14px; cursor: pointer; }
.more-btn:hover { background: var(--accent-soft); }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); }
.loading-inline { padding: 8px; justify-content: flex-start; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Content */
.prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 22px 18px; margin-top: 8px; }
.prose h2 { font-size: 1.25rem; margin: 20px 0 8px; }
.prose li { margin-bottom: 6px; }
.faq { border-top: 1px solid var(--border); padding: 4px 0; }
.faq summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.faq p { margin: 0 0 12px; color: var(--muted); }
.page { max-width: 760px; margin: 28px auto 48px; }
/* Content pages with ads: a 760px column holding the article and its ad slots */
.page-col { max-width: 760px; margin: 28px auto 48px; }
.page-col .page { margin: 0; }
.prose h3 { font-size: 1.05rem; margin: 16px 0 6px; }
.prose .lead { font-size: 1.05rem; }
.tip { border-left: 3px solid var(--border); padding: 2px 0 2px 12px; color: var(--muted); }

/* Footer */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .9rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding-top: 14px; padding-bottom: 14px; }
.footer-inner p { margin: 0; }
.footer-inner nav { display: flex; gap: 16px; }
.footer-inner a { color: var(--muted); }

/* Word sheet */
.sheet {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(520px, calc(100% - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.sheet::backdrop { background: rgba(10, 10, 20, .45); }
@media (max-width: 600px) {
  .sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; }
}
.sheet-inner { padding: 18px 20px 20px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h3 { margin: 0; font-size: 1.6rem; text-transform: lowercase; flex: 1; }
.score-pill { font-size: .8rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); padding: 3px 9px; border-radius: 999px; }
.sheet-def { margin: 12px 0 16px; color: var(--muted); min-height: 48px; }
.sheet-def p { margin: 0 0 8px; }
.sheet-def em { color: var(--text); font-style: normal; font-weight: 600; margin-right: 4px; }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-secondary {
  display: inline-flex; align-items: center; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-weight: 600; font-size: .92rem; border-radius: 10px; padding: 9px 14px; cursor: pointer; text-decoration: none;
}
.btn-secondary:hover { border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem;
  transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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