@font-face { font-family: Archivo; font-weight: 400; font-style: normal; font-display: swap; src: url(fonts/Archivo-Regular.ttf) format("truetype"); }
@font-face { font-family: Archivo; font-weight: 500; font-style: normal; font-display: swap; src: url(fonts/Archivo-Medium.ttf) format("truetype"); }
@font-face { font-family: Archivo; font-weight: 700; font-style: normal; font-display: swap; src: url(fonts/Archivo-Bold.ttf) format("truetype"); }
@font-face { font-family: Archivo; font-weight: 400; font-style: italic; font-display: swap; src: url(fonts/Archivo-Italic.ttf) format("truetype"); }

:root {
  --bg: color-mix(in srgb, var(--paper) 93%, var(--ink));
  --ui-bg: color-mix(in srgb, var(--paper) 88%, transparent);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: Archivo, system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
html.js, html.js body { height: 100%; overflow: hidden; overscroll-behavior: none; }
html.js #app { position: fixed; inset: 0; }

/* The slide text in index.html, for readers that run no scripts; the viewer replaces it. */
#static { max-width: 44rem; margin: 0 auto; padding: 2rem 1rem 4rem; line-height: 1.5; }
#static h1 { font-size: 2rem; margin: 0 0 .4rem; }
#static h2 { font-size: 1.3rem; margin: 2.2rem 0 .3rem; border-top: 1px solid var(--hair); padding-top: 1rem; }
#static .pos { color: var(--accent); font-variant-numeric: tabular-nums; margin-right: .4em; }
#static .sub { color: var(--dim); margin-top: 0; }
#static .pdf { font-size: .85rem; }
#static pre { overflow-x: auto; background: var(--inset); padding: .6rem .8rem; border-radius: 6px; }
#static table { border-collapse: collapse; } #static th, #static td { border: 1px solid var(--hair); padding: .25rem .6rem; text-align: left; }
#static blockquote { margin-left: 0; padding-left: 1rem; border-left: 3px solid var(--accent); }
#static a { color: var(--accent); }

/* Text for screen readers only. */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

/* The area slides may use: the viewport minus safe-area insets. */
#fit { position: absolute; top: var(--safe-t); right: var(--safe-r); bottom: var(--safe-b); left: var(--safe-l); pointer-events: none; }

/* ---- centered mode ---- */
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#app[data-layout="stack"] #stage { display: none; }
.slide {
  position: absolute; left: 0; top: 0; width: 1600px; height: 900px; background: var(--paper);
  transform-origin: 0 0; transform: scale(var(--k, 1)); user-select: none; -webkit-user-select: none;
  box-shadow: 0 0 0 1px var(--hair); overflow: hidden;
}
.slide > img, .slide > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }

/* The slide's text over its pixels (pointer devices): selectable and searchable, never seen. */
.slide .tl { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; overflow: clip; line-height: 1; text-size-adjust: none; -webkit-text-size-adjust: none; z-index: 1; pointer-events: none; }
.slide .tl { --scale-round-x: 1px; --scale-round-y: 1px; --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.slide .tl :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; pointer-events: auto; transform-origin: 0 0; user-select: text; -webkit-user-select: text; }
.slide .tl > :not(.markedContent, .endOfContent), .slide .tl .markedContent span:not(.markedContent) {
  z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height)); --scale-x: 1; --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.slide .tl .markedContent { display: contents; }
.slide .tl .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; -webkit-user-select: none; }
.slide .tl.selecting .endOfContent { top: 0; }
.slide .tl ::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.slide .tl .lnk { position: absolute; display: block; z-index: 2; cursor: pointer; }
.slide .tl .lnk:hover, .slide .tl .lnk:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); }

/* line 2 (counts, position) in the portrait strip */
.line2 { display: flex; align-items: baseline; justify-content: flex-end; white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; }
.counts { display: flex; align-items: baseline; gap: 0.7em; color: var(--dim); }
.counts .c { display: inline-block; transition: color .2s; }
.counts .c b { color: var(--ink); font-weight: 400; }
.counts .c.zero { visibility: hidden; }
.counts .c.hot, .counts .c.hot b { color: var(--accent); }
.line2 .pos { font-size: 1.5em; font-weight: 500; color: var(--ink); margin-left: 0.9em; letter-spacing: 0.01em; }
.line2 .pos i { font-style: normal; color: var(--accent); }
.mapbtn { position: absolute; border-radius: 6px; }
.mapbtn:hover, .mapbtn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 4px; }

/* ---- portrait: the column as a vertical stack ---- */
#stack {
  position: absolute; inset: 0; display: none; overflow-y: auto; overflow-x: hidden; scroll-snap-type: y mandatory;
  touch-action: pan-y; scrollbar-width: none; overscroll-behavior: contain;
  padding: calc(50dvh - var(--ch, 200px) / 2 - 18px) var(--safe-r) calc(50dvh - var(--ch, 200px) / 2 + 18px) var(--safe-l);
}
#stack::-webkit-scrollbar { display: none; }
#app[data-layout="stack"] #stack { display: block; }
#stack .cell { position: relative; width: var(--cw); height: var(--ch); margin: 0 auto 18px; scroll-snap-align: center; scroll-snap-stop: always; }
#stack .cell .slide { transform: scale(var(--k)); }
#hud {
  position: absolute; left: var(--safe-l); right: var(--safe-r); bottom: 0; padding: 12px 16px calc(14px + var(--safe-b));
  display: none; align-items: baseline; justify-content: space-between; gap: 12px; pointer-events: none;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
#app[data-layout="stack"][data-mode="slide"] #hud { display: flex; }
#hud .ttl { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#hud .line2 { line-height: 1.2; font-size: 12px; flex: none; }

/* ---- grid mode ---- */
#grid { position: absolute; inset: 0; background: var(--bg); touch-action: none; }
#board { position: absolute; transform-origin: 0 0; }
.t { position: absolute; display: block; background: var(--paper); box-shadow: 0 0 0 1px var(--hair); border-radius: 2px; overflow: visible; }
.t img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 2px; pointer-events: none; -webkit-user-drag: none; }
.t.here { outline: 1.5px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 3px; }
.t.sel { outline: 3px solid var(--accent); outline-offset: 4px; }
.t.picked::after { content: "\2713"; position: absolute; right: 6px; top: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--paper); font-size: 14px; line-height: 22px; text-align: center; font-weight: 700; pointer-events: none; }
.t .start { position: absolute; left: 0; top: 100%; margin-top: 0.5em; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); pointer-events: none; }
.t .start::before { content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--faint); margin-right: .6em; vertical-align: 1px; }

/* ---- chrome ---- */
#chrome {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 14px); transform: translateX(-50%);
  display: flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--ui-bg);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 0 0 1px var(--hair), 0 6px 24px rgba(0,0,0,.12);
  transition: opacity .3s, transform .3s; z-index: 5;
}
#app[data-layout="stack"] #chrome { bottom: auto; top: calc(var(--safe-t) + 10px); }
#chrome button { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--dim); }
#chrome button:hover, #chrome button:focus-visible { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); outline: none; }
#chrome button[aria-pressed="true"] { color: var(--accent); }
#chrome svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#app.idle:not(.keep) #chrome { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(6px); }
#app.idle:not(.keep) { cursor: none; }

.pop { position: absolute; z-index: 6; background: var(--paper); color: var(--ink); border-radius: 14px; box-shadow: 0 0 0 1px var(--hair), 0 14px 44px rgba(0,0,0,.2); }
#menu { left: 50%; bottom: calc(var(--safe-b) + 70px); transform: translateX(-50%); padding: 8px; min-width: 240px; max-width: calc(100vw - 24px); }
#app[data-layout="stack"] #menu { bottom: auto; top: calc(var(--safe-t) + 66px); }
#menu h2 { margin: 6px 12px 6px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); font-weight: 500; }
#menu h2:not(:first-child) { margin-top: 14px; }
#menu a, #menu button { display: flex; justify-content: space-between; gap: 24px; width: 100%; padding: 10px 12px; border-radius: 8px; color: inherit; text-decoration: none; font-size: 15px; text-align: left; }
#menu a:hover, #menu a:focus-visible, #menu button:hover, #menu button:focus-visible { background: var(--inset); outline: none; }
#menu small { color: var(--dim); font-size: 12px; align-self: center; }
#menu .hint, #menu #note { margin: 6px 12px; font-size: 12px; color: var(--dim); }
#menu #note[hidden] { display: none; }
#menu #note[data-kind="error"] { color: var(--accent); }
#menu { max-height: calc(100dvh - 90px); overflow-y: auto; }
@media (max-height: 520px) { #menu a, #menu button { padding: 6px 12px; font-size: 14px; } #menu h2 { margin: 4px 12px; } #menu h2:not(:first-child) { margin-top: 8px; } }
#help { inset: 0; margin: auto; width: min(480px, calc(100vw - 32px)); height: fit-content; padding: 22px 26px 20px; }
#help h2 { margin: 0 0 12px; font-size: 18px; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 22px; margin: 0; font-size: 14px; }
#help dt { white-space: nowrap; } #help dd { margin: 0; color: var(--dim); }
kbd { font: 500 12px Archivo, system-ui, sans-serif; padding: 2px 7px; border-radius: 5px; background: var(--inset); box-shadow: 0 0 0 1px var(--hair); margin-right: 3px; }
#scrim { position: absolute; inset: 0; z-index: 5; background: color-mix(in srgb, var(--ink) 16%, transparent); }

@media (prefers-reduced-motion: reduce) {
  #chrome, .counts .c { transition: none; }
}
