/* Chess Monocle - deep green sidebar app: dark green home + reader, light paper library/notes/settings.
   Everything is driven by the tokens below; the .light class re-skins a whole area, and
   [data-theme="noir"] on <html> swaps in the old black-and-white look. */
:root, .dark, .topbar {
  --bg: #0d2b26;          /* main background */
  --side: #0a211d;        /* sidebar */
  --bg-raised: #133832;   /* cards, panels */
  --bg-sunk: #0b2420;     /* inputs, wells */
  --desk: #0f2f2a;        /* behind the PDF pages */
  --fg: #eef1ea;
  --dim: #93aea4;         /* secondary text */
  --line: #1f4a41;        /* hairlines */
  --line-strong: #31685b;
  --gold: #dcaa45;        /* primary buttons */
  --amber: #e5b960;       /* accent text, "recognized" */
  --cyan: #62d6c2;        /* links, focus, highlighted diagram */
  --pink: #f0909f;        /* "needs review", errors */
  --mint: #7fd6a2;        /* "corrected", ok */
  --on-gold: #1b2a22;
  --glow: 0 0 14px rgba(98, 214, 194, .3);
  --side-w: 216px;
  --heading: "Cormorant Garamond", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
  --sq-dark: #769656;     /* board squares */
  --sq-light: #eeeed2;
}
:root[data-font="sans"] { --heading: var(--ui); }
:root[data-theme="noir"], :root[data-theme="noir"] .dark, :root[data-theme="noir"] .topbar {
  --bg: #0b0b0d; --side: #070708; --bg-raised: #131317; --bg-sunk: #070708; --desk: #18181c;
  --fg: #e9e6df; --dim: #8d8a85; --line: #2c2c33; --line-strong: #4a4a52;
  --gold: #f2c38b; --amber: #f2c38b; --cyan: #9ed8db; --pink: #f0a3bc; --mint: #a8e0bf;
  --glow: 0 0 12px rgba(242, 195, 139, .35);
  --sq-dark: #7d8187; --sq-light: #dcd8cf;
}
/* light paper areas (library, saved positions, notes, settings) */
.light {
  --bg: #f6f3ea; --bg-raised: #ffffff; --bg-sunk: #f1ede1;
  --fg: #1f2d29; --dim: #66776f; --line: #e3ddcd; --line-strong: #c9c2ad;
  --amber: #946512; --cyan: #17766a; --pink: #b83f5b; --mint: #2c8657;
  --glow: none;
  background: var(--bg); color: var(--fg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--ui); }
::selection { background: var(--gold); color: var(--on-gold); }
a { color: var(--cyan); }
code, .mono { font-family: var(--mono); }
.hidden { display: none !important; }
.muted { color: var(--dim); }
.warn { color: var(--amber); }
.error { color: var(--pink); }
.ok-text { color: var(--mint); }
* { scrollbar-color: var(--line-strong) transparent; }
svg.icon { width: 20px; height: 20px; flex: none; }

/* ---- app shell: sidebar + main ------------------------------------------ */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 20;
  background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px 16px;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 2px 8px 22px;
  color: var(--fg); text-decoration: none;
  font: 600 13px/1.15 var(--heading); letter-spacing: .24em; text-transform: uppercase;
}
.sidebar .brand img { width: 38px; height: 38px; }
.sidebar .brand, .topbar .brand { color: #e2b862; }
.dark { color: var(--fg); }

/* phone-only top bar (logo + search + settings); hidden elsewhere */
.topbar { display: none; }
.topbar .brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  font: 600 12px/1.15 var(--heading); letter-spacing: .24em; text-transform: uppercase;
}
.topbar .brand img { width: 34px; height: 34px; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--fg); }
.icon-btn:hover { background: rgba(255, 255, 255, .08); }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
  color: var(--dim); text-decoration: none; font-size: 14px;
}
.sidebar nav a:hover, .sidebar nav a:focus-visible { color: var(--fg); background: rgba(255, 255, 255, .05); outline: none; }
.sidebar nav a[aria-current="page"] { color: var(--fg); background: var(--bg-raised); box-shadow: inset 2px 0 0 var(--cyan); }
.sidebar .tagline {
  margin: auto 8px 0; padding-top: 16px; color: var(--dim);
  font: italic 15px/1.3 var(--heading);
}
.sidebar .tagline::after { content: ""; display: block; width: 26px; height: 2px; margin-top: 8px; background: var(--gold); }
.creator {
  text-align: center; padding: 8px 16px 24px; color: var(--dim);
  font: 11px var(--mono); letter-spacing: .2em; text-transform: uppercase;
}
.creator b { color: var(--fg); font-weight: normal; }
.main > .creator { margin-top: auto; }

/* page header used by the light pages */
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 22px 32px 6px; }
.page-head h1 { margin: 0; font: 600 34px/1.1 var(--heading); }
.page-head .grow { flex: 1; }
.page-body { padding: 10px 32px 28px; }
.search {
  display: flex; align-items: center; gap: 8px; min-width: 220px; flex: 0 1 320px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; color: var(--dim);
}
.search input[type=text] { flex: 1; min-width: 0; border: 0; background: none; color: var(--fg); font: inherit; padding: 8px 0; outline: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 16px; }
.chip {
  border: 1px solid var(--line-strong); background: none; color: var(--fg); font: inherit; font-size: 13px;
  padding: 5px 14px; border-radius: 999px; cursor: pointer;
}
.chip.on { background: var(--side); color: #eef1ea; border-color: var(--side); }
:root[data-theme="noir"] .light .chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ---- controls ----------------------------------------------------- */
.btn, select, input[type=text], input[type=number], textarea {
  font: inherit; color: var(--fg); background: var(--bg-sunk);
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 5px 12px;
}
.btn { cursor: pointer; font-size: 13px; transition: background .12s, border-color .12s, color .12s; }
a.btn { display: inline-block; text-decoration: none; }
.btn:hover { border-color: var(--fg); }
.btn:active, .btn.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--on-gold); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); border-color: var(--gold); }
.btn.go { background: #3a9971; border-color: #3a9971; color: #fff; font-weight: 600; }
.btn.danger { border-color: var(--pink); color: var(--pink); background: none; }
.btn.danger:hover { background: var(--pink); color: var(--bg); }
.btn.ghost { background: none; }
.btn.icon { display: inline-flex; align-items: center; gap: 6px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn:disabled:hover { border-color: var(--line-strong); }
.btn:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }
input[type=text] { min-width: 0; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
select option { background: var(--bg-raised); color: var(--fg); }
input[type=range] { accent-color: var(--cyan); }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: background .15s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + span { background: #2f9d7e; }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---- cards -------------------------------------------------------- */
.window {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px;
  margin: 22px 32px; max-width: 980px;
}
.window > h2 {
  margin: 0; border-bottom: 1px solid var(--line); color: var(--fg);
  font: 600 20px/1.2 var(--heading); padding: 12px 18px;
}
.window > h2 .back { float: right; font: 13px var(--ui); color: var(--dim); text-decoration: none; }
.window > h2 .back:hover { color: var(--fg); }
.window .content { padding: 16px 18px; }
.light .window { box-shadow: 0 1px 2px rgba(31, 45, 41, .05); }

/* ---- book covers (generated from the title) ----------------------- */
.cover {
  --c1: #2a6b58; --c2: #123a30;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch;
  aspect-ratio: 3 / 4; border-radius: 4px 8px 8px 4px; padding: 12% 10% 10%; overflow: hidden; position: relative;
  background: linear-gradient(160deg, var(--c1), var(--c2));
  box-shadow: inset 5px 0 0 rgba(0, 0, 0, .25), 0 6px 14px rgba(0, 0, 0, .3);
  color: #fff; text-align: center;
}
.cover .glyph { position: absolute; top: 12%; left: 0; right: 0; font-size: 34px; opacity: .55; line-height: 1; }
.cover .cover-title { font: 600 clamp(11px, 1.3vw, 15px)/1.15 var(--heading); letter-spacing: .02em; overflow-wrap: anywhere; }

/* ---- home --------------------------------------------------------- */
.hero {
  position: relative; padding: 56px 40px 46px; min-height: 300px; overflow: hidden;
  background:
    radial-gradient(circle at 82% 40%, rgba(98, 214, 194, .22), transparent 38%),
    linear-gradient(120deg, #0a211d 0%, #123a31 55%, #1a4a3c 100%);
  border-bottom: 1px solid var(--line);
}
.hero-logo { position: absolute; right: 7%; top: 50%; width: 240px; height: 240px; transform: translateY(-50%); opacity: .9; filter: drop-shadow(0 0 30px rgba(98, 214, 194, .25)); }
.hero h1 { margin: 0 0 6px; font: 600 54px/1.05 var(--heading); }
.hero .motto { margin: 0 0 14px; font: italic 24px/1.2 var(--heading); color: var(--amber); }
.hero p.lead { max-width: 480px; color: #cfdcd5; margin: 0 0 22px; }
.hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero .btn { padding: 9px 22px; font-size: 14px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; padding: 26px 40px 20px; }
.home h2.section { margin: 0 0 14px; font: 600 24px/1.2 var(--heading); }
.recent { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.book-card { display: flex; flex-direction: column; gap: 8px; color: var(--fg); text-decoration: none; min-width: 0; }
.book-card:hover .cover, .book-card:focus-visible .cover { transform: translateY(-3px); }
.book-card .cover { transition: transform .15s; }
.book-card b { font-weight: 600; line-height: 1.25; }
.book-card .meta { font-size: 12px; color: var(--dim); }
.book-card .go { color: var(--cyan); font-size: 13px; }
.quick { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px; padding: 14px; align-self: start; }
.quick h3 { margin: 0 0 8px; font: 600 15px var(--ui); }
.quick a, .quick button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 6px; border: 0; background: none;
  border-top: 1px solid var(--line); color: var(--fg); font: inherit; text-decoration: none; cursor: pointer; text-align: left;
}
.quick a:first-of-type { border-top: 0; }
.quick a:hover, .quick button:hover { color: var(--cyan); }
.quick a span.sub { display: block; font-size: 12px; color: var(--dim); }
.quote { margin: 14px 4px 0; color: var(--dim); font: italic 16px/1.35 var(--heading); }
.home-section { max-width: 820px; }
.about h3 { font: 600 18px var(--heading); color: var(--amber); margin: 22px 0 8px; }
.about ol, .about ul { padding-left: 22px; margin: 0; }
.about li { margin: 4px 0; }
.keys td { padding: 3px 14px 3px 0; }
kbd { border: 1px solid var(--line-strong); background: var(--bg-sunk); padding: 0 6px; border-radius: 4px; font: 12px var(--mono); }
.swatch { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--cyan); vertical-align: -1px; }
.swatch.review { border-color: var(--pink); }
.swatch.corrected { border-color: var(--mint); }

/* ---- library ------------------------------------------------------ */
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 22px 18px; }
.book-tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.book-tile a.cover-link { text-decoration: none; color: inherit; }
.book-tile .cover { transition: transform .15s; }
.book-tile a.cover-link:hover .cover { transform: translateY(-3px); }
.book-tile h3 { margin: 4px 0 0; font: 600 15px/1.25 var(--ui); overflow-wrap: anywhere; }
.book-tile .meta { font-size: 12px; color: var(--dim); }
.book-tile .file { font-size: 11px; }
.book-tile .actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.book-tile .actions .btn { padding: 3px 9px; font-size: 12px; }
.book-tile.add {
  border: 1.5px dashed var(--line-strong); border-radius: 8px; color: var(--dim); align-items: center; justify-content: center;
  aspect-ratio: 3 / 4; cursor: pointer; background: none; font: inherit; gap: 6px;
}
.book-tile.add:hover { color: var(--fg); border-color: var(--fg); }
.book-tile details.more > summary { display: none; list-style: none; }
.book-tile details.more > summary::-webkit-details-marker { display: none; }
.books.list { grid-template-columns: 1fr; gap: 0; }
.books.list .book-tile { flex-direction: row; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.books.list .book-tile .cover { width: 48px; padding: 4px; }
.books.list .book-tile .cover .glyph, .books.list .book-tile .cover .cover-title { display: none; }
.books.list .book-tile .info { flex: 1; min-width: 0; }
.books.list .book-tile .actions { margin: 0; }
.books.list .book-tile.add { aspect-ratio: auto; flex-direction: row; padding: 12px; border-radius: 8px; justify-content: center; }
.import-options { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; }
.progress { height: 8px; border-radius: 999px; margin-top: 8px; background: var(--bg-sunk); border: 1px solid var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--gold); width: 0; transition: width .3s; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input[type=text] { flex: 1; }
.row .grow, .grow { flex: 1; }
.drop-zone {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 18px; background: var(--bg-sunk);
}
.drop-zone.over { border-color: var(--cyan); box-shadow: var(--glow); }
.job { border: 1px solid var(--line-strong); border-radius: 10px; padding: 12px; margin-top: 12px; background: var(--bg-sunk); }
.storage { margin: 18px 0 0; font-size: 12px; }

/* ---- saved positions + notes -------------------------------------- */
.table-card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pos-head, .pos-row { display: grid; grid-template-columns: 76px minmax(120px, 1.1fr) minmax(0, 1.6fr) 110px 40px; gap: 14px; align-items: center; padding: 10px 16px; }
.pos-head { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid var(--line); }
.pos-row { border-bottom: 1px solid var(--line); }
.pos-row:last-child { border-bottom: 0; }
.pos-row:hover { background: rgba(127, 127, 127, .06); }
.pos-row .title { font-weight: 600; }
.pos-row .sub { font-size: 12px; color: var(--dim); }
.pos-row .note-edit { width: 100%; min-height: 36px; padding: 4px 8px; font-size: 13px; background: transparent; border-color: transparent; }
.pos-row .note-edit:hover, .pos-row .note-edit:focus { background: var(--bg-sunk); border-color: var(--line-strong); }
.mini-board { display: grid; grid-template-columns: repeat(8, 1fr); width: 64px; height: 64px; border-radius: 4px; overflow: hidden; background: var(--sq-light); box-shadow: 0 0 0 1px var(--line-strong); }
.mini-board i { display: grid; place-items: center; font-style: normal; font-size: 8px; line-height: 1; }
.mini-board i.d { background: var(--sq-dark); }
.mini-board i.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 1px #000; }
.mini-board i.k { color: #111; }
.menu-btn { border: 0; background: none; color: var(--dim); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 6px; }
.menu-btn:hover { color: var(--fg); background: rgba(127, 127, 127, .15); }
.empty { padding: 40px 16px; text-align: center; color: var(--dim); }

.notes-layout { display: grid; grid-template-columns: minmax(240px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.note-list { display: grid; gap: 10px; }
.note-card {
  text-align: left; font: inherit; color: var(--fg); cursor: pointer;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.note-card:hover { border-color: var(--line-strong); }
.note-card.active { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan); }
.note-card b { display: block; font-size: 15px; }
.note-card .snippet { margin: 4px 0 8px; color: var(--dim); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.note-card .foot { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--dim); }
.tag { background: #e4efe9; color: #285a49; border-radius: 999px; padding: 1px 10px; font-size: 11px; }
:root:not([data-theme="noir"]) .tag { background: #dfece6; }
.note-editor { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px; padding: 16px; position: sticky; top: 16px; }
.note-editor input[type=text] { width: 100%; font: 600 20px var(--heading); margin-bottom: 8px; }
.note-editor textarea { min-height: 260px; }

/* ---- settings ------------------------------------------------------ */
.settings { max-width: 760px; }
.setting-group { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 18px; }
.setting-group h2 { margin: 0; padding: 12px 18px; font: 600 20px var(--heading); border-bottom: 1px solid var(--line); }
.setting { display: flex; align-items: center; gap: 16px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .label { flex: 1; }
.setting .label small { display: block; color: var(--dim); }
.setting select { min-width: 170px; }
.setting input[type=range] { width: 200px; }
.setting output { min-width: 28px; text-align: right; font-family: var(--mono); }

/* ---- reader ------------------------------------------------------- */
body:has(.viewer) { --side-w: 64px; height: 100vh; overflow: hidden; }
body:has(.viewer) .app { height: 100vh; min-height: 0; }
body:has(.viewer) .sidebar nav a span, body:has(.viewer) .sidebar .brand span,
body:has(.viewer) .sidebar .tagline { display: none; }
body:has(.viewer) .sidebar { padding: 14px 8px; }
body:has(.viewer) .sidebar nav a { justify-content: center; padding: 11px 0; }
body:has(.viewer) .sidebar .brand { justify-content: center; padding: 0 0 18px; }
body:has(.viewer) .main { height: 100vh; min-height: 0; }
.titlebar {
  flex: none; min-height: 52px; display: flex; align-items: center; gap: 10px; padding: 6px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.titlebar .back-link { display: flex; align-items: center; color: var(--fg); text-decoration: none; padding: 6px; border-radius: 6px; }
.titlebar .back-link:hover { background: rgba(255, 255, 255, .07); }
.titlebar .crumb { font: 600 20px var(--heading); max-width: 280px; overflow: hidden; text-overflow: ellipsis; color: var(--fg); }
.titlebar .spacer { flex: 1; }
.titlebar .label { color: var(--dim); font-size: 13px; }
.titlebar .btn, .titlebar select, .titlebar input { font-size: 13px; padding: 4px 9px; }
.titlebar-tools { display: flex; align-items: center; gap: 8px; }
.pager { display: flex; align-items: center; gap: 4px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 2px 4px; }
.pager .btn { border: 0; background: none; padding: 2px 8px; }
.pager input { width: 54px; text-align: center; border: 0; background: none; padding: 2px; -moz-appearance: textfield; appearance: textfield; }
.pager input::-webkit-outer-spin-button, .pager input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.viewer {
  --panel-w: 1fr;
  display: grid; grid-template-columns: minmax(200px, 1fr) 6px var(--panel-w);
  flex: 1; min-height: 0;
}
#splitter {
  background: var(--bg); border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  cursor: col-resize; touch-action: none;
  background-image: linear-gradient(var(--dim) 0 0); background-size: 2px 36px; background-position: center; background-repeat: no-repeat;
}
#splitter:hover, #splitter.dragging { background-image: linear-gradient(var(--cyan) 0 0); border-color: var(--cyan); }
body.resizing { cursor: col-resize; user-select: none; }
.viewer.panel-collapsed { grid-template-columns: 1fr; }
.viewer.panel-collapsed #splitter, .viewer.panel-collapsed #panel { display: none; }
body.resizing #pages, body.resizing #board { pointer-events: none; }

.viewer.board-full { grid-template-columns: 1fr; }
.viewer.board-full #pages, .viewer.board-full #splitter { display: none; }
.viewer.board-full #panel { border-left: 0; padding: 16px 24px; }
.viewer.board-full #panel-board {
  display: grid; grid-template-columns: auto minmax(320px, 1fr);
  grid-template-rows: repeat(10, auto) 1fr; column-gap: 24px; align-items: start;
}
.viewer.board-full #panel-board > * { grid-column: 2; }
.viewer.board-full #panel-board > .board-area { grid-column: 1; grid-row: 1 / -1; width: min(calc(100vh - 40px), 65vw); max-width: none; margin: 0; }
body:has(.board-full) .titlebar, body:has(.board-full) .sidebar, body:has(.board-full) .thumbs { display: none; }
body:has(.board-full) .app { grid-template-columns: 1fr; }

#pages {
  overflow: auto; position: relative; padding: 18px 0 40px;
  background: var(--desk) radial-gradient(rgba(255, 255, 255, .04) 1px, transparent 1px) 0 0 / 22px 22px;
}
.page { position: relative; margin: 0 auto 22px; background: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .45); }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .textLayer { z-index: 2; }
.page .page-number { position: absolute; right: 0; bottom: -20px; font: 11px var(--mono); letter-spacing: .12em; color: var(--dim); }
:root[data-page-numbers="off"] .page .page-number { display: none; }
.board-box {
  position: absolute; z-index: 3; border: 2px solid var(--cyan); border-radius: 3px;
  background: rgba(98, 214, 194, .06); cursor: pointer; padding: 0;
}
.board-box:hover { background: rgba(98, 214, 194, .18); }
.board-box.review { border-color: var(--pink); background: rgba(240, 144, 159, .08); }
.board-box.corrected { border-color: var(--mint); }
.board-box.active { box-shadow: 0 0 0 3px rgba(13, 43, 38, .9), 0 0 18px rgba(98, 214, 194, .55); background: rgba(98, 214, 194, .12); }
:root[data-highlight="off"] .board-box:not(.active):not(:hover) { border-color: transparent; background: none; }
:root[data-highlight="off"] .board-box:not(.active):not(:hover) .tag { display: none; }
.board-box .tag {
  position: absolute; left: -2px; top: -21px; background: var(--cyan); color: #06231e;
  font: 600 11px/1 var(--ui); padding: 5px 8px; border-radius: 4px 4px 0 0; white-space: nowrap;
}
.board-box.review .tag { background: var(--pink); }
.board-box.corrected .tag { background: var(--mint); }

.thumbs {
  flex: none; display: flex; justify-content: center; gap: 10px; padding: 8px 12px;
  background: var(--side); border-top: 1px solid var(--line); overflow-x: auto;
}
.thumb { flex: none; border: 2px solid transparent; border-radius: 4px; padding: 0; background: none; cursor: pointer; color: var(--dim); font: 11px var(--mono); text-align: center; }
.thumb canvas, .thumb .blank { display: block; width: 52px; height: 68px; background: #f6f3ea; border-radius: 2px; }
.thumb.on { border-color: var(--cyan); color: var(--fg); }
.thumb:hover { border-color: var(--line-strong); }

#panel { overflow-y: auto; overflow-x: hidden; padding: 14px 16px 24px; }
.viewer #panel { background: var(--side); }
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.panel-head h3 { margin: 0; font: 600 20px var(--heading); flex: 1; }
.badge { font: 600 11px var(--ui); padding: 2px 9px; border-radius: 999px; border: 1px solid var(--cyan); color: var(--cyan); }
.badge.review { border-color: var(--pink); color: var(--pink); }
.badge.corrected { border-color: var(--mint); color: var(--mint); }
.empty-panel { color: var(--dim); margin-top: 60px; text-align: center; }
.empty-panel .big { font-size: 44px; color: var(--fg); opacity: .5; }

.crop-preview { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.crop-preview img:not([src]) { display: none; }
.crop-preview img { width: 120px; height: 120px; object-fit: contain; background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; }
.crop-preview .facts { font-size: 12px; flex: 1; min-width: 0; color: var(--dim); }
.crop-preview .facts b { color: var(--amber); font-weight: 600; }
.crop-preview .facts div:nth-child(2) { color: var(--fg); }

.board-area { display: flex; gap: 6px; max-width: max(300px, calc(100vh - 52px - 78px - 300px)); margin: 0 auto; }
.evalbar { width: 10px; margin: 27px 0; background: #1b3a33; border: 1px solid var(--line-strong); border-radius: 3px; position: relative; overflow: hidden; }
.evalbar > div { position: absolute; left: 0; right: 0; bottom: 0; background: #f0f2ec; height: 50%; transition: height .4s; }
.evalbar.flipped { background: #f0f2ec; }
.evalbar.flipped > div { background: #1b3a33; }
.board-frame {
  flex: 1; min-width: 0; padding: 26px; border-radius: 8px;
  background: var(--bg-raised); border: 1px solid var(--line-strong);
}
#board { aspect-ratio: 1; box-shadow: 0 0 0 1px var(--line-strong); }
#board cg-board { background: repeating-conic-gradient(var(--sq-dark) 0 25%, var(--sq-light) 0 50%) 0 0 / 25% 25%; }
#board cg-board square.last-move { background-color: rgba(229, 185, 96, .5); }
#board cg-board square.selected { background-color: rgba(98, 214, 194, .5); }
#board cg-board square.move-dest { background: radial-gradient(rgba(13, 43, 38, .45) 19%, transparent 20%); }
#board cg-board square.oc.move-dest { background: radial-gradient(transparent 0%, transparent 79%, rgba(13, 43, 38, .35) 80%); }
#board .cg-shapes { opacity: 1; }
#board cg-board square.check { background: radial-gradient(ellipse at center, rgba(240, 144, 159, 1) 0%, rgba(240, 144, 159, .6) 30%, transparent 75%); }
#board coords { opacity: 1; font: 12px var(--mono); color: var(--dim); }
#board coords coord { color: inherit !important; text-shadow: none; flex: 1 1 0; display: flex; align-items: center; justify-content: center; }
#board coords.ranks { left: -24px; top: 0; width: 18px; height: 100%; }
#board coords.ranks coord { transform: none; }
#board coords.files { left: 0; bottom: -26px; width: 100%; height: 24px; text-transform: lowercase; }

.tabs { display: flex; gap: 0; margin: 10px 0 8px; border-bottom: 1px solid var(--line); }
.tabs .btn { flex: 1; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 4px; color: var(--dim); }
.tabs .btn:hover { color: var(--fg); }
.tabs .btn.on { background: none; color: var(--fg); border-bottom-color: var(--cyan); }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.toolbar > span:not(.grow) { color: var(--dim); font-size: 13px; }
.toolbar .grow { flex: 1; }
.notice { border: 1px solid var(--amber); border-left-width: 3px; border-radius: 6px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.notice.error { border-color: var(--pink); color: var(--fg); }
.moves { font-family: var(--mono); font-size: 13px; min-height: 22px; word-wrap: break-word; }
.moves .num { color: var(--dim); }

.engine { border: 1px solid var(--line-strong); border-radius: 10px; margin-top: 10px; background: var(--bg-sunk); overflow: hidden; }
.engine .engine-head { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 6px 10px; color: var(--dim); font: 12px var(--mono); }
.engine .score { font-size: 18px; margin-left: auto; font-family: var(--mono); color: var(--fg); }
.engine .lines { padding: 6px 10px; font-family: var(--mono); font-size: 12.5px; }
.engine .line { padding: 4px 0; cursor: pointer; border-bottom: 1px dashed var(--line); }
.engine .line:hover { color: var(--cyan); }
.engine .line b { display: inline-block; min-width: 52px; color: var(--amber); font-weight: normal; }
.engine .status { padding: 5px 10px; font-size: 12px; color: var(--dim); }
.fen-row { display: flex; gap: 6px; margin-top: 10px; }
.fen-row input { flex: 1; font-family: var(--mono); font-size: 12px; }

.palette.cg-wrap { display: flex; flex-wrap: wrap; gap: 4px; width: auto; height: auto; margin: 6px 0; }
.palette.cg-wrap piece, .palette .tool {
  position: static; display: block; pointer-events: auto; width: 40px; height: 40px; cursor: pointer;
  background-color: var(--sq-dark); background-size: cover; border: 1px solid transparent; border-radius: 4px; transform: none; will-change: auto;
}
.palette .tool { color: var(--fg); background-color: var(--bg-raised); font: 18px/38px var(--ui); text-align: center; }
.palette .selected { border-color: var(--gold) !important; background-color: var(--gold); }
.palette .sep { width: 100%; height: 0; }

/* ---- scan page ----------------------------------------------------------- */
.scan {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 520px); gap: 0 20px;
  max-width: 1400px; padding: 0 32px; align-items: start; width: 100%;
}
.scan .window { margin: 22px 0 0; max-width: none; }
.scan-panel { margin-top: 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-raised); }
.scan-saved { grid-column: 1 / -1; margin-bottom: 22px !important; }
.scan-photo.over { outline: 1px dashed var(--cyan); }
.photo-area { position: relative; margin-top: 12px; touch-action: none; user-select: none; }
.photo-area canvas { display: block; width: 100%; height: auto; background: var(--bg-sunk); }
.photo-area svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#quad .edge { fill: rgba(98, 214, 194, .08); stroke: var(--cyan); stroke-width: 2; vector-effect: non-scaling-stroke; }
#quad .grid { fill: none; stroke: rgba(229, 185, 96, .75); stroke-width: 1; vector-effect: non-scaling-stroke; }
#quad .top { stroke: var(--amber); stroke-width: 4; vector-effect: non-scaling-stroke; }
#quad .handle { cursor: grab; }
#quad .handle .hit { fill: transparent; }
#quad .handle .dot { fill: rgba(11, 36, 32, .45); stroke: var(--cyan); stroke-width: 3; vector-effect: non-scaling-stroke; }
#quad .handle.first .dot { stroke: var(--amber); }
#crop { cursor: zoom-in; }
.scan-card img[data-open] { cursor: zoom-in; }
.scan.board-full { grid-template-columns: 1fr; max-width: none; padding: 0 24px; }
.scan.board-full .scan-photo, .scan.board-full .scan-saved, .scan.board-full #panel-empty { display: none; }
.scan.board-full .scan-panel { margin-top: 16px; padding: 16px 24px; }
.scan.board-full #panel-board {
  display: grid; grid-template-columns: auto minmax(320px, 1fr);
  grid-template-rows: repeat(12, auto) 1fr; column-gap: 24px; align-items: start;
}
.scan.board-full #panel-board > * { grid-column: 2; }
.scan.board-full #panel-board > .board-area { grid-column: 1; grid-row: 1 / -1; width: min(calc(100vh - 80px), 65vw); max-width: none; margin: 0; }
body.scan-full .sidebar, body.scan-full .topbar, body.scan-full .creator { display: none; }
body.scan-full .app { grid-template-columns: 1fr; }
.saved-scans { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.scan-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-sunk); padding: 8px; }
.scan-card.active { border-color: var(--cyan); }
.scan-card img { width: 84px; height: 84px; flex: none; background: #fff; object-fit: contain; border-radius: 4px; }
.scan-card .grow { flex: 1; min-width: 0; }
.scan-card .btn { margin-top: 6px; }
.fen-short { font-size: 11px; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ---- narrower screens ----------------------------------------------------- */
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: 1fr; }
  .hero-logo { width: 160px; height: 160px; opacity: .45; }
}
@media (max-width: 900px) {
  .viewer { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  #splitter { display: none; }
  #panel { border-left: 0; border-top: 1px solid var(--line-strong); }
  .scan { grid-template-columns: 1fr; padding: 0 12px; }
  .notes-layout { grid-template-columns: 1fr; }
  .note-editor { position: static; }
}

/* ---- phones: the sidebar becomes a bottom tab bar --------------------------- */
@media (max-width: 700px) {
  .app { display: block; min-height: 100dvh; padding-bottom: 60px; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: 60px; width: auto;
    flex-direction: row; padding: 0; border-right: 0; border-top: 1px solid var(--line); z-index: 60;
  }
  .sidebar .brand, .sidebar .tagline { display: none; }
  .sidebar nav a[href="settings.html"] { display: none; }
  .topbar { display: flex; position: sticky; top: 0; z-index: 30; padding: 8px 12px; background: var(--side); border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; flex: 1; gap: 0; }
  .sidebar nav a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 0; font-size: 10px; border-radius: 0; }
  .sidebar nav a[aria-current="page"] { box-shadow: inset 0 2px 0 var(--cyan); }
  body:has(.viewer) .sidebar nav a span { display: block; }
  body:has(.viewer) .sidebar nav a { padding: 6px 0; }
  body:has(.viewer) .sidebar { padding: 0; }
  .page-head { padding: 16px 14px 4px; }
  .page-head h1 { font-size: 28px; }
  .page-body { padding: 8px 14px 24px; }
  .window { margin: 14px 12px; }
  .window .content { padding: 14px 12px; }
  .hero { padding: 32px 18px 28px; min-height: 0; }
  .hero h1 { font-size: 38px; }
  .hero .motto { font-size: 20px; }
  .hero-logo { display: none; }
  .home-grid { padding: 18px 14px; }
  .books { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 10px; }
  .book-tile h3 { font-size: 12.5px; }
  .book-tile .meta { font-size: 11px; }
  .book-tile details.more > summary { display: block; cursor: pointer; text-align: center; color: var(--dim); font-size: 20px; line-height: 1; padding: 2px; }
  .book-tile .actions .btn { padding: 4px 8px; }
  .hero .actions { flex-direction: column; align-items: stretch; }
  .hero .actions .btn { text-align: center; }
  #continue-detail { display: none; }
  .recent { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 112px; overflow-x: auto; padding-bottom: 6px; }
  .cover .cover-title { font-size: 12px; }
  .pos-head { display: none; }
  .pos-row { grid-template-columns: 64px minmax(0, 1fr) 36px; }
  .pos-row .col-notes, .pos-row .col-date { grid-column: 2 / 3; }
  .setting { flex-wrap: wrap; }
  .setting input[type=range] { width: 140px; }

  .titlebar { flex-wrap: wrap; gap: 4px 8px; padding: 6px 10px; }
  .titlebar .crumb { flex: 1; min-width: 0; font-size: 17px; }
  .titlebar .spacer { display: none; }
  .titlebar-tools { order: 10; width: 100%; padding: 4px 0; overflow-x: auto; scrollbar-width: none; border-top: 1px solid var(--line); }
  .titlebar-tools > * { flex: none; }
  .btn, select, input[type=text], input[type=number] { padding: 8px 12px; }

  body:has(.viewer) { display: block; height: 100dvh; }
  body:has(.viewer) .app { height: 100dvh; padding-bottom: 60px; display: block; }
  body:has(.viewer) .main { height: 100%; }
  /* the page stays visible above; a picked board slides up as a sheet below it */
  .viewer { display: grid; grid-template-columns: 1fr; grid-template-rows: minmax(0, 36%) minmax(0, 1fr); flex: 1; min-height: 0; height: auto; }
  .viewer.panel-collapsed, .viewer.board-full { grid-template-rows: minmax(0, 1fr); }
  body:has(.board-full) .app { padding-bottom: 0; }
  #pages { height: auto; padding: 10px 0 30px; }
  .thumbs { display: none; }
  .viewer #panel {
    position: static; padding: 0 12px 20px; border-top: 1px solid var(--line-strong); border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 24px rgba(0, 0, 0, .35);
  }
  .viewer #panel::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 8px auto 4px; }
  .viewer .panel-head { position: sticky; top: 0; z-index: 5; background: var(--side); padding: 8px 0; margin-bottom: 4px; }
  .viewer .crop-preview { display: none; }
  .panel-head h3 { font-size: 17px; }
  .board-area { max-width: none; }
  .board-frame { padding: 22px; }
  .crop-preview img { width: 96px; height: 96px; }
  .engine .score { font-size: 16px; }
  .viewer.board-full #panel-board { display: block; }
  .viewer.board-full #panel-board > .board-area { width: auto; }
  .scan { padding: 0 10px; }
  .scan.board-full #panel-board { display: block; }
  .scan.board-full #panel-board > .board-area { width: auto; }
}

.book-spine { width: 32px; height: 44px; flex: none; display: grid; place-items: center; background: var(--bg-sunk); border-radius: 3px; font-size: 22px; }

/* ---- accounts: landing, sign in / up, account page ------------------------------- */
body.public {
  min-height: 100dvh; display: block;
  background: radial-gradient(ellipse at 70% 10%, #164038 0%, #0a211d 55%, #071714 100%); color: #eef1ea;
}
.auth-brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: #e2b862;
  font: 600 20px/1.05 var(--heading); letter-spacing: .14em; }
.auth-brand img { width: 44px; height: 44px; }
.auth-page { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: 28px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: #f5f1e7; color: #1c2924; border-radius: 12px;
  padding: 28px 28px 24px; box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.auth-foot { margin: 0; color: #93aea4; font: italic 16px var(--heading); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form h1 { margin: 0; text-align: center; font: 600 30px/1.15 var(--heading); }
.auth-form .sub { margin: 0; text-align: center; color: #55645c; font-size: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #1c2924; }
.auth-form input[type=email], .auth-form input[type=password], .auth-form input[type=text] {
  width: 100%; font-size: 16px; padding: 11px 12px; background: #fff; color: #1c2924;
  border: 1px solid #cfc7b2; border-radius: 7px; font-weight: 400;
}
.auth-form input:focus-visible { outline: 2px solid #1a493a; outline-offset: 1px; }
.auth-form small { font-weight: 400; color: #66776f; }
.auth-form .pw { position: relative; display: block; }
.auth-form .pw input { padding-right: 62px; }
.auth-form .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: 0;
  color: #1a493a; font: 600 12px var(--ui); padding: 8px 10px; cursor: pointer; }
.auth-form .check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
.auth-form .check input { margin-top: 3px; accent-color: #1a493a; }
.auth-form a { color: #1a493a; }
.auth-form .forgot { align-self: flex-end; font-size: 12.5px; margin-top: -4px; }
.auth-form .btn { background: #fff; color: #1c2924; border-color: #cfc7b2; text-align: center; text-decoration: none; }
.auth-form .btn.primary { background: #1a493a; border-color: #1a493a; color: #f5f1e7; }
.auth-form .btn.wide, .btn.wide { width: 100%; padding: 12px; font-size: 15px; }
.auth-form .alt { margin: 4px 0 0; text-align: center; font-size: 13px; color: #55645c; }
.auth-form .or { display: block; text-align: center; font-size: 12px; color: #66776f; margin: 4px 0 8px; }
.auth-form .oauth-buttons { display: flex; flex-direction: column; gap: 8px; }
.auth-form .mail { width: 48px; height: 48px; margin: 0 auto; color: #1a493a; }
.auth-form .linklike { background: none; border: 0; color: #1a493a; text-decoration: underline; cursor: pointer; font: 13px var(--ui); }
.auth-banner { margin-bottom: 14px; padding: 10px 12px; border-radius: 7px; font-size: 13.5px; background: #e8dfce; color: #1c2924; }
.auth-banner.error { background: #f6dfe4; color: #8d2339; }
.auth-banner.ok { background: #dcecdf; color: #1d5a37; }

.landing-nav { display: flex; align-items: center; gap: 18px; padding: 18px clamp(16px, 5vw, 56px); }
.landing-nav .grow { flex: 1; }
.landing-nav .nav-link { color: #c9d4cc; text-decoration: none; font-size: 14px; }
.landing-nav .btn { color: #e2b862; border-color: #e2b862; background: none; text-decoration: none; }
.landing-hero { display: flex; align-items: center; justify-content: space-between; gap: 40px;
  padding: clamp(36px, 9vw, 110px) clamp(16px, 5vw, 56px); max-width: 1100px; margin: 0 auto; }
.landing-hero h1 { margin: 0 0 18px; font: 600 clamp(40px, 7vw, 68px)/1.05 var(--heading); }
.landing-hero .lead { max-width: 560px; font-size: 18px; line-height: 1.55; color: #dfe6df; }
.landing-hero .actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 26px 0 22px; }
.landing-hero .actions .btn { padding: 12px 26px; font-size: 15px; text-decoration: none; }
.landing-hero .btn.ghost { color: #e2b862; border-color: #e2b862; }
.landing-hero .motto { color: #93aea4; font: italic 18px var(--heading); margin: 0; }
.hero-ring { width: clamp(120px, 24vw, 280px); flex: none; opacity: .9; }
.landing-steps { max-width: 760px; margin: 0 auto; padding: 8px clamp(16px, 5vw, 56px) 36px; }
.landing-steps h2 { font: 600 28px var(--heading); color: #e2b862; }
.landing-steps li { margin: 8px 0; color: #dfe6df; line-height: 1.55; }
body.public .creator { padding: 20px; text-align: center; color: #93aea4; }
@media (max-width: 700px) { .landing-hero { flex-direction: column-reverse; align-items: flex-start; } .landing-nav .nav-link { display: none; } }

.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; position: relative;
  background: #1a493a; color: #f5f1e7; font: 600 13px var(--ui); text-decoration: none; border: 1px solid var(--line-strong);
}
.avatar .icon { width: 18px; height: 18px; }
.avatar.big { width: 64px; height: 64px; font-size: 22px; flex: none; }
.avatar[data-sync="error"]::after, .avatar[data-sync="offline"]::after, .avatar[data-sync="syncing"]::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--pink); border: 2px solid var(--side);
}
.avatar[data-sync="offline"]::after { background: var(--amber); }
.avatar[data-sync="syncing"]::after { background: var(--cyan); }
.account .window { max-width: 720px; margin-left: 0; margin-right: 0; }
.profile-row { display: flex; align-items: center; gap: 16px; }
.profile-row .grow { flex: 1; min-width: 0; }
.profile-name { font: 600 22px var(--heading); }
.account-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.account-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.account-form input { width: 100%; max-width: 420px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.account .small { font-size: 12.5px; }
.account-actions { margin: 4px 0 24px; }
.meter { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; max-width: 420px; }
.meter span { display: block; height: 100%; background: var(--cyan); }
#nav-account { margin-top: auto; }
@media (max-width: 700px) { .sidebar #nav-account { display: none; } .topbar .avatar { margin-left: 8px; } }
