/* Paper, ink and one vermilion seal. */
:root, [data-theme=light] {
  color-scheme: light;
  --bg: #f2eee6; --card: #faf8f3; --ink: #2b2925; --muted: #6b655c; --line: #dcd4c6; --line-2: #bdb19f; --field: #958b7d;
  --accent: #b4553a; --chip: #ece7dc; --err-bg: #f2e2d8; --ok: #566d47;
  --u1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 9' preserveAspectRatio='none'%3E%3Cpath d='M2 6C18 3.2 34 7.6 52 5.2S84 3 98 4.8' fill='none' stroke='%23a6543a' stroke-width='2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  --u2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 9' preserveAspectRatio='none'%3E%3Cpath d='M2 4Q28 8.2 58 5.2T98 5.6' fill='none' stroke='%23a6543a' stroke-width='2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
}
[data-theme=dark] {
  color-scheme: dark;
  --bg: #1c1a17; --card: #23211d; --ink: #e9e3d7; --muted: #9c9387; --line: #37332d; --line-2: #554d42; --field: #746c60;
  --accent: #d9805f; --chip: #2c2925; --err-bg: #3b2b25; --ok: #9cb487;
  --u1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 9' preserveAspectRatio='none'%3E%3Cpath d='M2 6C18 3.2 34 7.6 52 5.2S84 3 98 4.8' fill='none' stroke='%23d48463' stroke-width='2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  --u2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 9' preserveAspectRatio='none'%3E%3Cpath d='M2 4Q28 8.2 58 5.2T98 5.6' fill='none' stroke='%23d48463' stroke-width='2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; color: var(--ink);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .25 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  font: 15px/1.6 "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
h1, h2, .brand span, .pcard, .avg, .seal, .vote {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif", Georgia, serif; }
a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; max-width: 920px; margin: 0 auto; padding: 22px 16px 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand span { font-size: 21px; letter-spacing: .04em; }
.mark { width: 38px; height: 40px; color: var(--ink); transition: transform .6s ease; }
.mark .back { fill: var(--chip); } .mark .front { fill: var(--card); } .mark .dot { fill: var(--accent); }
.brand:hover .mark { transform: rotate(-6deg); }
.right { display: flex; align-items: center; gap: 4px; }
button.linkish, button.icon { margin: 0; padding: 4px 10px 6px; background: none; border: 0; box-shadow: none;
  color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline dashed var(--line-2); text-underline-offset: 4px; }
button.icon { padding: 6px; display: inline-flex; text-decoration: none; }
button.linkish:hover, button.icon:hover { color: var(--ink); transform: none; box-shadow: none; }
button.icon:hover svg { transform: rotate(-12deg); }
button.icon svg { width: 20px; height: 20px; transition: transform .2s ease; }
[data-theme=dark] .to-dark, [data-theme=light] .to-light { display: none; }

/* layout */
main { flex: 1; width: 100%; max-width: 920px; margin: 0 auto; padding: 18px 16px 48px; }
h1 { font-size: 28px; font-weight: 500; margin: 0 0 6px; letter-spacing: .01em; }
h2 { font-size: 18px; font-weight: 500; margin: 0 0 12px; padding-bottom: 7px; width: fit-content;
  background: var(--u, var(--u1)) no-repeat left bottom / 100% 8px; }
.grid .card + .card h2 { --u: var(--u2); }
.sub { color: var(--muted); margin: 0 0 18px; }
.card { background: var(--card); border: 1.5px solid var(--line-2); padding: 22px;
  border-radius: 16px 5px 14px 6px / 6px 14px 5px 16px; }
.card + .card { border-radius: 6px 15px 5px 13px / 13px 6px 15px 5px; }
.card.narrow { max-width: 420px; margin: 48px auto; }
.grid { display: grid; gap: 22px; grid-template-columns: 3fr 2fr; margin-top: 30px; }
.foot { width: 100%; max-width: 920px; margin: 0 auto; padding: 0 16px 28px; color: var(--muted); font-size: 13px; }

/* forms: writing on a line */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 2px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink); cursor: pointer; }
label.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
input[type=text] { width: 100%; padding: 8px 2px; border: 0; border-bottom: 1.5px solid var(--field); border-radius: 0;
  background: transparent; color: var(--ink); font: inherit; outline: none; }
input[type=text]:focus { border-bottom-color: var(--accent); }
::placeholder { color: var(--muted); opacity: 1; }
button { display: inline-block; margin-top: 16px; padding: 8px 18px 9px; border: 1.5px solid var(--ink);
  border-radius: 12px 4px 10px 5px / 5px 10px 4px 12px; background: var(--ink); color: var(--card);
  font: inherit; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease; }
button:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--line-2); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { margin-top: 0; }
.wide-btn { width: 100%; padding: 11px 18px 12px; font-size: 16px; }
.join-code { margin-top: 22px; }
.grow { flex: 1; min-width: 160px; }
#join-form .row { margin-top: 20px; }
.msg.err { margin: 14px 0 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--err-bg);
  border-radius: 2px 10px 8px 2px; font-size: 14px; }

/* the session code above the story */
.session { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; font-size: 14px; }
#room-code { font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.session .linkish { padding: 0 0 0 6px; }

/* the card settings */
dialog { width: min(440px, calc(100vw - 32px)); padding: 22px; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line-2); border-radius: 16px 5px 14px 6px / 6px 14px 5px 16px; }
dialog::backdrop { background: rgb(28 26 23 / .35); }
dialog h2 { margin-bottom: 8px; }
dialog > .small { margin: 0 0 4px; }
.label { font-size: 13px; color: var(--muted); margin: 20px 0 8px; }

/* the preset: a select written on a line, like the other fields */
select { width: 100%; padding: 8px 26px 8px 2px; border: 0; border-bottom: 1.5px solid var(--field); border-radius: 0;
  background: transparent var(--chev) no-repeat right 4px center / 12px 8px; color: var(--ink); font: inherit;
  appearance: none; -webkit-appearance: none; cursor: pointer; outline: none; }
select:focus-visible { border-bottom-color: var(--accent); outline: none; }
select option { color: #2b2925; background: #faf8f3; }
:root, [data-theme=light] { --chev: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b655c' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
[data-theme=dark] { --chev: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239c9387' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }

/* the deck being edited: small paper cards, each with an ink x to take it out */
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 12px 10px; margin: 0; padding: 6px 0 2px; }
.chip { position: relative; display: grid; place-items: center; min-width: 40px; height: 54px; padding: 0 6px; background: var(--bg);
  border: 1.5px solid var(--line-2); border-radius: 7px 3px 6px 4px / 4px 6px 3px 7px;
  font: 17px "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }
.chip:nth-child(3n+2) { border-radius: 4px 7px 3px 6px / 6px 3px 7px 4px; }
.chip:nth-child(3n) { border-radius: 6px 4px 7px 3px / 3px 7px 4px 6px; }
.chip-face svg { width: 18px; height: 18px; display: block; }
.chip-x { position: absolute; top: -8px; right: -8px; display: grid; place-items: center; width: 20px; height: 20px;
  margin: 0; padding: 0; border: 1.5px solid var(--line-2); border-radius: 50% 45% 50% 48%;
  background: var(--card); color: var(--muted); opacity: 0; transition: opacity .15s ease, color .15s ease; }
.chip-x svg { width: 12px; height: 12px; display: block; }
.chip:hover .chip-x, .chip-x:focus-visible { opacity: 1; }
.chip-x:hover { color: var(--accent); border-color: var(--accent); transform: none; box-shadow: none; }
@media (hover: none) { .chip-x { opacity: 1; } } /* touch screens have no hover: always show it */
.ghost-chip { background: transparent; border-style: dashed; }
.chip-add { display: flex; align-items: center; gap: 1px; margin: 0; padding: 0; width: 100%; height: 100%;
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; justify-content: center; }
.chip-add svg { width: 15px; height: 15px; }
.chip-add:hover { color: var(--ink); transform: none; box-shadow: none; }

.add-card { display: flex; gap: 10px; align-items: end; margin-top: 16px; }
.add-card input { flex: 1; min-width: 0; }
.add-card button { margin: 0; }
.dialog-end { justify-content: flex-end; margin-top: 22px; }
.dialog-end button { margin: 0; }

/* the story line */
.story label { margin-top: 0; }
.story input { font-size: 22px; padding: 6px 2px 8px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif", Georgia, serif; }

/* the deck: hand-cut paper cards */
.deck { display: grid; grid-template-columns: repeat(var(--n, 13), minmax(0, 1fr)); gap: 10px; margin-top: 26px;
  max-width: calc(var(--n, 13) * 78px); } /* fewer cards stay card-sized instead of stretching */
.pcard { position: relative; margin: 0; aspect-ratio: 5 / 7; padding: 0; display: grid; place-items: center;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--line-2); font-size: 24px;
  border-radius: 9px 4px 8px 5px / 5px 8px 4px 9px; transition: transform .18s ease, box-shadow .18s ease, background .18s ease; }
.pcard:nth-child(3n+2) { border-radius: 5px 9px 4px 8px / 8px 4px 9px 5px; }
.pcard:nth-child(3n) { border-radius: 8px 5px 9px 4px / 4px 9px 5px 8px; }
.pcard:hover:not(:disabled) { transform: translateY(-4px) rotate(-1.5deg); box-shadow: 3px 4px 0 var(--line); }
.pcard[aria-pressed=true] { background: var(--ink); color: var(--card); border-color: var(--ink);
  transform: translateY(-8px) rotate(-2deg); box-shadow: 4px 6px 0 var(--line-2); }
.pcard[aria-pressed=true]::after { content: ""; position: absolute; top: 7px; right: 7px; width: 7px; height: 7px;
  background: var(--accent); border-radius: 50% 40% 55% 45%; }
.pcard svg { width: 26px; height: 26px; }
.vote svg { width: 18px; height: 18px; }
.dist .k svg { width: 20px; height: 20px; vertical-align: middle; }
.watching { margin: 14px 0 0; }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 26px; }
.actions button { margin: 0; }
.status { font-size: 14px; }
.actions .cards-link { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 2px; }
.cards-link svg { width: 17px; height: 17px; transition: transform .3s ease; }
.cards-link:hover svg { transform: rotate(45deg); }

/* the table of people */
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line-2); min-height: 52px; }
.people li:last-child { border-bottom: 0; }
.people .name { overflow-wrap: anywhere; }
.people .away { opacity: .5; }
.tag { font-size: 12px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 10px 6px 9px 5px; padding: 0 7px; white-space: nowrap; }
.vote { margin-left: auto; flex: none; display: grid; place-items: center; min-width: 30px; height: 40px; padding: 0 4px; font-size: 16px;
  border: 1.5px dashed var(--line-2); border-radius: 5px 3px 5px 3px; color: var(--muted); }
.vote.in { border-style: solid; border-color: var(--ink); background: var(--ink); }
.vote.shown { border-style: solid; border-color: var(--ink); background: var(--card); color: var(--ink); }
.vote.flip { animation: flip .35s ease both; } /* only a card that just turned over or changed */
.vote.none { border: 0; width: auto; font-size: 13px; font-family: inherit; }
@keyframes flip { from { transform: rotateY(90deg); } to { transform: none; } }

/* the result */
.avg-row { display: flex; align-items: center; gap: 16px; }
.avg { font-size: 52px; line-height: 1; font-weight: 500; font-variant-numeric: tabular-nums; }
.avg-label { color: var(--muted); font-size: 13px; letter-spacing: .06em; text-transform: lowercase; }
.seal { display: inline-grid; place-items: center; width: 62px; height: 62px; margin-left: auto; color: var(--accent);
  border: 2.5px solid var(--accent); border-radius: 6px 9px 7px 8px; transform: rotate(-8deg); font-size: 13px; font-style: italic;
  line-height: 1.05; text-align: center; letter-spacing: .04em; }
.seal.stamp { animation: stamp .3s ease-out both; }
@keyframes stamp { from { transform: rotate(-8deg) scale(1.6); opacity: 0; } }
.dist { list-style: none; margin: 18px 0 0; padding: 0; }
.dist li { display: grid; grid-template-columns: 38px 1fr 26px; gap: 10px; align-items: center; padding: 3px 0; }
.dist .k { font-family: "Iowan Old Style", Palatino, Georgia, serif; font-size: 17px; text-align: center; }
.dist .track { display: block; }
.dist .bar { display: block; height: 10px; background: var(--ink); border-radius: 2px 6px 3px 5px; min-width: 6px; }
.dist .n { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.progress { font-size: 15px; margin: 0; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.dots i { width: 10px; height: 10px; border: 1.5px solid var(--line-2); border-radius: 50% 40% 55% 45%; }
.dots i.on { background: var(--ink); border-color: var(--ink); }

@media (max-width: 680px) {
  .grid { grid-template-columns: 1fr; }
  .deck { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); max-width: none; }
  .pcard { font-size: 20px; }
  .card.narrow { margin: 24px auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
