/* The window itself: title bar, sidebar drawer, fitting any window size, and the desktop-app touches. */

/* ---------- title bar ---------- */
#main { --bar-h: 40px; }
.topbar { display: flex; align-items: center; gap: 4px; height: var(--bar-h); flex: none; padding: 0 10px 0 8px; border-bottom: 1px solid var(--line); background: var(--sidebar); min-width: 0; }
.topbar .icon-btn { width: 30px; height: 28px; flex: none; }
.topbar-title { font-size: 12.5px; color: var(--muted); margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-search { display: flex; align-items: center; gap: 8px; height: 27px; padding: 0 8px 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--muted); cursor: pointer; font-size: 12.5px; flex: none; }
.topbar-search:hover { border-color: var(--line-hover); color: var(--ink-soft); }
.topbar-search svg { width: 13px; height: 13px; }
.topbar .chip { text-decoration: none; margin-right: 6px; }
#main.flush-view .topbar { display: none; }
.nav-toggle { display: none; }
#app.sidebar-hidden .nav-toggle, #app.narrow .nav-toggle { display: grid; }

/* Inside the desktop window the bars are the window's title bar: they drag the window, and keep clear of the
   minimise / maximise / close buttons that Windows draws in the top right corner. */
html.shell .topbar, html.shell .wb-top, html.shell .sidebar .brand { -webkit-app-region: drag; }
html.shell .topbar > *, html.shell .wb-top > *, html.shell .brand-link { -webkit-app-region: no-drag; }
html.shell .topbar > .spacer, html.shell .wb-top > .spacer, html.shell .topbar-title, html.shell .wb-top > .wb-name { -webkit-app-region: drag; }
html.shell .wb-top a, html.shell .wb-top button { -webkit-app-region: no-drag; }
html.shell .topbar, html.shell .wb-top { padding-right: 146px; }
html.shell .wb-top { min-height: 40px; }
html.shell body { user-select: none; }
html.shell .prose, html.shell .console-out, html.shell .pane-body, html.shell .result-body, html.shell input, html.shell textarea, html.shell pre, html.shell .ide-output, html.shell .modal, html.shell .flash-card, html.shell .qa { user-select: text; }
html.shell a, html.shell img { -webkit-user-drag: none; }

/* ---------- sidebar: fixed when there is room, a drawer when there is not ---------- */
.brand { cursor: default; padding: 0; }
.brand-link { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px; cursor: pointer; flex: 1; }
.side-warning { display: flex; gap: 9px; align-items: flex-start; margin: 0 14px 10px; padding: 9px 11px; border-radius: 9px; font-size: 12px; line-height: 1.45; color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); text-decoration: none; }
.side-warning svg { width: 15px; height: 15px; flex: none; margin-top: 1px; }
.scrim { display: none; }
/* a hidden or floating sidebar takes no column at all, so the page gets the whole width */
#app.narrow, #app.sidebar-hidden { grid-template-columns: minmax(0, 1fr); }
#app.narrow .sidebar { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(var(--sidebar-width), 86vw); transform: translateX(-102%); transition: transform .2s var(--ease); box-shadow: var(--shadow); display: flex; }
#app.narrow.sidebar-open .sidebar { transform: none; }
#app.narrow.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, .45); animation: fadeIn .15s; }
#app.narrow.sidebar-hidden .sidebar { display: flex; }

/* ---------- pages fit the space they have (not the size of the screen) ---------- */
#view { container-type: inline-size; container-name: view; }
@container view (max-width: 980px) {
  .hero { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lesson-layout { grid-template-columns: minmax(0, 1fr); max-width: var(--reading-width); }
  .toc { display: none; }
}
@container view (max-width: 700px) {
  .page { padding: 26px 20px 72px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .display { font-size: calc(30px * var(--text-scale)); }
  .trail-item { grid-template-columns: 40px minmax(0, 1fr); }
  .trail-card { flex-wrap: wrap; gap: 10px; }
  .lesson-foot { grid-template-columns: 1fr; }
  .setting { flex-wrap: wrap; gap: 8px 18px; }
  .card.keys { grid-template-columns: 1fr; }
  .list-row .meta { display: none; }
  .done-box { flex-wrap: wrap; }
  .tabs { overflow-x: auto; }
}
@container view (max-width: 480px) {
  .page { padding: 20px 14px 64px; }
  .practice-card .btn { display: none; }
  .card { padding: 16px; }
}
.card.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 28px; font-size: 13.5px; }
.card.keys kbd { margin-left: 3px; }

/* ---------- fixes ---------- */
/* the ring's own circle is rotated so it fills from the top; a tick drawn inside it must not be */
.ring svg { transform: none; }
.ring > svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring span svg { width: 44%; height: 44%; color: var(--c, var(--good)); transform: none; }
/* practice tasks: one tidy row each */
.card.link.practice-card { display: flex; align-items: center; gap: 14px; padding: 13px 16px; }
.practice-card .btn { flex: none; }
.practice-card .status-dot { flex: none; }
.done-box { gap: 12px 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.done-box .spacer { flex: 1; }

/* new project dialog */
.cap-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .13em; text-transform: uppercase; color: var(--faint); margin: 10px 0 6px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; max-height: 44vh; overflow-y: auto; padding: 2px; }
.tpl { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); cursor: pointer; }
.tpl:hover { border-color: var(--line-hover); }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tpl b { font-size: 13.5px; }
.tpl span { font-size: 12px; color: var(--muted); line-height: 1.4; }
.tpl small { font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal { max-height: 90vh; overflow-y: auto; }
.overlay { padding-left: 12px; padding-right: 12px; }

/* focus rings only for the keyboard, never after a click */
:focus:not(:focus-visible) { outline: none; }
button, a, .nav-item, .lesson-link, .tree-row { -webkit-tap-highlight-color: transparent; }

/* ---------- compact sidebar: a strip of icons ---------- */
.side-collapse { flex: none; margin-right: 10px; width: 28px; height: 28px; }
.side-collapse svg { width: 14px; height: 14px; }
#app.sidebar-mini:not(.narrow):not(.sidebar-hidden) { grid-template-columns: 58px minmax(0, 1fr); }
.sidebar.mini .brand { flex-direction: column; gap: 4px; padding: 12px 0 4px; }
.sidebar.mini .brand-link { padding: 0; flex: none; justify-content: center; }
.sidebar.mini .brand-link > div:last-child { display: none; }
.sidebar.mini .side-collapse { margin: 0; }
.sidebar.mini .side-warning { justify-content: center; margin: 0 9px 8px; padding: 8px 0; }
.sidebar.mini .side-warning span { display: none; }
.sidebar.mini .side-search { margin: 4px 9px 8px; padding: 0; height: 34px; justify-content: center; font-size: 0; gap: 0; }
.sidebar.mini .side-search kbd { display: none; }
.sidebar.mini .side-quick { grid-template-columns: 1fr; gap: 6px; margin: 0 9px 8px; }
.sidebar.mini .side-quick .btn { padding: 8px 0; font-size: 0; gap: 0; position: relative; }
.sidebar.mini .side-quick .btn.has-due::after { content: ""; position: absolute; top: 5px; right: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sidebar.mini .side-scroll { padding: 4px 9px 12px; scrollbar-width: none; }
.sidebar.mini .side-scroll::-webkit-scrollbar { display: none; }
.sidebar.mini .nav-item { justify-content: center; padding: 9px 0; gap: 0; }
.sidebar.mini .nav-item span { display: none; }
.sidebar.mini .nav-item.active::before { left: -9px; }
.sidebar.mini .side-course { justify-content: center; padding: 10px 0 6px; margin-top: 6px; border-top: 1px solid var(--line); }
.sidebar.mini .side-course .name, .sidebar.mini .side-course .pct { display: none; }
.sidebar.mini .side-label { font-size: 0; padding: 0; margin: 8px 4px 6px; border-top: 1px solid var(--line); }
.ms-mini { display: grid; place-items: center; height: 28px; margin: 4px 0; border-radius: 8px; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .04em; color: var(--ms, var(--accent)); text-decoration: none;
  border: 1px solid color-mix(in srgb, var(--ms, var(--accent)) 28%, transparent);
  background: linear-gradient(to right, color-mix(in srgb, var(--ms, var(--accent)) 24%, transparent) var(--p, 0%), transparent 0); }
.ms-mini:hover { text-decoration: none; border-color: var(--ms, var(--accent)); }
.ms-mini.active { border-color: var(--ms, var(--accent)); box-shadow: 0 0 0 1px var(--ms, var(--accent)); color: var(--ink); }
.sidebar.mini .side-user { margin: 0 9px 6px; padding: 5px 0; justify-content: center; }
.sidebar.mini .side-user .who, .sidebar.mini .side-user > svg { display: none; }
.sidebar.mini .side-foot { flex-direction: column; padding: 8px 0 10px; gap: 4px; }
.sidebar.mini .side-foot .streak { margin: 0 0 2px; padding: 0; flex-direction: column; gap: 1px; font-family: var(--font-mono); font-size: 10.5px; }

/* =====================================================================================================
   The redesigned shell: a header on every page; the course menu only inside a course.
   ===================================================================================================== */
:root { --header-h: 56px; }
#app { display: flex; flex-direction: column; height: 100vh; }
#app, #app.narrow, #app.sidebar-hidden, #app.sidebar-mini:not(.narrow):not(.sidebar-hidden) { grid-template-columns: none; }
.shell-body { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
#app.no-sidebar .shell-body, #app.narrow .shell-body, #app.sidebar-hidden .shell-body { grid-template-columns: minmax(0, 1fr); }
#app.sidebar-mini:not(.narrow):not(.sidebar-hidden):not(.no-sidebar) .shell-body { grid-template-columns: 58px minmax(0, 1fr); }
#app.no-sidebar .sidebar, #app.no-sidebar .scrim { display: none !important; }
#app.narrow .sidebar { top: var(--header-h); }
#app.narrow.sidebar-open .scrim { top: var(--header-h); }
#app:not(.narrow):not(.sidebar-hidden) .nav-toggle { display: none; }
#app.sidebar-hidden .nav-toggle, #app.narrow .nav-toggle { display: grid; }

/* ---------- header ---------- */
.site-header { height: var(--header-h); flex: none; display: flex; align-items: center; gap: 8px; padding: 0 18px 0 14px; position: relative; z-index: 45;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--sidebar) 94%, transparent); backdrop-filter: saturate(1.2) blur(10px); }
.site-header .spacer { flex: 1; }
.h-brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; margin: 0 18px 0 4px; flex: none; }
.h-brand:hover { text-decoration: none; }
.h-brand .brand-tile { width: 30px; height: 30px; border-radius: 8px; }
.h-brand .brand-tile svg { width: 19px; height: 19px; }
.h-brand .brand-name { font-size: 20px; }
.h-nav { display: flex; align-items: center; gap: 2px; min-width: 0; }
.hnav { position: relative; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; text-decoration: none; white-space: nowrap; }
.hnav:hover { color: var(--ink); background: var(--hover); text-decoration: none; }
.hnav.active { color: var(--ink); }
.hnav.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -10px; height: 2px; border-radius: 2px; background: var(--accent); }
.h-sep { display: grid; place-items: center; color: var(--faint); margin: 0 2px; }
.h-sep svg { width: 13px; height: 13px; }
.h-course { display: flex; align-items: center; gap: 8px; padding: 4px 11px 4px 5px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-size: 14px; text-decoration: none; min-width: 0; }
.h-course:hover, .h-course.active { border-color: var(--line-hover); text-decoration: none; }
.h-course .glyph, .side-course-head .glyph { font-family: var(--font-mono); font-size: 10px; font-weight: 700; padding: 4px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); flex: none; }
.h-course .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-search { display: flex; align-items: center; gap: 8px; height: 34px; min-width: 230px; padding: 0 8px 0 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--field); color: var(--muted); cursor: pointer; font-size: 13px; }
.h-search:hover { border-color: var(--line-hover); color: var(--ink-soft); }
.h-search span { flex: 1; text-align: left; }
.h-search svg { width: 14px; height: 14px; flex: none; }
.h-streak { display: flex; align-items: center; gap: 5px; padding: 0 8px; height: 34px; border-radius: 9px; color: var(--muted); font-size: 13px; cursor: default; }
.h-streak svg { width: 16px; height: 16px; color: var(--accent); }
.h-streak b { color: var(--ink); font-weight: 600; }
.h-streak .lv { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .06em; padding: 2px 6px; border-radius: 6px; background: var(--selected); color: var(--ink-soft); margin-left: 3px; }
.h-user { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 9px 0 4px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font-size: 13.5px; }
.h-user:hover, .h-user.open { border-color: var(--line-hover); }
.h-user svg { width: 13px; height: 13px; color: var(--muted); }
.h-user .avatar, .user-menu .avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; font-weight: 600; text-transform: uppercase;
  background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); flex: none; }
.user-menu { min-width: 240px; }
.user-menu .um-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 6px; }
.user-menu .um-head .avatar { width: 34px; height: 34px; font-size: 14px; }
.user-menu .um-head .n { font-size: 14px; font-weight: 600; }
.user-menu .um-head .r { font-size: 11.5px; color: var(--muted); }
@media (max-width: 1100px) { .h-search { min-width: 0; } .h-search span, .h-search kbd { display: none; } .h-search { width: 36px; padding: 0; justify-content: center; } }
@media (max-width: 760px) {
  .site-header { padding: 0 10px; gap: 4px; }
  .h-brand { margin-right: 6px; }
  .h-brand .brand-name, .h-streak .lv, .h-user .n, .h-user > svg, .h-theme { display: none; }
  .h-user { padding: 0 4px; }
  .hnav { padding: 7px 9px; }
  .h-course .t { max-width: 90px; }
}
@media (max-width: 520px) { .h-sep, .h-course { display: none; } .h-streak { display: none; } }

/* ---------- the course menu ---------- */
.sidebar { min-height: 0; }
.side-top { display: flex; align-items: center; gap: 8px; padding: 14px 10px 10px 14px; }
.side-course-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: var(--ink); text-decoration: none; padding: 4px; margin: -4px; border-radius: 9px; }
.side-course-head:hover { background: var(--hover); text-decoration: none; }
.side-course-head .glyph { font-size: 11px; padding: 0; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: color-mix(in srgb, var(--cc, var(--accent)) 20%, transparent); color: var(--cc, var(--accent)); }
.side-course-head .who { display: flex; flex-direction: column; min-width: 0; }
.side-course-head .name { font-family: var(--font-display); font-size: 17px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-course-head .sub { font-size: 11.5px; color: var(--muted); }
.side-top .side-collapse { margin: 0; }
.side-progress { height: 3px; margin: 0 14px 6px; border-radius: 3px; background: var(--selected); overflow: hidden; }
.side-progress i { display: block; height: 100%; background: var(--cc, var(--accent)); border-radius: 3px; }
.side-scroll .side-label:first-child { padding-top: 8px; }
.sidebar.mini .side-top { flex-direction: column; padding: 12px 0 8px; gap: 8px; }
.sidebar.mini .side-course-head { flex: none; margin: 0; padding: 0; }
.sidebar.mini .side-course-head .who { display: none; }

/* ---------- open pages (no course menu) get a little more room ---------- */
#app.no-sidebar .page { max-width: 1160px; }
#app.no-sidebar .page.narrow { max-width: calc(var(--reading-width) + 96px); }
