/* Puzzles: the wide layout for a tablet and a desktop. A separate file, not part of index.html.
   A phone (< 700 px) is untouched: every rule here is under a media query.

   Breakpoints
   · 700 px, a tablet: a wider column (up to 1040), cards and list rows in a grid of two columns, the tabs on top in the header, sheets ("More", "Settings", "Solved") as a window in the centre.
   · "board at the side": a width from 700 px and a screen not narrower than 5:4 (a 1024x768 tablet, a laptop, a browser window): the board is large by the screen HEIGHT, the rest in a column at the right.
     A portrait tablet (768x1024): the board on top across the column (but not taller than the screen minus the buttons), the buttons and the texts under it.
   · 1024 px, a desktop: a game page has three columns instead of two.
   · Mouse hover only where a mouse exists (hover: hover and pointer: fine), at any width; a phone never gets hover.

   The cell size is computed by the game module from the width of .board-root; only the width of .board-root and the cell cap --cell-max (the modules read it, 54 by default) change here.
   Board selectors start with .board-root: the styles of the games are put into <head> after this file and would win at equal specificity. */

@media (min-width: 700px) {
  body { padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }
  .wrap { max-width: 1040px; padding: 0 24px; }
  body[data-screen="play"] .wrap, body[data-screen="lesson"] .wrap { max-width: 1180px; }
  header.top { border-bottom: 1px solid var(--line); }
  header.top h1 { font-size: 1.4rem; }

  /* tabs: on top in the centre of the header (on a phone they are pinned to the bottom) */
  nav.tabs { top: env(safe-area-inset-top, 0px); bottom: auto; left: 50%; right: auto; transform: translateX(-50%); height: 52px; align-items: center; gap: 4px; padding: 0; border: 0; background: none; }
  nav.tabs button { flex: none; min-height: 40px; padding: 0 18px; border-radius: 20px; font-size: .95rem; }
  nav.tabs button[aria-current="page"] { background: var(--accent-soft); box-shadow: none; }
  #toast { bottom: 24px; }

  /* sheets: a window in the centre */
  #sheet { left: 50%; right: auto; top: 50%; bottom: auto; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 48px)); max-width: none; max-height: min(86vh, 760px); margin: 0; padding: 22px; border-radius: 20px; border: 1px solid var(--line); box-shadow: 0 24px 80px rgba(0, 0, 0, .45); }

  /* "Today", "Games", a game page, practice: a grid of cards */
  body:is([data-screen="home"], [data-screen="games"], [data-screen="game"], [data-screen="train"]) #main { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; align-content: start; }
  #main > .sec, #main > .pbar, #main > .mh, #main > .hintline, #main > .list, #main > .more, #main > .empty, #main > .left, #main > .nudge, #main > #unf { grid-column: 1 / -1; }
  #main > .sec { margin: 10px 0 -4px; }
  #main > .mh { margin: 6px 2px -4px; }
  #main > .card { margin: 0; }
  #main > .streak, #main > .alldone { grid-column: 1 / -1; justify-self: start; min-width: 300px; margin: 0; }
  #main > .nudge { width: min(100%, 520px); margin: 0; }
  #main > .left, #main > .hintline { margin: 0 2px; }
  #main > .more { justify-self: center; width: auto; min-width: 260px; margin: 0; }
  #unf .more { display: block; width: auto; min-width: 260px; margin: 12px auto 0; }
  #unf .sec { margin-top: 14px; }

  /* a game card is narrower than ~440 px (two in a row on a tablet, three on a game page): the mark "solved · 1:17" goes to a row under the title, otherwise the title keeps ~80 px and breaks mid-word */
  .gcard { container-type: inline-size; }
  @container (max-width: 440px) {
    .gcard .gmain { flex-wrap: wrap; row-gap: 0; }
    .gcard .gmain .mid { flex: 1 1 120px; }
    .gcard .gmain .st { flex: 0 0 100%; text-align: left; padding-left: 56px; margin-top: -2px; }
  }

  /* list rows are separate cards in a grid (a phone has one column with a shared frame) */
  .list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; background: none; border: 0; border-radius: 0; overflow: visible; }
  .list > .row, .list > .row:first-child { border: 1px solid var(--line); border-radius: var(--radius); min-height: 56px; }

  /* stats: cards in a grid */
  body[data-screen="stats"] #main > div:not([class]) { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px 16px; align-items: start; }
  body[data-screen="stats"] #main > div:not([class]) > .sec, body[data-screen="stats"] #main > div:not([class]) > .empty { grid-column: 1 / -1; margin: 8px 0 -4px; }
  body[data-screen="stats"] #main > div:not([class]) > .streak { grid-column: 1 / -1; justify-self: start; min-width: 300px; margin: 0; }
  body[data-screen="stats"] #main > div:not([class]) > .kv { margin: 0; }

  /* a task and a lesson: the board is large by the room available; the cell cap is above the phone's 54 */
  #main > .board-root { --cell-max: 64; width: min(100%, max(300px, calc(100vh - 280px))); width: min(100%, max(300px, calc(100dvh - 280px))); margin: 0 auto; }
  #main > .board-root:has(.st-wrap) { width: min(100%, max(280px, calc((100vh - 360px) * .75))); width: min(100%, max(280px, calc((100dvh - 360px) * .75))); } /* "Strands": a 6x8 board is taller than wide, the column is narrower */
  #main > .board-root:has(.wf-wrap) { width: min(100%, 560px); } /* "Word from word": the found-words list and the tiles go in a column, wider than ~560 px is not needed */
  body[data-screen="lesson"] #main > .board-root { --cell-max: 76; }  /* lesson boards are small (4x4..7x7): on a big screen they can be larger */
  .board-root .tn-wrap, .board-root .sb-wrap, .board-root .br-wrap, .board-root .wv-wrap, .board-root .st-wrap { width: fit-content; margin: 0 auto; } /* the wrapper is the size of the board: the end-of-task effects (night, lights) cover the board, not the whole column width */
  .tools { flex-wrap: nowrap; }
  .tools .btn, .tools .btn.fill { flex: 1 1 0; min-width: 0; }
  .tools .btn.fill { flex-grow: 1.7; }  /* the long label "Fill with dots" fits in one row */
  .hint { min-height: 1.35em; }
  .pbar h2 { font-size: 1.25rem; }
  .pstat { font-size: 1rem; }
  details.how { padding: 0 16px; }
}

@media (min-width: 700px) and (max-width: 899px) { /* a narrow tablet: tabs in the centre of the header would touch the title */
  header.top h1 { font-size: 1.3rem; }
  nav.tabs { gap: 2px; }
  nav.tabs button { padding: 0 12px; }
}

@media (min-width: 1024px) {
  body[data-screen="game"] #main { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  body[data-screen="game"] .list:not(#extra-list) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* board at the side: a landscape tablet, a laptop, a browser window */
@media (min-width: 700px) and (min-aspect-ratio: 5/4) {
  body:is([data-screen="play"], [data-screen="lesson"]) #main { --side: clamp(260px, 27vw, 340px); display: grid; grid-template-columns: minmax(0, 1fr) var(--side); grid-template-rows: repeat(8, auto) 1fr; column-gap: 28px; align-content: start; padding-top: 8px; }
  body:is([data-screen="play"], [data-screen="lesson"]) #main > * { grid-column: 2; }
  body:is([data-screen="play"], [data-screen="lesson"]) #main > .empty { grid-column: 1 / -1; }
  body:is([data-screen="play"], [data-screen="lesson"]) #main > .board-root { grid-column: 1; grid-row: 1 / -1; align-self: start; width: min(100%, max(300px, calc(100vh - 92px))); width: min(100%, max(300px, calc(100dvh - 92px))); position: sticky; top: 60px; }  /* the column is longer than the screen: the page scrolls, the board stays in place */
  body:is([data-screen="play"], [data-screen="lesson"]) #main > .pbar { margin: 0 0 6px; }  /* the panel: "Back" and the timer are the first row, the title under them (as on a phone: the layout is in css/back.css); the top is level with the board. On game and practice pages the top margin stays the base one so the button does not stick to the header */
  #main > .pbar h2 { font-size: 1.4rem; }
  #main > .pbar .timer { font-size: 1.7rem; }
  #main > .pstat { font-size: 1.1rem; margin: 6px 2px 12px; }
  #main > .tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }
  #main > .tools .btn { flex: none; min-height: 46px; padding: 8px 10px; }
  #main > .tools .btn.fill { grid-column: 1 / -1; }
  #main > .hintbox { min-height: 3em; font-size: 1rem; margin: 0 2px 8px; }  /* room for the hint text: its appearing and vanishing does not move "How to play" */
  #main > .hint { text-align: left; margin: 0 2px 8px; }
  #main > .ltext { font-size: 1rem; margin: 6px 2px 12px; }
  #main > .guide { margin: 0 0 12px; }
  #main > .done-box { margin-top: 0; }
  #main > details.how { margin-top: 4px; }
}

/* a column wider than ~330 px: "Undo", "Start over", "Hint" in one row, as on a phone (a narrower column has two buttons per row) */
@media (min-width: 1240px) and (min-aspect-ratio: 5/4) {
  body:is([data-screen="play"], [data-screen="lesson"]) #main { --side: 360px; }
  #main > .tools { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #main > .tools .btn { padding: 8px 4px; font-size: .9rem; }
}

/* hover: only where there is a mouse */
@media (hover: hover) and (pointer: fine) {
  .btn:not([disabled]):hover, .pill:hover, .chips button:hover { border-color: var(--accent); background: var(--accent-soft); }
  .btn.pri:not([disabled]):hover { background: var(--accent); filter: brightness(1.1); }
  .card:hover, .row:hover, .themeopt:hover, .nudge:hover, details.how > summary:hover { border-color: var(--accent); }
  .card:hover, .row:hover { background: var(--accent-soft); }
  .card.done:hover { background: var(--surface2); }
  .gcard .gmore:hover { background: var(--accent-soft); color: var(--accent); }
  .nudge:hover { filter: brightness(.97); }
  nav.tabs button:hover { color: var(--ink); background: var(--surface2); }
  nav.tabs button[aria-current="page"]:hover { color: var(--accent); }
  details.how > summary:hover, details.solved-today > summary:hover { color: var(--accent); }
  #toast button:hover { opacity: .8; }
  .board-root .tn-board:not(.frozen) .cell:not(.tree):not(.locked):not(.house):hover { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 1; }
  .board-root .tn-board:not(.frozen) .clue:hover { background: var(--pz-hl-soft); border-radius: 6px; color: var(--pz-hl); }
  .board-root .sb-board:not(.frozen) .cell:not(.locked):hover { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 3; }
  .board-root .br-board:not(.frozen) .br-isl:hover .disc { box-shadow: 0 0 0 3px var(--accent); }
  .board-root .wv-wrap:not(.frozen) .wv-t:hover { box-shadow: inset 0 0 0 3px var(--accent); }
  .board-root .wv-wrap:not(.frozen) .wv-a:hover { background: var(--accent); color: #fff; }
  .board-root .st-wrap:not(.frozen) .st-c:not(.f):hover { box-shadow: 0 0 0 3px var(--accent); }
  .board-root .wf-wrap .wf-t:not(.used):hover { box-shadow: 0 0 0 3px var(--accent); }
  .board-root .an-wrap .an-t:not(.used):not(.drag):hover { box-shadow: 0 0 0 3px var(--accent); }
  .board-root .an-wrap .an-s.fill:hover { border-color: var(--accent); }
  .board-root .an-wrap .an-ab:not(:disabled):hover { border-color: var(--accent); background: var(--accent-soft); }
  .board-root .an-wrap .an-ab.pri:not(:disabled):hover { background: var(--accent); filter: brightness(1.1); }
  .board-root .an-wrap .an-erase:not(:disabled):hover { border-color: var(--accent); background: var(--accent-soft); }
  .xs-chips button:not(:disabled):hover, .xs-seg button:hover { border-color: var(--accent); }
}
