:root {
  --bg: #12151c;
  --bg-elevated: #1a1f2b;
  --bg-input: #0e1117;
  --border: #2a3344;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #e6a23c;
  --accent-dim: #b87a1f;
  --ok: #3dba7a;
  --danger: #e06c75;
  --focus: #5b8def;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #2a2218 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, #1a2438 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

body {
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 3rem;
}

.shell {
  max-width: 920px;
  margin: 0 auto;
}

header.hero {
  margin-bottom: 1.75rem;
}

header.hero h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

header.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 40rem;
}

.panel {
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.bar {
  flex: 1;
  height: 10px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.2s ease;
}

.pct {
  font-family: var(--mono);
  font-size: 0.85rem;
  min-width: 3.5rem;
  text-align: right;
  color: var(--accent);
}

.status-line {
  font-size: 0.92rem;
  color: var(--muted);
  min-height: 1.4em;
}

.level-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.pill {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--bg-input);
}

.pill.ready {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  min-height: 2.25rem;
}

/* Hide number spinners when type=number is used */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.field-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.n-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.n-buttons button {
  min-width: 2.4rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.95rem;
}

.n-buttons button:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--muted);
}

.n-buttons button.active {
  color: #1a1206;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.n-buttons button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.modes {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.modes button {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

.modes button.active {
  color: var(--text);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-input));
}

.grid-values {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

button.primary {
  background: var(--accent);
  color: #1a1206;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}

button.ghost:hover {
  color: var(--text);
  border-color: var(--muted);
}

.hidden {
  display: none !important;
}

.results {
  font-family: var(--mono);
  font-size: 0.88rem;
  max-height: 22rem;
  overflow: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  white-space: pre-wrap;
}

.results:empty::before {
  content: "Solutions will appear here.";
  color: var(--muted);
}

.meta {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

footer.note {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 560px) {
  .row-2 {
    grid-template-columns: 1fr;
  }
}

/* How it works */
.explain-body h3 {
  margin: 1.35rem 0 0.45rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.explain-body h3:first-child {
  margin-top: 0.25rem;
}

.explain-body p {
  margin: 0 0 0.75rem;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
  max-width: 42rem;
}

.explain-body a {
  color: var(--accent);
}

.explain-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}

.formula {
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.explain-list {
  margin: 0 0 0.85rem;
  padding-left: 1.25rem;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
}

.explain-list li {
  margin-bottom: 0.35rem;
}

.explain-note {
  font-size: 0.9rem;
  color: var(--muted) !important;
}

.table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0 0.75rem;
}

.count-table {
  width: 100%;
  max-width: 22rem;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.88rem;
}

.count-table th,
.count-table td {
  text-align: left;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

.count-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.count-table td:last-child {
  text-align: right;
}

.demo-toolbar {
  margin-top: 0.5rem;
}

.demo-list {
  list-style: none;
  margin: 0.75rem 0 0.35rem;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: 22rem;
}

.demo-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.demo-item:last-child {
  border-bottom: none;
}

.demo-item.match {
  color: var(--text);
  background: color-mix(in srgb, var(--ok) 14%, transparent);
}

.demo-expr {
  overflow-wrap: anywhere;
}

.demo-side {
  display: flex;
  flex-shrink: 0;
  gap: 0.85rem;
  align-items: baseline;
}

.demo-delta {
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 4.5rem;
  text-align: right;
}

.demo-item.match .demo-delta {
  color: var(--ok);
}

.demo-val {
  flex-shrink: 0;
  color: inherit;
  min-width: 4.5rem;
  text-align: right;
}

