/* ============================================================
   Puzzle Press
   Ink on paper, a slate desk, and one pencil-yellow accent.
   ============================================================ */
:root {
  --ink: #1E2A38;
  --muted: #5B6878;
  --line: #C3CCD6;
  --paper: #FFFFFF;
  --desk: #D5DBE2;
  --pencil: #F2B705;
  --pencil-deep: #C99500;
  --danger: #B42318;
  --ui-font: 'Atkinson Hyperlegible', 'Segoe UI', Arial, sans-serif;
  --book-font: 'Atkinson Hyperlegible', Arial, Helvetica, sans-serif;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--desk);
}
body.is-page { background: var(--paper); }
a { color: var(--ink); text-underline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 20; }
.skip:focus { left: 8px; }
body.is-busy { cursor: progress; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
code { font-size: .92em; background: #EEF1F4; padding: 0 4px; border-radius: 3px; }

/* ---------- site header (every page) ---------- */
.site-header {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 20px;
  background: var(--ink); color: var(--paper);
}
.site-header .brand { color: var(--paper); text-decoration: none; }
.site-header .brand-mark { border-color: var(--paper);
  background:
    linear-gradient(var(--paper), var(--paper)) 33.3% 0 / 1px 100% no-repeat,
    linear-gradient(var(--paper), var(--paper)) 66.6% 0 / 1px 100% no-repeat,
    linear-gradient(var(--paper), var(--paper)) 0 33.3% / 100% 1px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 0 66.6% / 100% 1px no-repeat,
    linear-gradient(var(--pencil), var(--pencil)) 50% 50% / 33.3% 33.3% no-repeat; }
.site-nav { display: flex; gap: 4px; margin-left: auto; }
.site-nav a { color: #D5DBE2; text-decoration: none; padding: 6px 12px; border-radius: var(--radius); font-weight: 700; font-size: 14px; }
.site-nav a:hover { color: var(--paper); background: #ffffff1a; }
.site-nav a[aria-current="page"] { color: var(--ink); background: var(--pencil); }
.site-header :focus-visible { outline-color: var(--pencil); }

/* ---------- tool page: fills the screen ---------- */
.tool-shell { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto auto 1fr; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.tool-title { font-size: 18px; margin: 0; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px;
  border: 2px solid var(--ink);
  background:
    linear-gradient(var(--ink), var(--ink)) 33.3% 0 / 1px 100% no-repeat,
    linear-gradient(var(--ink), var(--ink)) 66.6% 0 / 1px 100% no-repeat,
    linear-gradient(var(--ink), var(--ink)) 0 33.3% / 100% 1px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 0 66.6% / 100% 1px no-repeat,
    linear-gradient(var(--pencil), var(--pencil)) 50% 50% / 33.3% 33.3% no-repeat;
}

/* The page meter is the one thing that always matters for KDP. */
.meter { flex: 1; max-width: 460px; margin-left: auto; }
.meter-numbers { display: flex; align-items: baseline; gap: 6px; font-size: 14px; color: var(--muted); }
.meter-numbers strong { color: var(--ink); font-size: 20px; }
.meter-sep { width: 1px; height: 14px; background: var(--line); margin: 0 6px; align-self: center; }
.meter-track { height: 6px; background: #E6EAEE; border-radius: 3px; margin: 4px 0 3px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--pencil); transition: width .25s ease; }
.meter-note { font-size: 12px; color: var(--muted); }
.meter.is-bad .meter-fill { background: var(--danger); }
.meter.is-bad .meter-note { color: var(--danger); font-weight: 700; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.link-quiet { color: var(--muted); font-size: 14px; margin-left: 6px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #F1F3F5; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--pencil); border-color: var(--pencil-deep); }
.btn-primary:hover:not(:disabled) { background: #F7C531; }
.btn-small { padding: 7px 12px; font-size: 14px; align-self: flex-end; }
.btn-danger { color: var(--danger); border-color: var(--danger); }

/* ---------- layout ---------- */
.workspace { display: grid; grid-template-columns: 380px 1fr; min-height: 0; overflow: hidden; }
.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 4px 20px 32px;
}
.desk { overflow: auto; padding: 24px; min-width: 0; }

/* ---------- sidebar panels ---------- */
.panel { padding: 16px 0 18px; border-bottom: 1px solid var(--line); }
.panel:last-child { border-bottom: 0; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  width: 100%;
}
.field textarea { resize: vertical; line-height: 1.4; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px #F2B70555; }
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .field { margin-bottom: 12px; }
.field-row .btn-small { margin-bottom: 12px; }
.grow { flex: 1; }
.w-80 { width: 80px; flex: none; }
.w-110 { width: 110px; flex: none; }
.help { font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
.seed-row { margin-top: 4px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--ink); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; text-align: center; padding: 8px; font-weight: 700; font-size: 14px; }
.segmented label + label span { border-left: 1.5px solid var(--ink); }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 3px solid var(--pencil); outline-offset: -4px; }

.checks { border: 0; padding: 0; margin: 0 0 12px; }
.checks legend { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; padding: 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--ink); margin: 0; }

/* ---------- status ---------- */
.status { max-width: 760px; margin: 0 auto 24px; }
.status p { margin: 0 0 8px; font-weight: 700; }
.progress { height: 8px; background: #FFFFFF99; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--pencil); transition: width .15s linear; }
.warnings { margin: 8px 0 0; padding-left: 18px; color: var(--danger); font-size: 14px; }
.warnings:empty { display: none; }
.warnings > li { margin-bottom: 6px; }
.warnings > li.is-info { color: var(--muted); list-style: none; margin-left: -18px; padding-left: 18px; position: relative; }
.warnings > li.is-info::before { content: 'Tip'; position: absolute; left: -18px; font-size: 11px; font-weight: 700; color: var(--ink); background: #F2B70566; border-radius: 3px; padding: 0 4px; top: 2px; }
.warnings > li.is-info summary { color: var(--muted); }
.warnings details { color: var(--ink); margin-top: 2px; }
.warnings summary { cursor: pointer; color: var(--danger); font-weight: 700; font-size: 13px; }
.warnings details ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; max-height: 260px; overflow-y: auto; }

/* ---------- dialog ---------- */
.print-help { border: 0; border-radius: 10px; padding: 24px 28px; max-width: 460px; color: var(--ink); font-family: var(--ui-font); }
.print-help::backdrop { background: #1E2A3899; }
.print-help h2 { margin: 0 0 12px; font-size: 20px; }
.print-help ol { padding-left: 20px; margin: 0 0 12px; }
.print-help li { margin-bottom: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; grid-template-rows: none; }
.login-card { background: var(--paper); padding: 28px; border-radius: 10px; width: min(360px, 92vw); display: grid; gap: 14px; }
.login-card .brand { margin-bottom: 4px; }
.form-error { color: var(--danger); margin: 0; font-weight: 700; }

/* ============================================================
   The book itself (what goes into the PDF)
   ============================================================ */
.book { --pw: 8.5in; --ph: 11in; --mt: .55in; --mb: .75in; --mo: .5in; --mg: .375in; }

.page {
  width: var(--pw);
  height: var(--ph);
  margin: 0 auto 24px;
  background: #fff;
  color: #000;
  position: relative;
  overflow: hidden;
  font-family: var(--book-font);
  box-shadow: 0 1px 2px #1E2A3840, 0 6px 18px #1E2A3826;
  /* Big books stay fast on screen: off-screen pages are skipped until you scroll to them. */
  content-visibility: auto;
  contain-intrinsic-size: var(--pw) var(--ph);
}
/* Page 1 is a right-hand page, so odd pages have the gutter on the left. */
.page.recto { padding: var(--mt) var(--mo) var(--mb) var(--mg); }
.page.verso { padding: var(--mt) var(--mg) var(--mb) var(--mo); }
.page-body { height: 100%; }

.folio { position: absolute; bottom: .35in; font-size: 10pt; text-align: center; }
.recto .folio { left: var(--mg); right: var(--mo); }
.verso .folio { left: var(--mo); right: var(--mg); }

.sheet { display: grid; height: 100%; }
.item { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden; }
.item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: .3em; }
.item-num { font-weight: 700; }
.item-num::before { content: '#'; }
.item-label { font-size: .8em; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.grid { display: block; overflow: visible; }
.grid text { font-family: var(--book-font); text-anchor: middle; dominant-baseline: middle; fill: #000; }
.sd line, .sd rect { fill: none; stroke: #000; vector-effect: non-scaling-stroke; }
.sd .thin { stroke-width: .9px; stroke: #333; }
.sd .thick { stroke-width: 2.4px; }
.sd .frame { stroke-width: 3px; }
.sd text { font-size: 60px; }
.sd .given { font-weight: 700; }
.sd .solved { font-weight: 400; fill: #555; }

.ws .frame { fill: none; stroke: #000; stroke-width: 2.4px; vector-effect: non-scaling-stroke; }
.ws text { font-size: 56px; font-weight: 700; }
.ws .hit { fill: var(--pencil); fill-opacity: .55; stroke: none; }

.word-list { list-style: none; margin: .14in 0 0; padding: 0; display: grid; grid-auto-flow: column; column-gap: 10px; }
.word-list li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 0; }

/* front matter */
.fm .page-body { display: flex; flex-direction: column; }
.fm-title .page-body { justify-content: center; align-items: center; text-align: center; }
.fm-title h1 { font-size: 36pt; line-height: 1.1; margin: 0 0 .25in; max-width: 90%; }
.fm-sub { font-size: 16pt; margin: 0 0 .6in; max-width: 85%; }
.fm-author { font-size: 14pt; margin: 0; }
.fm-copy .page-body { justify-content: flex-end; font-size: 9.5pt; line-height: 1.5; }
.fm-copy p { margin: 0 0 .08in; max-width: 4.2in; }
.fm-rules .page-body { justify-content: center; font-size: 12pt; line-height: 1.6; }
.fm-rules h2 { font-size: 22pt; margin: 0 0 .25in; }
.fm-rules p { margin: 0 0 .15in; max-width: 5in; }
.fm-divider .page-body { justify-content: center; align-items: center; }
.fm-divider h2 { font-size: 32pt; margin: 0; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .tool-shell { height: auto; display: block; }
  .toolbar { flex-wrap: wrap; }
  .site-header { flex-wrap: wrap; gap: 8px; }
  .site-nav { margin-left: 0; }
  .meter { order: 3; flex-basis: 100%; max-width: none; }
  .workspace { display: block; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .desk { padding: 16px 8px; }
  .page { zoom: .45; }
}

@media (prefers-reduced-motion: reduce) {
  .meter-fill, .progress-fill { transition: none; }
}

/* ---------- print: only the book ---------- */
@media print {
  html, body { background: #fff; height: auto; display: block; }
  .site-header, .site-footer, .toolbar, .sidebar, .status, dialog, .content-section, .skip,
  .ad, ins.adsbygoogle, .google-auto-placed, .adsbygoogle-noablate { display: none !important; }
  .tool-shell { height: auto; display: block; }
  .workspace { display: block; }
  .desk { padding: 0; overflow: visible; }
  .page {
    margin: 0;
    box-shadow: none;
    zoom: 1;
    content-visibility: visible;
    break-after: page;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .page:last-child { break-after: auto; }
}

/* ---------- ad spots (never printed, never inside the book) ---------- */
.ad { margin: 0 auto 24px; max-width: 760px; text-align: center; min-height: 100px; }
.ad-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.ad-placeholder { border: 2px dashed var(--line); color: var(--muted); display: grid; place-items: center; border-radius: var(--radius); background: #ffffff80; }
.page ins.adsbygoogle, .page .google-auto-placed, .book > ins, .book > .google-auto-placed { display: none !important; }

/* ---------- content pages (guides, about, privacy) ---------- */
.page-main { padding: 40px 20px 56px; }
.content-section { background: var(--paper); border-top: 1px solid var(--line); padding: 48px 20px 40px; }
.prose { max-width: 68ch; margin: 0 auto; font-size: 17px; line-height: 1.65; }
.prose h1 { font-size: 34px; line-height: 1.15; margin: 0 0 16px; }
.prose h2 { font-size: 22px; line-height: 1.25; margin: 36px 0 10px; }
.prose p { margin: 0 0 16px; }
.prose .lead { font-size: 19px; color: var(--muted); }
.prose .meta, .prose .crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.prose details { border-bottom: 1px solid var(--line); padding: 10px 0; }
.prose summary { font-weight: 700; cursor: pointer; }
.prose details p { margin: 8px 0 4px; }
.prose code { font-size: .88em; }
.prose .ad-inline { margin: 28px auto; }
.guide-list { list-style: none; padding: 0; margin: 24px 0 0; }
.guide-list li { border-top: 1px solid var(--line); padding: 18px 0 4px; }
.guide-list h2 { font-size: 20px; margin: 0 0 6px; }
.guide-list p { color: var(--muted); }
.guide-links { padding-left: 20px; }
.guide-links li { margin-bottom: 6px; }
.cta { margin: 36px 0 8px; padding: 20px 22px; background: #F2B70526; border-left: 4px solid var(--pencil); border-radius: var(--radius); }
.cta p { margin: 0 0 12px; }
.cta .btn { display: inline-block; text-decoration: none; }

/* ---------- footer ---------- */
.site-footer { background: var(--ink); color: #C3CCD6; padding: 28px 20px; font-size: 14px; }
.footer-inner { max-width: 960px; margin: 0 auto; display: grid; gap: 12px; }
.footer-brand { display: flex; align-items: center; gap: 10px; color: var(--paper); font-weight: 700; margin: 0; }
.footer-brand .brand-mark { width: 18px; height: 18px; border-color: var(--paper); background: linear-gradient(var(--pencil), var(--pencil)) 50% 50% / 33.3% 33.3% no-repeat; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.site-footer a { color: var(--paper); }
.footer-note { margin: 0; font-size: 12.5px; }

@media (max-width: 600px) {
  .prose { font-size: 16px; }
  .prose h1 { font-size: 28px; }
  .page-main { padding-top: 28px; }
}
