/* ---------- the Library (library.js): famous games, as shelves of cards ----------
   Drawn only with the look's tokens (looks.css), so it suits every look. Each card's little board is a grid whose
   pieces sit on cells named by classes (f0-f7 across, r0-r7 down, as drawn), since the page's policy allows no style
   attributes. */
#library { max-width: 1280px; margin: 0 auto; }
.lib-head { margin: 4px 0 18px; }
.lib-title, .rp-title { font: var(--display-weight) clamp(1.875rem, 4.2vw, 2.75rem) / 1.08 var(--font-display); margin: 0 0 8px; letter-spacing: -0.01em; }
[data-look="arcade"] .lib-title, [data-look="arcade"] .rp-title {
  background: linear-gradient(90deg, #67e8f9, #a855f7 55%, #f472b6); -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-look="club"] .lib-title, [data-look="club"] .rp-title { color: var(--accent); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5), 0 0 28px rgba(228, 180, 69, 0.25); }
[data-look="pop"] .lib-title, [data-look="pop"] .rp-title { color: var(--accent); }
.lib-sub { color: var(--muted); max-width: 64ch; margin: 0; font-size: 1.0625rem; line-height: 1.5; }

/* the game of the day: its board plays the finish, beside its name */
.lib-hero {
  --bs: min(380px, calc(100vw - 72px));
  position: relative; overflow: hidden; isolation: isolate;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 32px; align-items: center;
  padding: 26px; margin: 0 0 26px;
  background: var(--card-bg); border: 1px solid var(--card-line); border-radius: calc(var(--card-radius) + 6px);
  box-shadow: var(--card-shadow); backdrop-filter: var(--card-blur);
}
.lib-hero::before {  /* two soft lights in the look's colours, drifting */
  content: ""; position: absolute; inset: -45%; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side at 22% 50%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 72%),
    radial-gradient(closest-side at 82% 28%, color-mix(in srgb, var(--accent-2) 20%, transparent), transparent 70%);
  animation: lib-drift 22s ease-in-out infinite alternate;
}
@keyframes lib-drift { to { transform: translate(7%, -5%) rotate(10deg) scale(1.06); } }
.still .lib-hero::before { animation: none; }
@media (prefers-reduced-motion: reduce) { .lib-hero::before { animation: none; } }
.lib-hero-board { width: var(--bs); }
.lib-hero-board .board { cursor: default; }
.lib-kicker {
  display: inline-block; margin-bottom: 10px; padding: 4px 12px; border-radius: 999px;
  font: 700 0.8125rem var(--font-body); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}
.lib-hero h3 { font: var(--display-weight) clamp(1.625rem, 3.4vw, 2.375rem) / 1.12 var(--font-display); margin: 0 0 10px; }
.lib-hero-players { font-size: 1.125rem; font-weight: 600; margin: 0 0 6px; }
.lib-hero .muted { margin: 0 0 18px; line-height: 1.5; }
.lib-hero-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.lib-hero-buttons .button-link { padding: 10px 20px; font-weight: 700; }
@media (max-width: 760px) {
  .lib-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 18px; gap: 18px; }
  .lib-hero-buttons { justify-content: center; }
}

/* the collections to show, and the search */
.lib-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: 0 0 22px; }
.lib-search { flex: 1 1 260px; max-width: 420px; padding: 9px 14px; font-size: 1rem; }
#lib-count { font-variant-numeric: tabular-nums; }

/* a collection: its heading, a line about it, and its cards */
.lib-shelves { display: grid; gap: 34px; }
.lshelf-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.lshelf-head h2 { font: var(--display-weight) 1.5rem var(--font-display); margin: 0; }
.lshelf-n { color: var(--muted); font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.lshelf-blurb { color: var(--muted); margin: 4px 0 14px; max-width: 70ch; }
.lshelf-head::after {  /* a rule that runs off from the heading */
  content: ""; flex: 1 1 40px; align-self: center; height: 1px; min-width: 40px;
  background: linear-gradient(90deg, var(--card-line), transparent);
}
.lgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 18px; }
@media (max-width: 480px) { .lgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }

/* a card: the game's last position, and what it is */
.lcard {
  display: flex; flex-direction: column; min-width: 0; color: inherit; text-decoration: none;
  background: var(--card-bg); border: 1px solid var(--card-line); border-radius: var(--card-radius);
  box-shadow: var(--card-shadow); backdrop-filter: var(--card-blur); overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s, border-color 0.2s;
}
.lcard:hover, .lcard:focus-visible {
  transform: translateY(-5px); border-color: color-mix(in srgb, var(--accent) 60%, var(--card-line));
  box-shadow: var(--card-shadow), 0 16px 34px -14px color-mix(in srgb, var(--accent) 55%, transparent),
    0 0 calc(26px * var(--glow)) color-mix(in srgb, var(--accent) 30%, transparent);
  outline: none;
}
.still .lcard, .still .lcard:hover { transition: none; transform: none; }
.lthumb {
  position: relative; padding: 12px 12px 0;
  background: radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%);
}
.lres {
  margin-left: auto; padding: 1px 9px; border-radius: 999px;
  font: 800 0.8125rem var(--font-body); font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.lres.rw { background: #f4f1ea; color: #1e1e1e; }
.lres.rb { background: #1e1e22; color: #f4f1ea; }
.lres.rd { background: linear-gradient(90deg, #f4f1ea 50%, #1e1e22 50%); color: #888; }
.lbody { display: flex; flex-direction: column; gap: 3px; padding: 11px 14px 13px; min-width: 0; flex: 1; }
.lname { font: var(--display-weight) 1.0625rem / 1.25 var(--font-display); }
.lplayers { font-size: 0.9375rem; font-weight: 600; color: color-mix(in srgb, var(--text) 85%, var(--muted)); }
.lmeta { color: var(--muted); font-size: 0.875rem; line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lfoot { margin-top: auto; padding-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 0.8125rem; color: var(--muted); }
.lwait { color: var(--info); }
.lempty { padding: 36px; text-align: center; background: var(--card-bg); border: 1px dashed var(--card-line); border-radius: var(--card-radius); }

/* the little board */
.mini {
  display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); aspect-ratio: 1; width: 100%;
  border-radius: max(4px, calc(var(--board-radius) * 0.55)); overflow: hidden;
  background: conic-gradient(var(--sq-dark) 0 25%, var(--sq-light) 0 50%, var(--sq-dark) 0 75%, var(--sq-light) 0) 0 0 / 25% 25%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18), 0 10px 22px -10px rgba(0, 0, 0, 0.5);
}
[data-look="club"] .mini { background: url("looks/club-board.74a520a08966.webp") center / 100% 100% no-repeat, var(--sq-dark); box-shadow: 0 0 0 2px #3a2718, 0 0 0 3px rgba(228, 180, 69, 0.5), 0 10px 22px -10px rgba(0, 0, 0, 0.6); }
.mini > * { grid-row: 1; grid-column: 1; min-width: 0; }
.mini img { width: 100%; height: 100%; z-index: 2; pointer-events: none; transition: transform 0.25s; }
.mini .hl { background: var(--last); z-index: 1; }
.mini .chk { z-index: 1; background: radial-gradient(closest-side, rgba(255, 40, 60, 0.95), rgba(255, 40, 60, 0.45) 55%, transparent); }
.lcard:hover .mini img { transform: translateY(-1px); }
.mini .f0 { grid-column: 1; } .mini .f1 { grid-column: 2; } .mini .f2 { grid-column: 3; } .mini .f3 { grid-column: 4; }
.mini .f4 { grid-column: 5; } .mini .f5 { grid-column: 6; } .mini .f6 { grid-column: 7; } .mini .f7 { grid-column: 8; }
.mini .r0 { grid-row: 1; } .mini .r1 { grid-row: 2; } .mini .r2 { grid-row: 3; } .mini .r3 { grid-row: 4; }
.mini .r4 { grid-row: 5; } .mini .r5 { grid-row: 6; } .mini .r6 { grid-row: 7; } .mini .r7 { grid-row: 8; }
[data-look="quiet"] .lib-title { color: var(--accent); }
.lmore { margin: 14px 0 0; text-align: center; }
.lmore button { padding: 9px 22px; font-weight: 700; border-radius: 999px; }

/* ---------- cards or a list: the switch at the end of the tools ---------- */
.lview { display: inline-flex; gap: 2px; margin-left: auto; padding: 3px; border-radius: 999px; background: var(--ctl-bg); box-shadow: inset 0 0 0 1px var(--ctl-line); }
.lview button { display: grid; place-items: center; width: 42px; height: 32px; padding: 0; border: 0; border-radius: 999px; background: none; color: var(--muted); }
.lview button:hover { color: var(--text); box-shadow: none; }
.lview button[aria-pressed="true"] {
  color: var(--on-accent); background: var(--accent);
  box-shadow: 0 0 calc(16px * var(--glow)) color-mix(in srgb, var(--accent) 60%, transparent);
}
.lview svg { display: block; width: 18px; height: 18px; fill: currentColor; }
/* the page as it changes from one to the other */
.lib-shelves.swapped > * { animation: lib-swap 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes lib-swap { from { opacity: 0; transform: translateY(10px); } }

/* ---------- the list (libTable): every game a row, a heading to sort by for each column ----------
   The columns' widths are set here, not by what's in them (table-layout: fixed), so the list never runs wider than
   the page: a long name or opening ends in "…" and says the rest on hover. */
.lib-shelves.as-list { display: block; }
.ltable-wrap {
  background: color-mix(in srgb, var(--card-solid) 88%, transparent); border: 1px solid var(--card-line);
  border-radius: var(--card-radius); box-shadow: var(--card-shadow); overflow: clip;
}
.ltable { table-layout: fixed; }
.ltable th, .ltable td {
  padding: 10px 12px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom;
  border-bottom-color: color-mix(in srgb, var(--card-line) 65%, transparent);
}
.ltable tbody tr:last-child td { border-bottom: 0; }
.ltable th.lt-white, .ltable th.lt-black { width: 17%; }
.ltable th.lt-result { width: 8rem; }  /* room for "Resultado" and its arrow */
.ltable th.lt-year { width: 4.75rem; }
.ltable th.lt-event { width: 25%; }
.ltable th.lt-moves { width: 6.5rem; }
.ltable .lt-moves { text-align: right; }
.ltable thead th {
  position: sticky; top: 0; z-index: 2; padding: 13px 12px 11px; background: var(--card-solid);
  border-bottom: 0; box-shadow: inset 0 -1px 0 var(--card-line); transition: color 0.15s;
}
.ltable thead th:not([aria-sort="none"]) { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
/* which way a column is sorted: an arrowhead by its heading, faint under the pointer before it's pressed */
.lt-arrow {
  display: inline-block; width: 0; height: 0; margin-left: 6px; vertical-align: 0.1em; opacity: 0;
  border: 4px solid transparent; border-top: 0; border-bottom: 6px solid currentColor; transition: opacity 0.15s;
}
th[data-col]:hover .lt-arrow, th[data-col]:focus-visible .lt-arrow { opacity: 0.4; }
th[aria-sort="ascending"] .lt-arrow, #lib-dir .lt-arrow { opacity: 1; }
th[aria-sort="descending"] .lt-arrow, #lib-dir.down .lt-arrow { opacity: 1; transform: rotate(180deg); }
.lib-shelves.sorted th:not([aria-sort="none"]) .lt-arrow { animation: lt-arrow 0.35s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes lt-arrow { from { scale: 0.2; } }

/* a row: the players by their colours, the result as on the cards, and the row under the pointer lit */
.ltable tbody tr { transition: background 0.15s, box-shadow 0.15s; scroll-margin-top: 50px; scroll-margin-bottom: 8px; }
.ltable tbody tr[data-id]:hover, .ltable tbody tr[data-id]:focus-visible {
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  box-shadow: inset 3px 0 0 var(--accent), inset 0 0 calc(34px * var(--glow)) color-mix(in srgb, var(--accent) 12%, transparent);
}
.lib-shelves.sorted .ltable tr[data-id] { animation: lt-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes lt-in { from { opacity: 0; transform: translateY(7px); } }
.ltable td.lt-white { position: relative; overflow: visible; }
.lt-clip { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lt-event-box { display: flex; gap: 8px; min-width: 0; }
.lt-game { flex: none; color: var(--muted); }
.lt-side {
  display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--muted) 70%, transparent);
}
.lt-side.w { background: #f4f1ea; }
.lt-side.b { background: #1e1e22; }
.lt-first { color: var(--muted); }
.ltable td.lt-year, .ltable td.lt-moves { font-variant-numeric: tabular-nums; }
.ltable td.lt-opening { color: var(--muted); }
.ltable .lres { display: inline-block; margin: 0; }
.lt-long { display: none; }
.lt-wait { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--info); vertical-align: 0.1em; }
/* a named game: its name on a line of its own over the players, running on past its cell */
.ltable tr.named td.lt-white { padding-top: 32px; }
.lt-name {
  position: absolute; left: 12px; top: 9px; max-width: calc(200% - 12px); overflow: hidden; text-overflow: ellipsis;
  font: var(--display-weight) 0.9375rem / 1.25 var(--font-display); color: var(--accent);
}
/* in the collections' order, each collection's name over its games */
.ltable tr.lt-group, .ltable tr.lt-group:hover { cursor: default; background: none; }
.ltable tr.lt-group th {
  padding: 26px 12px 9px; text-transform: none; letter-spacing: 0; color: var(--text);
  font: var(--display-weight) 1.25rem var(--font-display);
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--accent) 7%, transparent));
}
.ltable tr.lt-group:first-child th { padding-top: 16px; }
.lt-group .lshelf-n { margin-left: 10px; font: 500 0.875rem var(--font-body); }

/* the board of the row under the pointer (showPeek) */
.lpeek {
  position: fixed; z-index: 40; width: 204px; padding: 10px 10px 9px; pointer-events: none;
  opacity: 0; visibility: hidden; transform: translateY(6px) scale(0.96);
  transition: opacity 0.14s, transform 0.2s cubic-bezier(0.2, 1.3, 0.4, 1), visibility 0s 0.14s;
  background: var(--card-solid); border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--card-line)); border-radius: var(--card-radius);
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.55), 0 0 calc(26px * var(--glow)) color-mix(in srgb, var(--accent) 32%, transparent);
}
.lpeek.on { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.lpeek-name { margin-top: 9px; font: var(--display-weight) 1rem / 1.25 var(--font-display); }
.lpeek-meta { margin-top: 2px; color: var(--muted); font-size: 0.8125rem; line-height: 1.35; }

/* "Sort by": the headings' work where there's no room for headings */
.lsort { display: none; }
#lib-dir { flex: none; width: 38px; height: 38px; }
#lib-dir .lt-arrow { margin: 0; transition: transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1); }

/* a narrow window (a phone): each row stacks into a few lines, the result at its corner */
@media (max-width: 860px) {
  .lsort { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
  .lsort label { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; color: var(--muted); white-space: nowrap; }
  .lsort select { flex: 1; min-width: 0; padding: 8px 10px; }
  .ltable thead { display: none; }
  .ltable, .ltable tbody, .ltable tr, .ltable tr.lt-group th { display: block; }
  .ltable tr[data-id] { position: relative; padding: 11px 76px 11px 14px; border-bottom: 1px solid color-mix(in srgb, var(--card-line) 65%, transparent); line-height: 1.45; }
  .ltable tr[data-id]:last-child { border-bottom: 0; }
  .ltable td { display: inline; padding: 0; border: 0; white-space: normal; overflow: visible; color: var(--muted); font-size: 0.875rem; }
  .ltable td.lt-white, .ltable td.lt-black { display: block; color: var(--text); font-size: 1rem; }
  .ltable tr.named td.lt-white { padding-top: 0; }
  .lt-name { position: static; display: block; max-width: none; margin-bottom: 2px; font-size: 1.0625rem; white-space: normal; }
  .ltable td.lt-result { position: absolute; right: 14px; top: 12px; }
  .ltable td.lt-year:not(:empty)::after, .ltable td.lt-event:not(:empty)::after, .ltable td.lt-opening:not(:empty)::after { content: " · "; }
  .lt-event-box, .lt-event-box .lt-clip { display: inline; }
  .lt-game::before { content: "· "; }
  .lt-short { display: none; }
  .lt-long { display: inline; }
  .ltable tr.lt-group th { padding: 22px 14px 8px; white-space: normal; }
}
@media (max-width: 480px) { .lview button { width: 46px; height: 38px; } }

.still .lib-shelves.swapped > *, .still .lib-shelves.sorted .ltable tr[data-id], .still .lib-shelves.sorted .lt-arrow { animation: none; }
.still .lpeek, .still .ltable tbody tr, .still #lib-dir .lt-arrow { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .lib-shelves.swapped > *, .lib-shelves.sorted .ltable tr[data-id], .lib-shelves.sorted .lt-arrow { animation: none; }
  .lpeek, #lib-dir .lt-arrow { transition: none; }
}
