/* ---------- Pools (terms of a sequence) ---------- */
.pools { display: grid; grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); gap: 12px; }
.pool {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 10px 8px;
  border-radius: 16px;
  background: var(--well);
  box-shadow: inset 0 0 0 1px var(--panel-line);
  text-align: center;
  min-width: 0;
}
.pool-label { font-weight: 900; font-size: var(--step--1); color: var(--mist); text-transform: uppercase; letter-spacing: 0.08em; }
.pool-body {
  width: 100%; min-height: 112px;
  display: grid; place-items: center;
  padding: 8px;
  border-radius: 12px;
  background: rgba(31, 127, 140, 0.25);
}
.pool-count { font-weight: 900; font-variant-numeric: tabular-nums; }
.pool--build { background: rgba(246, 214, 139, 0.1); box-shadow: inset 0 0 0 2px var(--sand); }
.pool--build .pool-label { color: var(--sand); }
.pool--win { box-shadow: inset 0 0 0 3px var(--kelp); background: rgba(108, 197, 159, 0.16); }
.pool--far { background: transparent; box-shadow: inset 0 0 0 2px dashed var(--panel-line); border: 2px dashed var(--panel-line); }
.far-q { font-family: var(--font-display); font-size: 2.6rem; color: var(--sand); }
.empty { color: var(--mist); font-style: italic; font-size: var(--step--1); }

.t-count { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 120px; font-size: 1.15rem; line-height: 1.2; }
.t-count span { animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.t-groups { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 140px; }
.t-group {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0;
  max-width: 3.6em;
  padding: 2px 4px; border-radius: 10px;
  background: rgba(108, 197, 159, 0.25);
  box-shadow: inset 0 0 0 1px var(--kelp);
  font-size: 0.8rem; line-height: 1.15;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.t-squares {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 2px;
  width: calc(var(--n) * 12px + (var(--n) - 1) * 2px);
  max-width: 100%;
}
.t-squares i { display: block; aspect-ratio: 1; border-radius: 2px; background: var(--sky); box-shadow: inset 0 -2px 0 rgba(10, 34, 48, 0.3); }
.t-squares i.edge { background: var(--sand); }
.t-tri { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.t-tri-row { display: flex; gap: 2px; }
.t-tri-row i { display: block; width: 10px; height: 10px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #e9e2f7 45%, #a99cc4); }
.t-tri-row:last-child i { background: radial-gradient(circle at 35% 30%, #fff, var(--sand) 50%, var(--sand-deep)); }
.t-number { font-family: var(--font-display); font-size: 2.2rem; color: var(--sand); }

.build-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; }
.build-controls .btn--ghost { min-width: 54px; }

/* ---------- Options & rule cards ---------- */
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 10px; }
.option {
  display: flex; flex-direction: column; align-items: center; gap: 0;
  padding: 12px 10px;
  border-radius: 16px;
  background: var(--well-strong);
  box-shadow: inset 0 0 0 2px var(--panel-line), 0 4px 0 rgba(2, 12, 18, 0.45);
  transition: transform 0.08s, background 0.15s;
}
.option:hover:not(:disabled) { background: rgba(234, 247, 244, 0.2); }
.option:active:not(:disabled) { transform: translateY(3px); }
.option-num { font-family: var(--font-display); font-size: var(--step-3); line-height: 1.1; color: var(--sand); }
.option-unit { font-size: var(--step--1); font-weight: 800; color: var(--mist); }
.is-right { background: var(--kelp) !important; box-shadow: 0 4px 0 var(--kelp-deep) !important; }
.is-right .option-num, .is-right .option-unit { color: var(--ink); }
.is-wrong { background: rgba(255, 107, 127, 0.25) !important; box-shadow: inset 0 0 0 2px var(--danger) !important; opacity: 0.75; }

.cards { display: flex; flex-direction: column; gap: 10px; }
.rule-card {
  text-align: left;
  padding: 14px 16px 14px 48px;
  border-radius: 14px;
  background: var(--well-strong);
  box-shadow: inset 0 0 0 2px var(--panel-line);
  font-weight: 800;
  position: relative;
}
.rule-card::before {
  content: ""; position: absolute; left: 16px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%);
  border-radius: 50%; box-shadow: inset 0 0 0 2px var(--mist);
}
.rule-card:hover:not(:disabled) { background: rgba(234, 247, 244, 0.2); }
.rule-card.is-right { color: var(--ink); }
.rule-card.is-right::before { background: var(--ink); box-shadow: none; }

/* ---------- Number stones ---------- */
.stones { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.stone {
  min-width: 74px; height: 74px; padding: 0 10px;
  border-radius: 46% 54% 50% 50% / 55% 50% 50% 45%;
  background: radial-gradient(circle at 35% 30%, #fff1c9, var(--sand) 55%, var(--sand-deep));
  color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 5px 0 rgba(2, 12, 18, 0.45);
  font-family: var(--font-display);
  font-size: 1.7rem;
  line-height: 1;
  transition: transform 0.1s;
}
button.stone:hover:not(:disabled) { transform: translateY(-3px); }
.stone--gap { background: transparent; color: var(--sand); box-shadow: none; border: 3px dashed var(--sand); }
.stone.is-fixed { background: radial-gradient(circle at 35% 30%, #dff7ea, var(--kelp) 60%, var(--kelp-deep)); color: var(--ink); border: 0; }
.stone.is-wrong { opacity: 0.4; }
.stone-old { font-size: 0.85rem; opacity: 0.7; }

/* ---------- Number pad ---------- */
.numpad { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.np-grid { display: grid; grid-template-columns: repeat(3, 66px); gap: 8px; }
.np-key {
  height: 54px; border-radius: 14px;
  background: var(--well-strong);
  box-shadow: 0 4px 0 rgba(2, 12, 18, 0.5);
  font-family: var(--font-display); font-size: 1.5rem;
  transition: transform 0.06s;
}
.np-key:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(2, 12, 18, 0.5); }
.np-key--go { background: var(--kelp); color: var(--ink); box-shadow: 0 4px 0 var(--kelp-deep); }
.np-key--go:disabled { opacity: 0.4; }
.np-key--del { color: var(--mist); }
.np-note { font-size: var(--step--1); color: var(--mist); font-weight: 700; }

/* ---------- Pattern parade ---------- */
.parade { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.parade-item {
  width: 60px; height: 60px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--well);
  font-size: 2rem;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.parade-slot { border: 3px dashed var(--panel-line); background: transparent; font-family: var(--font-display); color: var(--mist); font-size: 1.5rem; }
.parade-slot.active { border-color: var(--sand); color: var(--sand); }
.parade-slot.filled { border: 0; background: rgba(108, 197, 159, 0.25); font-family: inherit; font-size: 2rem; }
.parade-options { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; padding-top: 6px; }
.parade-option {
  width: 74px; height: 74px; border-radius: 20px;
  background: var(--well-strong);
  box-shadow: 0 5px 0 rgba(2, 12, 18, 0.5), inset 0 0 0 2px var(--panel-line);
  font-size: 2.4rem;
  transition: transform 0.08s;
}
.parade-option:active { transform: translateY(4px); }

/* ---------- Line-up ---------- */
.sort-label { text-align: center; }
.sort-line { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; padding: 12px; border-radius: 16px; background: rgba(31, 127, 140, 0.25); }
.sort-spot { width: 76px; height: 86px; border-radius: 16px; border: 2px dashed var(--panel-line); display: grid; place-items: center; }
.sort-pool { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.pebble {
  width: 76px; height: 86px; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--well-strong);
  box-shadow: 0 5px 0 rgba(2, 12, 18, 0.5), inset 0 0 0 2px var(--panel-line);
}
.pebble.gone { visibility: hidden; }
.pebble--placed { background: rgba(108, 197, 159, 0.3); box-shadow: inset 0 0 0 2px var(--kelp); }
.pebble-critter { font-size: 1.6rem; line-height: 1; }
.pebble-num { font-family: var(--font-display); font-size: 1.5rem; color: var(--sand); line-height: 1; }

/* ---------- Balance scale ---------- */
.scale { position: relative; width: min(100%, 460px); height: 230px; margin: 0 auto; }
.beam {
  --tilt: 0deg;
  position: absolute; left: 4%; right: 4%; top: 120px; height: 12px;
  background: linear-gradient(var(--sand), var(--sand-deep));
  border-radius: 8px;
  transform: rotate(var(--tilt));
  transition: transform 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}
.scale.wobble .beam { animation: wobble 2.4s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.pan {
  position: absolute; bottom: 100%;
  width: 44%;
  display: flex; flex-direction: column; align-items: center;
  transform-origin: 50% 100%;
  transform: rotate(calc(-1 * var(--tilt)));
  transition: transform 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pan--l { left: -2%; }
.pan--r { right: -2%; }
.pan-load { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 2px; min-height: 52px; padding: 0 4px 2px; max-width: 100%; }
.pan-critter { font-size: 1.6rem; line-height: 1; }
.weight {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px 8px; border-radius: 10px;
  background: var(--panel-solid); box-shadow: inset 0 0 0 2px var(--sand);
  font-family: var(--font-display); font-size: 1.2rem; color: var(--sand);
}
.weight-shell { font-size: 1rem; }
.dish { width: 100%; height: 16px; border-radius: 0 0 60px 60px; background: linear-gradient(var(--mist), #6f9fa3); }
.post { position: absolute; left: 50%; top: 122px; bottom: 16px; width: 14px; transform: translateX(-50%); background: linear-gradient(90deg, var(--sand-deep), var(--sand), var(--sand-deep)); border-radius: 6px 6px 0 0; z-index: 1; }
.base { position: absolute; left: 50%; bottom: 0; width: 140px; height: 18px; transform: translateX(-50%); border-radius: 12px 12px 4px 4px; background: var(--sand-deep); }
.scale.balanced .beam { box-shadow: 0 0 24px var(--kelp); }
.equation { text-align: center; font-weight: 800; font-size: var(--step-1); }
.guess { display: inline-block; min-width: 2.2ch; padding: 0 6px; border-radius: 8px; background: var(--well-strong); color: var(--sand); font-family: var(--font-display); text-align: center; }
.balance-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: center; }

/* ---------- Current machine ---------- */
.machine-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.machine { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 18px; background: rgba(31, 127, 140, 0.25); box-shadow: inset 0 0 0 2px var(--panel-line); }
.machine-head, .mrow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; text-align: center; }
.machine-head { font-weight: 900; color: var(--mist); text-transform: uppercase; letter-spacing: 0.1em; font-size: var(--step--1); }
.machine-core { font-size: 1.6rem; display: inline-block; animation: spin 5s linear infinite; color: var(--sand); }
@keyframes spin { to { transform: rotate(360deg); } }
.mval {
  padding: 8px 6px; border-radius: 12px;
  background: var(--panel-solid);
  font-family: var(--font-display); font-size: 1.5rem; color: var(--foam);
  font-variant-numeric: tabular-nums;
}
.mval.q { color: var(--sand); box-shadow: inset 0 0 0 2px var(--sand); }
.mval.is-fixed { background: var(--kelp); color: var(--ink); box-shadow: none; }
.marrow { color: var(--mist); font-weight: 900; letter-spacing: 0.05em; }
.mrow--q { margin-top: 4px; padding-top: 10px; border-top: 2px dashed var(--panel-line); }
.sub-prompt { font-weight: 800; margin-bottom: 8px; }

/* ---------- Mirror pool ---------- */
.mirror-wrap { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; padding: 10px; border-radius: 16px; background: rgba(31, 127, 140, 0.25); }
.mirror { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 40px)); gap: 4px; }
.cell { aspect-ratio: 1; border-radius: 7px; background: var(--well); min-width: 18px; }
.cell.src.on { background: var(--sand); box-shadow: inset 0 -3px 0 var(--sand-deep); }
.cell.tgt { background: var(--well-strong); box-shadow: inset 0 0 0 1px var(--panel-line); transition: background 0.1s, transform 0.1s; }
.cell.tgt:hover { background: rgba(234, 247, 244, 0.22); }
.cell.tgt.on { background: var(--kelp); box-shadow: inset 0 -3px 0 var(--kelp-deep); }
.cell.oops { background: var(--danger) !important; }
.mirror--win .cell.on { animation: popIn 0.4s both; }
.mirror-line { position: absolute; pointer-events: none; }
.mirror-line--v { top: 4px; bottom: 4px; left: 50%; border-left: 3px dashed var(--sky); transform: translateX(-50%); }
.mirror-line--h { left: 4px; right: 4px; top: 50%; border-top: 3px dashed var(--sky); transform: translateY(-50%); }
.mirror-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .balance-layout, .machine-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .pools { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
  .pool-body { min-height: 92px; }
  .stone { min-width: 60px; height: 60px; font-size: 1.4rem; }
  .np-grid { grid-template-columns: repeat(3, 60px); }
  .np-key { height: 48px; }
  .parade-item { width: 48px; height: 48px; font-size: 1.6rem; }
  .parade-option { width: 62px; height: 62px; font-size: 2rem; }
  .pebble, .sort-spot { width: 64px; height: 76px; }
  .scale { height: 210px; }
  .beam { top: 110px; }
  .post { top: 112px; }
}

/* ---------- Kid-readable minimums and compact layouts for small screens ---------- */
.pool-label { font-size: 1rem; }
.pool-count { font-size: 1.05rem; }
.option-unit { font-size: 1rem; }
.stone-old { font-size: 1rem; }

@media (max-width: 520px), (max-height: 640px) {
  .pools { grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 6px; }
  .pool { padding: 6px 4px; gap: 4px; }
  .pool-body { min-height: 72px; padding: 4px; }
  .far-q { font-size: 2rem; }
  .t-number { font-size: 1.8rem; }
  .t-count { font-size: 1rem; }
  .options { grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; }
  .option { padding: 8px 6px; }
  .option-num { font-size: var(--step-2); }
  .cards { gap: 8px; }
  .rule-card { padding: 10px 12px 10px 42px; }
  .np-grid { grid-template-columns: repeat(3, 58px); gap: 6px; }
  .np-key { height: 46px; }
  .stones { gap: 8px; }
  .stone { min-width: 58px; height: 58px; font-size: 1.45rem; }
  .parade-item { width: 46px; height: 46px; font-size: 1.6rem; }
  .parade-option { width: 60px; height: 60px; font-size: 2rem; }
  .pebble, .sort-spot { width: 62px; height: 72px; }
  .sort-line { padding: 8px; gap: 8px; }
  .machine { padding: 10px; gap: 6px; }
  .mval { padding: 6px; font-size: 1.35rem; }
  .scale { height: 200px; }
  .beam { top: 104px; }
  .post { top: 106px; }
}

/* Mirror tiles size themselves to the window height, so big mirrors fit without shrinking any text. */
.mirror { grid-template-columns: repeat(var(--cols), minmax(0, min(40px, calc((100dvh - 330px) / var(--rows))))); }
.machine-head { font-size: 1rem; }
.empty { font-size: 1rem; }

/* Short, wide screens (landscape phones, small laptops): put each puzzle's parts side by side. */
@media (max-height: 640px) and (min-width: 640px) {
  .puzzle--rule .fit, .puzzle--predict .fit, .puzzle--missing .fit, .puzzle--balance .fit {
    display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: center; gap: 16px;
  }
  .puzzle--predict .options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .puzzle--mirror .fit { flex-direction: row; align-items: center; justify-content: center; }
  .puzzle--mirror .mirror-actions { flex-direction: column; }
  .mirror { grid-template-columns: repeat(var(--cols), minmax(0, min(40px, calc((100dvh - 190px) / var(--rows))))); }
  .puzzle--sort .fit { gap: 8px; }
  .intro .intro-tags { display: none; }
  .intro h3 { font-size: var(--step-2); }
}
@media (max-height: 640px) and (min-width: 640px) {
  .puzzle--predict .fit, .puzzle--rule .fit { display: flex; flex-direction: column; gap: 10px; }
  .puzzle--predict .pools, .puzzle--rule .pools { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: minmax(0, 1fr); }
  .puzzle--predict .pool-body, .puzzle--rule .pool-body { min-height: 60px; }
  .puzzle--predict .options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .puzzle--rule .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .np-key { height: 42px; }
  .np-note { display: none; }
}
@media (max-height: 640px) and (min-width: 640px) {
  .scale { height: 160px; }
  .beam { top: 84px; }
  .post { top: 86px; }
  .base { height: 14px; }
  .equation { font-size: var(--step-0); }
  .machine { padding: 8px; gap: 4px; }
  .mval { padding: 3px 6px; font-size: 1.2rem; }
  .mrow--q { padding-top: 6px; margin-top: 2px; }
  .rule-card { padding: 8px 10px 8px 38px; }
  .rule-card::before { left: 12px; }
}
/* Small screens: shrink the drawings (not the words) so tall pools don't force the whole puzzle smaller. */
@media (max-width: 520px), (max-height: 640px) {
  .t-group { font-size: 0.66rem; }
  .t-count { font-size: 0.9rem; }
  .t-tri-row i { width: 8px; height: 8px; }
  .t-squares { width: calc(var(--n) * 9px + (var(--n) - 1) * 2px); }
}

/* ---------- "Show me why" panel ---------- */
.explain {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px; border-radius: 14px;
  background: rgba(246, 214, 139, 0.1); box-shadow: inset 0 0 0 2px var(--sand);
}
.explain-title { font-weight: 900; color: var(--sand); }
.explain p { font-size: var(--step-0); }
.xs-strip { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 2px; }
.xs-stone {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 52px; padding: 4px 8px; border-radius: 12px;
  background: var(--panel-solid); font-family: var(--font-display); font-size: 1.3rem; line-height: 1.1;
}
.xs-pool { font-family: var(--font-body); font-size: 0.8rem; color: var(--mist); font-weight: 800; }
.xs-q { color: var(--sand); box-shadow: inset 0 0 0 2px var(--sand); }
.xs-jump { display: inline-flex; flex-direction: column; align-items: center; font-weight: 900; color: var(--kelp); min-width: 34px; font-size: 1rem; }
.xs-arrow { color: var(--mist); line-height: 1; }
.xs-mark { color: var(--danger); }
.xs-groups { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.xs-group { padding: 4px 10px; border-radius: 12px; background: var(--panel-solid); box-shadow: inset 0 0 0 2px var(--kelp); font-size: 1.3rem; }
.xs-more { color: var(--mist); font-size: 1.4rem; }
.xs-sides { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; font-weight: 900; font-size: var(--step-0); }
.xs-heavy { color: var(--danger); }
.xs-line { position: relative; height: 54px; margin: 0 8px; border-bottom: 3px solid var(--mist); }
.xs-dot {
  position: absolute; bottom: -14px; transform: translateX(-50%);
  min-width: 34px; padding: 2px 6px; border-radius: 10px; text-align: center;
  background: var(--sand); color: var(--ink); font-family: var(--font-display); font-size: 1.1rem;
}
.xs-end { position: absolute; bottom: -26px; left: 0; color: var(--mist); font-size: 0.9rem; font-weight: 800; }
.xs-end--r { left: auto; right: 0; }
.cell.example { box-shadow: 0 0 0 3px var(--sand), 0 0 18px var(--sand) !important; animation: pulseCell 0.8s ease-in-out infinite alternate; }
@keyframes pulseCell { from { transform: scale(0.92); } to { transform: scale(1.04); } }

/* ---------- Twin currents ---------- */
.twins { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.twin-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.twin-label { font-weight: 900; color: var(--mist); min-width: 70px; text-align: right; }
.twin-stone { min-width: 56px; height: 56px; font-size: 1.35rem; }
.twin-row:last-child .twin-stone { background: radial-gradient(circle at 35% 30%, #dff7ea, var(--kelp) 60%, var(--kelp-deep)); }

/* ---------- Number net ---------- */
.net { display: grid; grid-template-columns: repeat(4, minmax(0, 92px)); gap: 10px; justify-content: center; }
.net-fish {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 16px;
  background: var(--well-strong); box-shadow: 0 4px 0 rgba(2, 12, 18, 0.5), inset 0 0 0 2px var(--panel-line);
}
.net-icon { font-size: 1.3rem; line-height: 1; }
.net-num { font-family: var(--font-display); font-size: 1.6rem; color: var(--sand); line-height: 1; }
.net-fish.on { background: var(--kelp); box-shadow: 0 4px 0 var(--kelp-deep); }
.net-fish.on .net-num { color: var(--ink); }
.net-fish.oops { background: var(--danger) !important; }

/* Number pad ± key spans the bottom row. */
.np-key--sign { grid-column: 1 / -1; color: var(--sand); }
@media (max-width: 520px), (max-height: 640px) {
  .net { grid-template-columns: repeat(4, minmax(0, 76px)); gap: 8px; }
  .net-num { font-size: 1.35rem; }
  .xs-stone { min-width: 44px; font-size: 1.1rem; padding: 3px 6px; }
}
/* Readable minimums for the why panel and twin labels. */
.xs-pool { font-size: 0.9rem; }
.twin-label { font-size: 1rem; }
.explain-title { font-size: 1rem; }
.help-example { padding: 10px 14px; border: 2px solid var(--sand); border-radius: 16px; background: var(--panel-solid); max-width: 100%; text-align: center; }
.help-example h3 { font-size: var(--step-0); }
.help-example p { margin: 6px 0; }
.mirror-example { font-size: 1.8rem; direction: ltr; }
.guided-target { outline: 3px dashed var(--sand); outline-offset: 3px; }
@media (max-height: 640px) {
  .xs-pool { display: none; }
  .explain { padding: 6px 10px; gap: 4px; }
  .explain p { font-size: 1rem; }
  .twin-stone { min-width: 48px; height: 48px; font-size: 1.2rem; }
  .twins { gap: 6px; }
}
@media (max-height: 640px) and (min-width: 640px) {
  .puzzle--twins .fit { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: center; gap: 12px; }
  .puzzle--twins .explain { grid-column: 1 / -1; }
  .puzzle--twins .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .puzzle--pick .fit { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: center; gap: 12px; }
  .puzzle--pick .explain { grid-column: 2; grid-row: 1; }
  .puzzle--pick .mirror-actions { grid-column: 1; }
}
/* Twin rows must stay lined up (each bottom number directly under its top number), so they never wrap. */
.twin-row { display: grid; grid-template-columns: auto repeat(var(--count, 5), minmax(0, 56px)); gap: 6px; flex-wrap: nowrap; }
.twin-stone { min-width: 0; width: 100%; aspect-ratio: 1; height: auto; padding: 0; }
@media (max-width: 520px) {
  .twin-label { min-width: 0; font-size: 0.95rem; }
  .twin-row { gap: 5px; grid-template-columns: auto repeat(var(--count, 5), minmax(0, 52px)); }
  .twin-stone { font-size: 1.15rem; }
}
/* Drawn pieces inside puzzles */
.parade-item .art { width: 72%; height: 72%; }
.parade-option .art { width: 70%; height: 70%; }
.pebble-critter .art, .pan-critter .art { width: 1.6rem; height: 1.6rem; }
.net-icon .art { width: 1.5rem; height: 1.5rem; }
.weight-shell .art { width: 1.1rem; height: 1.1rem; }
.t-count .art { width: 1.25em; height: 1.25em; }
.t-group .art { width: 1.15em; height: 1.15em; }
.xs-group .art { width: 1.3rem; height: 1.3rem; }

/* ---------- Puzzle look: each type has its own colour on the stage ---------- */
.stage { --type: var(--sand); border-top: 5px solid var(--type); }
.stage-head .eyebrow { color: var(--type); }
.chip--type { border-color: var(--type); color: var(--foam); background: color-mix(in srgb, var(--type) 22%, transparent); }

/* ---------- Transitions between puzzles ---------- */
.fit.swim-in { animation: swim-in 0.38s cubic-bezier(.2,.8,.3,1.2); }
.fit.swim-out { animation: swim-out 0.26s ease-in forwards; }
@keyframes swim-in { from { opacity: 0; translate: 60px 0; } }
@keyframes swim-out { to { opacity: 0; translate: -60px 0; } }

/* ---------- Ghost-hand tutorial ---------- */
.stage { position: relative; }
.ghost { position: absolute; z-index: 5; pointer-events: none; transition: left 0.9s ease-in-out, top 0.9s ease-in-out; }
.ghost-hand { position: absolute; left: -6px; top: 4px; font-size: 2.6rem; filter: drop-shadow(0 4px 6px rgba(0,0,0,.4)); opacity: 0.92; }
.ghost-ring { position: absolute; left: -26px; top: -26px; width: 52px; height: 52px; border-radius: 50%; border: 4px solid var(--sand); opacity: 0; }
.ghost.tap .ghost-hand { animation: ghost-tap 0.5s ease-out 0.9s; }
.ghost.tap .ghost-ring { animation: ghost-ring 0.7s ease-out 0.95s; }
@keyframes ghost-tap { 50% { transform: translateY(8px) scale(0.92); } }
@keyframes ghost-ring { from { opacity: 0.9; transform: scale(0.4); } to { opacity: 0; transform: scale(1.5); } }

@media (prefers-reduced-motion: reduce) {
  .fit.swim-in, .fit.swim-out { animation: none; }
  .ghost { transition: none; }
}

/* ---------- Stick shapes ---------- */
.stick-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: stretch; gap: 10px; }
.stick-card { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 6px; padding: 10px 12px; border-radius: 16px; background: var(--well); border: 2px solid var(--panel-line); }
.stick-svg { height: 64px; width: auto; max-width: calc(var(--w) * 40px + 16px); overflow: visible; }
.stick-svg line { stroke: var(--sand); stroke-width: 3.2; stroke-linecap: round; }
.stick-card--q { border-style: dashed; border-color: var(--sand); justify-content: center; min-width: 96px; }
.stick-q { font-family: var(--font-display); font-size: var(--step-3); color: var(--sand); line-height: 1; }

/* ---------- Story problems ---------- */
.story-card { max-width: 640px; margin: 0 auto; padding: 14px 18px; border-radius: 18px; background: var(--well); border: 2px solid var(--panel-line); font-size: var(--step-1); line-height: 1.35; }
.story-card p { margin: 0 0 8px; }
.story-lines { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.story-lines li { padding: 6px 12px; border-radius: 12px; background: var(--well-strong); font-weight: 800; }
.story-ask { font-weight: 800; color: var(--sand); }
.story-q { display: inline-block; min-width: 2.2em; padding: 0 8px; border-radius: 10px; border: 2px dashed var(--sand); text-align: center; font-family: var(--font-display); }

/* ---------- Tables and graphs ---------- */
.table-layout { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 18px; }
.tide-table { border-collapse: separate; border-spacing: 0; font-size: var(--step-1); border-radius: 16px; overflow: hidden; border: 2px solid var(--panel-line); }
.tide-table th { background: var(--well-strong); padding: 8px 18px; font-family: var(--font-display); font-weight: 400; }
.tide-table td { padding: 6px 18px; text-align: center; font-weight: 800; border-top: 1px solid var(--panel-line); }
.tide-table td + td, .tide-table th + th { border-left: 2px solid var(--panel-line); }
.tide-table .gap-row td { padding: 0; color: var(--mist); }
.tide-table .ask-row td { background: color-mix(in srgb, var(--sand) 16%, transparent); }
.table-q { font-family: var(--font-display); color: var(--sand); }
.graph { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.graph-bars { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding: 0 8px; border-bottom: 3px solid var(--mist); }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; width: 46px; position: relative; }
.bar-fill { width: 100%; height: var(--h); border-radius: 10px 10px 0 0; background: var(--type, var(--sky)); }
.bar-val { font-weight: 800; font-size: var(--step--1); margin-bottom: 3px; }
.bar-x { position: absolute; bottom: -26px; font-weight: 800; }
.bar--q .bar-fill { background: transparent; border: 3px dashed var(--sand); border-bottom: 0; }
.bar--gap { justify-content: center; color: var(--mist); width: 20px; }
.graph-axis { margin-top: 24px; font-weight: 800; color: var(--mist); font-size: var(--step--1); }
@media (max-height: 640px) {
  .graph-bars { height: 130px; }
  .stick-svg { height: 46px; }
  .story-card { font-size: var(--step-0); padding: 10px 14px; }
}

/* ---------- Accessibility: right and wrong never rely on colour alone ---------- */
.is-right, .is-wrong, .is-fixed { position: relative; }
.is-right::after, .is-wrong::after, .stone.is-fixed::after {
  position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font: 900 15px/1 var(--font-body); pointer-events: none;
}
.is-right::after, .stone.is-fixed::after { content: '✓'; background: var(--kelp); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.is-wrong::after { content: '✗'; background: var(--danger); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.is-wrong { text-decoration: line-through; text-decoration-thickness: 3px; }
/* Number shortcuts for answer buttons, shown while a keyboard is in use. */
.kbd-hints .option::before, .kbd-hints .parade-option::before, .kbd-hints .rule-card[data-key]::after {
  content: attr(data-key); position: absolute; top: 4px; left: 6px; font: 800 12px/1 var(--font-body); color: var(--mist);
}
.kbd-hints .option, .kbd-hints .parade-option { position: relative; }

/* Landscape phones: stories, stick shapes and charts sit beside their answer area. */
@media (max-height: 640px) and (min-width: 640px) {
  .puzzle--story .fit, .puzzle--sticks .fit {
    display: grid; grid-template-columns: minmax(0, 1.5fr) auto; align-items: center; gap: 16px;
  }
  .table-layout { flex-wrap: nowrap; }
  .story-card { font-size: var(--step-0); padding: 8px 12px; }
  .story-card p { margin-bottom: 4px; }
  .story-lines { gap: 4px; margin-bottom: 4px; }
  .story-lines li { padding: 3px 10px; }
  .stick-row { gap: 6px; }
  .stick-card { padding: 6px 8px; gap: 2px; }
  .stick-svg { height: 40px; }
  .stick-q { font-size: var(--step-2); }
  .tide-table { font-size: var(--step-0); }
  .tide-table td { padding: 2px 14px; }
  .tide-table th { padding: 4px 14px; }
  .graph-bars { height: 120px; }
  .puzzle--story .options, .puzzle--sticks .options, .puzzle--table .options { grid-template-columns: repeat(2, minmax(72px, 1fr)); }
}
