:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17201a;
  --muted: #64716a;
  --border: #d9e0da;
  --accent: #0f6b3a;
  --accent-ink: #ffffff;
  --accent-soft: #dff1e5;
  --star: #f2b01e;
  --star-off: #d5d9d3;
  --danger: #c0392b;
  --team-a: #c62828;
  --team-b: #1e8e3e;
  --warn-bg: #fff4d6; --warn-ink: #7a4d00; --warn-border: #f2d48a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101511; --surface: #182019; --surface-2: #1f2a21; --text: #eef3ee;
    --muted: #9aa89f; --border: #2c3a2f; --accent: #3ccf7a; --accent-ink: #08130c;
    --accent-soft: #1b3a27; --star: #ffc63a; --star-off: #3a463d;
    --team-a: #ff7b73; --team-b: #4fd47e;
    --warn-bg: #3a2f10; --warn-ink: #ffd98a; --warn-border: #5b4915;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #101511; --surface: #182019; --surface-2: #1f2a21; --text: #eef3ee;
  --muted: #9aa89f; --border: #2c3a2f; --accent: #3ccf7a; --accent-ink: #08130c;
  --accent-soft: #1b3a27; --star: #ffc63a; --star-off: #3a463d;
  --team-a: #ff7b73; --team-b: #4fd47e;
  --warn-bg: #3a2f10; --warn-ink: #ffd98a; --warn-border: #5b4915;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.no-nav { padding-bottom: 30px; }
header {
  background: var(--accent); color: var(--accent-ink);
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 5;
}
header h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .2px; }
header .pill { background: rgba(0,0,0,.15); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
header .pill.btn { cursor: pointer; border: none; color: inherit; font: inherit; font-size: 13px; font-weight: 600; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
input[type="text"], input[type="search"], input[type="password"] {
  width: 100%; padding: 12px 14px; font-size: 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
button {
  font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); padding: 11px 16px; border-radius: 10px;
  transition: transform .05s ease, background .15s ease;
}
button:active { transform: scale(.98); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 7px 11px; font-size: 14px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.block { width: 100%; }

/* Stars: picker (buttons) and display with fractional fill */
.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: none; padding: 2px; font-size: 24px; line-height: 1; color: var(--star-off); }
.stars button.on { color: var(--star); }
.rating { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.rating .r-stars { position: relative; display: inline-block; font-size: 15px; line-height: 1; letter-spacing: 1px; color: var(--star-off); }
.rating .r-stars .fill { position: absolute; left: 0; top: 0; overflow: hidden; color: var(--star); white-space: nowrap; }
.rating .r-num { font-size: 13px; font-weight: 700; min-width: 26px; text-align: right; }
.rating .r-votes { font-size: 11px; color: var(--muted); }

.muted { color: var(--muted); font-size: 14px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-border); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-top: 10px; }
.err { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 15px; }
.counter { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.counter small { font-size: 14px; color: var(--muted); font-weight: 600; margin-left: 4px; }

/* Generic list rows */
.item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: none; }
.item .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .name small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.item.clickable { cursor: pointer; }
.icon-btn { background: none; border: none; padding: 6px 8px; font-size: 18px; color: var(--muted); }

/* Presence rows */
.presence { display: flex; align-items: center; gap: 12px; padding: 11px 6px; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; }
.presence:last-child { border-bottom: none; }
.presence .check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border); display: grid; place-items: center; font-size: 14px; font-weight: 700; flex-shrink: 0; color: var(--accent-ink); }
.presence.on .check { background: var(--accent); border-color: var(--accent); }
.presence.on .name { font-weight: 700; }
.presence .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence .order { font-size: 12px; color: var(--muted); min-width: 28px; text-align: right; }

/* Teams */
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .teams { grid-template-columns: 1fr; } }
.team { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.team-head { padding: 10px 12px; color: #fff; display: flex; flex-direction: column; gap: 2px; }
.team.a .team-head { background: var(--team-a); }
.team.b .team-head { background: var(--team-b); }
.team-head strong { font-size: 15px; }
.team-head span { font-size: 13px; opacity: .9; }
.team ul { list-style: none; margin: 0; padding: 4px 0; }
.team li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.team li:last-child { border-bottom: none; }
.team li.selected { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: -2px; }
.team li .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Bottom nav */
nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--border); display: flex; padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; border: none; border-radius: 0; background: none; padding: 12px 4px 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; }
nav button .ico { font-size: 20px; line-height: 1; }
nav button.active { color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: all .2s ease; pointer-events: none; z-index: 20; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

dialog { border: none; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); width: min(92vw, 400px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .body { padding: 18px; }
dialog h3 { margin: 0 0 12px; font-size: 17px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Login / gate screen */
.gate { max-width: 380px; margin: 40px auto; text-align: center; }
.gate .logo { font-size: 52px; margin-bottom: 6px; }
.gate h2 { margin: 0 0 4px; font-size: 22px; text-transform: none; letter-spacing: 0; color: var(--text); }
.gate p { margin: 0 0 16px; }
.gate input { text-align: center; font-size: 20px; letter-spacing: 2px; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

/* Vote rows: name on the first line, controls on the second */
.vote-row { padding: 10px 2px; border-bottom: 1px solid var(--border); }
.vote-row:last-child { border-bottom: none; }
.vote-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 2px; }
.vote-row .ctrl { display: flex; align-items: center; gap: 6px; }
.vote-row .ctrl .stars { flex: 1; }
.vote-row .clear { background: none; border: none; color: var(--muted); font-size: 16px; padding: 4px 6px; visibility: hidden; }
.vote-row.voted .clear { visibility: visible; }
.vote-row .skip { padding: 6px 10px; font-size: 13px; font-weight: 600; color: var(--muted); background: transparent; white-space: nowrap; }
.vote-row.skipped .skip { background: var(--surface-2); color: var(--text); border-color: var(--text); }
.vote-row.skipped .stars button { opacity: .35; }
.vote-row.voted .name::after { content: ' ✓'; color: var(--accent); }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s ease; }
.status { font-size: 13px; color: var(--muted); min-height: 18px; }
.status.err { color: var(--danger); }
.legend { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend .s { color: var(--star); letter-spacing: 1px; }
