/* The page is one full-window terminal (spec 7.3). The client sets the terminal's own colors
   from the chosen theme; these match the default theme so nothing flashes before it starts. */

:root {
  --page-background: #2e3440;
  --page-text: #d8dee9;
  --panel-background: #2e3440;
  --panel-text: #eceff4;
  --panel-border: #88c0d0;
  --accent: #81a1c1;
  --focus-ring: #88c0d0;
  --body-font: system-ui, sans-serif;
  --body-size: 16px;
  --body-leading: 1.5;
  --heading-leading: 1.2;
  --measure: 40rem;
}

@font-face {
  font-family: "FiraCode Nerd Font Mono";
  src: url("fonts/FiraCodeNerdFontMono-Regular.woff2") format("woff2");
  font-weight: normal;
  font-display: block;
}

@font-face {
  font-family: "FiraCode Nerd Font Mono";
  src: url("fonts/FiraCodeNerdFontMono-Bold.woff2") format("woff2");
  font-weight: bold;
  font-display: block;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--page-background);
  color: var(--page-text);
}

/* The skip link is the first focusable element (WCAG 2.4.1). It sits off-screen until it is
   focused, so the terminal keeps the whole window. */
.skip-link {
  position: absolute;
  left: -100vw;
  top: 0;
  z-index: 200;
  padding: 0.75rem 1rem;
  background: var(--panel-background);
  color: var(--panel-text);
  font: var(--body-size)/var(--body-leading) var(--body-font);
  text-decoration: underline;
}

.skip-link:focus {
  left: 0;
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Credits are an ordinary readable page, independent of the terminal and JavaScript. */
.credits-page {
  box-sizing: border-box;
  height: auto;
  min-height: 100%;
  padding: 1rem;
  font: 1rem/1.6 var(--body-font);
  overflow-wrap: anywhere;
}

.credits-page > header,
.credits-page > main,
.credits-page > footer {
  max-width: 68ch;
  margin-inline: auto;
}

.credits-page a {
  color: var(--panel-border);
  text-underline-offset: 0.2em;
}

.credits-page a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

.credits-page h1 {
  font-size: clamp(1.75rem, 1.5rem + 1vw, 2.5rem);
  line-height: var(--heading-leading);
}

.credits-page h2 {
  margin-top: 2rem;
  font-size: 1.3rem;
  line-height: var(--heading-leading);
}

.credits-page dt {
  margin-top: 1rem;
  font-weight: bold;
}

.credits-page dd {
  margin: 0.25rem 0 0;
}

.credits-page nav a,
.credits-page footer a {
  display: inline-block;
  padding-block: 0.75rem;
}

/* Available to a screen reader, absent from the page. The heading names the terminal for a
   reader that never sees the rendered grid. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

#terminal {
  width: 100%;
  height: 100%;
}

/* Screen-reader mode adds xterm.js's live region: a 1px box that xterm's own style moves off-screen
   to the left but leaves where the flow puts it, below the full-height accessibility tree. That is
   1px below the window, so the page gained scrollbars that covered the hint line. Pinned to the top
   of its layer it stays off-screen and the page keeps the window's size. */
#terminal .xterm-accessibility .live-region {
  top: 0;
}

/* The fallback, for a browser without WebAssembly and for one without JavaScript. The
   terminal is hidden in the first case, so this is the whole page; the terminal fills the
   window in the second, so this needs its own space rather than a layer over it. */
#fallback,
#no-script {
  max-width: var(--measure);
  margin: 2rem auto;
  padding: 0 1rem;
  font: var(--body-size)/var(--body-leading) var(--body-font);
}

/* Without JavaScript the terminal never fills, and a terminal that is 100% of the window
   pushes this message below the fold, so a learner without JavaScript sees a blank page.
   The message is the whole page then, so the terminal gives up its height. */
#no-script {
  position: relative;
  z-index: 1;
}

html:has(#no-script) #terminal {
  height: auto;
}

#fallback h2,
#no-script h2 {
  margin-top: 0;
  font-size: 1.2rem;
  line-height: var(--heading-leading);
}

#fallback p,
#no-script p {
  margin: 0;
}

.captcha-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(0 0 0 / 75%);
  font: var(--body-size)/var(--body-leading) var(--body-font);
}

.captcha-panel {
  box-sizing: border-box;
  width: min(100%, 26rem);
  padding: 1.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 0.5rem;
  background: var(--panel-background);
  color: var(--panel-text);
}

.captcha-panel h2 {
  margin-top: 0;
  font-size: 1.2rem;
  line-height: var(--heading-leading);
}

/* A browser's own button style is 13.33px with a 35px height, which is below the 16px body
   size and the 44px target size. The panel's own colors replace the browser's, so the button
   reads the same as the text around it. */
.captcha-panel button {
  margin-top: 1rem;
  min-height: 44px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font: var(--body-size)/var(--body-leading) var(--body-font);
  color: var(--panel-text);
  background: var(--panel-background);
  border: 1px solid var(--panel-border);
  border-radius: 0.25rem;
}

.captcha-panel button:hover {
  background: #3b4252;
}

.captcha-panel button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* The preview host follows the active application palette. The child is unstyled HTML. */
.html-preview {
  box-sizing: border-box;
  width: min(60rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 1rem;
  border: 2px solid var(--panel-border);
  background: var(--panel-background);
  color: var(--panel-text);
  font: 1rem/var(--body-leading) var(--body-font);
}
.html-preview::backdrop { background: rgb(0 0 0 / 65%); }
.html-preview h2 { margin: 0; font-size: clamp(1.3rem, 1.1rem + 1vw, 1.7rem); }
.html-preview-controls { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-block: 0.75rem; }
.html-preview button {
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--panel-border);
  background: var(--panel-background);
  color: var(--panel-text);
  font: inherit;
  cursor: pointer;
}
.html-preview button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
.html-preview iframe { display: block; box-sizing: border-box; width: 100%; height: min(60dvh, 35rem); border: 1px solid var(--panel-border); background: white; }
.html-preview-diagnostics, .html-preview-note { max-width: 70ch; overflow-wrap: anywhere; }
