/* Sudoku and math crossword on /play. Large print, no italics. */

.pl-wrap .pl-section { margin: 28px 0 4px; }
.pl-section-by { margin: 0 0 10px; color: #333; font-size: 1.15rem; }

.pl-games { list-style: none; margin: 16px 0 8px; padding: 0; display: grid; gap: 14px; grid-template-columns: 1fr; }
.pl-gamecard { display: flex; flex-direction: column; gap: 8px; min-height: 56px; padding: 16px 18px; background: var(--surface); border: 2px solid var(--border); border-top: 5px solid var(--wheat); border-radius: 8px; color: var(--text); text-decoration: none; }
.pl-gamecard:hover, .pl-gamecard:focus-visible { border-color: var(--slate); background: #fff; }
.pl-gamecard:focus-visible { outline: 3px solid var(--slate-dark); outline-offset: 2px; }
.pl-gamecard-title { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.45rem; line-height: 1.25; color: var(--slate-dark); font-style: normal; }
.pl-gamecard-text { font-size: 1.1rem; line-height: 1.45; color: #333; }
.pl-gamecard-go { font: 700 1.1rem/1.2 Arial, Helvetica, sans-serif; color: var(--slate); margin-top: 4px; }

@media (min-width: 700px) {
  .pl-games { grid-template-columns: repeat(2, 1fr); }
}

.pg-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.pg-level[aria-pressed="true"] { background: var(--slate); color: #fff !important; border-color: var(--slate); }
.pg-board { max-width: 680px; }

/* ---------- Sudoku grid ---------- */
.pg-su {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border: 3px solid #111;
  background: #111;
  gap: 1px;
  aspect-ratio: 1 / 1;
}
.pg-su-cell {
  appearance: none; -webkit-appearance: none;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  margin: 0; padding: 0;
  background: #fff; color: #111;
  font: 800 clamp(1.05rem, 5.6vw, 2rem)/1 Arial, Helvetica, "Liberation Sans", sans-serif;
  border: 0; border-radius: 0; cursor: pointer;
  min-width: 0; min-height: 0;
}
/* 3x3 box edges — not colour alone; thicker lines */
.pg-su-cell:nth-child(3n) { box-shadow: inset -3px 0 0 #111; }
.pg-su-cell:nth-child(9n) { box-shadow: none; }
.pg-su-cell:nth-child(n+19):nth-child(-n+27),
.pg-su-cell:nth-child(n+46):nth-child(-n+54) { box-shadow: inset 0 -3px 0 #111; }
.pg-su-cell:nth-child(21), .pg-su-cell:nth-child(24),
.pg-su-cell:nth-child(48), .pg-su-cell:nth-child(51) { box-shadow: inset -3px -3px 0 #111; }
.pg-su-cell.pg-given { background: #ece8df; font-weight: 800; cursor: default; }
.pg-su-cell.pg-selected { outline: 3px solid var(--slate-dark); outline-offset: -3px; z-index: 1; }
.pg-su-cell.pg-wrong { background: #fff; box-shadow: inset 0 0 0 3px #8b1d1d; background-image: repeating-linear-gradient(-45deg, #fde7e5, #fde7e5 6px, #fff 6px, #fff 12px); }
.pg-su-cell.pg-wrong::before { content: "!"; position: absolute; top: 1px; right: 3px; font: 800 .85rem/1 Arial, Helvetica, sans-serif; color: #8b1d1d; }
.pg-su-cell:focus-visible { outline: 3px solid var(--slate-dark); outline-offset: -3px; z-index: 1; }
.pg-su-cell.pg-revealed { background: #f4f4f4; }

/* ---------- Number pad (phone-style 3 by 3, then Clear) ---------- */
.pg-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px auto 0; max-width: 280px; }
.pg-pad[hidden] { display: none; }
.pg-key {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 56px; min-width: 48px;
  font: 800 1.5rem/1 Arial, Helvetica, sans-serif;
  background: #fff; color: var(--slate-dark);
  border: 2px solid var(--slate); border-radius: 8px; cursor: pointer;
}
.pg-key:hover { background: var(--parchment); }
.pg-key:focus-visible { outline: 3px solid var(--slate-dark); outline-offset: 2px; }
.pg-key-clear { font-size: 1.05rem; font-weight: 700; grid-column: 1 / -1; }
.pg-pad:has([data-n="0"]) .pg-key-clear { grid-column: span 2; }

/* Desktop: Sudoku pad sits to the right of the grid. Math crossword is unchanged. */
.pl-game-fill[data-fill-game="sudoku"] {
  container-type: inline-size;
  container-name: sudoku;
}
@container sudoku (min-width: 800px) {
  .pg-board {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 24px;
    max-width: 920px;
    margin: 0 auto;
  }
  .pg-su {
    margin: 0;
    flex: 1 1 auto;
    width: min(560px, calc(100% - 304px));
    max-width: 560px;
  }
  .pg-pad {
    margin: 0;
    flex: 0 0 280px;
    width: 280px;
    max-width: 280px;
  }
}
@media (min-width: 900px) {
  /* Fallback when container queries are unavailable */
  .pl-game-fill[data-fill-game="sudoku"] .pg-board {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 24px;
    max-width: 920px;
    margin: 0 auto;
  }
  .pl-game-fill[data-fill-game="sudoku"] .pg-su {
    margin: 0;
    flex: 1 1 auto;
    width: min(560px, calc(100% - 304px));
    max-width: 560px;
  }
  .pl-game-fill[data-fill-game="sudoku"] .pg-pad {
    margin: 0;
    flex: 0 0 280px;
    width: 280px;
    max-width: 280px;
  }
}

/* Live duplicate conflicts — every clashing cell, including givens. Not colour alone. */
.pg-su-cell.pg-peer { background: #e4edf2; }
.pg-su-cell.pg-given.pg-peer { background: #dfe4e4; }
.pg-su-cell.pg-same { background: #cfdce6; }
.pg-su-cell.pg-given.pg-same { background: #d4d8d6; }
.pg-su-cell.pg-conflict {
  color: #8b1d1d;
  background: #fde7e5;
  z-index: 1;
}
.pg-su-cell.pg-given.pg-conflict { background: #f4d4d0; }
.pg-su-cell.pg-conflict::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 3px solid #8b1d1d;
  pointer-events: none;
}
html.lp-hc .pg-su-cell.pg-conflict {
  color: #5a0000;
  background: #ffd4d0;
}
html.lp-hc .pg-su-cell.pg-conflict::after { border-width: 4px; }

/* A digit with all 9 placed is crossed out on the pad, but stays usable. */
.pg-key.pg-key-done {
  position: relative;
  color: #3a3a3a;
  background: #e8e6e0;
  border-color: #666;
}
.pg-key.pg-key-done::after {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: #222;
  transform: rotate(-22deg);
  pointer-events: none;
}
html.lp-hc .pg-key.pg-key-done::after { height: 5px; background: #000; }

/* Keep the Sudoku Clear key full width. The shared pad rule shrinks Clear
   when a data-n="0" key exists; Sudoku's Clear itself uses data-n="0". */
.pl-game-fill[data-fill-game="sudoku"] .pg-key-clear {
  grid-column: 1 / -1;
}

/* ---------- Math crossword ---------- */
.pg-mx {
  display: grid;
  grid-template-columns: minmax(3.2rem, 1fr) 2.2rem minmax(3.2rem, 1fr) 2.2rem minmax(3.6rem, 1.15fr);
  grid-auto-rows: minmax(3.4rem, auto);
  gap: 6px 4px;
  align-items: stretch;
  max-width: 520px;
  margin: 8px auto 0;
  font-style: normal;
}
.pg-mx-cell {
  appearance: none; -webkit-appearance: none;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  margin: 0; padding: 0 4px;
  background: #fff; color: #111;
  font: 800 clamp(1.2rem, 6vw, 1.85rem)/1 Arial, Helvetica, "Liberation Sans", sans-serif;
  border: 3px solid var(--slate-dark); border-radius: 8px; cursor: pointer;
  min-height: 56px;
}
.pg-mx-cell.pg-given { background: #ece8df; cursor: default; }
.pg-mx-cell.pg-given::after { content: "given"; position: absolute; left: 0; right: 0; bottom: 3px; font: 700 .55rem/1 Arial, Helvetica, sans-serif; letter-spacing: .02em; text-transform: uppercase; color: #333; pointer-events: none; }
.pg-mx-cell.pg-selected { outline: 3px solid #111; outline-offset: 2px; }
.pg-mx-cell.pg-wrong { border-style: dashed; border-color: #8b1d1d; background-image: repeating-linear-gradient(-45deg, #fde7e5, #fde7e5 6px, #fff 6px, #fff 12px); }
.pg-mx-cell.pg-wrong::before { content: "!"; position: absolute; top: 2px; right: 5px; font: 800 1rem/1 Arial, Helvetica, sans-serif; color: #8b1d1d; }
.pg-mx-cell.pg-revealed { background: #f4f4f4; }
.pg-mx-cell:focus-visible { outline: 3px solid #111; outline-offset: 2px; }
.pg-mx-op, .pg-mx-eq, .pg-mx-blank {
  display: flex; align-items: center; justify-content: center;
  font: 800 1.6rem/1 Arial, Helvetica, sans-serif; color: #111;
}
.pg-mx-eq { font-weight: 700; }
.pg-mx-clue {
  grid-column: 1 / -1;
  font: 600 1.05rem/1.35 Arial, Helvetica, sans-serif;
  color: #333;
  margin: 4px 0 0;
}

/* ---------- Full-screen overrides for fill-in games ---------- */
html.pl-fs-on .pl-game-fill {
  grid-template-areas: "bar" "board" "pad";
  grid-template-columns: minmax(0, 1fr);
  touch-action: auto;
}
html.pl-fs-on .pl-game-fill.pl-fs-land {
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 18rem);
  grid-template-rows: auto 1fr;
  grid-template-areas: "board bar" "board pad";
}
html.pl-fs-on .pl-game-fill .pg-board { display: contents; }
html.pl-fs-on .pl-game-fill .pg-gridwrap { grid-area: board; justify-self: center; align-self: start; width: var(--fs-s, min(94vw, 58dvh)); max-width: none; }
html.pl-fs-on .pl-game-fill .pg-su { max-width: none; width: 100%; }
html.pl-fs-on .pl-game-fill .pg-mx { max-width: none; width: 100%; }
html.pl-fs-on .pl-game-fill .pg-pad {
  grid-area: pad; display: grid; margin: 0; max-width: none; width: 100%;
  align-self: start;
}
html.pl-fs-on .pl-game-fill .pg-toolbar,
html.pl-fs-on .pl-game-fill .pl-levelnote,
html.pl-fs-on .pl-game-fill .pl-help,
html.pl-fs-on .pl-game-fill > .pl-controls { display: none !important; }
html.pl-fs-on .pl-game-fill .pl-progress,
html.pl-fs-on .pl-game-fill .pl-message { display: none !important; }
html.pl-fs-on .pl-game-fill .pg-key { min-height: 48px; font-size: 1.3rem; }
html.pl-fs-on .pl-game-fill .pg-su-cell { font-size: clamp(1rem, 6cqw, 2.1rem); }
html.pl-fs-on .pl-game-fill .pg-mx-cell { min-height: 48px; }

@media (min-width: 600px) {
  .pl-gamecard-title { font-size: 1.6rem; }
  .pg-key { min-height: 60px; }
  .pg-pad { max-width: 320px; }
}
