/* ==========================================================================
   LearnStuffs - app shell
   Top bar, left sidebar, main canvas, footer bar. Calm palette, both themes,
   borders and spacing carry the structure. No shadows, no glow, no emoji.
   ========================================================================== */

:root {
  --bg: #101418;
  --surface: #171e26;
  --surface-2: #1c242e;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --text: #e7eaee;
  --text-muted: #9aa5b1;
  --text-dim: #6f7a86;
  --accent: #6b8fd4;
  --accent-soft: rgba(107, 143, 212, .13);
  --teal: #4fa89b;
  --teal-soft: rgba(79, 168, 155, .13);
  --green: #5aa87a;
  --green-soft: rgba(90, 168, 122, .14);
  --amber: #c99a5b;
  --amber-soft: rgba(201, 154, 91, .14);
  --rose: #c4777f;
  --rose-soft: rgba(196, 119, 127, .14);
  --violet: #8b7fc4;
  --violet-soft: rgba(139, 127, 196, .14);
  --code-bg: #10171e;
  --r-lg: 10px;
  --r-md: 8px;
  --r-sm: 6px;
  --side: 340px;
  --top: 54px;
  --foot: 34px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --line: rgba(16, 20, 24, .10);
  --line-2: rgba(16, 20, 24, .18);
  --text: #1b2430;
  --text-muted: #5c6675;
  --text-dim: #7b8794;
  --accent: #33558f;
  --accent-soft: rgba(51, 85, 143, .10);
  --teal: #2f7f74;
  --teal-soft: rgba(47, 127, 116, .10);
  --green: #3d8560;
  --green-soft: rgba(61, 133, 96, .12);
  --amber: #96682c;
  --amber-soft: rgba(150, 104, 44, .12);
  --rose: #a2565f;
  --rose-soft: rgba(162, 86, 95, .12);
  --violet: #6b5aa8;
  --violet-soft: rgba(107, 90, 168, .12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }

button { font: inherit; color: inherit; }

/* ---------- shell grid ---------------------------------------------------- */
.app {
  display: grid;
  height: 100vh;
  grid-template-columns: var(--side) minmax(0, 1fr);
  grid-template-rows: var(--top) minmax(0, 1fr) var(--foot);
  grid-template-areas:
    "top  top"
    "side main"
    "side foot";
}

/* ---------- top bar ------------------------------------------------------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; border-radius: var(--r-md); display: flex;
  align-items: center; justify-content: center; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--line); }
.brand b { font-size: .97rem; letter-spacing: .01em; white-space: nowrap; }
.topbar #theme { margin-left: auto; }

.search { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 0 9px; height: 34px; color: var(--text-dim); }
.search:focus-within { border-color: var(--accent); color: var(--accent); }
.search input { flex: 1 1 auto; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: .88rem; }
.search input::placeholder { color: var(--text-dim); }
.search .clear { border: 0; background: transparent; color: var(--text-dim); cursor: pointer;
  display: flex; padding: 2px; }
.search .clear:hover { color: var(--text); }

/* the canvas strip finds text inside the open guide, not in the list */
.canvas-tools .search { flex: 1 1 auto; min-width: 0; }
.search.off { opacity: .55; }
.search.off input { cursor: not-allowed; }
.find-count { flex: none; min-width: 78px; text-align: right; font-size: .78rem;
  color: var(--text-dim); font-variant-numeric: tabular-nums; }
.find-count.none { color: var(--amber); }
.find-nav { flex: none; display: flex; gap: 4px; }

.top-actions { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }

.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px;
  border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--bg);
  color: var(--text-muted); cursor: pointer; font-size: .84rem; white-space: nowrap; }
.btn:hover { color: var(--text); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { color: var(--text-muted); border-color: var(--line-2); }
.btn.tiny { height: 24px; padding: 0 9px; font-size: .77rem; gap: 5px; }
.btn.tiny .ico-sm { width: 13px; height: 13px; }

.icon-btn { width: 34px; height: 34px; flex: none; display: flex; align-items: center;
  justify-content: center; border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--bg); color: var(--text-muted); cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn.small { width: 26px; height: 26px; }

/* ---------- sidebar ------------------------------------------------------- */
.sidebar {
  grid-area: side;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
/* the Guides / Slides switch: two collections, each from its own folder */
.section-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); }
.section-tab { display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 30px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text-muted); cursor: pointer; font-size: .84rem;
  min-width: 0; white-space: nowrap; }
.section-tab:hover { color: var(--text); }
.section-tab:focus-visible { outline: 0; border-color: var(--accent); }
.section-tab[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent);
  color: var(--text); }
.section-tab[aria-selected="true"] .ico-sm { color: var(--accent); }
.tab-count { font-size: .72rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* the sidebar header stacks its two list controls: the filter, then the sort */
.side-head { display: flex; flex-direction: column; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); }
.side-head .search { flex: none; width: 100%; }
.side-head .sort { flex: none; min-width: 0; }

/* ---------- sidebar foot: the rescan ------------------------------------ */
.side-foot { flex: none; display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid var(--line); padding: 10px; }
.btn.full { width: 100%; justify-content: center; }
.btn[hidden] { display: none; }

.guide-list { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 8px 8px 14px; }
.group-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-dim); font-weight: 650; padding: 14px 8px 6px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.group:first-child .group-label { padding-top: 4px; }

.guide {
  display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 9px; align-items: start;
  width: 100%; text-align: left; padding: 8px 9px; margin-bottom: 2px;
  border: 1px solid transparent; border-radius: var(--r-md); background: transparent;
  cursor: pointer; color: var(--text-muted);
}
.guide:hover { background: var(--surface-2); color: var(--text); }
.guide .ico-sm { margin-top: 2px; color: var(--text-dim); }
.guide.active { background: var(--accent-soft); border-color: var(--accent);
  color: var(--text); }
.guide.active .ico-sm { color: var(--accent); }
.guide-text { min-width: 0; }
.guide-title { display: block; font-size: .87rem; line-height: 1.35; color: inherit;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guide-meta { display: block; font-size: .72rem; color: var(--text-dim); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guide.hidden { display: none; }

.list-empty { padding: 18px 10px; font-size: .84rem; color: var(--text-dim); }
.list-error { margin: 10px 6px; padding: 11px 12px; font-size: .82rem; border-radius: var(--r-md);
  border: 1px solid var(--rose); background: var(--rose-soft); color: var(--text); }
.list-error b { color: var(--rose); }

.side-foot { flex: none; border-top: 1px solid var(--line); padding: 10px 12px 12px; }

/* the sidebar folds away completely, leaving the full width to the canvas */
.app.no-side { grid-template-columns: 0 minmax(0, 1fr); }
.app.no-side .sidebar { display: none; }

/* ---------- canvas -------------------------------------------------------- */
.canvas { grid-area: main; position: relative; min-width: 0; min-height: 0;
  background: var(--bg); display: flex; flex-direction: column; }

/* One control strip over the content. It sits outside the iframe, so it stays
   put while a guide scrolls inside it. */
.canvas-tools { flex: none; position: relative; display: flex; align-items: center;
  gap: 10px; padding: 10px 12px; background: var(--surface);
  border-bottom: 1px solid var(--line); }

.sort { position: relative; }
.side-head .sort-btn { width: 100%; }
.sort-btn { display: inline-flex; align-items: center; gap: 8px; height: 34px;
  padding: 0 10px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text-muted); border-radius: var(--r-md); font-size: .84rem;
  cursor: pointer; white-space: nowrap; }
.sort-btn .chev { margin-left: auto; }
.sort-btn:hover { color: var(--text); border-color: var(--accent); }
.sort-btn[aria-expanded="true"] { color: var(--text); border-color: var(--accent); }
.sort-btn .chev { transition: transform .16s ease; }
.sort-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 236px; z-index: 30;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: var(--r-md); padding: 5px; box-shadow: 0 12px 28px rgba(0, 0, 0, .3); }
/* in the sidebar the sort button is full width, so the menu matches it */
.side-head .menu { left: 0; right: 0; min-width: 0; }
.menu[hidden] { display: none; }
.menu-head { margin: 0; padding: 7px 9px 4px; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-dim); font-weight: 650; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }
.menu-item { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 9px; border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--text-muted); font: inherit; font-size: .84rem; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); color: var(--text);
  outline: 0; }
.menu-item[aria-selected="true"] { color: var(--text); }
.menu-item .tick { flex: none; width: 15px; height: 15px; color: var(--accent); opacity: 0; }
.menu-item[aria-selected="true"] .tick { opacity: 1; }

#frame { flex: 1 1 auto; width: 100%; height: 100%; border: 0; background: #fff; }
html[data-theme="dark"] #frame { background: #101418; }
#slide-frame { flex: 1 1 auto; width: 100%; height: 100%; border: 0; background: var(--bg); }

.loadbar { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--accent-soft); overflow: hidden; z-index: 3; }
.loadbar span { display: block; width: 34%; height: 100%; background: var(--accent);
  animation: slide 1.15s ease-in-out infinite; }
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}
@media (prefers-reduced-motion: reduce) { .loadbar span { animation-duration: 2.4s; } }

.empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 36px 26px; gap: 2px;
  overflow-y: auto; }
.empty[hidden] { display: none; }
.empty-mark { width: 46px; height: 46px; border-radius: var(--r-lg); display: flex;
  align-items: center; justify-content: center; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--line); margin-bottom: 14px; }
.empty h1 { margin: 0 0 6px; font-size: 1.28rem; font-weight: 640; letter-spacing: -.01em; }
.empty p { margin: 0; color: var(--text-muted); max-width: 52ch; font-size: .91rem; }
.empty-steps { margin: 18px 0 20px; padding: 0; list-style: none; text-align: left;
  display: grid; gap: 7px; max-width: 52ch; counter-reset: s; }
.empty-steps[hidden] { display: none; }
.empty-steps li { position: relative; padding-left: 26px; color: var(--text-muted);
  font-size: .87rem; }
.empty-steps li::before { counter-increment: s; content: counter(s); position: absolute;
  left: 0; top: 1px; width: 18px; height: 18px; border-radius: 50%; font-size: .68rem;
  display: flex; align-items: center; justify-content: center; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--line); }
.empty code { font-family: var(--mono); font-size: .8rem; }
.empty code { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 1px 5px; }

/* ---------- footer bar ---------------------------------------------------- */
.footbar {
  grid-area: foot;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: .78rem;
  color: var(--text-muted);
  min-width: 0;
}
.status { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.status.ok .dot { background: var(--green); }
.status.busy .dot { background: var(--amber); }
.status.warn .dot { background: var(--rose); }
.foot-file { font-family: var(--mono); font-size: .76rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto;
  min-width: 0; }
.foot-meta { color: var(--text-dim); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.foot-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.foot-scan { margin-left: auto; color: var(--text-dim); white-space: nowrap;
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- drawer, scrim, toast ----------------------------------------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.scrim.show { opacity: 1; pointer-events: auto; }

.toast { position: fixed; left: 50%; bottom: 46px; transform: translate(-50%, 10px);
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text);
  border-radius: var(--r-md); padding: 9px 14px; font-size: .84rem; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .16s ease, transform .16s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- narrow screens ----------------------------------------------- */
@media (max-width: 1080px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas:
    "top" "main" "foot"; }
  .app.no-side { grid-template-columns: minmax(0, 1fr); }
  /* on narrow screens the sidebar is an off-canvas drawer, so it must stay in the
     layout even when it was folded away on a wide screen */
  .app.no-side .sidebar { display: flex; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(330px, 88vw);
    display: flex; z-index: 50; transform: translateX(-101%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .foot-meta { display: none; }
}

@media (max-width: 720px) {
  :root { --top: 50px; }
  .brand b { font-size: .9rem; }
  .btn span { display: none; }
  .btn { padding: 0 9px; }
  .foot-file { max-width: 34vw; }
  .foot-scan { font-size: .72rem; }
}

@media (max-width: 560px) {
  .canvas-tools { gap: 8px; padding: 9px 10px; }
  .sort-btn #sort-label { display: none; }
  .sort-btn { padding: 0 9px; gap: 6px; }
}
