/* Plot Holes: a storybook with holes punched in it. Light: cream notebook paper with a red margin line and tomato
   accents. Dark: a reading lamp at night (plum-black page, warm paper-white text). Story text is Alegreya (a book
   face), the interface Nunito, the title Fredoka. Every player has a colour (c0-c11) for their words. */
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 300 900; font-display: swap; src: url(/fonts/nunito-latin-wght-normal.woff2) format("woff2"); }
@font-face { font-family: "Fredoka"; font-style: normal; font-weight: 600; font-display: swap; src: url(/fonts/fredoka-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Alegreya"; font-style: normal; font-weight: 400; font-display: swap; src: url(/fonts/alegreya-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Alegreya"; font-style: normal; font-weight: 700; font-display: swap; src: url(/fonts/alegreya-latin-700-normal.woff2) format("woff2"); }

:root {
  --bg: #FBF5E9; --bg2: #F2E9D6; --card: #FFFDF7; --ink: #2B2118; --muted: #74675A; --line: #E4D8C1;
  --rule: rgba(82, 132, 196, .16); --margin: rgba(214, 72, 46, .35);
  --accent: #D6482E; --on-accent: #FFFFFF; --good: #2E7D4F; --bad: #B23A48; --backdrop: rgba(40, 28, 18, .45);
  --p0: #D6482E; --p1: #2F6FC4; --p2: #2E8B57; --p3: #8E44AD; --p4: #C77800; --p5: #C2185B; --p6: #00838F; --p7: #6D4C41;
  --p8: #3949AB; --p9: #7A8C00; --p10: #E65100; --p11: #546E7A;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --story: "Alegreya", Georgia, "Times New Roman", serif;
  --head: "Fredoka", "Nunito", system-ui, sans-serif;
  --lb-panel: var(--card); --lb-panel2: var(--bg2); --lb-text: var(--ink); --lb-muted: var(--muted); --lb-line: var(--line);
  --lb-accent: var(--accent); --lb-ink: var(--on-accent); --lb-bad: var(--bad); --lb-font: var(--font); --lb-head: var(--head);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16131D; --bg2: #221D2B; --card: #1E1A26; --ink: #F5ECDD; --muted: #B4A99A; --line: #352E40;
  --rule: rgba(140, 170, 230, .07); --margin: rgba(255, 120, 90, .25);
  --accent: #FF7B5C; --on-accent: #2A0E06; --good: #7BD69E; --bad: #FF8A98; --backdrop: rgba(0, 0, 0, .6);
  --p0: #FF7B5C; --p1: #6EA8FF; --p2: #5BD18D; --p3: #C792EA; --p4: #FFB74D; --p5: #FF6FA8; --p6: #4DD0E1; --p7: #C8A27E;
  --p8: #8C9EFF; --p9: #C6D84A; --p10: #FF9E40; --p11: #9FB4C0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.45; min-height: 100vh; min-height: 100dvh;
  -webkit-text-size-adjust: 100%; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
a { color: inherit; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ page frame */
.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; }
.back { text-decoration: none; color: var(--muted); font-size: .95rem; white-space: nowrap; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; color: var(--ink); }
@media (hover: hover) { .icon-btn:hover { background: var(--bg2); } }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 8px; gap: 10px; flex-wrap: wrap; }
h1 { font: 600 2rem/1 var(--head); margin: 0; letter-spacing: .01em; display: flex; align-items: center; gap: 10px; }
/* the mark: a page with a hole punched through it */
.h-mark { width: 24px; height: 28px; flex: none; border-radius: 4px; background: radial-gradient(circle at 50% 56%, var(--bg) 0 4.6px, transparent 5.2px),
  repeating-linear-gradient(180deg, transparent 0 6px, var(--margin) 6px 7px), var(--card); border: 2px solid var(--accent); }
.sub { margin: 0; color: var(--muted); font-size: .95rem; white-space: nowrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.intro p { margin: 0; font-size: 1rem; }
.fine { margin: 6px 0 0; color: var(--muted); font-size: .88rem; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 0 16px; min-height: 40px; font-weight: 700; cursor: pointer; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .92rem; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
@media (hover: hover) { .btn:hover:not(:disabled) { border-color: var(--accent); } }
.go { border: 0; background: var(--accent); color: var(--on-accent); border-radius: 999px; padding: 0 26px; min-height: 48px; font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.go:disabled { opacity: .5; }
@media (hover: hover) { .go:hover:not(:disabled) { filter: brightness(1.06); } }
.home .lb-box { margin-top: 12px; }
.sets { margin-top: 12px; }
.pt-h { margin: 0 0 8px; font: 600 1.15rem/1.2 var(--head); }
.pt-sl { display: block; font-size: .8rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pt-set { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; padding: 8px 0; border-top: 1px dashed var(--line); }
.pt-seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--bg2); border-radius: 999px; padding: 3px; }
.pt-seg button { border: 0; background: transparent; border-radius: 999px; padding: 0 12px; min-height: 34px; font-weight: 700; font-size: .9rem; cursor: pointer; color: var(--muted); }
.pt-seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(40, 28, 18, .18); }
.pt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px dashed var(--line); }
.pt-row .fine { margin: 0; flex-basis: 100%; }
.story-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 0 10px; }
.story-now { display: flex; flex-direction: column; min-width: 0; }
.story-now b { font: 600 1.15rem/1.25 var(--head); }
.story-now small { color: var(--muted); font-size: .85rem; }
.story-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.next-line { margin: 0; font-weight: 700; }

/* ------------------------------------------------------------ the game */
.game { margin-top: 4px; }
.g-head { text-align: center; margin: 4px 0 10px; }
.g-kick { margin: 0; font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.g-title { margin: 2px 0 0; font: 600 1.5rem/1.2 var(--head); }
.g-sub { margin: 4px auto 0; color: var(--muted); max-width: 30em; font-size: .95rem; }
.g-bar { height: 8px; border-radius: 99px; background: var(--bg2); overflow: hidden; margin: 0 0 12px; }
.g-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left center; transition: transform .25s linear; }
.g-bar.low i { background: var(--bad); }
.g-seats { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 0; margin: 16px 0 0; }
.g-seats li { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: .88rem; font-weight: 700; }
.g-seats li small { color: var(--muted); font-weight: 600; }
.g-seats li.done { border-color: var(--good); }
.g-seats li.done small { color: var(--good); }
.g-seats li.gone { opacity: .5; }
.g-seats li.me { box-shadow: inset 0 0 0 1px var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); flex: none; }
.g-foot { text-align: center; margin: 18px 0 4px; }
.g-leave { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: .9rem; min-height: 40px; }
.c0 { --pc: var(--p0); } .c1 { --pc: var(--p1); } .c2 { --pc: var(--p2); } .c3 { --pc: var(--p3); } .c4 { --pc: var(--p4); } .c5 { --pc: var(--p5); }
.c6 { --pc: var(--p6); } .c7 { --pc: var(--p7); } .c8 { --pc: var(--p8); } .c9 { --pc: var(--p9); } .c10 { --pc: var(--p10); } .c11 { --pc: var(--p11); }
.pchip { display: inline-block; padding: 0 8px; border-radius: 999px; background: var(--pc); color: #fff; font-weight: 800; font-size: .85rem; }
:root[data-theme="dark"] .pchip { color: #1A1420; }

/* ---- filling in */
.fill { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.fill-i { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.fill-l { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.fill-l b { font: 600 1.2rem/1.2 var(--head); }
.fill-ex { color: var(--muted); font-size: .9rem; }
.fill-row { display: flex; gap: 8px; }
.fill-in { flex: 1; min-width: 0; height: 48px; border: 2px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font: 700 1.1rem var(--story); padding: 0 12px; }
.fill-in:focus { border-color: var(--accent); outline: none; }
.fill-in:disabled { opacity: .7; }
.fill-in.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.97); background: color-mix(in srgb, var(--accent) 18%, var(--bg)); } 100% { transform: none; } }
.fill-ins { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg2); border-radius: 12px; padding: 0 12px; min-height: 48px; font-weight: 800; font-size: .9rem; cursor: pointer; }
.fill-ins svg { width: 20px; height: 20px; fill: var(--accent); }
.fill-ins:disabled { opacity: .5; }
@media (max-width: 360px) { .fill-ins span { display: none; } .fill-ins { padding: 0 13px; } }
.fill-act { text-align: center; margin-top: 14px; }
.fill-state { margin: 8px 0 0; color: var(--muted); font-size: .92rem; text-align: center; }

/* ---- the story page: ruled paper with a margin line */
.page { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 6px 18px 18px 6px; padding: 18px 18px 22px 34px;
  background-image: linear-gradient(90deg, transparent 22px, var(--margin) 22px 23.5px, transparent 23.5px), repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
  box-shadow: 0 2px 12px rgba(40, 28, 18, .08); font: 1.18rem/1.65 var(--story); }
.page::before { content: ""; position: absolute; left: 6px; top: 22px; bottom: 22px; width: 10px;
  background: radial-gradient(circle, var(--bg) 0 4px, transparent 4.5px) 0 0 / 10px 64px repeat-y; }
.st-line { margin: 0 0 10px; }
.st-title { margin: 4px 0 12px; }
.st-title h3 { margin: 0; font: 600 1.4rem/1.2 var(--head); }
.st-title.st-next { margin-top: 26px; padding-top: 14px; border-top: 2px dashed var(--line); }
.st-cat { margin: 0; font: 800 .74rem/1.3 var(--font); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.in { animation: lineIn .45s ease-out both; }
@keyframes lineIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* a player's word: bold in their colour, their name under it */
.w { display: inline-flex; flex-direction: column; align-items: center; vertical-align: top; line-height: 1.15; margin: 0; padding: 0 2px 1px; border-radius: 6px;
  background: color-mix(in srgb, var(--pc) 13%, transparent); }
.w .wt { font-weight: 700; color: var(--pc); border-bottom: 2px solid var(--pc); }
.w .wb { font: 800 .6rem/1.2 var(--font); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.w.auto .wt { border-bottom-style: dashed; }
.w.cb .wt { border-bottom-style: double; border-bottom-width: 3px; }
.in .w { animation: wordIn .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.in .w.d1 { animation-delay: .12s; } .in .w.d2 { animation-delay: .24s; } .in .w.d3 { animation-delay: .36s; } .in .w.d4 { animation-delay: .48s; } .in .w.d5 { animation-delay: .6s; }
@keyframes wordIn { from { opacity: 0; transform: scale(.6) rotate(-4deg); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .in, .in .w, .fill-in.pop { animation: none; } }
.rev-ctl { display: flex; justify-content: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.vote .w[data-i] { cursor: pointer; outline-offset: 2px; }
@media (hover: hover) { .vote .w[data-i]:hover { background: color-mix(in srgb, var(--pc) 26%, transparent); } }
.vote .w.nov { opacity: .55; }
.vote .w.picked { background: var(--pc); }
.vote .w.picked .wt { color: #fff; border-color: #fff; }
.vote .w.picked .wb { color: #fff; }
:root[data-theme="dark"] .vote .w.picked .wt, :root[data-theme="dark"] .vote .w.picked .wb { color: #1A1420; border-color: #1A1420; }

/* ---- scores */
.wins { display: grid; gap: 10px; margin-bottom: 14px; }
.win { text-align: center; background: var(--card); border: 2px solid var(--pc); border-radius: 18px; padding: 14px; }
.win-w { margin: 0; font: 700 1.8rem/1.2 var(--story); color: var(--pc); }
.win-by { margin: 4px 0; font-weight: 700; }
.win-ctx { margin: 6px 0 0; color: var(--muted); font: 1rem/1.5 var(--story); }
.board { list-style: none; padding: 0; margin: 0 0 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.board li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.board li:first-child { border-top: 0; }
.board li.me { font-weight: 800; }
.board .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pl { color: var(--good); font-weight: 800; }
.board .sc { font: 600 1.2rem var(--head); min-width: 2ch; text-align: right; }
.again-story { margin: 0 0 12px; }
.again-story summary { cursor: pointer; font-weight: 700; padding: 8px 0; min-height: 40px; }
.next { text-align: center; }
.next .story-row, .next .pt-set { text-align: left; }
.next .go { margin-top: 12px; }

/* ------------------------------------------------------------ the story picker */
dialog.dlg { border: 1px solid var(--line); border-radius: 20px; background: var(--card); color: var(--ink); max-width: min(460px, calc(100vw - 24px)); width: 100%; padding: 24px 20px;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; }
dialog.dlg.dlg-wide { max-width: min(640px, calc(100vw - 16px)); padding: 22px 16px; }
dialog.dlg::backdrop { background: var(--backdrop); }
dialog.dlg h2 { margin: 0 0 10px; font: 600 1.35rem/1.2 var(--head); }
dialog.dlg p { margin: 6px 0; }
dialog.dlg form:first-child { position: sticky; top: 0; height: 0; z-index: 3; }
.x { position: absolute; top: -14px; right: -8px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--bg2); font-size: 1.5rem; cursor: pointer; line-height: 1; }
dialog.dlg .go { display: block; margin: 14px auto 0; }
.pk-top { text-align: center; margin-bottom: 10px; }
.pk-top .go { margin: 0 auto; }
.pk-q { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); padding: 0 12px; font: inherit; font-size: 1rem; }
.pk-cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.pk-chip, .pk-tog { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 0 11px; min-height: 34px; font-size: .86rem; font-weight: 700; cursor: pointer; color: var(--muted); }
.pk-chip.on, .pk-tog.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pk-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pk-count { margin: 10px 0 6px; }
.pk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pk-row { display: flex; align-items: stretch; gap: 4px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.pk-row.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pk-item { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; border-radius: 14px; }
.pk-item b { font: 600 1.05rem/1.25 var(--head); }
.pk-meta { color: var(--muted); font-size: .86rem; }
.pk-meta2 { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .8rem; color: var(--muted); font-weight: 700; margin: 2px 0 0; }
.tag { border-radius: 6px; padding: 0 6px; background: var(--bg2); color: var(--ink); text-transform: capitalize; }
.pk-star { flex: none; width: 44px; border: 0; background: none; font-size: 1.3rem; color: var(--muted); cursor: pointer; border-radius: 14px; }
.pk-star.on { color: #E3A008; }
.pk-none { color: var(--muted); padding: 10px; }
.pv-top { display: flex; justify-content: flex-start; gap: 6px; align-items: center; margin-bottom: 8px; padding-right: 40px; }
.pv-top .pk-star { height: 40px; }
.pv-h { margin: 2px 0 4px; font: 600 1.4rem/1.2 var(--head); }
.page.pv { margin-top: 12px; font-size: 1.08rem; }
.bk { display: inline-block; font: 800 .78rem/1.5 var(--font); letter-spacing: .02em; padding: 0 8px; margin: 0 1px; border-radius: 999px; background: var(--bg2); border: 1px dashed var(--accent); color: var(--accent); vertical-align: 1px; }
.bk.cb { border-style: solid; }
.st-hid { margin: 0 0 12px; filter: blur(2px); }
.st-hid i { display: block; height: 11px; margin: 9px 0; border-radius: 6px; background: var(--line); max-width: 100%; }
.pv-note { color: var(--muted); font: italic .92rem/1.4 var(--font); margin: 6px 0 0; }
.pv-act { text-align: center; margin-top: 12px; }
.pv-act .btn { margin-top: 8px; }

/* ------------------------------------------------------------ toast, footer */
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ad-inline { margin: 18px 0; }
.foot { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; padding: 18px 0 30px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); margin-top: 10px; }
.foot a { color: var(--muted); }
@media (max-width: 400px) { .wrap { padding: 0 12px; } h1 { font-size: 1.7rem; } .page { padding: 14px 12px 18px 30px; font-size: 1.1rem; } }
