:root {
  --bg: #0a0d12;
  --bg-2: #0f141c;
  --panel: #131a24;
  --panel-2: #182230;
  --line: #22303f;
  --text: #e8eef6;
  --muted: #8fa1b5;
  --dim: #64748b;
  --accent: #3fd0e0;
  --accent-2: #7c5cff;
  --amber: #f6ad55;
  --green: #45d483;
  --red: #f2617a;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

/* the UA rule [hidden]{display:none} loses to any explicit display rule below,
   which silently showed the nav and the user chip on the signed-out screens */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(63, 208, 224, .10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(124, 92, 255, .10), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ---------------------------------------------------------------- topbar */
#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 18, .82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: 17px;
}
.brand .dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(63, 208, 224, .16), 0 0 18px rgba(63, 208, 224, .8);
}
.brand small { color: var(--dim); font-weight: 500; font-size: 12px; margin-left: 2px; }
nav { display: flex; gap: 4px; margin-left: 8px; }
nav a {
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 14px;
  text-decoration: none;
}
nav a:hover { color: var(--text); background: var(--panel); }
nav a.active { color: #0a0d12; background: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.userchip {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--muted);
  white-space: nowrap;
}
input[type="checkbox"] {
  width: 16px; height: 16px; min-width: 16px;
  accent-color: var(--accent);
  padding: 0;
}
@media (max-width: 560px) {
  #topbar { gap: 10px; padding: 10px 14px; }
  nav a { padding: 6px 9px; font-size: 13px; }
  #username { display: none; }
  .brand small { display: none; }
  main { padding: 18px 14px 60px; }
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #061016; font-weight: 700; font-size: 12px;
}

/* ------------------------------------------------------------------ shell */
main { max-width: 1180px; margin: 0 auto; padding: 26px 22px 80px; }
.grid { display: grid; gap: 16px; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12.5px; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ------------------------------------------------------------------ forms */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 6px; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c1118;
  color: var(--text);
  font: inherit;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(63, 208, 224, .13); }
textarea { resize: vertical; min-height: 90px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 15px;
  transition: transform .06s ease, border-color .15s ease, background .15s ease;
}
button:hover { border-color: #2f4053; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121a; font-weight: 650; }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; }
button.danger { border-color: rgba(242, 97, 122, .5); color: var(--red); background: transparent; }
button.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------------- auth */
.auth-wrap { max-width: 430px; margin: 6vh auto 0; }
body.auth-view main { padding: 12px 22px 24px; }
body.auth-view .auth-wrap { margin: 4vh auto 0; }
.auth-wrap .card { padding: 26px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.auth-tabs button { flex: 1; }
.auth-tabs button.primary { background: var(--accent); }

/* -------------------------------------------------------------- dashboard */
.hero {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 18px;
  align-items: stretch;
}
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } }

.hero .kicker {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
.hero h1 { margin: 6px 0 8px; font-size: 24px; }
.hero p { margin: 0 0 14px; color: #c3d0de; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(63, 208, 224, .1);
  border: 1px solid rgba(63, 208, 224, .28);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.pill.amber { background: rgba(246, 173, 85, .1); border-color: rgba(246, 173, 85, .3); color: var(--amber); }
.pill.green { background: rgba(69, 212, 131, .1); border-color: rgba(69, 212, 131, .3); color: var(--green); }

.stat { display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.stat .big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; }
.bar { height: 8px; border-radius: 99px; background: #1b2532; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.week-group { margin-top: 22px; }
.week-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; }
.sessions { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 12px; }
.sess {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px 12px;
  cursor: pointer;
  transition: border-color .15s ease, transform .08s ease;
}
.sess:hover { border-color: #33506a; transform: translateY(-1px); }
.sess.done { border-color: rgba(69, 212, 131, .38); background: linear-gradient(180deg, rgba(69, 212, 131, .07), var(--panel)); }
.sess.today { border-color: rgba(63, 208, 224, .55); box-shadow: 0 0 0 1px rgba(63, 208, 224, .25) inset; }
.sess .n {
  position: absolute; top: 12px; right: 13px;
  font-size: 11.5px; font-weight: 700; color: var(--dim);
}
.sess .blk { font-weight: 650; font-size: 14px; padding-right: 30px; }
.sess .meta { margin-top: 6px; font-size: 12px; color: var(--muted); }
.sess .marks { margin-top: 9px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 10.5px; padding: 2px 7px; border-radius: 6px;
  background: #1a2432; color: var(--muted); border: 1px solid var(--line);
}
.tag.ok { color: var(--green); border-color: rgba(69, 212, 131, .3); }

/* ----------------------------------------------------------------- reader */
.reader {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 980px) { .reader { grid-template-columns: 1fr; } }
.pdfpane {
  background: #0b0f15;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 70vh;
}
#pdfhost { display: flex; flex-direction: column; gap: 10px; padding: 12px; max-height: 78vh; overflow: auto; }
#pdfhost canvas { width: 100%; height: auto; border-radius: 6px; background: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.pdfbar { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 12.5px; color: var(--muted); }

.side { display: grid; gap: 14px; }
.timer { display: flex; align-items: center; gap: 14px; }
.clock { font-size: 30px; font-weight: 750; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.clock.low { color: var(--amber); }

.note { border-left: 2px solid var(--line); padding: 6px 0 6px 12px; margin: 10px 0; font-size: 13px; color: #c3d0de; white-space: pre-wrap; }
.note .when { color: var(--dim); font-size: 11.5px; margin-bottom: 4px; display: block; }

/* ------------------------------------------------------------------ admin */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
tr:hover td { background: rgba(255, 255, 255, .015); }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650; }
.badge.pending { background: rgba(246, 173, 85, .14); color: var(--amber); }
.badge.approved { background: rgba(69, 212, 131, .14); color: var(--green); }
.badge.rejected { background: rgba(242, 97, 122, .14); color: var(--red); }
.badge.admin { background: rgba(124, 92, 255, .16); color: #b7a6ff; }

/* ------------------------------------------------------------------ toast */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all .22s ease; z-index: 90; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: rgba(242, 97, 122, .5); }

.empty { text-align: center; color: var(--dim); padding: 40px 0; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ course switcher */
#coursesel {
  width: auto; min-width: 170px; padding: 7px 10px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; margin-left: 14px;
}
.coursetitle { margin: 0 0 14px; }
.coursetitle h2 { display: inline; margin-right: 10px; }

/* ----------------------------------------------------------------- exercises */
.exchapter { margin-top: 20px; }
.exlist { display: grid; gap: 8px; }
.exitem {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--panel); color: var(--text); text-decoration: none;
}
.exitem:hover { border-color: #33506a; text-decoration: none; }
.exitem.passed { border-color: rgba(69, 212, 131, .4); background: linear-gradient(180deg, rgba(69,212,131,.06), var(--panel)); }
.exname { font-weight: 600; font-size: 14px; }
.exmeta { font-size: 12px; color: var(--muted); }
.exstate { color: var(--green); font-weight: 700; }

.exwrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .exwrap { grid-template-columns: 1fr; } }
.exprompt { position: sticky; top: 78px; }
.prompttext {
  white-space: pre-wrap; background: transparent; color: #cfdae6; padding: 0;
  font-family: inherit; font-size: 13.5px; line-height: 1.65; margin: 10px 0 0;
}
/* Code editor: a transparent textarea over a highlighted <pre>, kept in sync.
   Both layers must share font, padding, line-height and tab-size or the caret
   drifts away from the coloured text. */
.editor {
  position: relative; height: 360px; background: #0a1017;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.editor .hl, .editor .codearea {
  position: absolute; inset: 0; margin: 0; padding: 12px 14px; border: 0;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 13px; line-height: 1.55; letter-spacing: 0; tab-size: 4;
  white-space: pre; word-break: normal; overflow-wrap: normal;
}
.editor .hl { overflow: hidden; color: #e6edf5; pointer-events: none; }
.editor .hl code { font: inherit; background: none; color: inherit; }
.editor .codearea {
  width: 100%; height: 100%; background: transparent; color: transparent;
  caret-color: #7cc4ff; resize: none; outline: none; overflow: auto;
}
.editor .codearea::selection { background: rgba(63, 208, 224, .28); }
@media (max-height: 820px) { .editor { height: 300px; } }

.c-kw  { color: #ff7ab6; }                 /* def if import else … */
.c-bi  { color: #7cc4ff; }                 /* print len range … */
.c-str { color: #9be5a3; }                 /* "text" and 'text' */
.c-num { color: #f6c177; }
.c-com { color: #6f8194; font-style: italic; }
.result { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; font-size: 14px; }
.result.good { background: rgba(69, 212, 131, .1); border: 1px solid rgba(69, 212, 131, .35); color: var(--green); }
.result.bad { background: rgba(242, 97, 122, .08); border: 1px solid rgba(242, 97, 122, .3); color: #ffb3c1; }
.testrow {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 10px;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.testrow .mark { font-weight: 700; width: 14px; }
.testrow.ok .mark { color: var(--green); }
.testrow.bad .mark { color: var(--red); }
.testrow .err { margin-left: auto; color: #ffb3c1; font-size: 12px; font-family: "Cascadia Mono", Consolas, monospace; }
.errbox { margin: 8px 0 0; background: #12161d; padding: 8px 10px; border-radius: 6px; color: #ffd7dd; font-size: 12px; white-space: pre-wrap; }
