:root {
  --bg: #faf8f5;
  --card: #fff;
  --text: #22201c;
  --muted: #8a847a;
  --line: #e8e3dc;
  --accent: #d9822b;
  --danger: #c0392b;
  --ok: #2e8b57;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --card: #211f24;
    --text: #ece8e2;
    --muted: #8f8a84;
    --line: #34313a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.logo { font-weight: 700; font-size: 20px; letter-spacing: -.3px; }
.gear { font-size: 20px; color: var(--muted); }
.gear:hover { color: var(--text); }

main { padding: 24px 24px 64px; }
h1 { font-size: 24px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* course tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile .name { font-weight: 600; }
.tile { position: relative; }
.tile .more {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.tile .more:hover { background: var(--bg); color: var(--text); }
.tile .menu {
  position: absolute;
  top: 40px;
  right: 8px;
  z-index: 1;
  min-width: 140px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.tile .menu button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.tile .menu button:hover { background: var(--bg); }
.shelf { margin-top: 32px; }
.shelf summary { color: var(--muted); cursor: pointer; margin-bottom: 14px; font-size: 14px; }
.shelf .tile { opacity: .7; }

/* tabs */
.back { display: inline-block; color: var(--muted); margin-bottom: 10px; }
.back:hover { color: var(--text); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0; }
.tabs a {
  padding: 8px 14px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  margin-bottom: -1px;
}
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.pills { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.pills a {
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}
.pills .upload {
  margin-left: auto;
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.pills .upload:hover { color: var(--accent); border-color: var(--accent); }
.pills a.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* file list */
.files { list-style: none; padding: 0; margin: 0; }
.files li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.files li:hover { background: var(--card); }
.files .icon { width: 22px; text-align: center; }
.files .dl {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
}
.files .dl:hover { background: var(--bg); color: var(--accent); }
.course-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.files .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#new { margin-bottom: 12px; }

/* editor */
.editor { display: flex; flex-direction: column; height: 100%; padding: 16px 24px; gap: 10px; }
.editor-bar { display: flex; gap: 10px; }
.editor-bar input { flex: 1; }
.editor-bar select { width: auto; }
.editor textarea {
  flex: 1;
  resize: none;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font: 14px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
}
.editor textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* info */
.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 14px;
}
.note h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md :first-child { margin-top: 0; }
.md :last-child { margin-bottom: 0; }
.md pre, .md code { background: var(--bg); border-radius: 4px; }
.md pre { padding: 12px; overflow: auto; }
.md code { padding: 1px 4px; font-size: .92em; }
.md pre code { padding: 0; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; }
.md img { max-width: 100%; }

/* viewer modal */
dialog#viewer {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
  flex-direction: column;
}
dialog#viewer[open] { display: flex; }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.viewer-bar strong { flex: 1; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar a, .viewer-bar .link { color: var(--accent); font-size: 14px; }
[hidden] { display: none !important; }
.viewer-bar button { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
#viewer-body { flex: 1; overflow: auto; }
#viewer-body iframe { width: 100%; height: 100%; border: 0; display: block; }
#viewer-body > img { display: block; max-width: 100%; margin: 24px auto; }
#viewer-body > .md, #viewer-body > pre { margin: 0; padding: 24px; }
#viewer-body > pre { white-space: pre-wrap; font-size: 14px; }

/* settings */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }
form.grid { display: grid; gap: 10px; max-width: 420px; }
input, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  justify-self: start;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: none; color: var(--muted); border: 1px solid var(--line); }
.copy {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.copy { align-items: flex-start; }
.copy pre {
  flex: 1;
  margin: 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 12px;
  max-height: 220px;
  overflow: auto;
}
.copy code {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 13px;
  overflow-x: auto;
  white-space: nowrap;
}
.err { color: var(--danger); font-size: 14px; margin: 0; }
.err:empty { display: none; }

/* login */
.login { max-width: 300px; margin: 15vh auto 0; text-align: center; }
.login form { display: grid; gap: 10px; margin-top: 20px; }
.login .btn { justify-self: stretch; }

.card h2 .link {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}
#general-form { padding: 0; height: auto; }
#general-form textarea { min-height: 300px; }
