/* Learn section components: background board, numbered cells, step-through examples, diagrams. */

html {
  scroll-behavior: smooth;
}

/* Faint sudoku board fixed behind the page so glass surfaces have structure to blur.
   Lines are centred on the viewport; learn.js places highlighted cells on the same 64px grid. */
.board {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background-image:
    linear-gradient(to right, rgb(var(--ink) / 0.045) 1.5px, transparent 1.5px),
    linear-gradient(to bottom, rgb(var(--ink) / 0.045) 1.5px, transparent 1.5px),
    linear-gradient(to right, rgb(var(--ink) / 0.022) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(var(--ink) / 0.022) 1px, transparent 1px);
  background-size: 192px 192px, 192px 192px, 64px 64px, 64px 64px;
  background-position: center top;
  -webkit-mask-image: linear-gradient(to right, #000 0%, rgb(0 0 0 / 0.25) 28%, rgb(0 0 0 / 0.25) 72%, #000 100%);
  mask-image: linear-gradient(to right, #000 0%, rgb(0 0 0 / 0.25) 28%, rgb(0 0 0 / 0.25) 72%, #000 100%);
}

.board span {
  position: absolute;
  width: 64px;
  height: 64px;
  left: calc(50% - 32px + var(--x) * 64px);
  top: calc(var(--y) * 64px);
}

.board .is-yellow {
  background: rgb(var(--yellow) / 0.45);
}

.board .is-sage {
  background: rgb(var(--sage) / 0.45);
}

.board .is-coral {
  background: rgb(var(--coral) / 0.25);
}

/* ---------- Numbered cells and lists ---------- */

/* A number in a yellow cell: section numbers, lesson numbers, step numbers. */
.cell-num {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  border-radius: 0.875rem;
  background: rgb(var(--yellow));
  color: rgb(var(--ink));
  font-weight: 700;
  font-size: 1.375rem;
  box-shadow: inset 0 0 0 1px rgb(var(--ink) / 0.08);
}

.cell-num-sm {
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  font-size: 0.95rem;
}

/* ---------- Step-through examples ---------- */

.stepper-track {
  display: flex;
  gap: 0.375rem;
}

.stepper-segment {
  flex: 1;
  padding: 0.5rem 0;
  cursor: pointer;
}

.stepper-segment::before {
  content: '';
  display: block;
  height: 0.375rem;
  border-radius: 9999px;
  background: rgb(var(--ink) / 0.1);
  transition: background-color 0.3s ease;
}

.stepper-segment:hover::before {
  background: rgb(var(--ink) / 0.2);
}

.stepper-segment.is-done::before {
  background: rgb(var(--yellow) / 0.55);
}

.stepper-segment.is-active::before {
  background: rgb(var(--yellow));
}

.stepper-slide {
  display: none;
}

.stepper-slide.is-active {
  display: grid;
  animation: step-in 0.35s ease both;
}

/* App screenshots already include the board's rounded frame and shadow. */
.stepper-image {
  width: 100%;
}

/* The quoted hint text the app shows for each step; .callout is the same box without the label. */
.hint,
.callout {
  position: relative;
  border-radius: 1rem;
  padding: 1rem 1.125rem;
  background: rgb(var(--yellow) / 0.28);
  border: 1px solid rgb(var(--yellow) / 0.9);
  font-weight: 500;
  font-size: 1.0625rem;
  line-height: 1.45;
}

.hint::before {
  content: 'In-app hint';
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgb(var(--ink) / 0.55);
}

@keyframes step-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* A cell with pencil marks (rendered by learn.js from data-candidates). */
.mini-cell {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  flex-shrink: 0;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0.3rem;
  border-radius: 0.7rem;
  background: rgb(var(--yellow));
  box-shadow: inset 0 0 0 1px rgb(var(--ink) / 0.08);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  color: rgb(var(--ink) / 0.8);
}

.mini-cell span {
  display: grid;
  place-items: center;
}

/* An eliminated candidate in before/after notation. */
.removed {
  border-radius: 0.25rem;
  padding: 0 0.2em;
  background: rgb(var(--coral) / 0.35);
  text-decoration: line-through;
}

/* ---------- Hero sudoku box ---------- */

.sudoku-box {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  aspect-ratio: 1;
  border-radius: 1.5rem;
  overflow: hidden;
  background: rgb(var(--cell));
  border: 2.5px solid rgb(var(--ink) / 0.8);
  box-shadow: 0 30px 60px -28px rgb(var(--ink) / 0.45);
}

.sudoku-box > div {
  display: grid;
  place-items: center;
  border-right: 1px solid rgb(var(--ink) / 0.14);
  border-bottom: 1px solid rgb(var(--ink) / 0.14);
  font-weight: 700;
  font-size: clamp(2rem, 6vw, 3.25rem);
  line-height: 1;
}

.sudoku-box > div:nth-child(3n) {
  border-right: 0;
}

.sudoku-box > div:nth-child(n + 7) {
  border-bottom: 0;
}

.sudoku-box .given {
  background: rgb(var(--given));
}

.sudoku-box .focus {
  background: rgb(var(--yellow));
}

.pencil {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 78%;
  height: 78%;
  font-size: clamp(0.65rem, 1.6vw, 0.9rem);
  font-weight: 500;
  color: rgb(var(--ink) / 0.75);
}

.pencil span {
  display: grid;
  place-items: center;
}

.focus .pencil,
.focus .pen {
  grid-area: 1 / 1;
}

.focus .pencil {
  width: 78%;
  height: 78%;
  animation: pencil-out 5s ease-in-out infinite;
}

.focus .pen {
  color: rgb(var(--pen));
  animation: pen-in 5s ease-in-out infinite;
}

@keyframes pencil-out {
  0%, 40% { opacity: 1; }
  50%, 90% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes pen-in {
  0%, 40% { opacity: 0; transform: scale(0.6); }
  50%, 90% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.6); }
}

/* ---------- Demo boards (rendered by learn.js) ---------- */

/* A full board styled after the app; font size follows the board's width. */
.demo-board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  border-radius: 1.25rem;
  overflow: hidden;
  background: #f5f3f0;
  border: 2px solid #bababa;
  box-shadow: 0 18px 40px -20px rgb(var(--ink) / 0.35);
}

.demo-board > span {
  display: grid;
  place-items: center;
  font-size: 5.6cqi;
  font-weight: 700;
  line-height: 1;
  color: #121212;
  border-right: 1px solid rgb(var(--ink) / 0.1);
  border-bottom: 1px solid rgb(var(--ink) / 0.1);
}

.demo-board > span.edge-r {
  border-right: 2px solid #bababa;
}

.demo-board > span.edge-b {
  border-bottom: 2px solid #bababa;
}

.demo-board > span.last-col {
  border-right: 0;
}

.demo-board > span.last-row {
  border-bottom: 0;
}

.demo-board .given {
  background: rgb(var(--given));
}

/* Numbers the player fills in, in the app's pen colour. */
.demo-board .added {
  color: rgb(var(--pen));
}

.stepper-slide.is-active .demo-board .added {
  animation: digit-in 0.35s ease both;
}

/* Same highlight colours as the app's tutorial: row yellow, column blue, box green. */
.demo-board .hl-row {
  background: rgb(var(--yellow) / 0.55);
}

.demo-board .hl-col {
  background: rgb(var(--sage) / 0.8);
}

.demo-board .hl-box {
  background: rgb(var(--olive) / 0.4);
}

/* Pencil marks: digit d sits at position d in a 3×3 grid, as in the app. */
.demo-board .marks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  width: 86%;
  height: 86%;
  font-size: max(2.4cqi, 7px);
  font-weight: 500;
  color: rgb(var(--pencil) / 0.85);
}

.demo-board .marks span {
  display: grid;
  place-items: center;
}

/* Hint highlights, using the app's colour for each role. */
.demo-board > .role-p {
  background: rgb(var(--yellow) / 0.85);
}

.demo-board > .role-s {
  background: rgb(var(--sage) / 0.9);
}

.demo-board > .role-a {
  background: rgb(var(--orange) / 0.85);
}

.demo-board > .role-w {
  background: rgb(var(--coral) / 0.65);
}

.demo-board > .role-g {
  background: rgb(var(--olive) / 0.55);
}

@keyframes digit-in {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Grid diagrams (rendered by learn.js) ---------- */

.grid-diagram {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border-radius: 0.75rem;
  overflow: hidden;
  background: rgb(var(--cell));
  border: 2px solid rgb(var(--ink) / 0.7);
}

.grid-diagram span {
  border-right: 1px solid rgb(var(--ink) / 0.1);
  border-bottom: 1px solid rgb(var(--ink) / 0.1);
}

.grid-diagram span.edge-r {
  border-right: 2px solid rgb(var(--ink) / 0.5);
}

.grid-diagram span.edge-b {
  border-bottom: 2px solid rgb(var(--ink) / 0.5);
}

.grid-diagram span.last-col {
  border-right: 0;
}

.grid-diagram span.last-row {
  border-bottom: 0;
}

.grid-diagram span.is-soft {
  background: rgb(var(--sage) / 0.75);
}

.grid-diagram span.is-strong {
  background: rgb(var(--yellow));
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .stepper-slide.is-active,
  .stepper-slide.is-active .demo-board .added,
  .focus .pen {
    animation: none;
  }

  .focus .pencil {
    animation: none;
    opacity: 0;
  }
}
