:root {
  color-scheme: dark;
  --bg: #0f1115;
  --fg: #e7e9ee;
  --muted: #9aa3b2;
  --card: #171a21;
  --border: #242936;
  --border-strong: #2f3647;
  --accent: #7cc4ff;
  --good: #6aaa64;
  --warn: #c9b458;
  --bad: #787c7e;
  --radius: 8px;
  --maxw: 820px;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body { display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  max-width: var(--maxw); width: 100%; margin: 0 auto;
}
.topbar .brand { color: var(--muted); font-size: 0.9rem; }
.topbar .title { font-weight: 700; }
.topbar .title a { color: inherit; text-decoration: none; }
.topbar .title a:hover { color: var(--accent); text-decoration: none; }
.topbar .stats { margin-left: auto; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

main {
  flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: 1rem; display: flex; flex-direction: column; gap: 1rem;
}

.foot {
  max-width: var(--maxw); width: 100%; margin: 0 auto;
  padding: 1rem; font-size: 0.85rem; border-top: 1px solid var(--border);
}
.foot strong { color: var(--fg); font-weight: 600; }

.muted { color: var(--muted); }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* ---- Ghost / step buttons ---- */
.ghost {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-radius: 6px; cursor: pointer; font: inherit; padding: 0.25rem 0.55rem;
}
.ghost:hover { color: var(--fg); border-color: var(--border-strong); }
.ghost.small { font-size: 0.8rem; padding: 0.1rem 0.4rem; }
.ghost.step {
  width: 2.2rem; height: 2.2rem; padding: 0;
  font-size: 1.25rem; line-height: 1;
  border: 1px solid var(--border-strong); color: var(--fg);
  display: inline-flex; align-items: center; justify-content: center;
}
.ghost.step:hover { border-color: var(--accent); background: var(--card); }
.ghost.step:active { transform: translateY(1px); }

/* ---- Fieldsets ---- */
fieldset.length-control, fieldset.pins {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.5rem 0.75rem 0.75rem; margin: 0;
}
fieldset legend {
  padding: 0 0.4rem; color: var(--muted); font-size: 0.85rem;
  display: inline-flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}

/* ---- Length slider ---- */
.length-val {
  font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums;
  background: var(--border-strong); padding: 0.1rem 0.5rem; border-radius: 6px;
  min-width: 2.4rem; text-align: center; font-size: 0.95rem;
}
.length-row {
  display: flex; align-items: center; gap: 0.75rem; margin-top: 0.4rem;
}
.length-row input[type="range"] {
  flex: 1; min-width: 0; accent-color: var(--accent);
  height: 1.8rem;
}

/* ---- Pinned positions ---- */
.pins-row {
  display: flex; gap: 6px; margin-top: 0.4rem; flex-wrap: wrap;
  align-items: center;
}
.pin-cell {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: block;
}
.pin {
  appearance: none; -webkit-appearance: none;
  box-sizing: border-box;
  display: block;
  width: 100%; height: 100%;
  background: var(--card);
  border: 2px solid var(--border-strong);
  background-clip: padding-box;
  color: var(--fg);
  padding: 0; margin: 0;
  text-align: center;
  font: inherit; font-size: 1.2rem; font-weight: 700; text-transform: uppercase;
  border-radius: 6px;
  outline: none;
  vertical-align: middle;
  line-height: 1;
}
.pin:focus {
  box-shadow: 0 0 0 2px rgba(124, 196, 255, 0.45);
  position: relative;
  z-index: 1;
}
.pin.filled {
  background: var(--good);
  color: #fff;
}

/* ---- Results ---- */
.results { display: flex; flex-direction: column; gap: 0.5rem; }
.results-header {
  display: flex; align-items: baseline; gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}
.results-header #count { font-weight: 700; }
.rows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
}
.word {
  display: inline-block;
  padding: 0.4rem 0.55rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit; font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: 0.04em;
  color: var(--fg);
}
.word b {
  color: var(--good);
  font-weight: 700;
}
.empty { padding: 2rem; text-align: center; }

/* ---- Mobile ---- */
@media (max-width: 600px) {
  main { padding: 0.75rem; gap: 0.75rem; }
  .topbar { padding: 0.6rem 0.75rem; gap: 0.6rem; flex-wrap: wrap; }
  .topbar .title { font-size: 0.95rem; }
  .topbar .stats { font-size: 0.75rem; flex-basis: 100%; margin-left: 0; }
  fieldset.length-control, fieldset.pins { padding: 0.4rem 0.6rem 0.6rem; }
  .rows { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .word { font-size: 0.9rem; padding: 0.35rem 0.4rem; }
}

@media (max-width: 420px) {
  .pin-cell { width: 36px; height: 36px; }
  .pin { font-size: 1rem; }
  .pins-row { gap: 4px; }
  .ghost.step { width: 2rem; height: 2rem; font-size: 1.1rem; }
}
