@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("fonts/manrope-latin-wght-normal.woff2") format("woff2");
}

/* Tokens. Every margin, padding and gap uses the --s scale so spacing stays consistent. */
:root {
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;
  --r: 8px;

  --fs-s: 0.8125rem;
  --fs-b: 0.9375rem;
  --fs-m: 1rem;
  --fs-l: 1.25rem;
  --fs-xl: 1.75rem;

  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f3f6fc;
  --surface: #ffffff;
  --field: #ffffff;
  --ink: #0c1a33;
  --muted: #4f607c;
  --line: #d6dfef;
  --blue: #1e4fd8;
  --blue-hover: #173fb0;
  --blue-ink: #ffffff;
  --danger: #b42318;

  --brand: #0a2463;
  --brand-ink: #ffffff;
  --brand-muted: #b9c8ee;
  --navy: #0a2463;
  --navy-active: #17358a;
  --navy-ink: #e6edff;
  --navy-muted: #b9c8ee;
  --navy-line: #24408f;

  --code-bg: #0c1a3d;
  --code-ink: #e6edff;
}

[data-theme="dark"] {
  --bg: #081025;
  --surface: #0f1a35;
  --field: #0b1530;
  --ink: #e7eefc;
  --muted: #9fb1d4;
  --line: #22335e;
  --blue: #6b96ff;
  --blue-hover: #8aacff;
  --blue-ink: #06112a;
  --danger: #ff9a90;

  --brand: #0c1d4f;
  --navy: #050c1e;
  --navy-active: #122456;
  --navy-line: #16265a;

  --code-bg: #050c1e;
}

/* Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-m);
  line-height: 1.6;
  overflow-wrap: break-word;
}

body.lock {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--fs-xl);
  font-weight: 800;
}

h2 {
  font-size: var(--fs-l);
  font-weight: 700;
}

h3 {
  font-size: var(--fs-m);
  font-weight: 700;
}

p {
  margin: 0;
}

a {
  color: var(--blue);
}

img,
svg {
  max-width: 100%;
}

code,
pre,
.mono {
  font-family: var(--mono);
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.grow {
  flex: 1 1 14rem;
  min-width: 0;
}

/* Layout shell */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: inherit;
  font-size: var(--fs-l);
  font-weight: 800;
  letter-spacing: -0.01em;
  text-decoration: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--s5);
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--blue);
  color: var(--blue-ink);
  font: inherit;
  font-size: var(--fs-b);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: var(--blue-hover);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn.secondary:hover {
  background: var(--bg);
}

.btn.text {
  background: transparent;
  color: var(--blue);
  padding: 0 var(--s3);
}

.btn.text:hover {
  background: transparent;
  text-decoration: underline;
}

.btn.block {
  width: 100%;
}

.btn.small {
  min-height: 36px;
  padding: 0 var(--s3);
  font-size: var(--fs-s);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

/* Forms */
.field {
  display: grid;
  gap: var(--s2);
  margin-bottom: var(--s4);
  min-width: 0;
}

label,
.label {
  font-size: var(--fs-b);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

textarea {
  min-height: 120px;
  line-height: 1.5;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: 0;
  border-color: var(--blue);
}

.hint {
  color: var(--muted);
  font-size: var(--fs-s);
}

.pw {
  position: relative;
}

.pw input {
  padding-right: 72px;
}

.pw-toggle {
  position: absolute;
  top: var(--s1);
  right: var(--s1);
  bottom: var(--s1);
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: var(--fs-b);
  font-weight: 600;
  cursor: pointer;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s4);
  font-weight: 600;
}

.check input {
  width: 20px;
  min-height: 20px;
  height: 20px;
  padding: 0;
  accent-color: var(--blue);
}

.form-msg {
  min-height: var(--s5);
  margin-bottom: var(--s3);
  font-size: var(--fs-b);
}

.form-msg[data-error="true"] {
  color: var(--danger);
  font-weight: 600;
}

.form-lead {
  margin: var(--s2) 0 var(--s5);
}

.form-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s5);
  font-size: var(--fs-b);
}

.form-links a {
  font-weight: 600;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
}

/* Signed out screen */
.auth {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}

.brand {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--s7);
  min-width: 0;
  padding: var(--s7);
  background: var(--brand);
  color: var(--brand-ink);
}

.brand h1 {
  max-width: 12ch;
  font-size: clamp(2.25rem, 4.5vw, 3.25rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.brand-copy p {
  max-width: 44ch;
  margin-top: var(--s4);
  color: var(--brand-muted);
}

.net {
  width: 100%;
  max-width: 420px;
  height: auto;
}

.net-line {
  stroke: #ffffff;
  stroke-opacity: 0.22;
  stroke-width: 1.5;
}

.net-node {
  fill: #ffffff;
}

.auth-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: var(--s8) var(--s5);
}

.auth-tools {
  position: absolute;
  top: var(--s4);
  right: var(--s4);
}

.auth-box {
  width: 100%;
  max-width: 400px;
}

/* Signed in shell */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: var(--s5) var(--s4);
  background: var(--navy);
  color: var(--navy-ink);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s2);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.nav a {
  display: block;
  padding: var(--s3) var(--s3);
  border-radius: var(--r);
  color: var(--navy-muted);
  font-size: var(--fs-b);
  font-weight: 600;
  text-decoration: none;
}

.nav a:hover {
  color: #ffffff;
}

.nav a[aria-current="page"] {
  background: var(--navy-active);
  color: #ffffff;
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  margin-top: auto;
  padding-top: var(--s4);
  border-top: 1px solid var(--navy-line);
}

.who {
  padding: 0 var(--s3);
  margin-bottom: var(--s2);
  color: var(--navy-muted);
  font-size: var(--fs-s);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-btn {
  padding: var(--s3);
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--navy-ink);
  font: inherit;
  font-size: var(--fs-b);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.side-btn:hover {
  background: var(--navy-active);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(5, 12, 30, 0.6);
}

.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: none;
}

main {
  flex: 1;
  min-width: 0;
  padding: var(--s7) var(--s6) var(--s7);
}

main:focus {
  outline: none;
}

.page {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.page-head {
  margin-bottom: var(--s6);
}

.page-head p {
  margin-top: var(--s2);
  max-width: 60ch;
}

.block {
  margin-bottom: var(--s7);
}

.block > h2 {
  margin-bottom: var(--s4);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

/* Lists as rows */
.rows {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2) var(--s4);
  padding: var(--s4) 0;
  border-bottom: 1px solid var(--line);
}

.row-link {
  color: inherit;
  text-decoration: none;
}

.row-link:hover .row-title {
  color: var(--blue);
}

.row-title {
  font-weight: 700;
}

.row-meta {
  color: var(--muted);
  font-size: var(--fs-b);
}

.panel {
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  min-width: 0;
}

.empty {
  padding: var(--s5) 0;
  color: var(--muted);
}

/* Lesson text */
.prose {
  max-width: 70ch;
}

.prose > * + * {
  margin-top: var(--s4);
}

.prose h2 {
  margin-top: var(--s6);
}

.prose h3 {
  margin-top: var(--s5);
}

.prose ul,
.prose ol {
  margin: 0;
  padding-left: var(--s5);
}

.prose li + li {
  margin-top: var(--s2);
}

.prose code {
  padding: 0 var(--s1);
  border-radius: 4px;
  background: var(--line);
  font-size: 0.9em;
}

.prose pre {
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  overflow-x: auto;
  padding: var(--s4);
  border-radius: var(--r);
  background: var(--code-bg);
  color: var(--code-ink);
  font-size: var(--fs-b);
  line-height: 1.6;
  tab-size: 2;
}

.prose pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s3);
  max-width: 70ch;
  margin-top: var(--s7);
  padding-top: var(--s5);
  border-top: 1px solid var(--line);
}

/* Problem page */
.problem {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: var(--s6);
  align-items: start;
}

.problem-side,
.problem-work {
  min-width: 0;
}

.editor {
  display: block;
  width: 100%;
  min-height: 320px;
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: var(--mono);
  font-size: var(--fs-b);
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  resize: vertical;
}

.editor-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin: var(--s3) 0 var(--s5);
}

.feedback {
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}

.feedback:focus {
  outline: none;
}

.feedback > p {
  margin-top: var(--s2);
}

.err {
  color: var(--danger);
  font-weight: 600;
}

.results {
  margin: var(--s4) 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.result {
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}

.result-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s2) var(--s4);
}

.result-head span {
  color: var(--muted);
}

.result-head span.fail {
  color: var(--ink);
  font-weight: 800;
}

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--s1) var(--s4);
  margin: var(--s3) 0 0;
  font-size: var(--fs-b);
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  overflow-x: auto;
  font-family: var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console {
  margin-top: var(--s4);
}

.console pre {
  margin: var(--s2) 0 0;
  max-width: 100%;
  overflow-x: auto;
  padding: var(--s3);
  border-radius: var(--r);
  background: var(--code-bg);
  color: var(--code-ink);
  font-size: var(--fs-s);
}

/* Circuit simulator */
.sim {
  margin: var(--s5) 0;
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
}

.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--s4);
}

.sim-controls .field {
  width: 9rem;
}

.sim-out {
  min-height: var(--s7);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.sim-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-b);
  font-variant-numeric: tabular-nums;
}

.sim-table th,
.sim-table td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.sim-table thead th {
  color: var(--muted);
  font-weight: 600;
}

.sim-note {
  margin-top: var(--s3);
}

.sim-edit,
.sim-help {
  margin-top: var(--s4);
}

.sim-edit summary,
.sim-help summary {
  min-height: 44px;
  padding: var(--s3) 0;
  font-weight: 600;
  cursor: pointer;
}

.sim-edit .editor {
  min-height: 140px;
  margin-bottom: var(--s3);
}

.sim-help ul {
  margin: var(--s2) 0;
  padding-left: var(--s5);
}

.sim-help p + ul,
.sim-help ul + p {
  margin-top: var(--s2);
}

.sim-help code {
  padding: 0 var(--s1);
  border-radius: 4px;
  background: var(--line);
}

.sim-title {
  margin-top: var(--s5);
}

/* Tabs (channels, admin) */
.tabs {
  display: flex;
  gap: var(--s2);
  margin-bottom: var(--s5);
  overflow-x: auto;
  padding-bottom: var(--s1);
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-b);
  font-weight: 600;
  text-decoration: none;
}

.tab:hover {
  background: var(--surface);
}

.tab[aria-current="page"] {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--blue-ink);
}

/* Hub chat */
.chat {
  display: flex;
  flex-direction: column;
  height: min(68vh, 640px);
  height: min(68dvh, 640px);
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}

.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  min-height: 0;
  padding: var(--s4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.msg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s1) var(--s3);
}

.msg-head time {
  color: var(--muted);
  font-size: var(--fs-s);
}

.msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.linklike {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-s);
  text-decoration: underline;
  cursor: pointer;
}

.chat-form {
  display: flex;
  gap: var(--s2);
  padding: var(--s3);
  border-top: 1px solid var(--line);
}

.chat-form input {
  flex: 1;
}

/* Admin */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--s4);
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.code-area {
  font-family: var(--mono);
  font-size: var(--fs-b);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.admin-note {
  min-height: var(--s5);
  margin-bottom: var(--s3);
  font-weight: 600;
}

.link-out {
  margin-top: var(--s4);
}

/* Footer */
.site-footer {
  padding: var(--s6) var(--s6);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s5);
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.copyright {
  color: var(--muted);
  font-size: var(--fs-b);
}

.contact {
  font-size: var(--fs-b);
}

.contact-title {
  font-weight: 800;
}

/* Tablet and phone */
@media (max-width: 900px) {
  .auth {
    grid-template-columns: minmax(0, 1fr);
  }

  .brand {
    gap: var(--s5);
    padding: var(--s5) var(--s4) var(--s6);
  }

  .brand h1 {
    max-width: none;
    font-size: clamp(2rem, 9vw, 2.5rem);
  }

  .net {
    display: none;
  }

  .auth-panel {
    align-items: flex-start;
    padding: var(--s6) var(--s4) var(--s7);
  }

  .auth-tools {
    top: var(--s2);
    right: var(--s2);
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }

  .sidebar.open {
    transform: none;
    visibility: visible;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s2) var(--s4);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .topbar-title {
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  main {
    padding: var(--s5) var(--s4) var(--s6);
  }

  .problem {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s5);
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .site-footer {
    padding: var(--s5) var(--s4);
  }
}

@media (min-width: 901px) {
  .only-mobile {
    display: none;
  }
}

@media (max-width: 480px) {
  .kv {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .kv dd {
    margin-bottom: var(--s2);
  }

  .btn {
    padding: 0 var(--s4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
