/* Shared design for every printable app: glass UI on screen, plain A4 pages on print. */
:root {
  --text: #1c1c1e;
  --muted: #5b5b66;
  --glass: rgba(255, 255, 255, 0.45);
  --glass-strong: rgba(255, 255, 255, 0.7);
  --stroke: rgba(255, 255, 255, 0.75);
  --shadow: 0 10px 40px rgba(31, 38, 135, 0.15);
  --accent: #0a84ff;
  --bg: #e9eef8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --text: #f2f2f7;
    --muted: #a1a1aa;
    --glass: rgba(40, 40, 52, 0.45);
    --glass-strong: rgba(70, 70, 90, 0.6);
    --stroke: rgba(255, 255, 255, 0.18);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
    --bg: #12131a;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
/* Plain gradients: a big blur() filter gets tiled by the GPU on wide screens and shows seams. */
.bg {
  position: fixed; inset: 0; z-index: -1;
  /* The first two layers fade the top and bottom edges to plain --bg, the colour the phone's status bar and
     bottom bar use (theme-color), so there is no hard line where the browser chrome meets the page. */
  background:
    linear-gradient(var(--bg), transparent 90px),
    linear-gradient(to top, var(--bg), transparent 90px),
    radial-gradient(90vmax 70vmax at 0% -10%, rgba(255, 159, 10, 0.16), transparent 65%),
    radial-gradient(80vmax 70vmax at 105% 110%, rgba(10, 132, 255, 0.12), transparent 65%),
    var(--bg);
}

.app { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; padding: 24px; align-items: start; max-width: 1280px; margin: 0 auto; }
.side { position: sticky; top: 24px; display: grid; gap: 16px; }
.support { padding: 14px 22px; display: grid; gap: 12px; justify-items: center; }
.ad-slot { width: 100%; min-height: 250px; }
.ad-slot.banner { min-height: 90px; }
.coffee {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px;
  background: #ffdd00; color: #111; font-weight: 600; text-decoration: none;
}
.glass {
  background: var(--glass);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--stroke);
  border-radius: 28px;
  box-shadow: var(--shadow), inset 0 1px 0 var(--stroke);
}
.controls { padding: 22px; display: grid; gap: 16px; }
h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.sub { margin: 2px 0 0; color: var(--muted); }
.field { display: grid; gap: 6px; }
.field > span, legend { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.seg { display: flex; padding: 3px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--stroke); }
.seg label { flex: 1; text-align: center; padding: 7px 6px; border-radius: 999px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(10, 132, 255, 0.4); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
select, input[type=number], textarea {
  font: inherit; color: var(--text); width: 100%;
  padding: 9px 12px; border-radius: 14px;
  background-color: var(--glass-strong); border: 1px solid var(--stroke);
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.buttons .primary { flex-basis: 100%; } /* Print gets its own row under New puzzles and Share link */
button {
  flex: 1; font: inherit; font-weight: 600; padding: 11px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--stroke); color: var(--text); background: var(--glass-strong);
}
button.primary { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 4px 16px rgba(10, 132, 255, 0.35); }
button:active { transform: scale(0.98); }
[hidden] { display: none !important; }

/* Preview: A4 sheets */
.preview { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; justify-items: center; min-width: 0; }
.page {
  /* Always laid out at true A4 width, then scaled to fit small screens (fitPages), so the content never
     spills past the page edge on phones and matches the printed layout. */
  width: 210mm; min-height: 297mm; padding: 14mm; zoom: var(--page-zoom, 1);
  background: #fff; color: #111; border-radius: 6px; box-shadow: var(--shadow);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
.page h2 { margin: 0 0 2mm; font-size: 24pt; }
.page .meta { display: flex; justify-content: space-between; gap: 8mm; margin-bottom: 6mm; font-size: 12pt; }
.page .meta span { flex: 1; border-bottom: 1px solid #999; padding-bottom: 1mm; }
.howto { font-size: 12pt; margin: 0 0 5mm; }
.answers ol { font-size: 13pt; line-height: 1.8; padding-left: 8mm; break-inside: avoid; }
.answers h3 { margin: 5mm 0 0; font-size: 13pt; }
.howto b { font-size: 14pt; white-space: nowrap; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .side { position: static; }
}

@media print {
  /* Margins live on @page and pages fill whatever is left, so browsers that add their own margins
     or headers (Safari) shrink the content instead of spilling each sheet onto a second one. */
  @page { size: A4; margin: 12mm; }
  body { background: #fff; min-height: 0; }
  .bg, .side { display: none !important; }
  .app { display: block; padding: 0; max-width: none; }
  .preview { display: block; justify-items: normal; }
  .page { width: auto; max-width: none; min-height: 0; padding: 0; zoom: 1; border-radius: 0; box-shadow: none; break-after: page; }
  .page:last-child { break-after: auto; }
  /* If a browser leaves less room than we planned for (Safari headers, Letter paper), move a whole puzzle or
     answer grid to the next sheet instead of cutting it in half. */
  .flow > *, .pgrid, .page svg, .page table { break-inside: avoid; }
}


/* Home page */
.hub { max-width: 1080px; margin: 0 auto; padding: 32px 24px; display: grid; gap: 24px; }
.hub-head { padding: 26px; display: flex; flex-wrap: wrap; gap: 16px; align-items: end; justify-content: space-between; }
.hub-head h1 { font-size: 32px; }
.hub-head .field { min-width: 200px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card { padding: 24px; display: grid; gap: 10px; align-content: start; color: inherit; text-decoration: none; transition: transform 0.15s; }
.card:hover { transform: translateY(-3px); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.card svg { width: 44px; height: 44px; color: var(--accent); }
/* Each app keeps its own colour, from the pixel-art palette, so the cards are easy to tell apart. */
.card:nth-child(6n+1) svg { color: #e53935; }
.card:nth-child(6n+2) svg { color: #fb8c00; }
.card:nth-child(6n+3) svg { color: #43a047; }
.card:nth-child(6n+4) svg { color: #1e88e5; }
.card:nth-child(6n+5) svg { color: #8e24aa; }
.card:nth-child(6n+6) svg { color: #00897b; }
.card h2 { margin: 0; font-size: 20px; }
.card p { margin: 0; color: var(--muted); }
@media (max-width: 600px) { .hub { padding: 16px; } .hub-head h1 { font-size: 26px; } }

/* Logo: mark + wordmark, links home. The ".es" is in the brand orange so the domain sticks. */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 22px; letter-spacing: -0.03em; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand-name span { color: #f57c00; }
.brand.big { font-size: 34px; gap: 14px; margin-bottom: 10px; }
.brand.big img { width: 52px; height: 52px; border-radius: 13px; }
.controls .brand { margin-bottom: 8px; }
.controls h1 { font-size: 19px; }

/* About / FAQ text for people and search engines, and the footer with links to every app */
.site-foot { max-width: 1280px; margin: 0 auto; padding: 0 24px 32px; display: grid; gap: 16px; }
.about { padding: 22px 26px; }
.about h2 { margin: 0 0 8px; font-size: 18px; }
.about h3 { margin: 16px 0 4px; font-size: 15px; }
.about p { margin: 0; color: var(--muted); }
.foot-links { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: center; font-size: 13px; }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:first-child { font-weight: 700; color: var(--text); }
.foot-links a:hover { text-decoration: underline; }
/* left/right + auto margins centre it; left: 50% would cap its width at half the screen. */
.thanks { position: fixed; left: 16px; right: 16px; bottom: 20px; margin: 0 auto; width: fit-content; z-index: 5;
  padding: 14px 16px 16px 20px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
  background: color-mix(in srgb, var(--glass-strong) 40%, var(--bg)); border-radius: 22px; } /* near-opaque so the page doesn't smear through */
/* Narrow screens: message and close button on top, coffee button below. Wide screens: one row. */
.thanks .coffee { grid-row: 2; justify-self: start; }
.thanks button { grid-column: 2; grid-row: 1; align-self: start; width: 32px; height: 32px; padding: 0; border-radius: 50%; }
@media (min-width: 700px) {
  .thanks { grid-template-columns: auto auto auto; padding: 10px 12px 10px 20px; border-radius: 999px; }
  .thanks .coffee { grid-row: 1; grid-column: 2; }
  .thanks button { grid-column: 3; align-self: center; }
}
#legal { display: grid; gap: 14px; }
.legal-page section { padding: 22px 26px; }
#legal a, .about a { color: var(--accent); text-decoration: none; font-weight: 600; overflow-wrap: anywhere; }
#legal a:hover, .about a:hover { text-decoration: underline; }
.legal-page h2 { margin: 0 0 6px; font-size: 17px; }
.legal-page p { margin: 0; color: var(--muted); max-width: 75ch; }
.site-foot .copyright { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
@media (max-width: 900px) { .site-foot { padding: 0 16px 24px; } }

/* Every printed sheet ends with the site name and the usage terms (--sheet-foot, set per language in app.js),
   so a worksheet passed around leads back here and says it is not for resale. */
.page::after { content: var(--sheet-foot, "printabl.es"); display: block; margin-top: 2mm; text-align: right; font-size: 9pt; font-weight: 700; color: #999; }

@media print {
  .site-foot, .support, .thanks { display: none !important; }
}

/* paginate() measures pages at the printed size: A4 minus 12mm margins. */
.preview.measuring .page { width: 210mm !important; max-width: none !important; padding: 12mm !important; min-height: 0 !important; }

/* Browsers skip background colours when printing unless told otherwise; worksheets rely on them
   (nonogram answers, word search highlights, letter tiles, key tables). */
.page, .page * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
#free-links ul { margin: 0; padding-left: 20px; columns: 2 260px; color: var(--muted); }
#free-links li { padding: 3px 0; break-inside: avoid; }
