/* Light is the default. Dark applies only when <html data-theme="dark">. */
:root {
  --bg:        #ffffff;
  --surface:   #ffffff;
  --surface-2: #f2f3f5;
  --border:    #e2e4e9;
  --text:      #1c1e26;
  --muted:     #67707f;
  --accent:    #4f6bed;
  --accent-ink:#ffffff;
  --star:      #f5a623;
  --star-off:  #d3d7de;
  --danger:    #d64545;
  --good:      #2a9d63;
  --note-text: #3a4150;
  --topbar-bg: rgba(255,255,255,.82);
  --radius:    12px;
  --shadow:    0 6px 24px rgba(20,23,33,.08);
}

:root[data-theme="dark"] {
  --bg:        #0f1117;
  --surface:   #181b23;
  --surface-2: #1f232d;
  --border:    #2b303c;
  --text:      #e7e9ee;
  --muted:     #949bab;
  --accent:    #6c8cff;
  --accent-ink:#ffffff;
  --star:      #ffc857;
  --star-off:  #3a3f4c;
  --danger:    #ff6b6b;
  --good:      #4bd18c;
  --note-text: #cdd2dd;
  --topbar-bg: rgba(15,17,23,.82);
  --shadow:    0 6px 24px rgba(0,0,0,.35);
}

html { color-scheme: light dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  transition: background .12s, border-color .12s, opacity .12s;
}
button:hover        { border-color: var(--accent); }
button:disabled     { opacity: .5; cursor: default; }
button.primary      { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost        { background: transparent; }
button.link         { background: none; border: none; color: var(--muted); padding: 4px 6px; }
button.link:hover   { color: var(--danger); }

input, textarea {
  font: inherit;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

.error {
  color: var(--danger);
  background: rgba(255,107,107,.09);
  border: 1px solid rgba(255,107,107,.3);
  border-radius: 9px;
  padding: 9px 12px;
  margin: 10px 0 0;
  font-size: 14px;
}
.error:empty { display: none; }

/* ── Login ───────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }
.login-card button { width: 100%; margin-top: 20px; }

/* ── App shell ───────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 16px; letter-spacing: .2px; }
.topbar .right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.topbar .who { color: var(--muted); font-size: 13px; }
.topbar .who b { color: var(--text); }

button.icon-btn { padding: 6px 9px; font-size: 15px; line-height: 1; }

/* anchor styled as a button */
.btn-link {
  display: inline-block;
  font-size: 14px; text-decoration: none;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  padding: 8px 14px; border-radius: 9px;
}
.btn-link:hover { border-color: var(--accent); }

.banner {
  font-size: 13.5px;
  padding: 10px 14px; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2);
}
.banner-good { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }

.theme-fab {
  position: fixed; top: 14px; right: 14px; z-index: 20;
  padding: 6px 9px; font-size: 15px; line-height: 1;
  background: var(--surface); box-shadow: var(--shadow);
}

.container { max-width: 760px; margin: 0 auto; padding: 22px 20px 80px; }

.add-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.add-card .row { display: flex; gap: 10px; }
.add-card .row input { flex: 1; }
.add-card textarea { margin-top: 10px; }

.toolbar {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 0 14px;
  font-size: 13px; color: var(--muted);
}
.toolbar .spacer { flex: 1; }
.toolbar select {
  font: inherit; font-size: 13px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}

/* ── Name card ───────────────────────────────────── */
.name-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.name-card.needs-vote { border-color: rgba(108,140,255,.55); }

.name-head { display: flex; align-items: flex-start; gap: 12px; }
.name-title { flex: 1; min-width: 0; }
.name-title h3 { margin: 0; font-size: 18px; word-break: break-word; }
.name-title .meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.name-note {
  margin: 5px 0 3px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-left: 2px solid var(--border);
  border-radius: 0 7px 7px 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--note-text);
  white-space: pre-wrap;
}

.score-badge {
  text-align: center;
  flex-shrink: 0;
  min-width: 62px;
}
.score-badge .num { font-size: 22px; font-weight: 700; }
.score-badge .num.empty { color: var(--muted); font-weight: 500; font-size: 15px; }
.score-badge .lbl { font-size: 11px; color: var(--muted); }

.stars { display: inline-flex; gap: 2px; }
.stars button {
  border: none; background: none; padding: 0 2px;
  font-size: 22px; line-height: 1;
  color: var(--star-off);
}
.stars button.on { color: var(--star); }
.stars button:hover { color: var(--star); }

.rate-row {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.rate-row .label { font-size: 13px; color: var(--muted); }
.rate-row .clear { font-size: 12px; }

.breakdown { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.breakdown span { display: inline-block; margin-right: 12px; }
.breakdown b { color: var(--text); }

.pending-pill {
  display: inline-block;
  font-size: 11px; font-weight: 600;
  color: var(--accent);
  background: rgba(108,140,255,.12);
  border: 1px solid rgba(108,140,255,.3);
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 8px;
  vertical-align: middle;
}

/* ── Comments ────────────────────────────────────── */
.comments { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.comments .toggle { font-size: 13px; color: var(--muted); background: none; border: none; padding: 0; }
.comments .toggle:hover { color: var(--text); }
.comment { font-size: 13.5px; margin: 10px 0; }
.comment .who { color: var(--muted); font-size: 12px; }
.comment .body { white-space: pre-wrap; word-break: break-word; }
.comment-form { display: flex; gap: 8px; margin-top: 10px; }
.comment-form input { flex: 1; }

.empty-state { text-align: center; color: var(--muted); padding: 60px 20px; }

@media (max-width: 520px) {
  .add-card .row { flex-direction: column; }
  .name-head { flex-wrap: wrap; }
}
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; }
  .topbar .who { display: none; }
}

/* ── Simulation view ─────────────────────────────── */
#sim-toggle.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.sim-hint {
  display: none;
  font-size: 12.5px; color: var(--muted);
  padding: 8px 10px; margin-bottom: 12px;
  border: 1px dashed var(--border); border-radius: 8px;
}
body.sim-mode .sim-hint { display: block; }

#sim-panel {
  display: none;
  position: fixed;
  top: var(--topbar-h, 54px); right: 0; bottom: 0; left: var(--sim-list-w, 340px);
  flex-direction: column;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  z-index: 5;
}
body.sim-mode #sim-panel { display: flex; }
.sim-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}
.sim-bar .sim-name { color: var(--muted); }
.sim-bar .sim-name b { color: var(--text); }
.sim-bar-right { display: flex; align-items: center; gap: 10px; }
.sim-bar .sim-open { font-size: 12px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.sim-bar .sim-open:hover { color: var(--accent); }
#sim-close { padding: 5px 10px; font-size: 12px; }
#sim-frame { flex: 1; width: 100%; border: 0; background: #fff; }

/* When simulating: list becomes a fixed narrow column on the left */
body.sim-mode { overflow: hidden; }
body.sim-mode .container {
  position: fixed;
  top: var(--topbar-h, 54px); left: 0; bottom: 0;
  width: var(--sim-list-w, 340px); max-width: none;
  margin: 0; padding: 14px 14px 40px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
body.sim-mode .add-card,
body.sim-mode .toolbar,
body.sim-mode .sec-head,
body.sim-mode .name-note,
body.sim-mode .breakdown,
body.sim-mode .comments,
body.sim-mode .rate-row { display: none; }
body.sim-mode .sec { margin-bottom: 10px; }

body.sim-mode .name-card {
  padding: 11px 12px;
  cursor: pointer;
}
body.sim-mode .name-card:hover { border-color: var(--accent); }
body.sim-mode .name-card.sim-selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
body.sim-mode .name-title h3 { font-size: 15px; }
body.sim-mode .score-badge .num { font-size: 16px; }
body.sim-mode .score-badge .lbl { display: none; }

@media (max-width: 720px) {
  #sim-panel { left: 0; top: auto; height: 55vh; border-left: 0; border-top: 1px solid var(--border); }
  body.sim-mode .container {
    width: 100%; bottom: auto; height: 45vh;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
}

/* ── Sections ────────────────────────────────────── */
.sec { margin-bottom: 30px; }
.sec:last-child { margin-bottom: 0; }
.sec-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 0 0 12px; padding-bottom: 7px;
  border-bottom: 2px solid var(--border);
}
.sec-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.sec-count { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* the "still to rate" section stands out */
.sec-torate .sec-head { border-bottom-color: var(--accent); }
.sec-torate .sec-head h2,
.sec-torate .sec-count { color: var(--accent); }
.sec-torate .sec-count { font-weight: 600; }

/* ── Compact list (default) ──────────────────────── */
.compact-toggle { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.compact-toggle input { width: auto; margin: 0; }

.compact .breakdown,
.compact .comments { display: none; }
.compact .name-card { padding: 10px 13px; margin-bottom: 8px; }
.compact .name-title h3 { font-size: 15px; }
.compact .name-title .meta { margin-top: 1px; }
.compact .score-badge { min-width: 48px; }
.compact .score-badge .num { font-size: 17px; }
.compact .score-badge .lbl { font-size: 10px; }
.compact .rate-row { margin-top: 8px; padding-top: 8px; }
.compact .name-note { margin: 4px 0 2px; font-size: 12.5px; }

/* ── Results page ───────────────────────────────── */
.rank-row {
  display: flex; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.rank-row.leader { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.rank-num {
  font-size: 22px; font-weight: 700; color: var(--muted);
  min-width: 28px; text-align: right;
}
.rank-row.leader .rank-num { color: var(--accent); }
.rank-body { flex: 1; min-width: 0; }
.rank-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.rank-name { font-size: 17px; font-weight: 600; word-break: break-word; }
.rank-avg { font-size: 20px; font-weight: 700; }
.rank-bar {
  margin: 8px 0 6px;
  height: 6px; border-radius: 999px;
  background: var(--surface-2); overflow: hidden;
}
.rank-bar span { display: block; height: 100%; background: var(--accent); }
.rank-meta { font-size: 12px; color: var(--muted); }
.rank-scores { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.rank-scores span { display: inline-block; margin-right: 12px; }
.rank-scores b { color: var(--text); }
.rank-note {
  margin-top: 8px; padding: 8px 11px;
  background: var(--surface-2); border-left: 2px solid var(--border);
  border-radius: 0 8px 8px 0;
  font-size: 13px; color: var(--note-text); white-space: pre-wrap;
}
