/* ==========================================================================
   DKW iBooks — Pearl.
   Base type, the application shell shared by learners, trainers and staff,
   and the components every page is built from. Values come from tokens.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  margin: 0;
  min-width: 320px;
  font-family: var(--ds-font);
  font-size: var(--ds-text-base);
  line-height: var(--ds-leading);
  color: var(--ds-ink);
  background: var(--ds-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Arabic reads in Alexandria, with room between lines and no tracking. */
:lang(ar), [dir="rtl"] { font-family: var(--ds-font-ar); line-height: var(--ds-leading-ar); letter-spacing: 0; }

img, video { display: block; max-width: 100%; height: auto; }
svg { max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, pre, kbd { font-family: var(--ds-font-mono); font-size: .9em; }

h1, h2, h3, h4 {
  margin: 0 0 var(--ds-space-3);
  color: var(--ds-ink);
  font-weight: 650;
  line-height: 1.22;
  text-wrap: balance;
}
h1 { font-size: var(--ds-h1); letter-spacing: -.015em; }
h2 { font-size: var(--ds-h2); letter-spacing: -.01em; }
h3 { font-size: var(--ds-h3); }
h4 { font-size: var(--ds-text-base); }
:lang(ar) h1, :lang(ar) h2 { letter-spacing: 0; }
p { margin: 0 0 var(--ds-space-4); }
small { font-size: var(--ds-text-small); }

:focus-visible { outline: var(--ds-focus-ring); outline-offset: 2px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; inset-block-start: -100px; inset-inline-start: var(--ds-space-4); z-index: 2000;
  padding: 12px 18px; background: var(--ds-surface); border-radius: var(--ds-radius-control);
  box-shadow: var(--ds-shadow); font-weight: 600;
}
.skip-link:focus { inset-block-start: var(--ds-space-3); }

.icon { display: inline-block; flex: none; width: 20px; height: 20px; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
/* Arrows and chevrons point the way the text reads. */
[dir="rtl"] .icon-dir { transform: scaleX(-1); }

/* ------------------------------------------------------------ utilities */

.wrap { width: min(100%, var(--ds-content-max)); margin-inline: auto; }
.wrap-narrow { width: min(100%, 780px); margin-inline: auto; }
.stack > * + * { margin-block-start: var(--ds-space-4); }
.row { display: flex; gap: var(--ds-space-3); align-items: center; }
.row-between { display: flex; flex-wrap: wrap; gap: var(--ds-space-4); align-items: center; justify-content: space-between; }
.grid { display: grid; gap: var(--ds-space-5); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 232px), 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.section { padding-block: 0; }
.section-tight { padding-block: 0; }
.mt-0 { margin-block-start: 0; }
.mb-0 { margin-block-end: 0; }
.text-muted { color: var(--ds-text-muted); }
.text-sm { font-size: var(--ds-text-help); }
.text-center { text-align: center; }
.eyebrow {
  display: inline-flex; align-items: center; gap: var(--ds-space-2);
  color: var(--ds-primary); font-size: var(--ds-text-small); font-weight: 650;
}

/* ------------------------------------------------------------- the shell */

.shell { min-height: 100dvh; }

.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 70;
  display: flex; flex-direction: column;
  width: var(--ds-sidebar-width);
  background: var(--ds-surface);
  border-inline-end: 1px solid var(--ds-border);
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--ds-space-3);
  min-height: var(--ds-topbar-height); padding-inline: var(--ds-space-5);
  border-block-end: 1px solid var(--ds-border);
}
.sidebar__brand > .sidebar__close { display: none; margin-inline-start: auto; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: var(--ds-space-4) var(--ds-space-3); scrollbar-width: thin; }
.sidebar__group {
  margin: var(--ds-space-5) var(--ds-space-3) var(--ds-space-2);
  color: var(--ds-text-muted); font-size: var(--ds-text-small); font-weight: 600;
}
.sidebar__group:first-child { margin-block-start: var(--ds-space-1); }
.sidebar__foot { padding: var(--ds-space-4); border-block-start: 1px solid var(--ds-border); }

.navlink {
  position: relative;
  display: flex; align-items: center; gap: var(--ds-space-3);
  min-height: var(--ds-control-height); padding: 10px 14px; margin-block: 2px;
  border-radius: var(--ds-radius-control);
  color: var(--ds-ink-secondary); font-size: var(--ds-text-control); font-weight: 550;
  transition: background-color var(--ds-duration) var(--ds-ease), color var(--ds-duration) var(--ds-ease);
}
.navlink .icon { color: var(--ds-muted); transition: color var(--ds-duration) var(--ds-ease); }
.navlink:hover { background: var(--ds-surface-muted); color: var(--ds-ink); }
.navlink:hover .icon { color: var(--ds-ink-secondary); }
.navlink[aria-current="page"] { background: var(--ds-primary-soft); color: var(--ds-primary); font-weight: 650; }
.navlink[aria-current="page"] .icon { color: var(--ds-primary); }
.navlink[aria-current="page"]::before {
  content: ""; position: absolute; inset-block: 10px; inset-inline-start: -12px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--ds-primary);
}
[dir="rtl"] .navlink[aria-current="page"]::before { border-radius: 3px 0 0 3px; }
.navlink__badge { margin-inline-start: auto; }

.shell__main { min-width: 0; margin-inline-start: var(--ds-sidebar-width); }

.topbar {
  position: sticky; inset-block-start: 0; z-index: 60;
  display: flex; align-items: center; gap: var(--ds-space-3);
  min-height: var(--ds-topbar-height); padding-inline: var(--ds-space-6);
  background: rgba(255, 255, 255, .94);
  border-block-end: 1px solid var(--ds-border);
  backdrop-filter: blur(8px);
}
.topbar > .topbar__menu, .topbar > .topbar__brand { display: none; }
.topbar__spacer { flex: 1; }

.content { padding: var(--ds-space-6) var(--ds-space-6) var(--ds-space-8); }
.content > .flash-stack { width: min(100%, var(--ds-content-max)); margin: 0 auto var(--ds-space-5); }

.shell-scrim {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(27, 31, 36, .32);
  opacity: 0; pointer-events: none;
  transition: opacity var(--ds-duration) var(--ds-ease);
}

/* ----------------------------------------------------------------- brand */

.brand { display: inline-flex; align-items: center; gap: var(--ds-space-3); min-height: var(--ds-control-height); color: var(--ds-ink); }
.brand__logo { display: block; width: auto; max-height: 36px; }
.brand__mark { display: grid; place-items: center; flex: none; width: 36px; height: 36px; }
.brand__mark svg { width: 36px; height: 36px; }
.brand__text { display: grid; line-height: 1.15; }
.brand__text strong { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand__text small { color: var(--ds-text-muted); font-size: var(--ds-text-small); font-weight: 500; }

/* ------------------------------------------------------- account + avatar */

.avatar {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px;
  background: var(--ds-primary-soft); color: var(--ds-primary);
  border: 1px solid var(--ds-primary-line); border-radius: 50%;
  font-size: 15px; font-weight: 700; letter-spacing: .02em;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }

.account { position: relative; }
.account > summary { list-style: none; }
.account > summary::-webkit-details-marker { display: none; }
.account__button {
  display: flex; align-items: center; gap: var(--ds-space-3);
  min-height: var(--ds-control-height); padding: 2px 10px 2px 2px;
  border: 1px solid transparent; border-radius: var(--ds-radius-pill);
  cursor: pointer; user-select: none;
  transition: background-color var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease);
}
[dir="rtl"] .account__button { padding: 2px 2px 2px 10px; }
.account__button:hover, .account[open] .account__button { background: var(--ds-surface); border-color: var(--ds-border); }
.account__name { display: grid; line-height: 1.2; text-align: start; }
.account__name strong { max-width: 180px; overflow: hidden; font-size: 15px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.account__name small { color: var(--ds-text-muted); font-size: var(--ds-text-small); }
.account__chevron { color: var(--ds-muted); transition: transform var(--ds-duration) var(--ds-ease); }
.account[open] .account__chevron { transform: rotate(180deg); }
.account__menu {
  position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0; z-index: 80;
  width: min(300px, calc(100vw - 32px));
  padding: var(--ds-space-2);
  background: var(--ds-surface); border: 1px solid var(--ds-border);
  border-radius: 14px; box-shadow: var(--ds-shadow);
}
.account__head { display: flex; align-items: center; gap: var(--ds-space-3); padding: var(--ds-space-3); margin-block-end: var(--ds-space-1); border-block-end: 1px solid var(--ds-border); }
.account__head div { min-width: 0; }
.account__head strong, .account__head span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.account__head span { color: var(--ds-text-muted); font-size: var(--ds-text-small); }
.account__menu a {
  display: flex; align-items: center; gap: var(--ds-space-3);
  min-height: var(--ds-control-height); padding: 8px 12px;
  border-radius: var(--ds-radius-control); color: var(--ds-ink-secondary); font-size: var(--ds-text-control);
}
.account__menu a .icon { color: var(--ds-muted); }
.account__menu a:hover { background: var(--ds-surface-muted); color: var(--ds-ink); }
.account__menu hr { height: 1px; margin: var(--ds-space-1) 0; background: var(--ds-border); border: 0; }

.xp-pill {
  display: inline-flex; align-items: center; gap: var(--ds-space-2);
  min-height: 36px; padding: 4px 12px 4px 4px;
  background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-pill);
  color: var(--ds-ink-secondary); font-size: var(--ds-text-small); font-weight: 600; white-space: nowrap;
}
[dir="rtl"] .xp-pill { padding: 4px 4px 4px 12px; }
.xp-pill b { color: var(--ds-ink); font-variant-numeric: tabular-nums; }
.xp-pill__level {
  display: grid; place-items: center; width: 28px; height: 28px;
  background: var(--ds-gold-soft); color: var(--ds-gold-dark);
  border: 1px solid var(--ds-gold-line); border-radius: 50%; font-size: 13px; font-weight: 700;
}

/* ------------------------------------------------------------ page heads */

.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--ds-space-4); margin-block-end: var(--ds-space-6);
}
.page-head > div:first-child { min-width: 0; max-width: 72ch; }
.page-head h1 { margin: 0; }
.page-head p { margin: var(--ds-space-2) 0 0; color: var(--ds-text-muted); font-size: var(--ds-text-base); }
.page-head__actions { display: flex; flex-wrap: wrap; gap: var(--ds-space-3); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); margin-block-end: var(--ds-space-3); color: var(--ds-text-muted); font-size: var(--ds-text-small); }
.crumbs a:hover { color: var(--ds-primary); text-decoration: underline; text-underline-offset: 3px; }
.crumbs span[aria-hidden] { color: var(--ds-muted); }

/* --------------------------------------------------------------- buttons */

.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--ds-space-2);
  min-height: var(--ds-control-height); padding: 10px 20px;
  border: 1px solid transparent; border-radius: var(--ds-radius-control);
  font-size: var(--ds-text-control); font-weight: 600; line-height: 1.2; white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease),
              color var(--ds-duration) var(--ds-ease), box-shadow var(--ds-duration) var(--ds-ease);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--ds-primary); color: #fff; }
.btn-primary:hover { background: var(--ds-primary-hover); }
.btn-primary:active { background: #6F1F26; }

.btn-secondary, .btn-ghost { background: var(--ds-surface); border-color: var(--ds-border-strong); color: var(--ds-ink); }
.btn-secondary:hover, .btn-ghost:hover { background: var(--ds-surface-muted); border-color: #BDB7AC; }
.btn-secondary:active, .btn-ghost:active { background: var(--ds-surface-sunken); }

.btn-text, .btn-quiet { background: transparent; color: var(--ds-ink-secondary); padding-inline: 12px; }
.btn-text:hover, .btn-quiet:hover { background: var(--ds-surface-sunken); color: var(--ds-ink); }

.btn-danger { background: var(--ds-surface); border-color: var(--ds-danger-line); color: var(--ds-danger); }
.btn-danger:hover { background: var(--ds-danger-soft); border-color: var(--ds-danger); }

/* A decision that puts something live: approve, publish. */
.btn-accent { background: var(--ds-success); color: #fff; }
.btn-accent:hover { background: #1B5B48; }

.btn-sm { padding: 8px 14px; font-size: 15px; }
.btn-lg { min-height: 50px; padding: 12px 26px; font-size: 17px; }
.btn-block { width: 100%; }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: ds-spin .7s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after, .btn-text.is-loading::after, .btn-quiet.is-loading::after {
  border-color: var(--ds-border-strong); border-top-color: var(--ds-primary);
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--ds-control-height); height: var(--ds-control-height);
  background: transparent; border: 1px solid transparent; border-radius: var(--ds-radius-control);
  color: var(--ds-ink-secondary);
  transition: background-color var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease);
}
.icon-btn:hover { background: var(--ds-surface-sunken); color: var(--ds-ink); }
.icon-btn[aria-pressed="true"] { background: var(--ds-gold-soft); border-color: var(--ds-gold-line); color: var(--ds-gold-dark); }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-card);
  box-shadow: var(--ds-shadow-small);
}
.card-pad { padding: var(--ds-space-5); }
.card-hover { transition: transform var(--ds-duration) var(--ds-ease), box-shadow var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease); }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--ds-shadow); border-color: var(--ds-border-strong); }

.panel {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-card);
  box-shadow: var(--ds-shadow-small);
  overflow: hidden;
}
.panel__head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--ds-space-3);
  padding: var(--ds-space-4) var(--ds-space-5);
  border-block-end: 1px solid var(--ds-border);
}
.panel__head h2, .panel__head h3 { margin: 0; font-size: var(--ds-h3); font-weight: 650; }
.panel__body { padding: var(--ds-space-5); }

/* book card */
.book-card { display: flex; flex-direction: column; overflow: hidden; }
.book-card__cover { position: relative; aspect-ratio: 3 / 4; overflow: hidden; background: var(--ds-surface-sunken); }
.book-card__cover img { width: 100%; height: 100%; object-fit: cover; }
.book-card__level {
  position: absolute; inset-block-start: var(--ds-space-3); inset-inline-start: var(--ds-space-3);
  padding: 2px 10px; background: rgba(255, 255, 255, .94); border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-pill); color: var(--ds-primary); font-size: var(--ds-text-small); font-weight: 700;
}
.book-card__body { display: flex; flex: 1; flex-direction: column; gap: var(--ds-space-2); padding: var(--ds-space-4) var(--ds-space-4) var(--ds-space-5); }
.book-card__title { margin: 0; font-size: 18px; line-height: 1.3; }
.book-card__meta { color: var(--ds-text-muted); font-size: var(--ds-text-help); }
.book-card__foot { margin-block-start: auto; padding-block-start: var(--ds-space-2); }

/* ------------------------------------------------------------ indicators */

.progress { height: 8px; background: var(--ds-surface-sunken); border-radius: var(--ds-radius-pill); overflow: hidden; }
.progress__bar { height: 100%; background: var(--ds-primary); border-radius: inherit; transition: width .4s var(--ds-ease); }
.progress-lg { height: 10px; }
.progress--gold .progress__bar { background: var(--ds-gold); }
.progress--ok .progress__bar { background: var(--ds-success); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; min-height: 26px;
  border: 1px solid transparent; border-radius: var(--ds-radius-pill);
  font-size: var(--ds-text-small); font-weight: 600; line-height: 1.4; white-space: nowrap;
}
.badge-ok, .badge-warn, .badge-err, .badge-info { padding-inline-start: 9px; }
.badge-ok::before, .badge-warn::before, .badge-err::before, .badge-info::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.badge-ok      { background: var(--ds-success-soft); border-color: var(--ds-success-line); color: var(--ds-success); }
.badge-warn    { background: var(--ds-warning-soft); border-color: var(--ds-warning-line); color: var(--ds-warning); }
.badge-err     { background: var(--ds-danger-soft); border-color: var(--ds-danger-line); color: var(--ds-danger); }
.badge-info    { background: var(--ds-info-soft); border-color: var(--ds-info-line); color: var(--ds-info); }
.badge-neutral { background: var(--ds-surface-muted); border-color: var(--ds-border); color: var(--ds-ink-secondary); }
.badge-brand   { background: var(--ds-primary-soft); border-color: var(--ds-primary-line); color: var(--ds-primary); }
.badge-gold    { background: var(--ds-gold-soft); border-color: var(--ds-gold-line); color: var(--ds-gold-dark); }

.stat {
  display: grid; gap: 2px; padding: var(--ds-space-4) var(--ds-space-5);
  background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-inner);
}
.stat__value { color: var(--ds-ink); font-size: 26px; font-weight: 650; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--ds-text-muted); font-size: var(--ds-text-help); }

/* ----------------------------------------------------------------- forms */

.field { display: grid; gap: 6px; margin-block-end: var(--ds-space-4); }
.field > label, .field > .label { color: var(--ds-ink-secondary); font-size: var(--ds-text-help); font-weight: 600; }
.field .hint, .hint { color: var(--ds-text-muted); font-size: var(--ds-text-small); line-height: 1.5; }

.input, .select, .textarea {
  width: 100%; min-height: var(--ds-control-height); padding: 10px 14px;
  background: var(--ds-surface); border: 1px solid var(--ds-border-strong); border-radius: var(--ds-radius-control);
  color: var(--ds-ink); font-size: var(--ds-text-control); line-height: 1.4;
  transition: border-color var(--ds-duration) var(--ds-ease), box-shadow var(--ds-duration) var(--ds-ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ds-muted); }
.input:hover, .select:hover, .textarea:hover { border-color: #BDB7AC; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--ds-primary); outline: none; box-shadow: 0 0 0 3px rgba(176, 138, 54, .22); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: var(--ds-focus-ring); outline-offset: 1px; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--ds-surface-muted); color: var(--ds-text-muted); cursor: not-allowed; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--ds-danger); }
.textarea { min-height: 120px; resize: vertical; }
.select {
  appearance: none; padding-inline-end: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23414852' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center;
}
[dir="rtl"] .select { background-position: left 16px center; }

.check {
  display: flex; align-items: flex-start; gap: var(--ds-space-3);
  min-height: var(--ds-control-height); padding: 10px 14px;
  background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-control);
  cursor: pointer;
  transition: background-color var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease);
}
.check:hover { background: var(--ds-surface-muted); border-color: var(--ds-border-strong); }
.check:has(input:checked) { border-color: var(--ds-primary-line); background: #FFFBFB; }
.check input { flex: none; width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--ds-primary); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--ds-primary); }

fieldset { min-width: 0; }

/* -------------------------------------------------------- alerts + toasts */

.flash-stack { display: grid; gap: var(--ds-space-3); }
.alert {
  display: flex; align-items: flex-start; gap: var(--ds-space-3);
  padding: 14px 18px;
  background: var(--ds-surface); border: 1px solid var(--ds-border);
  border-inline-start-width: 4px; border-radius: var(--ds-radius-inner);
  color: var(--ds-ink); font-size: var(--ds-text-control); line-height: 1.5;
}
.alert > span { flex: 1; min-width: 0; }
.alert-ok   { background: var(--ds-success-soft); border-color: var(--ds-success-line); border-inline-start-color: var(--ds-success); }
.alert-err  { background: var(--ds-danger-soft); border-color: var(--ds-danger-line); border-inline-start-color: var(--ds-danger); }
.alert-info { background: var(--ds-info-soft); border-color: var(--ds-info-line); border-inline-start-color: var(--ds-info); }
.alert-warn { background: var(--ds-warning-soft); border-color: var(--ds-warning-line); border-inline-start-color: var(--ds-gold); }
.alert .btn { flex: none; }
.alert__close { margin-block: -8px; margin-inline: 0 -10px; }

/* ----------------------------------------------------------------- table */

/* Positioned, so visually hidden labels inside the table stay clipped by it. */
.table-wrap {
  position: relative;
  overflow-x: auto;
  background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-inner);
}
table.data { width: 100%; border-collapse: collapse; font-size: 16px; }
table.data th, table.data td { padding: 12px 16px; text-align: start; vertical-align: middle; border-block-end: 1px solid var(--ds-border); }
table.data th {
  background: var(--ds-surface-muted); color: var(--ds-ink-secondary);
  font-size: var(--ds-text-small); font-weight: 650; white-space: nowrap;
}
table.data tbody tr:last-child td { border-block-end: 0; }
table.data tbody tr { transition: background-color var(--ds-duration) var(--ds-ease); }
table.data tbody tr:hover { background: #FBFAF8; }
table.data .num { text-align: end; font-variant-numeric: tabular-nums; }
table.data a:not(.btn) { color: var(--ds-ink); font-weight: 600; }
table.data a:not(.btn):hover { color: var(--ds-primary); text-decoration: underline; text-underline-offset: 3px; }

/* ------------------------------------------------------ chips, tabs, pages */

.chip-row { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--ds-space-2);
  min-height: var(--ds-control-height); padding: 8px 16px;
  background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-pill);
  color: var(--ds-ink-secondary); font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: background-color var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease), color var(--ds-duration) var(--ds-ease);
}
.chip:hover { border-color: var(--ds-border-strong); color: var(--ds-ink); }
.chip[aria-pressed="true"], .chip.is-active, .chip[aria-current="page"] {
  background: var(--ds-primary-soft); border-color: var(--ds-primary-line); color: var(--ds-primary);
}
.chip .badge { min-height: 22px; padding-block: 0; }

.divider { height: 1px; margin-block: var(--ds-space-5); background: var(--ds-border); border: 0; }

details.accordion { border: 1px solid var(--ds-border); border-radius: var(--ds-radius-inner); background: var(--ds-surface); }
details.accordion > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3);
  min-height: var(--ds-control-height); padding: 10px 16px; font-weight: 600; cursor: pointer; list-style: none;
}
details.accordion > summary::-webkit-details-marker { display: none; }
details.accordion > div { padding: 0 16px 16px; }

/* ----------------------------------------------------------- empty, load */

.empty {
  display: grid; justify-items: center; gap: var(--ds-space-3);
  padding: var(--ds-space-7) var(--ds-space-5); text-align: center; color: var(--ds-text-muted);
}
.empty h2 { color: var(--ds-ink); font-size: var(--ds-h3); }
.empty p { max-width: 52ch; }
.empty__icon {
  display: grid; place-items: center; width: 56px; height: 56px;
  background: var(--ds-surface-muted); border: 1px solid var(--ds-border); border-radius: 50%;
  color: var(--ds-ink-secondary); font-size: 24px;
}
.empty__icon .icon { width: 24px; height: 24px; }

.skeleton {
  display: block; min-height: 1em;
  background: linear-gradient(90deg, var(--ds-surface-sunken) 0%, #F6F4F0 50%, var(--ds-surface-sunken) 100%);
  background-size: 200% 100%; border-radius: var(--ds-radius-control);
  animation: ds-shimmer 1.4s ease-in-out infinite;
}
@keyframes ds-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------------------------------------------------------------- footer */

.footer {
  padding: var(--ds-space-5) var(--ds-space-6);
  border-block-start: 1px solid var(--ds-border);
  color: var(--ds-text-muted); font-size: var(--ds-text-small);
}
.footer__inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--ds-space-2) var(--ds-space-5); width: min(100%, var(--ds-content-max)); margin-inline: auto; }

/* ------------------------------------------------------------- dashboard */

.dash { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--ds-space-5); align-items: start; }
.dash__main, .dash__side { display: grid; gap: var(--ds-space-5); min-width: 0; }

.continue { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: var(--ds-space-5); padding: var(--ds-space-5); }
.continue__cover { overflow: hidden; aspect-ratio: 3 / 4; background: var(--ds-surface-sunken); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-control); }
.continue__cover img { width: 100%; height: 100%; object-fit: cover; }
.continue h2 { margin: var(--ds-space-2) 0 var(--ds-space-1); }
.continue__meta { margin-block-end: var(--ds-space-4); color: var(--ds-text-muted); font-size: var(--ds-text-help); }
.continue__progress { display: grid; gap: var(--ds-space-2); max-width: 460px; margin-block-end: var(--ds-space-5); }
.continue__progress span { color: var(--ds-text-muted); font-size: var(--ds-text-help); }

.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--ds-space-3); margin-block-end: var(--ds-space-4); }
.section-head h2 { margin: 0; font-size: var(--ds-h2); }

.level { display: grid; gap: var(--ds-space-4); padding: var(--ds-space-5); }
.level__top { display: flex; align-items: center; gap: var(--ds-space-4); }
.level__badge {
  display: grid; place-items: center; width: 52px; height: 52px; flex: none;
  background: var(--ds-gold-soft); border: 1px solid var(--ds-gold-line); border-radius: 50%;
  color: var(--ds-gold-dark); font-size: 20px; font-weight: 700;
}
.level__facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ds-space-3); }
.level__facts div { padding: var(--ds-space-3) var(--ds-space-4); background: var(--ds-surface-muted); border-radius: var(--ds-radius-control); }
.level__facts b { display: block; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.level__facts span { color: var(--ds-text-muted); font-size: var(--ds-text-small); }

.list-rows { display: grid; margin: 0; padding: 0; list-style: none; }
.list-rows > li + li { border-block-start: 1px solid var(--ds-border); }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3);
  min-height: 56px; padding: 10px var(--ds-space-5);
  transition: background-color var(--ds-duration) var(--ds-ease);
}
a.list-row:hover { background: var(--ds-surface-muted); }
.list-row strong { display: block; font-size: 16px; font-weight: 600; line-height: 1.35; }
.list-row small { color: var(--ds-text-muted); }
.word-meter { display: grid; grid-template-columns: minmax(0, 1fr) 72px 40px; align-items: center; gap: var(--ds-space-3); }
.word-meter .progress { height: 6px; }
.word-meter__pct { color: var(--ds-text-muted); font-size: var(--ds-text-small); text-align: end; font-variant-numeric: tabular-nums; }

.profile-head { display: flex; align-items: center; gap: var(--ds-space-4); margin-block-end: var(--ds-space-6); }
.profile-head h1 { margin: 0; }
.profile-head p { margin: 2px 0 0; color: var(--ds-text-muted); }

/* ------------------------------------------------------------ responsive */

@media (max-width: 1279px) {
  .dash { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* Below 1024px the sidebar becomes a drawer opened from the top bar. */
@media (max-width: 1023px) {
  .shell__main { margin-inline-start: 0; }
  .sidebar {
    width: min(var(--ds-sidebar-width), 86vw);
    box-shadow: var(--ds-shadow);
    transform: translateX(-100%); visibility: hidden;
    transition: transform var(--ds-duration) var(--ds-ease), visibility 0s linear var(--ds-duration);
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .shell.is-nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--ds-duration) var(--ds-ease); }
  .shell.is-nav-open .shell-scrim { opacity: 1; pointer-events: auto; }
  .sidebar__brand > .sidebar__close, .topbar > .topbar__menu { display: inline-grid; }
  .topbar > .topbar__brand { display: inline-flex; }
  .topbar { padding-inline: var(--ds-space-5); }
  .content { padding: var(--ds-space-5) var(--ds-space-5) var(--ds-space-7); }
  .dash { grid-template-columns: minmax(0, 1fr); }
  .dash__side { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
}

/* The drawer shell behaves this way at every width. */
.shell--drawer .shell__main { margin-inline-start: 0; }
.shell--drawer .sidebar {
  width: min(var(--ds-sidebar-width), 86vw); box-shadow: var(--ds-shadow);
  transform: translateX(-100%); visibility: hidden;
  transition: transform var(--ds-duration) var(--ds-ease), visibility 0s linear var(--ds-duration);
}
[dir="rtl"] .shell--drawer .sidebar { transform: translateX(100%); }
.shell--drawer.is-nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--ds-duration) var(--ds-ease); }
.shell--drawer.is-nav-open .shell-scrim { opacity: 1; pointer-events: auto; }
.shell--drawer .sidebar__brand > .sidebar__close, .shell--drawer .topbar > .topbar__menu { display: inline-grid; }
.shell--drawer .topbar > .topbar__brand { display: inline-flex; }

@media (max-width: 767px) {
  .topbar { gap: var(--ds-space-2); padding-inline: var(--ds-space-4); }
  .topbar__brand .brand__text small { display: none; }
  .account__name, .account__chevron { display: none; }
  .account__button { padding: 2px; }
  .xp-pill { padding-inline-end: 10px; }
  .xp-pill .text-muted { display: none; }
  .content { padding: var(--ds-space-5) var(--ds-space-4) var(--ds-space-7); }
  .page-head { align-items: stretch; margin-block-end: var(--ds-space-5); }
  .page-head__actions, .page-head > .btn { width: 100%; }
  .page-head__actions .btn, .page-head > .btn { flex: 1 1 auto; }
  .panel__head, .panel__body, .card-pad { padding-inline: var(--ds-space-4); }
  .continue { grid-template-columns: 1fr; padding: var(--ds-space-4); }
  .continue__cover { display: none; }
  .grid-cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: var(--ds-space-4); }
  .level__facts { grid-template-columns: 1fr 1fr; }
  table.data th, table.data td { padding: 10px 12px; }
  .footer { padding-inline: var(--ds-space-4); }
}

/* On a phone the top bar keeps the menu, the brand and the account; the level card has the XP. */
@media (max-width: 479px) {
  .topbar .xp-pill { display: none; }
}

@media print {
  .sidebar, .topbar, .btn, .footer, .shell-scrim { display: none !important; }
  .shell__main { margin: 0; }
  body { background: #fff; }
}
