:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --sidebar: #ececef;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #d9d9de;
  --accent: #1f6fe0;
  --accent-text: #ffffff;
  --accent-soft: #dce9fb;
  --green: #1f9d55;
  --green-soft: #ddf3e6;
  --orange: #c26a00;
  --orange-soft: #fbecd7;
  --red: #c62828;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e20;
    --panel: #2a2a2d;
    --sidebar: #252528;
    --text: #f2f2f4;
    --muted: #a1a1a6;
    --border: #3d3d42;
    --accent: #4b8ff0;
    --accent-soft: #23395a;
    --green: #4cc27e;
    --green-soft: #1f3a2a;
    --orange: #f0a443;
    --orange-soft: #3d2e17;
    --red: #ff6b6b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
#app { display: flex; height: 100vh; }

/* Sidebar */
#sidebar {
  width: 240px; flex: none; display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--border); padding: 14px 10px 10px;
}
.side-title { font-weight: 600; font-size: 15px; padding: 2px 8px 12px; display: flex; align-items: center; gap: 8px; }
.side-title img { width: 22px; height: 22px; }
.side-label { font-size: 11px; font-weight: 600; color: var(--muted); padding: 10px 8px 4px; text-transform: uppercase; letter-spacing: .04em; }
.side-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 6px 8px; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; cursor: pointer;
}
.side-item:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.side-item.selected { background: var(--accent-soft); color: var(--accent); }
.side-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item.muted { color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot.on { background: var(--green); } .dot.paused { background: var(--orange); } .dot.off { background: var(--red); }
.side-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 10px 6px 0; display: flex; flex-direction: column; gap: 8px; }
.status-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status-line .grow { flex: 1; }
.icon { width: 16px; height: 16px; flex: none; }

/* Main */
#main { flex: 1; overflow: auto; }
.page { max-width: 860px; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 650; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 99px; vertical-align: 3px; margin-left: 8px; }
.badge.on { background: var(--green-soft); color: var(--green); }
.badge.paused { background: var(--orange-soft); color: var(--orange); }
.badge.off { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.click { cursor: pointer; }
.row.click:hover .grow { color: var(--accent); }
.students { padding: 0 0 8px 26px; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 16px; }
.students div { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }
.roster-names { line-height: 1.7; }
.log-row { display: flex; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.log-row:first-child { border-top: 0; }
.log-row .msg { flex: 1; min-width: 0; }
.log-row .msg div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
  background: var(--orange-soft); color: var(--orange); font-weight: 500; }
.banner.error { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.banner .grow { flex: 1; }
.empty { text-align: center; padding: 80px 20px; }
.empty h1 { font-size: 20px; font-weight: 600; margin: 12px 0 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 18px; }

/* Controls */
button.btn {
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); white-space: nowrap;
}
button.btn:hover { border-color: color-mix(in srgb, var(--text) 30%, var(--border)); }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.btn.danger { color: var(--red); }
button.btn:disabled { opacity: .45; cursor: default; }
button.btn.small { font-size: 12px; padding: 3px 9px; }
button.link { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
input[type=text], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.preview { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; padding: 10px 12px; background: var(--bg); border-radius: 7px; word-break: break-all; }
.error-text { color: var(--red); font-size: 13px; }
.check { display: flex; gap: 8px; align-items: flex-start; }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text);
  width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.3); }
.dlg { padding: 20px 22px; }
.dlg h2 { font-size: 16px; margin: 0 0 10px; }
.dlg p { margin: 0 0 12px; }
.dlg .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; align-items: center; }
.dlg .buttons .left { margin-right: auto; color: var(--muted); font-size: 13px; }
.dlg pre { white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 10px; border-radius: 7px; max-height: 180px; overflow: auto; margin: 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  #app { flex-direction: column; height: auto; min-height: 100vh; }
  #sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .page { padding: 20px 16px 40px; }
  .page-head { flex-wrap: wrap; }
}

/* Assignment review & graded matching */
.page.wide { max-width: 1120px; }
.card.hint { color: var(--muted); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 4px 0 8px; }
.seg { font: inherit; font-size: 13px; padding: 5px 12px; border: 0; background: var(--panel); color: var(--text); cursor: pointer; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg.on { background: var(--accent); color: var(--accent-text); }
.student-h { font-size: 15px; margin: 22px 0 8px; }
.pairs { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.pair:hover { border-color: var(--accent); }
figure { margin: 0; min-width: 0; }
figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--bg); border-radius: 6px; }
.thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--border); background: none; }
.thumb.placeholder.big { aspect-ratio: auto; height: 60vh; }
.match-row { display: grid; grid-template-columns: 200px 200px 1fr; gap: 14px; align-items: start; padding: 12px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.match-info { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.match-info select { max-width: 100%; }
.chip { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; }
.chip.ok { background: var(--green-soft); color: var(--green); }
.chip.warn { background: var(--orange-soft); color: var(--orange); }
.chip.none { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.match-footer { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 0;
  background: linear-gradient(transparent, var(--bg) 30%); }
.match-footer span { margin-right: auto; }
dialog.wide { width: min(1200px, calc(100vw - 32px)); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.compare img { width: 100%; max-height: 70vh; object-fit: contain; background: var(--bg); border-radius: 6px; }
@media (max-width: 700px) {
  .match-row { grid-template-columns: 1fr 1fr; }
  .match-info { grid-column: 1 / -1; }
  .compare { grid-template-columns: 1fr; }
}
