/* Puzzles page: five kinds of logic puzzle. Loads after site.css and lesson.css. */

.puzzles-page main { max-width: 44em; }
.puzzles-page .hero { grid-template-columns: minmax(0, 1fr); padding: 48px 0 32px; }

button { font: inherit; }
:focus-visible { outline: 3px solid var(--chalk); outline-offset: 2px; }

/* ---------- home: the five kinds ---------- */

.kinds { list-style: none; margin: 0; padding: 0; display: grid; gap: 28px; }
.kind {
  padding: 18px 18px 16px;
  border-radius: 6px;
  color: var(--ink);
  background: var(--kc);
  box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.3);
  transform: rotate(var(--tilt));
  animation: kind-in 520ms var(--spring) both;
}
.kind:nth-child(2) { animation-delay: 60ms; }
.kind:nth-child(3) { animation-delay: 120ms; }
.kind:nth-child(4) { animation-delay: 180ms; }
.kind:nth-child(5) { animation-delay: 240ms; }
@keyframes kind-in { from { opacity: 0; transform: translateY(24px) rotate(-3deg); } }

.kind-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.kind-name { margin: 0; font-size: 26px; line-height: 1.05; }
.kind-count { font-family: "Permanent Marker", cursive; font-size: 15px; color: var(--ink-soft); white-space: nowrap; }
.kind-blurb { margin: 6px 0 14px; font-weight: 600; }

.levels { display: flex; flex-wrap: wrap; gap: 10px; }
.level {
  display: grid; justify-items: center; align-content: center;
  min-width: 62px; min-height: 58px; padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink); text-decoration: none;
  box-shadow: inset 0 0 0 2px rgba(28, 20, 64, 0.25);
  transition: transform 160ms var(--spring);
}
.level:active { transform: scale(0.95); }
.level-n { font-size: 22px; font-weight: 800; line-height: 1; }
.level-d { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.level.is-done { background: var(--ink); color: var(--chalk); box-shadow: none; position: relative; }
.level.is-done .level-d { color: var(--chalk-dim); }
.level.is-done::after {
  content: "✓"; position: absolute; top: -8px; right: -8px;
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c3); color: var(--ink); font-size: 13px; font-weight: 800;
}

/* ---------- play view ---------- */

.play { padding-top: 22px; }
.back { color: var(--chalk); font-weight: 700; text-decoration: none; display: inline-block; padding: 6px 0; }
.play-kicker { margin: 14px 0 0; font-size: 13px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--kc); }
.play-title { margin: 2px 0 8px; font-size: 38px; line-height: 1; letter-spacing: -0.02em; }
.play-intro { margin: 0 0 16px; color: var(--chalk-dim); font-weight: 600; }
.board-tip { margin: 0 0 14px; font-size: 14px; color: var(--chalk-dim); }

.play-status { min-height: 1.5em; margin: 14px 0 8px; font-weight: 800; }
.play-status.is-good { color: var(--c3); }
.play-status.is-bad { color: var(--c1); }

.play-acts { display: flex; flex-wrap: wrap; gap: 10px; }
.act {
  border: 0; border-radius: 999px; padding: 11px 20px; cursor: pointer;
  font-weight: 800; color: var(--ink); background: var(--jot);
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.3);
}
.act.ghost { background: transparent; color: var(--chalk); box-shadow: inset 0 0 0 2px var(--chalk-dim); }
.act:active { transform: translateY(2px); }

.play-done {
  margin-top: 26px; padding: 18px 18px 16px;
  border-radius: 6px; color: var(--ink); background: var(--jot);
  box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.3);
  transform: rotate(-0.6deg);
  animation: done-in 560ms var(--spring) both;
  scroll-margin-top: 16px;
}
@keyframes done-in { from { opacity: 0; transform: scale(0.85) rotate(-4deg); } }
.done-kicker { margin: 0; font-family: "Permanent Marker", cursive; color: var(--ink-soft); }
.done-title { margin: 2px 0 8px; font-size: 26px; line-height: 1.1; }
.done-learn { margin: 10px 0 0; font-weight: 600; }
.done-why summary { cursor: pointer; font-weight: 800; margin-top: 6px; }
.done-why p { margin: 8px 0 0; }
.fact-notes p { margin: 8px 0 0; font-weight: 600; }
.fact-notes p::before { content: "Fact check: "; font-weight: 800; }
.done-acts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.done-link, .done-next {
  display: inline-block; padding: 10px 18px; border-radius: 999px;
  font-weight: 800; text-decoration: none;
}
.done-link { color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.done-next { color: var(--chalk); background: var(--ink); }

@keyframes flash { 0%, 100% { box-shadow: none; } 30%, 70% { box-shadow: 0 0 0 4px var(--c1); } }
.is-flash { animation: flash 900ms ease 2; }

.seg { display: inline-flex; border-radius: 999px; padding: 3px; gap: 3px; background: rgba(28, 20, 64, 0.12); }
.seg-b {
  border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer;
  font-weight: 800; color: var(--ink); background: transparent;
}
.seg-b[aria-pressed="true"] { background: var(--ink); color: var(--chalk); }

/* ---------- logic grid ---------- */

.clues { margin: 0 0 18px; padding: 14px 14px 14px 36px; border-radius: 6px; background: var(--chalk); color: var(--ink); box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.3); }
.clue { margin: 4px 0; font-weight: 600; cursor: pointer; }
.clue.is-used { opacity: 0.4; text-decoration: line-through; }

.gtable-wrap { margin: 0 0 18px; overflow-x: auto; }
.gtable { border-collapse: collapse; color: var(--chalk); }
.gtable caption { text-align: left; font-weight: 800; padding-bottom: 6px; color: var(--kc); }
.gcorner { width: 1px; }
.gcol { vertical-align: bottom; padding: 0 0 6px; }
.gcol span {
  display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg);
  max-height: 150px; font-size: 13px; font-weight: 700; line-height: 1.1; text-align: left;
}
.grow { text-align: right; padding-right: 8px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.gtable td { padding: 0; }
.gcell {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 0; margin: 0; cursor: pointer;
  background: rgba(255, 248, 236, 0.92); color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(28, 20, 64, 0.35);
  font-size: 20px; font-weight: 800;
}
.gcell.is-cross { color: var(--c1); }
.gcell.is-cross.is-auto { color: rgba(28, 20, 64, 0.3); }
.gcell.is-tick { background: var(--c3); }

/* ---------- oracles and tricksters ---------- */

.person, .fact {
  margin: 0 0 16px; padding: 14px 16px; border-radius: 6px;
  color: var(--ink); background: var(--pc, var(--chalk));
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.3);
  transition: box-shadow 200ms;
}
.fact { background: var(--chalk); border-left: 6px solid var(--kc); }
.person-name { margin: 0; font-size: 22px; font-weight: 800; }
.person-says { margin: 4px 0 12px; font-size: 18px; font-weight: 700; }
.person-says.is-silent { font-style: italic; font-weight: 600; color: var(--ink-soft); }
.fact-label { margin: 0; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.fact-claim { margin: 2px 0 12px; font-size: 18px; font-weight: 700; }
.why-wrong { margin: 0; font-size: 14px; font-weight: 700; }
.why-wrong:empty { display: none; }
.person.is-wrong, .fact.is-wrong { box-shadow: 0 0 0 4px var(--c1), 3px 4px 0 rgba(0, 0, 0, 0.3); }
.person.is-wrong .why-wrong { margin-top: 10px; }
.person.is-right, .fact.is-right { box-shadow: 0 0 0 4px var(--c3), 3px 4px 0 rgba(0, 0, 0, 0.3); }

/* ---------- circuits ---------- */

.circ { display: block; width: 100%; max-width: 480px; height: auto; margin: 0 auto 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.22); }
.wire { fill: none; stroke: rgba(255, 248, 236, 0.3); stroke-width: 3; stroke-linejoin: round; transition: stroke 200ms; }
.wire.is-on { stroke: var(--jot); stroke-width: 4; }
.switch { cursor: pointer; }
.switch rect { fill: var(--wall-deep); stroke: var(--chalk-dim); stroke-width: 2; transition: fill 160ms; }
.switch.is-on rect { fill: var(--jot); stroke: var(--jot); }
.switch-val { text-anchor: middle; font-size: 17px; font-weight: 800; fill: var(--chalk); pointer-events: none; }
.switch.is-on .switch-val { fill: var(--ink); }
.switch-label { text-anchor: middle; font-size: 13px; font-weight: 800; fill: var(--chalk); }
.gate rect { fill: var(--c4); stroke: var(--ink); stroke-width: 2; }
.gate-op { text-anchor: middle; font-size: 15px; font-weight: 800; fill: var(--ink); pointer-events: none; }
.gate.is-open { cursor: pointer; }
.gate.is-open rect { fill: var(--c6); stroke-dasharray: 5 4; stroke-width: 2.5; }
.lamp { fill: var(--wall-deep); stroke: var(--chalk-dim); stroke-width: 2; transition: fill 200ms; }
.lamp.is-on { fill: var(--jot); stroke: var(--jot); filter: drop-shadow(0 0 8px var(--jot)); }
.lamp-label { text-anchor: middle; font-size: 12px; font-weight: 800; fill: var(--chalk); }
.want { margin: 0; font-weight: 800; color: var(--jot); }

.tt-wrap { overflow-x: auto; }
.tt { border-collapse: collapse; margin: 0 auto; font-variant-numeric: tabular-nums; }
.tt th, .tt td { padding: 5px 9px; text-align: center; }
.tt th { font-size: 12px; font-weight: 800; color: var(--chalk-dim); }
.tt td { font-weight: 800; border-top: 1px solid rgba(255, 248, 236, 0.15); }
.tt .tt-want { color: var(--c4); }
.tt tr.is-cur td { background: rgba(255, 225, 77, 0.18); }
.tt tr { cursor: pointer; }
.tt-ok { color: var(--c3); }
.tt-no { color: var(--c1); }

/* ---------- hidden pictures ---------- */

.pix-mode { margin-bottom: 14px; background: rgba(255, 248, 236, 0.15); }
.pix-mode .seg-b { color: var(--chalk); }
.pix-mode .seg-b[aria-pressed="true"] { background: var(--jot); color: var(--ink); }

.pix {
  display: grid;
  grid-template-columns: auto repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  grid-template-rows: auto;
  width: max-content; margin: 0 auto;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.pix-corner { grid-row: 1; }
.pix-cc {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding-bottom: 4px; font-size: 13px; font-weight: 800; line-height: 1.15; align-self: end;
}
.pix-rc { display: flex; justify-content: flex-end; align-items: center; gap: 5px; padding-right: 6px; font-size: 13px; font-weight: 800; }
.pix-cc.is-met, .pix-rc.is-met { opacity: 0.35; }
.pix-cell {
  background: var(--chalk); box-shadow: inset 0 0 0 1px rgba(28, 20, 64, 0.3);
  display: grid; place-items: center; cursor: pointer;
  transition: background-color 120ms;
}
.pix-cell.edge-r { border-right: 2px solid var(--ink); }
.pix-cell.edge-b { border-bottom: 2px solid var(--ink); }
.pix-cell.is-fill { background: var(--ink); }
.pix-cell.is-cross::after { content: "✗"; color: var(--c1); font-weight: 800; font-size: calc(var(--cell) * 0.55); }
.pix.is-solved .pix-cell { box-shadow: none; border: 0; transition: background-color 600ms; }
.pix.is-solved .pix-cell.is-fill { background: var(--kc); }
.pix.is-solved .pix-cell:not(.is-fill) { background: transparent; }
.pix.is-solved .pix-cell.is-cross::after { content: none; }

/* ---------- Latin squares ---------- */

.sud {
  display: grid; grid-template-columns: repeat(var(--n), 1fr);
  width: min(100%, 420px); aspect-ratio: 1; margin: 0 auto;
  border: 3px solid var(--ink); border-radius: 4px; overflow: hidden;
  background: var(--chalk);
}
.sud-cell {
  border: 0; margin: 0; padding: 0; min-width: 0; cursor: pointer;
  display: grid; place-items: center;
  background: var(--chalk); color: #3b2fa0;
  box-shadow: inset -1px -1px 0 rgba(28, 20, 64, 0.25);
  font-size: calc(min(100vw, 420px) / var(--n) * 0.48); font-weight: 800;
}
.sud.is-wide .sud-cell { font-size: calc(min(100vw, 420px) / var(--n) * 0.36); }
.sud-cell.box-r { box-shadow: inset -3px 0 0 var(--ink), inset 0 -1px 0 rgba(28, 20, 64, 0.25); }
.sud-cell.box-b { box-shadow: inset 0 -3px 0 var(--ink), inset -1px 0 0 rgba(28, 20, 64, 0.25); }
.sud-cell.box-r.box-b { box-shadow: inset -3px -3px 0 var(--ink); }
.sud-cell.is-given { color: var(--ink); }
.sud-cell.is-rel { background: #efe6ff; }
.sud-cell.is-same { background: #ffe9a8; }
.sud-cell.is-sel { background: var(--jot); }
.sud-cell.is-clash .sud-v { color: #d0021b; }
.sud-notes { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 3px; padding: 2px; font-size: 10px; font-weight: 700; line-height: 1.1; color: var(--ink-soft); }
.sud-notes i { font-style: normal; }
.sud.is-solved .sud-cell { background: var(--kc); transition: background-color 500ms; }

.sud-pad { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 8px; width: min(100%, 420px); margin: 14px auto 0; }
.sud-key {
  border: 0; border-radius: 10px; padding: 12px 0; cursor: pointer;
  font-size: 20px; font-weight: 800; color: var(--ink); background: var(--chalk);
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.3);
}
.sud-key:active { transform: translateY(2px); box-shadow: none; }
.sud-key.is-erase { background: var(--c1); }
.sud-key.is-notes { font-size: 15px; background: transparent; color: var(--chalk); box-shadow: inset 0 0 0 2px var(--chalk-dim); }
.sud-key.is-notes[aria-pressed="true"] { background: var(--c4); color: var(--ink); box-shadow: none; }
.sud-legend { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px; width: min(100%, 420px); margin: 16px auto 0; padding: 0; font-size: 14px; color: var(--chalk-dim); }
.sud-legend li { display: flex; align-items: baseline; gap: 8px; padding: 4px 8px; border-radius: 8px; transition: background 0.15s, color 0.15s; }
.sud-legend b { min-width: 2.2em; font-size: 16px; color: var(--chalk); }
.sud-legend li.is-on { background: var(--c4); color: var(--ink); }
.sud-legend li.is-on b { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .kind, .play-done, .is-flash { animation: none; }
}
