/*
 * MatchstickGames — the frame of every page and the pages around the game (www/t/layout.php):
 * the sidebar tree, the phone's top bar and drawer, headings, tiles, the footer with the languages,
 * ad slots, and the SVG boards drawn by PHP (www/t/board.php). Colours come from styles.css, which
 * every page loads first. Spacing: 4 · 8 · 12 · 16 · 24 · 32 · 48.
 */

/* =========================================================================
   Frame: the sidebar and the content
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.app-main {
  min-width: 0;
}

.main,
.site-footer {
  width: 100%;
  max-width: 1200px;
  padding-inline: 48px;
}

.main {
  padding-top: 32px;
}

/* The sidebar: the only navigation */
.side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 24px 16px;
  overflow-y: auto;
  background: var(--side);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.logo {
  width: 28px;
  height: 28px;
  flex: none;
}

.logo line {
  stroke: var(--wood-flat);
  stroke-width: 3.2;
  stroke-linecap: round;
}

.logo circle {
  fill: var(--match-head);
}

.tree,
.tree ol {
  list-style: none;
}

.tree > li + li {
  margin-top: 4px;
}

.tree a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--ink);
  line-height: 1.35;
  text-decoration: none;
}

.tree a:hover {
  background: var(--accent-soft);
}

.tree a[aria-current] {
  background: var(--accent-soft);
  color: var(--accent);
}

.tree .cat > a {
  font-weight: 600;
}

.tree .cat > a .n {
  margin-left: auto;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* "8/8": the whole category solved in this browser (js/site.js) */
.tree .cat > a .n.all {
  color: var(--ok);
}

.tree .sets {
  margin: 4px 0 8px 12px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

/* A hidden set (the pilot) is not a set of the category above it: a block of its own under a line */
.tree .hidden-set {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.tree .set > a {
  font-size: 14px;
  color: var(--muted);
}

.tree .set.open > a {
  color: var(--ink);
  font-weight: 600;
}

.tree .set.open > a[aria-current] {
  color: var(--accent);
}

.tree .levels a {
  font-size: 14px;
}

.tree .levels .num {
  flex: none;
  width: 20px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tree .levels a[aria-current] {
  font-weight: 600;
}

.tree .levels a[aria-current] .num {
  color: var(--accent);
}

.tree .puzzle-item-status {
  margin-left: auto;
  font-size: 13px;
  color: var(--ok);
}

/* How to play and Statistics side by side; a long translation wraps to the next line */
.side-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: auto;
  font-size: 14px;
}

.side-foot a {
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.side-foot a:hover,
.side-foot a[aria-current] {
  background: var(--accent-soft);
  color: var(--ink);
}

.icon-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--accent-soft);
}

.icon-btn.off {
  opacity: 0.25;
  cursor: default;
}

/* The phone's bar, the drawer's ✕ and the dimmed page behind it: only below 1024 px */
.topbar,
.drawer-close,
.scrim {
  display: none;
}

/* =========================================================================
   Text
   ========================================================================= */
h1 {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}

.lead {
  max-width: 64ch;
  margin-top: 8px;
  font-size: 17px;
  color: var(--muted);
}

a.plain {
  color: inherit;
  text-decoration: none;
}

a.plain:hover {
  color: var(--accent);
}

.section {
  margin-top: 48px;
}

.set-meta {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}

.prose {
  max-width: 68ch;
}

.prose h2 {
  margin-top: 24px;
}

.prose p {
  margin-top: 8px;
}

/* A link inside running text keeps its underline: there colour alone may not tell it from the words
   around it (WCAG 1.4.1). Navigation, the footer, tables and "Next" go without it (styles.css) */
.prose p a {
  text-decoration: underline;
}

/* The table of what goes where (privacy page, Japanese only): three narrow columns still fit a
   phone, since Japanese wraps between any two characters */
.transfers {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
  line-height: 1.6;
}

.transfers th,
.transfers td {
  padding: 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.transfers thead th:nth-child(1) { width: 30%; }
.transfers thead th:nth-child(2) { width: 44%; }
.transfers thead th:nth-child(3) { width: 26%; }

.transfers thead th {
  border-top: 0;
  color: var(--muted);
  font-weight: 600;
}

.transfers tbody th {
  font-weight: 600;
}

/* Statistics (www/t/stats.php): the totals in a row, then one table of the puzzles played */
.stat-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
  margin-top: 24px;
  padding: 0;
  list-style: none;
}

.stat-totals li {
  display: flex;
  flex-direction: column;
}

.stat-totals b {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-totals span,
.stats-meta,
.stats-note {
  color: var(--muted);
  font-size: 14px;
}

.prose .stats-meta {
  margin-top: 12px;
}

.stats-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.4;
}

.stats-table th,
.stats-table td {
  padding: 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: baseline;
}

.stats-table thead th {
  border-top: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.stats-table tbody th {
  font-weight: 400;
}

.stats-table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The puzzle links of the table: "26. Title" (a column of "No." signs only made it busy); no
   underline, like every link (styles.css) */
.stats-n {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.prose .stats-note {
  margin-top: 24px;
}

@media (max-width: 600px) {
  .stats-table th,
  .stats-table td {
    padding: 8px 4px;
  }
  .stats-table .stats-n {
    display: block;
  }
  .stats-table thead th {
    font-size: 12px; /* five columns; the long Ukrainian headers carry soft hyphens */
  }
  .stats-table td.num:last-child {
    white-space: normal; /* "11 хв 49 с" in two lines on a 320 px phone */
  }
  .stats-table thead .num {
    white-space: normal; /* "Час (медіана)" in two lines leaves the titles more room */
    word-break: keep-all; /* but Japanese only at the bracket, not inside 挑戦 */
  }
}

/* =========================================================================
   Puzzle page (the game itself is in styles.css)
   ========================================================================= */
.statement,
.rule-note {
  max-width: 68ch;
}

.statement {
  margin-top: 8px;
}

.rule-note {
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
}

.next-link {
  margin-top: 24px;
  font-weight: 600;
}

/* With ads: a 300×600 column on the right from 1360 px (see ADS_ENABLED in www/t/data.php) */
.rail {
  display: none;
}

@media (min-width: 1360px) {
  .cols.with-rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 32px;
    align-items: start;
  }

  .with-rail .rail {
    display: block;
    position: sticky;
    top: 32px;
  }

  .with-rail .ad-below {
    display: none;
  }
}

/* =========================================================================
   Tiles: categories on the home page, puzzles of a set
   ========================================================================= */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 24px;
  list-style: none;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--board-bg);
  color: var(--ink);
  text-decoration: none;
}

.tile:hover {
  border-color: var(--accent);
}

.tile .thumb {
  width: 100%;
  height: 112px;
  margin-bottom: 8px;
}

.tile-n,
.tile-sub {
  font-size: 13px;
  color: var(--muted);
}

.tile-n {
  font-variant-numeric: tabular-nums;
}

.tile-title {
  font-weight: 600;
  line-height: 1.3;
}

.tile.solved::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 12px;
  color: var(--ok);
  font-weight: 700;
}

.cat-tiles {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.cat-tiles .thumb {
  height: 140px;
}

.cat-tiles .tile-title {
  font-size: 18px;
}

.cat-tiles .tile-n {
  margin-top: 4px;
}

/* "Start with puzzle 1" / "Continue" on the home page */
.continue {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 640px;
  min-height: 96px;
  margin-top: 24px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
  text-decoration: none;
}

.continue .thumb {
  flex: none;
  width: 88px;
  height: 64px;
}

.continue b {
  color: var(--accent);
}

.continue small {
  display: block;
  font-size: 14px;
  color: var(--muted);
}

/* =========================================================================
   SVG boards drawn by PHP (www/t/board.php): the start position and thumbnails
   ========================================================================= */
.board-svg .m {
  stroke: var(--wood-flat);
  stroke-width: 9;
  stroke-linecap: round;
}

.board-svg .mh {
  fill: var(--match-head);
}

/* Fixed matches (puzzle.fixed): grey, as .match.fixed in the game */
.board-svg .m.f {
  stroke: var(--fixed-flat);
}

.board-svg .mh.f {
  fill: var(--fixed-head);
}

.board-svg .cherry {
  stroke: none;
}

.board-svg .cherry-stem {
  stroke-width: 3;
}

/* =========================================================================
   Footer: every language, each in its own language
   ========================================================================= */
.site-footer {
  padding-bottom: 32px;
  font-size: 13px;
  color: var(--muted);
}

.site-footer::before {
  content: '';
  display: block;
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* The first row of the footer: languages on the left, the theme switch on the right; when they do not
   fit side by side the switch wraps under the languages, still on the left */
.footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  margin-bottom: 8px;
}

.footer-row .langs {
  margin-bottom: 0;
}

/* Theme switch: three small buttons in one pill, the chosen one filled */
.theme-switch {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.theme-switch[hidden] {
  display: none;
}

.theme-btn {
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.theme-btn:hover {
  color: var(--ink);
}

.theme-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--ink);
}

.theme-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.langs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 8px;
  font-size: 14px;
}

.langs [aria-current] {
  color: var(--ink);
  font-weight: 600;
}

/* =========================================================================
   Ad slots (ADS_ENABLED): fixed sizes reserved in the layout, so a banner appearing later moves
   nothing. Below the content 728×90 from 1100 px (narrower, 728 does not fit next to the sidebar)
   and 320×100 below that; never above the board.
   ========================================================================= */
.ad-below {
  margin-top: 32px;
}

.ad {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  margin-inline: auto;
  border: 1px dashed var(--ad-border);
  color: var(--ad-fg);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ad::before {
  content: attr(data-label);
}

.ad-728x90 { width: 728px; height: 90px; }
.ad-320x100 { width: 320px; height: 100px; }
.ad-300x600 { width: 300px; height: 600px; }

.ad-narrow {
  display: flex;
}

.ad-wide {
  display: none;
}

@media (min-width: 1100px) {
  .ad-narrow {
    display: none;
  }

  .ad-wide {
    display: flex;
  }
}

/* =========================================================================
   Phone and tablet: a thin bar and the tree in a drawer
   ========================================================================= */
@media (max-width: 1023px) {
  .app {
    display: block;
  }

  .side {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 100;
    width: min(320px, 86vw);
    height: auto;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  .side.open {
    visibility: visible;
    transform: none;
    transition: transform 0.2s ease;
  }

  .side.open + .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.35);
  }

  .drawer-open,
  .drawer-open body {
    overflow: hidden;
  }

  .drawer-close {
    display: inline-flex;
    position: absolute;
    top: 16px;
    right: 8px;
    color: var(--muted);
  }

  .brand {
    padding-right: 48px;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 52px;
    padding: 0 8px;
    background: var(--page);
    border-bottom: 1px solid var(--line);
  }

  .topbar-title {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    padding: 0 4px;
    color: var(--ink);
    line-height: 1.2;
    text-decoration: none;
  }

  .topbar-title b,
  .topbar-title small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-title b {
    font-size: 15px;
  }

  .topbar-title small {
    font-size: 12px;
    color: var(--muted);
  }

  .main,
  .site-footer {
    padding-inline: 16px;
  }

  .main {
    padding-top: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .lead {
    font-size: 16px;
  }

  .puzzle-page .statement {
    font-size: 15px;
    line-height: 1.5;
  }

  /* The rule note goes under the board, so that the board is on the first screen */
  .puzzle-col {
    display: flex;
    flex-direction: column;
  }

  .puzzle-col .rule-note {
    order: 1;
    margin-top: 12px;
  }

  .puzzle-col .puzzle-hints,
  .puzzle-col .next-link,
  .puzzle-col .ad-below {
    order: 2;
  }

  .section {
    margin-top: 32px;
  }

  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .tile {
    padding: 8px;
  }

  .tile .thumb {
    height: 88px;
  }

  .cat-tiles {
    grid-template-columns: minmax(0, 1fr);
  }

  .site-footer::before {
    margin-top: 32px;
  }
}

/* =========================================================================
   Consent to GA4 cookies (layout.php consent_banner(), js/analytics.js): shown only to visitors
   from the EEA, UK and CH who have not chosen. A card in the corner, over the page rather than in
   it, so nothing moves when it appears or goes; the page gets room under it to scroll past.
   Below the drawer of the phone (z-index 99–100), above the board and its pop-ups.
   ========================================================================= */
.consent {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  width: min(420px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--pop-border);
  border-radius: var(--radius);
  background: var(--pop-bg);
  color: var(--pop-fg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  line-height: 1.45;
}

.consent[hidden] {
  display: none;
}

.consent p {
  margin: 0 0 12px;
}

.consent-buttons {
  display: flex;
  gap: 8px;
}

.consent .consent-buttons .btn {
  flex: 1;
  justify-content: center;
}

.consent-open body {
  padding-bottom: 180px;
}

@media (max-width: 1023px) {
  .consent {
    right: 16px;
    bottom: 16px;
  }
}

/* =========================================================================
   Print: a puzzle page on one sheet (A4 or Letter, portrait or landscape)
   ========================================================================= */
/* The line with the site and the address exists for paper only */
.print-source {
  display: none;
}

@media print {
  @page {
    margin: 12mm;
  }

  html,
  body {
    background: #fff !important;
    color: #000;
  }

  /* Everything that is for the screen: navigation, buttons, the game's own layers, banners, ads.
     The board left on paper is the start position PHP draws as SVG (.board-static): SVG strokes
     print in colour even when the browser leaves background graphics out, while the matches of the
     game are CSS gradients and print as bare outlines */
  .side,
  .topbar,
  .drawer-close,
  .scrim,
  .site-footer,
  .consent,
  .ad,
  .ad-below,
  .rail,
  .controls,
  .puzzle-hints,
  .next-link,
  .board-grid-svg,
  .board-overlay-svg,
  .matches-layer,
  .match-ghost,
  .board-toast,
  .victory-banner {
    display: none !important;
  }

  .app {
    display: block;
    min-height: 0;
  }

  .main {
    max-width: none;
    padding: 0;
  }

  .cols,
  .puzzle-col {
    display: block;
    break-inside: avoid;
  }

  .print-source {
    display: block;
    margin: 0 0 4mm;
    font-size: 9pt;
    color: #555;
  }

  #puzzle-title {
    margin: 0 0 3mm;
    font-size: 18pt;
  }

  .statement {
    margin: 0 0 2mm;
    font-size: 12pt;
    max-width: none;
  }

  .rule-note {
    margin: 0;
    font-size: 10pt;
    color: #444;
    max-width: none;
  }

  .board-wrap {
    margin: 6mm 0 0;
  }

  /* About half the sheet: vh in print is the page area, so the board shrinks on a landscape sheet
     and the whole puzzle still fits on one page */
  .board-viewport {
    height: 52vh;
    background: none;
    border: 0.3mm solid #bbb;
    border-radius: 3mm;
    overflow: visible;
  }

  .board-static,
  .board-static[hidden] {
    display: flex !important;
    padding: 6%;
  }

  .target-preview-box {
    background: #fff;
  }
}
