:root {
  --bg: #eef2f0;
  --panel: #ffffff;
  --ink: #1a2421;
  --muted: #5c6b66;
  --line: #d5ddd9;
  --accent: #0d6b58;
  --accent-soft: #e3f3ef;
  --ok: #1a7f4e;
  --ok-soft: #dff5ea;
  --bad: #b53a2a;
  --bad-soft: #fde8e5;
  --warn: #9a6b12;
  --warn-soft: #faf0dc;
  --shadow: 0 1px 3px rgba(26, 36, 33, 0.06), 0 4px 16px rgba(26, 36, 33, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(165deg, #f3f7f5 0%, #e8efeb 100%);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.88em;
}
kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  background: #fff;
  font-size: 0.75em;
  margin-left: 0.25rem;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
}
.brand-link:hover { text-decoration: none; }
.brand-mark {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  letter-spacing: 0.04em;
}
.brand-text { font-weight: 600; font-size: 0.95rem; }
.top-nav { display: flex; gap: 0.25rem; }
.nav-link {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}
.nav-link:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.top-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.assessor-form {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  background: var(--accent-soft);
  padding: 0.25rem 0.5rem 0.25rem 0.65rem;
  border-radius: 999px;
}
.assessor-form label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.assessor-form select {
  border: none;
  border-radius: 999px;
  padding: 0.3rem 0.5rem;
  background: #fff;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.top-admin { display: flex; gap: 0.4rem; }

.container { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1.5rem 2rem; }

/* ---- Typography & layout ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0 0 0.35rem; font-size: 1.65rem; font-weight: 700; }
.lead { margin: 0; color: var(--muted); max-width: 42rem; }
.page-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.panel-header { margin-bottom: 1rem; }
.panel-header h2 { margin: 0 0 0.2rem; font-size: 1.15rem; }
.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.panel-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.panel-inset {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  min-height: 0;
}
.muted { color: var(--muted); }
.crumb { color: var(--muted); font-size: 0.88rem; }

/* ---- Stats ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem;
}
.stat-card-accent { border-color: #b8ddd4; background: linear-gradient(135deg, #fff, var(--accent-soft)); }
.stat-label { display: block; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat-value { display: block; font-size: 1.75rem; font-weight: 700; margin: 0.25rem 0 0.5rem; }
.stat-of { font-size: 1rem; font-weight: 500; color: var(--muted); }
.stat-meta { font-size: 0.82rem; color: var(--muted); }

.progress-bar {
  height: 8px;
  background: #e4ebe8;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-sm { height: 6px; }
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #14a085);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ---- Assignment cards ---- */
.assignment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}
.assignment-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: #fafcfb;
}
.assignment-card.is-you {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.assignment-card.is-taken {
  border-color: #e6b8b0;
  background: var(--bad-soft);
}
.assignment-claim {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--ink);
}
.assignment-claim.muted { color: var(--muted); }
.assignment-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.pill {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}
.assignment-topics { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.5rem; }
.topic-pill {
  font-size: 0.75rem;
  font-family: "IBM Plex Mono", monospace;
  background: #fff;
  border: 1px solid var(--line);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
}
.topic-pill:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.topic-pill-disabled {
  opacity: 0.55;
  cursor: default;
  background: #f0f3f1;
}
.assignment-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

/* ---- Topic cards (dashboard) ---- */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}
.topic-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1rem;
  background: #fafcfb;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.topic-card:hover { box-shadow: var(--shadow); }
.topic-card.is-mine { border-color: #9ecfc3; }
.topic-card.is-done { border-color: var(--ok); background: var(--ok-soft); }
.topic-card.is-locked {
  border-color: #e6b8b0;
  background: #faf6f5;
  opacity: 0.92;
}
.topic-card-head { display: flex; justify-content: space-between; align-items: center; }
.topic-id { font-size: 0.82rem; background: #e8efeb; padding: 0.15rem 0.4rem; border-radius: 4px; }
.topic-owner { font-size: 0.75rem; color: var(--muted); }
.topic-owner.is-you { color: var(--accent); font-weight: 600; }
.topic-locked-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--bad);
}
.topic-card-title { margin: 0; font-size: 0.95rem; font-weight: 600; line-height: 1.35; }
.topic-card-progress { display: flex; align-items: center; gap: 0.5rem; }
.topic-card-progress .progress-bar { flex: 1; }
.topic-card-pct { font-size: 0.78rem; font-weight: 600; color: var(--muted); min-width: 2.5rem; text-align: right; }
.topic-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.topic-card-stats strong { color: var(--ink); }
.topic-card-actions { display: flex; gap: 0.45rem; margin-top: auto; padding-top: 0.25rem; }
.warn { color: var(--warn); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-weight: 500;
  transition: filter 0.15s, transform 0.1s;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.small { padding: 0.35rem 0.65rem; font-size: 0.88rem; }
.btn.big { padding: 0.85rem 1rem; font-size: 1rem; width: 100%; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok kbd, .btn.bad kbd {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
}
.btn.disabled, .btn:disabled, .btn.loading {
  opacity: 0.5;
  pointer-events: none;
}
.ok { color: var(--ok); }
.bad { color: var(--bad); }

/* ---- Tables (results etc.) ---- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.table th { background: #f0f5f3; font-size: 0.85rem; font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }

.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Browse grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: #e8e0d2;
  display: block;
}
.card-meta { padding: 0.5rem 0.6rem; display: grid; gap: 0.2rem; }
.card.relevant { outline: 2px solid var(--ok); }
.card.not_relevant { outline: 2px solid var(--bad); }
.card.out-of-collection {
  outline: 2px dashed #c9a227;
}
.card.out-of-collection img.missing,
.card.out-of-collection img:not([src]),
.card img.missing {
  object-fit: contain;
  background: #2a2a2a;
  opacity: 0.85;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: #e8efeb;
}
.badge.relevant { background: var(--ok-soft); color: var(--ok); }
.badge.not_relevant { background: var(--bad-soft); color: var(--bad); }
.badge.unjudged { background: var(--warn-soft); color: var(--warn); }
.badge.warn {
  background: #f5ead0;
  color: #8a5a10;
  border: 1px solid #e2c98a;
}

/* ---- Topic guidance ---- */
.guide-block h4 {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.guide-block p { margin: 0 0 0.65rem; font-size: 0.86rem; line-height: 1.45; }
.topic-examples-judge h4, .topic-examples h4 {
  margin: 0.5rem 0 0.4rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.example-grid, .example-grid-judge {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}
.example-card, .example-card-judge {
  margin: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.example-card.relevant, .example-card-judge.relevant { outline: 2px solid var(--ok); }
.example-card.not_relevant, .example-card-judge.not_relevant { outline: 2px solid var(--bad); }
.example-card img, .example-card-judge img {
  width: 100%;
  min-height: 100px;
  max-height: 160px;
  object-fit: cover;
  display: block;
  background: #e8e0d2;
}
.example-card figcaption, .example-card-judge figcaption {
  padding: 0.35rem 0.45rem;
  font-size: 0.75rem;
  display: grid;
  gap: 0.15rem;
}
.example-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* ---- Judge page ---- */
body.judge-page { overflow: hidden; height: 100vh; }
body.judge-page .topbar { padding: 0.45rem 1rem; }
body.judge-page .top-admin { display: none; }
body.judge-page .container {
  max-width: none;
  width: 100%;
  padding: 0.5rem 0.75rem;
  height: calc(100vh - 2.75rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.judge-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.judge-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  box-shadow: var(--shadow);
}
.judge-toolbar-main { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.judge-back {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}
.judge-title { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.judge-title code { background: var(--accent-soft); padding: 0.1rem 0.35rem; border-radius: 4px; }
.judge-title-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  font-weight: 500;
}
.judge-toolbar-progress { min-width: 180px; }
.judge-progress-text { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; }
.judge-filters { margin: 0; }

.judge-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.5fr) minmax(240px, 0.8fr);
  gap: 0.5rem;
  align-items: stretch;
}
.judge-guidance { overflow: auto; }
.judge-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.judge-image-wrap {
  flex: 1;
  min-height: 0;
  background: #0f1412;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.judge-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.judge-image-id { margin: 0.35rem 0 0; font-size: 0.78rem; text-align: center; }
.judge-image-id code { word-break: break-all; color: var(--muted); }

.judge-side {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  overflow: auto;
}
.judge-side-actions { flex-shrink: 0; }
.judge-buttons { display: grid; gap: 0.45rem; }
.judge-buttons-primary { grid-template-columns: 1fr 1fr; }
.judge-buttons-secondary { grid-template-columns: 1fr 1fr 1fr; margin-top: 0.35rem; }
.judge-btn {
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 0.5rem;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
}
.judge-btn-icon { font-size: 1.35rem; line-height: 1; display: block; }
.judge-btn kbd { margin: 0; font-size: 0.7rem; }
.judge-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  background: #f4f8f6;
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
}
.judge-meta summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.25rem 0;
}
.run-list {
  max-height: 6rem;
  overflow: auto;
  margin: 0.35rem 0;
  padding-left: 1.1rem;
  font-size: 0.82rem;
}
.missing-box { color: #ccc; text-align: center; padding: 2rem; }

.empty-state { text-align: center; padding: 2rem; }
.empty-state .btn { margin: 0.5rem 0.35rem; }

/* ---- Start / login ---- */
.start-panel { max-width: 520px; margin: 2rem auto; }
.start-panel h1 { margin: 0 0 0.35rem; }
.start-error {
  background: var(--bad-soft);
  color: var(--bad);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  margin: 0 0 1rem;
}
.start-form { display: grid; gap: 0.85rem; margin-top: 1.25rem; }
.form-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--muted);
}
.form-field input,
.form-field select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  background: #fff;
}
.mode-fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin: 0;
  background: #fafcfb;
}
.mode-fieldset legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.35rem;
}
.btn-start { width: 100%; margin-top: 0.5rem; }
.organiser-login {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.organiser-login summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.organiser-form { margin-top: 0.75rem; }

.group-status { margin: 1.25rem 0; }
.group-status h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.group-status-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.group-status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafcfb;
}
.group-status-item.is-taken {
  border-color: #e6b8b0;
  background: var(--bad-soft);
}
.group-status-item.is-free {
  border-color: #b8d9c8;
  background: var(--ok-soft);
}
.group-status-item.is-yours {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.group-taken { display: block; font-size: 0.82rem; color: var(--bad); margin-top: 0.15rem; }
.group-free { display: block; font-size: 0.82rem; color: var(--ok); margin-top: 0.15rem; }
.taken-pill { background: var(--bad); }
.free-pill { background: var(--ok); }
.small-help { margin: 0.35rem 0 0; font-size: 0.8rem; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
}
.user-group { font-size: 0.78rem; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--ink);
  color: #fff;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 200;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--bad); }
.toast-info { background: var(--muted); }

.flash-ok { animation: flash 0.4s ease; }
@keyframes flash {
  from { box-shadow: 0 0 0 0 rgba(26, 127, 78, 0.5); }
  to { box-shadow: 0 0 0 10px rgba(26, 127, 78, 0); }
}

/* ---- Legacy compat ---- */
.hero, .topic-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  body.judge-page .judge-layout {
    grid-template-columns: minmax(220px, 0.85fr) minmax(0, 1.3fr) minmax(210px, 0.75fr);
  }
}

@media (max-width: 900px) {
  body.judge-page { overflow: auto; height: auto; }
  body.judge-page .container { height: auto; }
  .judge-toolbar { grid-template-columns: 1fr; }
  body.judge-page .judge-layout {
    grid-template-columns: 1fr;
  }
  .judge-image-wrap { min-height: 45vh; }
  .example-grid-judge { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .top-nav { display: none; }
}
