/* ==========================================================================
   Library Reader - Courses (Sleek)
   Namespaced under .crs. Reads the app tokens in css/variables.css directly.
   Course colour comes from the index hues, as a flat tint (no gradients).
   ========================================================================== */

.crs *, .crs *::before, .crs *::after { box-sizing: border-box; }
.crs img { max-width: 100%; height: auto; }
.crs { --crs-maxw: 760px; color: var(--ink); }

/* ============================ 1. Shelf ============================ */
.crs-shelf { max-width: 1240px; margin-inline: auto; padding: 22px clamp(16px, 2.6vw, 36px) 64px; }
.crs-shelf-head { margin-bottom: 18px; display: flex; flex-direction: column-reverse; }
.crs-shelf-head h1 { font: 700 30px/1.1 var(--font); letter-spacing: -.02em; margin-top: 2px; }
.crs-shelf-head p { font-size: 13.5px; font-weight: 500; color: var(--ink2); font-variant-numeric: tabular-nums; }

.crs-search { position: relative; display: flex; align-items: center; max-width: 560px; }
.crs-search > span { position: absolute; left: 14px; display: grid; color: var(--ink2); pointer-events: none; }
.crs-search svg { width: 18px; height: 18px; }
.crs-search input {
  width: 100%; min-height: 48px; padding: 0 16px 0 42px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface); font: 16px var(--font); color: var(--ink);
  outline: none; caret-color: var(--accent);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.crs-search input::placeholder { color: var(--ink2); }
.crs-search input:focus { border-color: var(--accent); box-shadow: var(--focus); }

.crs-grid { display: grid; gap: var(--gap); margin-top: 18px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }

.crs-card {
  position: relative; display: flex; flex-direction: column; overflow: hidden; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  animation: crs-rise var(--t-slow) var(--ease) backwards;
  animation-delay: calc(min(var(--i, 0), 12) * 45ms);
  transition: transform var(--t-base) var(--ease), border-color var(--t-fast) var(--ease);
}
@media (hover: hover) { .crs-card:hover { transform: translateY(-2px); border-color: var(--line-strong); } }
.crs-card:active { transform: scale(.99); }

.crs-cover {
  position: relative; aspect-ratio: 16 / 7; display: grid; place-items: center;
  background: hsl(var(--h1) 80% 94%); border-bottom: 1px solid var(--line-soft);
}
.crs-cover-glyph {
  font: 700 clamp(28px, 5vw, 38px)/1 var(--font); letter-spacing: -.04em;
  color: hsl(var(--h1) 55% 34%);
  transition: transform var(--t-base) var(--spring);
}
@media (hover: hover) { .crs-card:hover .crs-cover-glyph { transform: scale(1.06) rotate(-2deg); } }
.crs-cover-badge {
  position: absolute; top: 10px; right: 10px; padding: 5px 9px; border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.crs-card-body { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 16px 18px 18px; }
.crs-card-provider { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.crs-card-title {
  font: 700 17px/1.25 var(--font); letter-spacing: -.01em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.crs-card-meta { margin-top: auto; padding-top: 12px; display: grid; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.crs-ring-label { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 700; }

/* Progress bar (6px track, accent fill, grows from the left) */
.crs-bar { height: 6px; border-radius: var(--r-pill); background: var(--accent-soft); overflow: hidden; }
.crs-bar > i {
  display: block; height: 100%; width: var(--pct, 0%); border-radius: inherit; background: var(--accent);
  transform-origin: left; animation: grow .9s var(--ease) .15s backwards;
  transition: width var(--t-base) var(--ease);
}

/* ============================ 2. Course view ============================ */
.crs-course { max-width: calc(var(--crs-maxw) + 72px); margin-inline: auto; padding: 22px clamp(16px, 2.6vw, 36px) 64px; }
.crs-hero {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 22px 22px;
  animation: crs-rise var(--t-slow) var(--ease) backwards;
}
.crs-hero .crs-card-provider { margin-top: 12px !important; }
.crs-hero h1 { font: 700 clamp(24px, 3.4vw, 32px)/1.12 var(--font); letter-spacing: -.025em; margin: 4px 0 8px; text-wrap: balance; }
.crs-hero-desc { max-width: 62ch; font-size: 15px; line-height: 1.6; color: var(--ink2); margin-bottom: 14px; }
.crs-hero-stats { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13.5px; font-weight: 600; color: var(--ink2); font-variant-numeric: tabular-nums; }
.crs-hero .crs-bar { margin-top: 14px; }

.crs-back {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 12px 0 6px; margin-left: -6px;
  border-radius: var(--r-sm); font: 700 14px var(--font); color: var(--ink2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.crs-back:hover { background: var(--bg); color: var(--ink); }
.crs-back svg { width: 18px; height: 18px; }

.crs-sections { margin-top: var(--gap); }
.crs-section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  margin-bottom: 10px; overflow: hidden;
  animation: crs-rise var(--t-slow) var(--ease) backwards; animation-delay: calc(min(var(--i, 0), 12) * 45ms);
}
.crs-section-head {
  width: 100%; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 12px 18px 12px 14px;
  font: inherit; color: inherit; text-align: left;
  transition: background var(--t-fast) var(--ease);
}
.crs-section-head:hover { background: var(--surface-2); }
.crs-section-title { flex: 1; font-weight: 700; font-size: 15px; letter-spacing: -.005em; }
.crs-section-count { font-size: 13px; font-weight: 700; color: var(--ink2); font-variant-numeric: tabular-nums; }
.crs-chevron { width: 20px; height: 20px; flex: none; color: var(--ink2); transition: transform var(--t-base) var(--ease); }
.crs-chevron svg { width: 20px; height: 20px; }
.crs-section.is-open .crs-chevron { transform: rotate(90deg); }

.crs-section-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--t-base) var(--ease); }
.crs-section.is-open .crs-section-panel { grid-template-rows: 1fr; }
/* Closed panels leave the tab order: nothing focusable hides behind a 0fr row */
.crs-section-panel > div { overflow: hidden; visibility: hidden; transition: visibility 0s linear var(--t-base); }
.crs-section.is-open .crs-section-panel > div { visibility: visible; transition-delay: 0s; }
.crs-group-title { padding: 14px 18px 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); }

.crs-mod {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 18px;
  border-top: 1px solid var(--line-soft); transition: background var(--t-fast) var(--ease);
}
.crs-mod:hover { background: var(--surface-2); }
.crs-mod-title { flex: 1; min-height: 44px; font-size: 14.5px; font-weight: 600; line-height: 1.35; }
/* Done: the title strikes through left to right */
.crs-mod-text {
  background: linear-gradient(var(--ink2), var(--ink2)) no-repeat 0 56% / 0% 1.5px;
  transition: background-size var(--t-base) var(--ease), color var(--t-fast) var(--ease);
}
.crs-mod.is-done .crs-mod-text { color: var(--ink2); background-size: 100% 1.5px; }
.crs-mod.is-missing { opacity: .5; }
.crs-mod.is-missing .crs-mod-title { cursor: not-allowed; }

/* Checkbox: 22px, 7px radius, fills accent with a drawn tick; 44px hit area */
.crs-check {
  position: relative; width: 22px; height: 22px; flex: none; border-radius: 7px; padding: 0;
  border: 2px solid var(--ink3); background: transparent;
  display: grid; place-items: center;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-base) var(--spring);
}
.crs-check::before { content: ""; position: absolute; top: 50%; left: 50%; width: 44px; height: 44px; translate: -50% -50%; }
.crs-check:hover { border-color: var(--accent); }
.crs-check svg { width: 13px; height: 13px; color: #fff; stroke-width: 3.5; stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset .25s var(--ease) .05s; }
.crs-mod.is-done .crs-check { background: var(--accent); border-color: var(--accent); transform: scale(1.08); }
.crs-mod.is-done .crs-check svg { stroke-dashoffset: 0; }

/* ============================ 3. Module reader ============================ */
.crs-reader { max-width: calc(var(--measure) + 72px); margin-inline: auto; padding: 0 clamp(16px, 2.6vw, 36px) 40px; }
.crs-reader-head { padding: 22px 0 18px; margin-bottom: 22px; border-bottom: 1px solid var(--line); animation: crs-rise var(--t-slow) var(--ease) backwards; }
.crs-crumb { display: flex; align-items: center; gap: 4px 6px; flex-wrap: wrap; font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 8px; }
.crs-crumb button { min-height: 32px; font: inherit; color: var(--ink2); position: relative; }
.crs-crumb button::after { content: ""; position: absolute; inset: -6px 0; }
.crs-crumb button:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.crs-reader-head h1 { font: 700 clamp(26px, 3.6vw, 34px)/1.12 var(--font); letter-spacing: -.025em; margin-bottom: 14px; text-wrap: balance; }
.crs-reader-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.crs-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 700 14px var(--font); text-decoration: none; cursor: pointer;
  transition: transform var(--t-fast) var(--spring), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.crs-btn:hover { border-color: var(--line-strong); }
.crs-btn:active { transform: scale(.97); }
.crs-btn svg { width: 17px; height: 17px; }
.crs-btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.crs-btn-primary:hover { background: var(--ink-hover); border-color: var(--ink-hover); }

.crs-prose { animation: fadeIn var(--t-base) var(--ease) backwards; }

.crs-pager { display: flex; gap: 10px; margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--line); }
.crs-pager .crs-btn { flex: 1; }
.crs-pager .crs-btn[disabled] { opacity: .4; pointer-events: none; }

.crs-dockbar {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px;
  margin: 26px calc(clamp(16px, 2.6vw, 36px) * -1) 0; padding: 12px clamp(16px, 2.6vw, 36px);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.crs-dockbar .crs-btn { flex: 1; min-height: 48px; }

/* States */
.crs-empty, .crs-loading { padding: 64px 16px; text-align: center; color: var(--ink2); }
.crs-empty { max-width: 560px; margin: 22px auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 40px 24px; }
.crs-empty h2 { font: 700 20px/1.2 var(--font); color: var(--ink); margin-bottom: 6px; }
.crs-empty .crs-btn { margin-top: 14px; }
.crs-loading { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 14px; font-weight: 600; }
.crs-loading::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }

@keyframes crs-rise { from { opacity: 0; transform: translateY(14px) scale(.985); } }

.crs :where(button, a, input):focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.crs-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (max-width: 860px) {
  .crs-shelf, .crs-course { padding: 14px 16px calc(112px + env(safe-area-inset-bottom, 0px)); }
  .crs-shelf-head h1 { font-size: 26px; }
  .crs-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 12px; }
  .crs-card-body { padding: 12px 14px 14px; }
  .crs-card-title { font-size: 15px; }
  .crs-reader { padding: 0 16px 24px; }
  .crs-dockbar { margin: 26px -16px 0; padding-inline: 16px; }
}
