.narrow { max-width: 640px; }
.big { font-size: 3.4rem; }
:root {
  --grid-line: #5b6591;
  --tile: #fbfcff;
  --tile-fixed: #e9edfa;
  --tile-op: #fff3cf;
  --tile-eq: #d7dcf0;
  --tile-empty: #ffffff;
}
:root[data-theme="dark"] {
  --grid-line: #6f7cae;
  --tile: #1c2540;
  --tile-fixed: #27335a;
  --tile-op: #3a3520;
  --tile-eq: #33406b;
  --tile-empty: #141b30;
}
.setup { display: grid; gap: 10px; margin-bottom: 12px; }
.opt { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.lbl { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.opt .lbl { width: 70px; }
.g-stats { flex-wrap: nowrap; }
.g-stats .g-stat { flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px; text-align: center; }

.board-wrap {
  position: relative;
  padding: 14px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}
.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(var(--n, 9), 1fr);
  gap: 0;
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
  -webkit-user-select: none;
  user-select: none;
  filter: drop-shadow(0 6px 12px rgba(10, 14, 30, 0.22));
  transition: opacity 0.2s ease, filter 0.2s ease;
}
.board-wrap.busy .board { opacity: 0.25; filter: blur(2px); pointer-events: none; }
.busy-label {
  display: none;
  position: absolute;
  inset: 0;
  place-items: center;
  font-weight: 800;
  color: var(--ink);
}
.board-wrap.busy .busy-label { display: grid; }

/* Crossword tiles: joined edge to edge, so each equation reads as one connected strip */
.cell {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  margin: 0;
  border: 1px solid var(--grid-line);
  border-radius: 0;
  font: 800 calc(100cqi / var(--n, 9) * 0.46) var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--tile);
  transition: background 0.15s ease, transform 0.12s ease;
}
.cell.blank { visibility: hidden; border: 0; }
.cell.num { background: var(--tile-fixed); }
.cell.sym {
  background: var(--tile-op);
  font-weight: 700;
  font-size: calc(100cqi / var(--n, 9) * 0.4);
  color: var(--gold-deep);
}
:root[data-theme="dark"] .cell.sym { color: var(--gold); }
.cell.sym.eq { background: var(--tile-eq); color: var(--ink); }
.cell.empty {
  cursor: pointer;
  background: var(--tile-empty);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--blue) 35%, transparent);
}
.cell.empty:hover { background: color-mix(in srgb, var(--blue) 14%, var(--tile-empty)); }
.cell.empty.filled { background: var(--gold-soft); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--gold) 65%, transparent); }
.cell.empty.hinted { background: color-mix(in srgb, var(--purple) 16%, var(--tile-empty)); box-shadow: inset 0 0 0 3px var(--purple); }
.cell.empty.active { z-index: 2; background: color-mix(in srgb, var(--blue) 22%, var(--tile-empty)); box-shadow: 0 0 0 3px var(--focus); }
.cell.empty:focus-visible { z-index: 2; outline: 3px solid var(--focus); outline-offset: -3px; }
.cell.ok { background: color-mix(in srgb, var(--green) 24%, var(--tile)); color: var(--ink); }
.cell.sym.ok { color: var(--green); }
.cell.bad { background: color-mix(in srgb, var(--red) 22%, var(--tile)); }
.cell.sym.bad { color: var(--red); }
.cell.pop { animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.4); z-index: 1; }
@keyframes pop { from { transform: scale(0.85); } }

.bank-wrap { margin-top: 14px; display: grid; gap: 8px; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; align-content: flex-start; }
.bank-tile {
  min-width: 48px;
  height: 48px;
  padding: 0 12px;
  font: 800 1.15rem var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--on-gold);
  background: linear-gradient(180deg, #ffd25a, var(--gold));
  border: 1px solid var(--gold-deep);
  border-radius: 12px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 3px 0 var(--gold-deep);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.bank-tile:hover { transform: translateY(-2px); }
.bank-tile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold-deep); }
.bank-tile.selected { outline: 3px solid var(--focus); outline-offset: 2px; transform: translateY(-3px); }
.bank-tile:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.bank-done { color: var(--green); font-weight: 800; align-self: center; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.how { margin-top: 16px; }
.how summary { cursor: pointer; font-weight: 800; }
.how ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); line-height: 1.55; }
.how b { color: var(--ink); }

@media (max-width: 480px) {
  .board-wrap { padding: 8px; border-radius: 18px; }
}
