/* ==========================================================================
   CodeForge on LockIn: the LockIn bar on top, the account HUD inside it, and
   what a web page needs on top of the desktop layout (the bar above the app,
   a drawer instead of the sidebar on a phone, a lesson that scrolls as one
   page on a phone). CodeForge's own look lives in style.css, unchanged.
   LockIn's shared stylesheet is not loaded here: its .btn and its colour
   names would override CodeForge's, so the bar carries its own copies.
   ========================================================================== */

@font-face {
  font-family: "Archivo";
  src: url("/web/assets/fonts/archivo-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --top-h: 48px;
  /* LockIn: warm black, one flat signal yellow, Archivo */
  --lf-bg: #0c0c0d;
  --lf-line: #26262a;
  --lf-line-strong: #37373c;
  --lf-raised: #1c1c1f;
  --lf-text: #f3f2ee;
  --lf-muted: #a4a4a9;
  --lf-faint: #8a8a90;
  --lf-warn: #ffb020;
  --lf-accent: #ffd60a;
  --lf-accent-hover: #ffe14d;
  --lf-ink: #121212;
  --lf-font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
:root[data-theme="light"] {
  --lf-bg: #ffffff;
  --lf-line: #e5e5e5;
  --lf-line-strong: #d0d0d0;
  --lf-raised: #f1f2f4;
  --lf-text: #1b1f27;
  --lf-muted: #4b5260;
  --lf-faint: #5f6673;
  --lf-warn: #885800;
}

/* the bar takes its height off the top; the app fills the rest */
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.app { flex: 1; min-height: 0; height: auto; }

/* ---------------------------------------------------------------- bar */

.lf-top {
  flex: none; position: relative; z-index: 130;
  height: var(--top-h); display: flex; align-items: center; gap: 6px;
  padding: 0 14px 0 8px;
  background: var(--lf-bg); border-bottom: 1px solid var(--lf-line);
  font-family: var(--lf-font); font-size: 13px; color: var(--lf-text);
  -webkit-font-smoothing: antialiased;
}
.lf-top .ico { width: 16px; height: 16px; }
.lf-back {
  display: inline-flex; align-items: center; gap: 3px; height: 32px; padding: 0 9px 0 5px;
  border-radius: 4px; color: var(--lf-muted); font-weight: 650; text-decoration: none; white-space: nowrap;
}
.lf-back:hover { color: var(--lf-text); background: var(--lf-raised); }
.lf-sep { width: 1px; height: 22px; background: var(--lf-line); margin: 0 8px 0 2px; flex: none; }
.lf-brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; color: var(--lf-text); }
.lf-logo { width: 24px; height: 24px; flex: none; }
.lf-word {
  font-stretch: 62%; font-weight: 900; font-size: 22px; line-height: 1;
  letter-spacing: .4px; text-transform: uppercase; white-space: nowrap;
}
.lf-grow { flex: 1; min-width: 0; }
.lf-sync { color: var(--lf-faint); font-size: 12px; font-weight: 600; white-space: nowrap; margin-right: 10px; }
.lf-sync[data-state="error"], .lf-sync[data-state="offline"], .lf-sync[data-state="too-big"] { color: var(--lf-warn); }
.lf-menu {
  display: none; place-items: center; width: 36px; height: 36px; flex: none;
  background: none; border: 0; border-radius: 4px; color: var(--lf-text); cursor: pointer;
}
.lf-menu .ico { width: 19px; height: 19px; }
.lf-menu:hover, .lf-menu[aria-expanded="true"] { background: var(--lf-raised); }
.lf-top a:focus-visible, .lf-menu:focus-visible { outline: 2px solid var(--lf-accent); outline-offset: 1px; }

/* the Sparks HUD that /web/assets/lockin.js draws into #lockin-hud */
#lockin-hud { display: inline-flex; align-items: center; min-height: 28px; }
.lf-top .li-hud { display: inline-flex; align-items: center; gap: 10px; }
.lf-top .li-sparks {
  display: inline-flex; align-items: center; gap: 6px; height: 28px;
  background: var(--lf-accent); color: var(--lf-ink); border-radius: 4px; padding: 0 10px 0 8px;
  font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; line-height: 1;
}
.lf-top .li-sparks svg { width: 14px; height: 14px; fill: currentColor; stroke: none; display: block; }
.lf-top .li-sparks.bump { animation: li-bump .4s ease; }
@keyframes li-bump { 30% { transform: scale(1.12); } }
.lf-top .li-user { display: inline-flex; align-items: center; gap: 8px; color: var(--lf-text); font-weight: 650; text-decoration: none; }
.lf-top .li-user:hover { color: var(--lf-accent); }
:root[data-theme="light"] .lf-top .li-user:hover { color: var(--lf-text); }
.lf-top .li-avatar {
  width: 28px; height: 28px; border-radius: 4px; background: var(--lf-raised); border: 1px solid var(--lf-line-strong);
  display: grid; place-items: center; font-size: 13px; font-weight: 800; text-transform: uppercase; color: var(--lf-text);
}
.lf-top .li-user:hover .li-avatar { border-color: var(--lf-accent); }
.lf-top .li-login {
  display: inline-flex; align-items: center; height: 30px; padding: 0 13px; border-radius: 4px;
  background: var(--lf-accent); color: var(--lf-ink); font-weight: 800; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .6px; font-stretch: 87%; text-decoration: none; white-space: nowrap;
}
.lf-top .li-login:hover { background: var(--lf-accent-hover); }
/* the Messages link lockin.js adds: its own style reads --accent and --text, which mean something else in
   CodeForge (the chapter colour), so the bar pins LockIn's colours */
.lf-top .li-msg { color: var(--lf-muted); }
.lf-top .li-msg:hover { background: var(--lf-raised); color: var(--lf-text); }
.lf-top .li-msg-n { background: var(--lf-accent); color: var(--lf-ink); }

#li-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 8px); z-index: 1000;
  max-width: min(360px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 4px;
  background: var(--lf-accent); color: var(--lf-ink); font: 750 13px/1.4 var(--lf-font); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
#li-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------- app under the bar */

/* the sidebar footer keeps one line per control */
.side-foot .engine, .side-foot .text-btn { white-space: nowrap; }

/* the welcome sits under the bar, so signing in first stays one click away */
.welcome-layer { top: var(--top-h); }
.wc-account {
  margin: -8px 0 22px; padding: 11px 14px; border-radius: var(--r);
  background: var(--surface-2); border: 2px solid var(--line-soft);
  color: var(--dim); font-size: 13.4px; font-weight: 600; line-height: 1.55; max-width: 60ch;
}
.wc-account a { color: var(--sel-text); font-weight: 800; text-decoration: none; }
.wc-account a:hover { text-decoration: underline; }

.side-scrim { display: none; }

/* ---------------------------------------------------------------- phone */

@media (max-width: 760px) {
  .lf-top { padding: 0 10px 0 4px; gap: 2px; }
  .lf-menu { display: grid; }
  .lf-back { padding: 0 6px 0 4px; }
  .lf-back span, .lf-sync { display: none; }
  /* no room for the sentence: a sync problem shows as a short worded tag, the ordinary states not at all */
  .lf-top .lf-sync[data-state="error"], .lf-top .lf-sync[data-state="offline"], .lf-top .lf-sync[data-state="too-big"] {
    display: inline-flex; align-items: center; height: 22px; padding: 0 7px; margin-right: 6px;
    border: 1px solid currentColor; border-radius: 4px; font-size: 0;
  }
  .lf-top .lf-sync[data-state]::after { content: attr(data-short); font-size: 11.5px; font-weight: 700; }
  /* the bar has no spare room, so the logo stands in for the wordmark while the tag shows */
  .lf-top:has(.lf-sync[data-state="error"], .lf-sync[data-state="offline"], .lf-sync[data-state="too-big"]) .lf-word { display: none; }
  .lf-sep { margin: 0 8px 0 2px; }
  .lf-word { font-size: 20px; }
  .lf-top .li-hud { gap: 8px; }
  .lf-top .li-user > span:last-child { display: none; }
  /* nothing to open behind the welcome, so no menu button while it shows */
  body:has(#welcome-layer:not(.hidden)) .lf-menu { display: none; }

  /* the sidebar becomes a drawer over the page */
  .app, .app.side-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .app.side-collapsed .sidebar {
    display: flex; position: fixed; z-index: 120; top: var(--top-h); bottom: 0; left: 0;
    width: min(300px, 86vw); transform: translateX(-104%); visibility: hidden;
    transition: transform .2s ease, visibility 0s linear .2s;
  }
  .app.side-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow-pop); transition: transform .2s ease; }
  .side-scrim {
    display: block; position: fixed; z-index: 110; inset: var(--top-h) 0 0 0;
    background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .app.side-open .side-scrim { opacity: 1; pointer-events: auto; }
  .side-reveal { display: none !important; }

  .view { padding: 18px 16px 28px; }
  .view-head { flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
  .view-title { font-size: 23px; }
  .search { width: 100%; }
  .chapter-cards, .ref-items { grid-template-columns: minmax(0, 1fr); }

  /* a lesson scrolls as one page: task, then editor, then output */
  #view-lesson { overflow-y: auto; overscroll-behavior: contain; }
  .lesson-bar { position: sticky; top: 0; z-index: 5; padding: 8px 10px 8px 6px; gap: 6px; }
  .lesson-chapter, .lesson-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lesson-name { font-size: 15.5px; }
  .status-chip { display: none; }
  .lesson-bar-right { gap: 0; }
  .lesson-bar-right .btn { padding: 6px 8px; font-size: 11.5px; letter-spacing: .03em; }
  .lesson-grid { display: block; }
  .study-col { max-height: none; overflow: visible; border-right: 0; border-bottom: 2px solid var(--line-soft); }
  .study { padding: 18px 16px 24px; max-width: none; }
  .work-col { display: flex; flex-direction: column; }
  .work-col .editor-panel { height: 42vh; min-height: 240px; max-height: 480px; flex: none; }
  .work-col .output-panel { min-height: 210px; max-height: 72vh; flex: none; }
  .work-col .output-body { flex: 1 1 auto; }   /* the panel grows with its output, up to 72vh */
  /* after Run or Check the output scrolls up to sit just under the lesson bar */
  .output-panel { scroll-margin-top: 64px; }
  .scratch-grid .output-panel { scroll-margin-top: 12px; }
  .panel-bar { padding: 8px 10px; }
  .panel-bar-actions { gap: 5px; }
  .run-note { display: none; }
  .term { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .diag-compare { grid-template-columns: minmax(0, 1fr); }
  .step-dots { flex-wrap: wrap; justify-content: flex-end; }
  .sd { width: 16px; }

  .scratch-grid { flex: none; grid-template-rows: 46vh minmax(220px, auto); }

  /* welcome */
  .welcome-layer { place-items: start center; }
  .welcome { width: calc(100vw - 24px); margin: 12px 0 28px; padding: 22px 18px 20px; border-radius: 18px; }
  .wc-title { font-size: 23px; }
  .wc-foot { flex-wrap: wrap; row-gap: 12px; }
  .wc-actions { flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
  .wb-card { padding: 24px 18px 20px; }
  .wb-stats { gap: 6px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .side-scrim { transition: none !important; }
}

/* The live site shows Netlify's "Powered by Netlify" badge, fixed in the bottom right corner and 64px tall, above
   everything. On phones the welcome's buttons would open under it (a tap there opens Netlify's panel): while the badge
   is on the page, the welcome's button row stays in view just above it, and the welcome can scroll clear of it. */
@media (max-width: 520px) {
  html:has(> body > #nl-badge-frame) .wc-foot { position: sticky; bottom: 0; z-index: 2; margin: 0 -18px -20px; padding: 12px 18px calc(20px + 64px); background: var(--surface); border-radius: 0 0 16px 16px; }
}
