:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6a717d;
  --border: #dde1e6;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c43c35;
  --ok: #1e8a4c;
  --warn-bg: #fff4d6;
  --warn-border: #e8c768;
  --log-bg: #11151b;
  --log-text: #d6dbe2;
  --selected: #e9f0fc;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1a1e24;
    --text: #e6e9ee;
    --muted: #949ca8;
    --border: #2c323b;
    --accent: #5b8ff0;
    --danger: #e0645d;
    --ok: #4cc17f;
    --warn-bg: #3a3014;
    --warn-border: #7a6420;
    --log-bg: #0b0e12;
    --selected: #20304a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
[hidden] { display: none !important; }

header { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.narrow { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 14px; }
.narrow h1 { text-align: center; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

label { display: flex; gap: 6px; align-items: center; }
.narrow label { display: grid; gap: 4px; }

input[type=password], input:not([type]), input[type=text] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}
#paste-form input { flex: 1 1 260px; }

button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
button.quiet:hover { color: var(--text); }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-weight: 600;
}

#screen {
  width: 100%;
  aspect-ratio: 1280 / 900;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 12px;
}

details { margin-top: 14px; }
summary { cursor: pointer; color: var(--muted); }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 12px 0; padding: 10px 12px; }
legend { padding: 0 4px; color: var(--muted); }
#courses { display: grid; gap: 4px; max-height: 320px; overflow: auto; }
details > label { margin: 6px 0; }

#log {
  background: var(--log-bg);
  color: var(--log-text);
  font: 12.5px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
  padding: 12px;
  border-radius: 6px;
  height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
#progress { min-height: 1.5em; margin-top: 6px; white-space: pre; overflow: hidden; text-overflow: ellipsis; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: var(--selected); }
.status.finished { color: var(--ok); }
.status.failed, .status.interrupted { color: var(--danger); }
.status.running { color: var(--accent); }

h3 { font-size: 14px; margin: 16px 0 6px; }
code { font: 12.5px ui-monospace, "SF Mono", Menlo, monospace; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
#mcp-url { flex: 1 1 320px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
#grants td { border-bottom: 1px solid var(--border); }
#grants tr { cursor: default; }
#grants tbody tr:hover { background: none; }

/* --- navigation ------------------------------------------------------------------------------ */
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--card); color: var(--text); border: 1px solid var(--border); }
a { color: var(--accent); }
a.button {
  display: inline-block; font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); text-decoration: none;
}
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
a.button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
select {
  font: inherit; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); max-width: 100%;
}
input[type=search] {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card); color: var(--text); min-width: 0;
}

/* --- library ---------------------------------------------------------------------------------- */
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.searchbar input { flex: 1 1 280px; }
.searchbar select { flex: 0 1 220px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 14px; color: var(--muted); font-size: 14px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: 0.6; }
#lib-main h2 { margin: 18px 0 10px; }
.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.course {
  display: grid; gap: 6px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text); text-decoration: none;
}
.course:hover { border-color: var(--accent); }
.course .muted { font-size: 13px; }
.recent { list-style: none; margin: 0; padding: 8px 16px; }
.recent li { padding: 6px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.recent li:last-child { border-bottom: none; }
.recent .muted { font-size: 13px; }
.empty { text-align: center; padding: 28px 16px; }
.overview summary { font-weight: 600; color: var(--text); }
.overview .md { margin-top: 10px; }
table.files td { white-space: normal; overflow-wrap: anywhere; }
table.files td.type, table.files td.size { white-space: nowrap; width: 1%; }
table.files tbody tr { cursor: default; }
table.files tbody tr:hover { background: var(--selected); }
.note-flag { color: var(--accent); }
.badge {
  display: inline-block; font-size: 12px; padding: 2px 7px; border-radius: 999px;
  background: var(--selected); color: var(--text); white-space: nowrap;
}
.badge.kind-folder { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.badge.kind-note { background: var(--warn-bg); }
.loc { font-size: 13px; color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.results { display: grid; gap: 10px; }
.result { display: block; color: var(--text); text-decoration: none; margin: 0; }
.result:hover { border-color: var(--accent); }
.result-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.result-head strong { overflow-wrap: anywhere; }
.result .muted { font-size: 13px; margin-top: 2px; }
.result p { margin: 8px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
mark { background: #ffe58a; color: #1c1f24; border-radius: 2px; padding: 0 1px; }

.md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; }
.md ul { margin: 4px 0; padding-left: 1.2em; }
.md li { margin: 3px 0; overflow-wrap: anywhere; }
.md p { margin: 6px 0; }

/* --- viewer ----------------------------------------------------------------------------------- */
.viewer-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.viewer-head h2 { margin: 0 !important; overflow-wrap: anywhere; }
.viewer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.viewer-layout.wide-side { grid-template-columns: minmax(0, 1fr) 380px; }
@media (max-width: 900px) {
  .viewer-layout, .viewer-layout.wide-side { grid-template-columns: 1fr; }
}
.viewer-main > * + * { margin-top: 12px; }
.doc-frame {
  width: 100%; height: calc(100vh - 210px); min-height: 480px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.hint { margin: 0 0 8px; font-size: 13px; }
.player { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; display: block; }
.streams { margin-top: 8px; }
.summary summary { font-weight: 600; cursor: pointer; }
.transcript { position: relative; max-height: calc(100vh - 260px); min-height: 200px; overflow: auto; font-size: 14px; }
.transcript h4 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.cue { display: grid; grid-template-columns: auto 1fr; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.cue:hover { background: var(--selected); }
.cue.current { background: var(--selected); box-shadow: inset 3px 0 0 var(--accent); }
.cue .stamp { font: 12px ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); padding-top: 2px; }
.notes textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); resize: vertical;
}
.text-view { white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, "SF Mono", Menlo, monospace; max-height: calc(100vh - 220px); overflow: auto; margin: 0; }
.image-view { text-align: center; }
.image-view img { max-width: 100%; height: auto; }

/* --- uploads ---------------------------------------------------------------------------------- */
.dropzone { border-style: dashed; }
.dropzone.dragging { border-color: var(--accent); background: var(--selected); }
.uploads:not(:empty) { margin-top: 10px; display: grid; gap: 6px; }
.upload-row { display: grid; grid-template-columns: minmax(0, 1fr) 160px auto; gap: 10px; align-items: center; font-size: 14px; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row progress { width: 100%; }
.badge.kind-mine { margin-left: 8px; background: transparent; border: 1px solid var(--accent); color: var(--accent); }
table.files td.actions { white-space: nowrap; width: 1%; text-align: right; }
button.small { padding: 3px 8px; font-size: 13px; }

/* --- recordings in modules -------------------------------------------------------------------- */
.lecture-list { list-style: none; margin: 0 0 10px; padding: 0; }
.lecture-list li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--border); }
.lecture-list li:last-child { border-bottom: none; }
.lecture-list a { flex: 1 1 260px; overflow-wrap: anywhere; }
.recordings select { flex: 1 1 260px; }
.small-print { margin: 6px 0 0; font-size: 13px; }
.viewer-side select { width: 100%; }
