:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --text: #1d1b22;
  --muted: #6c6873;
  --line: #e4e1da;
  --link: #5b3cc4;
  --accent: #6741d9;
  --accent-soft: #efeafd;
  --herd: #2b8a3e;
  --herd-soft: #e6f6e9;
  --mine: #f59f00;
  --error-bg: #fdecea;
  --error: #a61b1b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121115;
    --panel: #1c1a21;
    --text: #e8e6ec;
    --muted: #9d98a6;
    --line: #2f2c36;
    --link: #b49cff;
    --accent: #9775fa;
    --accent-soft: #2a2340;
    --herd: #69db7c;
    --herd-soft: #1d3322;
    --mine: #ffc046;
    --error-bg: #3a1a1a;
    --error: #ff9b9b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .3rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1.15rem; margin: 0 0 .6rem; }
p { margin: .5rem 0; }

.top {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .7rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; font-size: 1.3rem; color: var(--accent); letter-spacing: -.03em; }
.logo:hover { text-decoration: none; }
.top nav { display: flex; gap: 1rem; }
.top nav a { color: var(--text); }

main { max-width: 1000px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.narrow { max-width: 600px; margin: 0 auto; }
.narrow.wide { max-width: 720px; }
.center { text-align: center; }

.box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.box > h2:first-child, .box summary h2 { margin-top: 0; }
.note { background: var(--accent-soft); padding: .6rem .8rem; border-radius: 8px; }
.hint { color: var(--muted); font-size: .88rem; font-weight: 400; }
.empty { color: var(--muted); }
.error { background: var(--error-bg); color: var(--error); padding: .5rem .7rem; border-radius: 6px; margin: 0; }
.meta { color: var(--muted); margin: 0; }
.gamehead { margin-bottom: 1rem; }
html.js .nojs { display: none; }
html:not(.js) .jsonly { display: none; }
.hp { position: absolute; left: -9999px; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .05em; color: var(--text); }

/* home */
.hero { text-align: center; padding: 2rem 0 1.5rem; }
.hero h1 { font-size: 2rem; }
.hero p { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card {
  display: flex; flex-direction: column; gap: .3rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem;
  color: var(--text); transition: transform .12s, border-color .12s;
}
a.card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.card h2 { margin: .2rem 0 0; font-size: 1.3rem; }
.card p { margin: 0; color: var(--muted); }
.card-icon { font-size: 2.4rem; line-height: 1; }
.card .tag { margin-top: auto; padding-top: .6rem; font-size: .82rem; color: var(--accent); font-weight: 600; }
.card.soon { opacity: .6; }

/* forms */
.form { display: flex; flex-direction: column; gap: .9rem; }
.form label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; width: 100%;
}
select { width: auto; padding: .2rem .4rem; font-size: .85rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
button { font: inherit; }
.btn {
  display: inline-block; cursor: pointer; font-weight: 600; font-size: .95rem;
  padding: .5rem 1.1rem; border-radius: 999px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.big { font-size: 1.1rem; padding: .7rem 1.6rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
button.link { border: 0; background: none; padding: 0; cursor: pointer; color: var(--link); font-size: .85rem; }
button.link:hover { text-decoration: underline; }
form.inline { display: inline; }

/* sheep landing */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.choice { margin-bottom: 0; }
.choice .btn { margin-top: .3rem; }
.how { margin: 0; padding-left: 1.4rem; }
.how li { margin: .35rem 0; }

/* new game wizard */
.stepnum { margin: 0; color: var(--accent); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.step h2 { margin: .1rem 0 .5rem; }
.step > input { margin: .4rem 0; }
.stepnav { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin: 1rem 0 0; }
.qbuild { margin: .8rem 0 .3rem; padding-left: 1.6rem; }
.qbuild:empty { display: none; }
.qbuild li { padding: .35rem 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.qbuild li:last-child { border-bottom: 0; }
.idea { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: left; }
html.js .ideas ul { columns: auto; display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; }
html.js .idea {
  cursor: pointer; font-size: .88rem; color: var(--text);
  padding: .2rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
}
html.js .idea:hover { border-color: var(--accent); }

/* about */
.about h2 { margin-top: 1.8rem; }
.about li { margin: .3rem 0; }

.ideas summary { cursor: pointer; color: var(--link); }
.ideas ul { columns: 2; font-size: .9rem; color: var(--muted); padding-left: 1.2rem; }
@media (max-width: 520px) { .ideas ul { columns: 1; } }

.answers label { font-weight: 500; }
.qnum {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.6rem; height: 1.6rem; margin-right: .3rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-weight: 700;
}

/* host links */
.links summary { cursor: pointer; list-style: none; }
.links summary::-webkit-details-marker { display: none; }
.links summary h2 { display: inline; }
.links summary h2::after { content: " ▾"; color: var(--muted); font-size: .9rem; }
.links[open] summary { margin-bottom: .4rem; }
.copyrow { display: flex; gap: .5rem; }
.copyrow input { font-size: .9rem; }

/* lobby */
.players { list-style: none; padding: 0; margin: 0; }
.players li { display: flex; gap: .6rem; align-items: baseline; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.players li:last-child { border-bottom: 0; }
.players li > span:first-child { flex: 1; }
.players li.done .hint { color: var(--herd); }
.qlist { margin: 0; padding-left: 1.4rem; }

/* reveal */
.current { border-color: var(--accent); }
.question h3 { display: flex; align-items: baseline; gap: .2rem; }
.groups { list-style: none; padding: 0; margin: .6rem 0; display: flex; flex-direction: column; gap: .45rem; }
.group {
  display: flex; gap: .7rem; align-items: center; flex-wrap: wrap;
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.group .count {
  flex-shrink: 0; min-width: 2.2rem; height: 2.2rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; background: var(--accent-soft); color: var(--accent);
}
.group .ans { flex: 1; min-width: 10rem; display: flex; flex-direction: column; }
.group .answer { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.group .who { color: var(--muted); font-size: .85rem; }
.group.herd { border-color: var(--herd); background: var(--herd-soft); }
.group.herd .count { background: var(--herd); color: #fff; }
.group.mine { box-shadow: inset 4px 0 0 var(--mine); }
.group.unrevealed { opacity: .55; border-style: dashed; }
.group .tools { display: flex; gap: .6rem; align-items: center; }
.group .merge { display: flex; gap: .4rem; align-items: center; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: .05rem .45rem; border-radius: 999px; background: var(--herd); color: #fff; vertical-align: middle;
}
.badge.muted { background: var(--line); color: var(--muted); }
.mypoints { font-weight: 500; margin-bottom: 0; }
.more { font-style: italic; }
.group.new { animation: pop .45s ease-out; }
@keyframes pop {
  from { transform: scale(.92); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .group.new { animation: none; } }

.scores { list-style: none; padding: 0; margin: 0; }
.scores li { display: flex; gap: .8rem; padding: .35rem .2rem; border-bottom: 1px solid var(--line); }
.scores li:last-child { border-bottom: 0; }
.scores .rank { width: 1.6rem; color: var(--muted); text-align: right; }
.scores .name { flex: 1; overflow-wrap: anywhere; }
.scores .points { font-weight: 800; }
.scores li.me { color: var(--accent); font-weight: 600; }
.final .scores li:first-child { font-size: 1.15rem; }
.final .scores li:first-child .name::after { content: " 🏆"; }

/* grouping console */
.waiting { color: var(--muted); font-style: italic; }
.gcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .6rem; margin: .8rem 0; }
.gcard {
  display: flex; flex-direction: column; gap: .4rem;
  padding: .5rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.gcard.over, .grouper.picking .gcard:hover { border-color: var(--accent); background: var(--accent-soft); }
.ghead { display: flex; gap: .4rem; align-items: center; }
.glabel { font-weight: 700; padding: .3rem .45rem; }
.gcount {
  flex-shrink: 0; min-width: 1.9rem; height: 1.9rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .9rem; background: var(--accent-soft); color: var(--accent);
}
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; min-height: 1rem; }
.chip {
  padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.chip:focus-visible { outline: 2px solid var(--accent); }
.chip .ctext { font-weight: 600; overflow-wrap: anywhere; }
.chip .cn { color: var(--accent); font-weight: 700; font-size: .85rem; }
.chip .who { display: block; color: var(--muted); font-size: .8rem; }
.chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.chip.dragging { opacity: .4; }
.newgroup {
  align-items: center; justify-content: center; min-height: 4rem;
  border-style: dashed; color: var(--muted); font-weight: 600; cursor: pointer;
}

/* thunderdome */
.players li.out > span:first-child { color: var(--muted); text-decoration: line-through; }
.tdnow { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .2rem; }
.clock { margin: 0; font-size: 3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; color: var(--accent); }
.clock .unit { font-size: 1.2rem; margin-left: .1rem; color: var(--muted); }
.clock.low { color: var(--error); }
.tdform .copyrow input { font-size: 1.1rem; }
.settings { display: flex; align-items: center; gap: .8rem; }
.settings label { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.round h2 { margin-top: 0; }
.tdanswers { list-style: none; padding: 0; margin: .4rem 0; display: flex; flex-direction: column; gap: .4rem; }
.tdans {
  display: flex; gap: .7rem; align-items: center;
  padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.tdans .mark {
  flex-shrink: 0; width: 2rem; height: 2rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800;
  background: var(--line); color: var(--muted);
}
.tdans .ans { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tdans .answer { font-weight: 700; overflow-wrap: anywhere; }
.tdans .who { color: var(--muted); font-size: .85rem; }
.tdans.ok { border-color: var(--herd); background: var(--herd-soft); }
.tdans.ok .mark { background: var(--herd); color: #fff; }
.tdans.bad .answer { text-decoration: line-through; text-decoration-color: var(--error); }
.tdans.bad .mark { background: var(--error-bg); color: var(--error); }
.tdans.new { animation: pop .45s ease-out; }
@media (prefers-reduced-motion: reduce) { .tdans.new { animation: none; } }
.rule { display: flex; gap: .3rem; flex-shrink: 0; }
.pill {
  cursor: pointer; width: 2.4rem; height: 2.4rem; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-weight: 800; font-size: 1rem;
}
.pill.dup { width: auto; padding: 0 .6rem; border-radius: 999px; font-size: .78rem; }
.pill.dup.flag { border-color: var(--mine); background: var(--mine); color: #000; }
.pill.yes.on { background: var(--herd); border-color: var(--herd); color: #fff; }
.pill.no.on { background: var(--error); border-color: var(--error); color: #fff; }
