:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel-2: #0f1526;
  --line: #24304e;
  --text: #e6ecf7;
  --muted: #8ea0c4;
  --accent: #56d3ff;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  min-height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand span { color: var(--accent); }

.brand small {
  color: var(--muted);
  font-weight: 500;
  margin-left: 0.35rem;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.you strong { color: inherit; }

.ghost-button {
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.ghost-button:hover { border-color: var(--accent); color: var(--accent); }
.ghost-button.has-error { border-color: #ff6b6b; color: #ff6b6b; }

.field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

select {
  font: inherit;
  font-size: 0.82rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.3rem 0.45rem;
}

.countdown {
  font-variant-numeric: tabular-nums;
  min-width: 2.6rem;
  text-align: center;
}

.countdown.ticking { color: var(--accent); }

/* ---------- connection status ---------- */

.status { display: inline-flex; align-items: center; gap: 0.4rem; }

.status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff9f43;
}

.connected .status i { background: #3ddc84; }
.connected .status-text::after { content: 'live'; }
.connected .status-text { font-size: 0; }
.connected .status-text::after { font-size: 0.85rem; }

/* ---------- editor page ---------- */

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.tabs { display: flex; gap: 0.25rem; }

.tab {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--accent);
}

#editor-pane {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

#editor { height: 100%; }
.cm-editor { height: 100%; }

#pointers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.pointer {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: flex-start;
  gap: 2px;
  transition: transform 90ms linear;
  will-change: transform;
}

.pointer svg { fill: currentColor; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5)); }

.pointer span {
  font-size: 11px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  color: #06121f;
  font-weight: 600;
  white-space: nowrap;
  transform: translateY(6px);
}

aside {
  flex: 0 0 300px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem;
  overflow-y: auto;
}

aside section + section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

aside h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

aside h2 span {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  margin-left: 0.25rem;
}

#peers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
}

#peers li { display: flex; align-items: center; gap: 0.45rem; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.peer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.peer-file {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.7rem;
}

.hint {
  margin-top: 1.25rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 0.3em;
  font-size: 0.9em;
}

/* ---------- live view page ---------- */

.view-page main { flex-direction: column; }

.stage-row {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.view-page #task {
  flex: 0 0 320px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem;
  overflow-y: auto;
}

.view-page #task[hidden] { display: none; }

#stage {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  background: #fff;
}

/* `display: flex` would otherwise beat the [hidden] attribute. */
#console[hidden] { display: none; }

#console {
  flex: 0 0 34%;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

#console-lines {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

#console-lines li {
  display: flex;
  gap: 0.75rem;
  padding: 0.2rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: pre-wrap;
  word-break: break-word;
}

#console-lines time { color: var(--muted); flex: 0 0 auto; }
#console-lines .error span { color: #ff8585; }
#console-lines .warn span { color: #ffce6b; }

/* ---------- locked files ---------- */

.tab.locked { color: var(--muted); }
.tab.locked.active { color: var(--accent); }

.banner {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  background: #3a2a12;
  color: #ffce6b;
  border-bottom: 1px solid var(--line);
}

/* The lock controls belong to the teacher; everyone else never sees them. */
#teacher-panel { display: none; }
body.teacher #teacher-panel { display: block; }

.locks {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.lock-toggle {
  font: inherit;
  font-size: 0.82rem;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.lock-toggle:hover { border-color: var(--accent); }

.lock-state {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lock-toggle.on {
  border-color: #ffce6b;
  color: #ffce6b;
}

.lock-toggle.on .lock-state { color: #ffce6b; }

/* ---------- the task panel ---------- */

#task-body {
  font-size: 0.85rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

#task-body > :first-child { margin-top: 0; }
#task-body > :last-child { margin-bottom: 0; }

#task-body h1 { font-size: 1.05rem; }
#task-body h2 { font-size: 0.95rem; }
#task-body h3 { font-size: 0.88rem; }

#task-body h1,
#task-body h2,
#task-body h3 {
  margin: 1.1em 0 0.4em;
  line-height: 1.25;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
}

#task-body ul,
#task-body ol { padding-left: 1.2em; }

#task-body li { margin: 0.2em 0; }

#task-body code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 0.3em;
  font-size: 0.9em;
}

#task-body pre {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.6rem;
  overflow-x: auto;
}

#task-body pre code { border: 0; padding: 0; background: none; }

#task-body blockquote {
  margin: 0.8em 0;
  padding-left: 0.8em;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

#task-body a { color: var(--accent); }
#task-body .empty { color: var(--muted); }

/* ---------- teacher login ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 1.25rem;
  width: min(320px, 90vw);
}

dialog::backdrop { background: rgba(4, 8, 18, 0.6); }

dialog h2 {
  margin: 0;
  font-size: 1rem;
}

dialog .hint { margin: 0.4rem 0 0.9rem; }

#password {
  font: inherit;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.error {
  margin: 0.5rem 0 0;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: #ff8585;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.ghost-button.primary {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- reset ---------- */

.danger-heading { margin-top: 1.5rem; }

.ghost-button.danger { border-color: #7f3b3b; color: #ff8585; }
.ghost-button.danger:hover { border-color: #ff8585; color: #ff8585; }

#teacher-panel .hint { margin-top: 0.5rem; }

.reset-notice {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  background: rgba(6, 10, 22, 0.92);
  z-index: 10;
  font-size: 1rem;
  line-height: 1.6;
}

.reset-notice[hidden] { display: none; }
