/* WorksheetHub — component layer. */

/* ------------------------------- buttons ------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 11px var(--s5); border-radius: var(--r-md); border: 1px solid transparent;
  font-family: var(--font-body); font-size: var(--step-0); font-weight: 600; line-height: 1.2;
  cursor: pointer; transition: background .15s, border-color .15s, transform .1s, color .15s;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.btn-primary { background: var(--btn-ink); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--btn-ink-hover); color: #fff; }

.btn-secondary { background: var(--surface); color: var(--link); border-color: var(--primary); }
.btn-secondary:hover { background: var(--primary-tint); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-success { background: var(--secondary); color: #fff; }
.btn-success:hover { filter: brightness(.94); }

.btn-lg { padding: 15px var(--s6); font-size: var(--step-1); border-radius: var(--r-lg); }
.btn-sm { padding: 7px var(--s3); font-size: var(--step--1); border-radius: var(--r-sm); }
.btn-block { width: 100%; }

/* ------------------------------- surfaces ------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s5); box-shadow: var(--shadow-1);
}
.card-flat { box-shadow: none; }
.card-pad-sm { padding: var(--s4); }
/* A card that is a link: inherit colour and lift on hover, but do NOT dictate
   `display` — variants such as .grade-card set their own, and a rule of equal
   or higher specificity here silently overrode them. */
a.card, .card-link { color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; }
.card { display: block; }
a.card:hover, .card-link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border-strong); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-head h3, .card-head h4 { margin: 0; }
.card-title-sm { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 0 0 var(--s3); font-family: var(--font-body); }

.tile-icon {
  width: 44px; height: 44px; border-radius: var(--r-md); flex: none;
  display: grid; place-items: center; font-size: 20px;
  background: var(--primary-tint); color: var(--brand-ink);
}
.tile-icon.green  { background: var(--secondary-light); color: var(--ok-ink); }
.tile-icon.orange { background: var(--accent-light);    color: var(--warn-ink); }
.tile-icon.red    { background: var(--danger-light);    color: var(--bad-ink); }
.tile-icon.lg { width: 56px; height: 56px; font-size: 26px; border-radius: var(--r-lg); }

/* --------------------------- badges & statuses --------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: var(--step--1); font-weight: 600; line-height: 1.5;
  background: var(--surface-2); color: var(--text-2);
}
.badge-primary { background: var(--primary-tint);    color: var(--brand-ink); }
.badge-success { background: var(--secondary-light); color: var(--ok-ink); }
.badge-warn    { background: var(--accent-light);    color: var(--warn-ink); }
.badge-danger  { background: var(--danger-light);    color: var(--bad-ink); }

.pill-count { background: var(--btn-ink); color: #fff; border-radius: var(--r-pill); font-size: 11px; font-weight: 700; padding: 1px 7px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px var(--s3); border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-size: var(--step--1); font-weight: 600; cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--link); text-decoration: none; }
.chip[aria-pressed="true"], .chip.is-active { background: var(--btn-ink); border-color: var(--btn-ink); color: #fff; }


.eyebrow {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 6px var(--s4); border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-1);
  font-size: var(--step--1); font-weight: 600; color: var(--text-2);
}

/* --------------------------------- forms --------------------------------- */
.field { display: block; margin-bottom: var(--s4); }
.field > .label, .label {
  display: block; font-size: var(--step--1); font-weight: 600;
  color: var(--text); margin-bottom: 6px;
}
.input, .select, .textarea {
  width: 100%; padding: 11px var(--s4);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font-family: var(--font-body); font-size: var(--step-0);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.select {
  appearance: none; padding-right: var(--s6); cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%2364748B' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right var(--s3) center;
}
.hint { font-size: var(--step--1); color: var(--text-3); margin-top: 6px; }

/* What a form says when the server refuses it. Announced to a screen reader
   through role="alert", so it needs no colour to be noticed. */
.form-error {
  font-size: var(--step--1);
  color: var(--bad-ink);
  background: var(--danger-light);
  border-left: 3px solid var(--bad-ink);
  padding: 10px 14px;
  margin: 0 0 16px;
  border-radius: var(--r-sm);
}

.search-box { position: relative; }
.search-box .input { padding-left: 44px; height: 50px; border-radius: var(--r-pill); }
.search-box .search-ico { position: absolute; left: var(--s4); top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }

.check-row { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) 0; }
.check-row input { margin-top: 4px; accent-color: var(--primary); width: 18px; height: 18px; flex: none; }

/* ------------------------------ progress bars ------------------------------ */
.bar { height: 8px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .4s ease; }
.bar.green > span  { background: var(--secondary); }
.bar.orange > span { background: var(--accent); }
.bar-lg { height: 12px; }

.donut { display: grid; place-items: center; position: relative; width: 96px; height: 96px; flex: none; }
.donut svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.donut .track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.donut .value { fill: none; stroke: var(--primary); stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray .5s ease; }
.donut .donut-label { position: absolute; font-family: var(--font-head); font-weight: 700; font-size: var(--step-1); }

/* --------------------------------- stats --------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s4); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4) var(--s5); box-shadow: var(--shadow-1); }
.stat .stat-label { font-size: var(--step--1); color: var(--text-2); font-weight: 500; }
.stat .stat-value { font-family: var(--font-head); font-size: var(--step-3); font-weight: 700; line-height: 1.1; margin-top: 6px; }
.stat .stat-foot { font-size: var(--step--1); color: var(--text-3); margin-top: 4px; }
.stat .row-between { align-items: flex-start; flex-wrap: nowrap; }

/* --------------------------------- lists --------------------------------- */
.list { display: grid; gap: var(--s2); }
.list-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3); border-radius: var(--r-md); color: inherit;
}
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item .list-title { font-weight: 600; font-size: var(--step-0); color: var(--text); }
.list-item .list-sub { font-size: var(--step--1); color: var(--text-2); }
.list-divided .list-item + .list-item { border-top: 1px solid var(--border); border-radius: 0; }

.table { width: 100%; border-collapse: collapse; font-size: var(--step-0); }
.table th, .table td { text-align: left; padding: var(--s3); border-bottom: 1px solid var(--border); }
.table th { font-size: var(--step--1); text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 700; }
.table tbody tr:hover { background: var(--surface-2); }
.table-scroll { overflow-x: auto; }

/* --------------------------------- misc --------------------------------- */
.empty { text-align: center; padding: var(--s8) var(--s5); color: var(--text-2); }
.empty .empty-ico {
  display: inline-grid; place-items: center; width: 64px; height: 64px;
  border-radius: 50%; background: var(--surface-2); color: var(--text-3);
  margin-bottom: var(--s4);
}

.toast-host { position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: var(--s2); pointer-events: none; }
.toast {
  background: var(--text); color: var(--surface); padding: var(--s3) var(--s5);
  border-radius: var(--r-pill); box-shadow: var(--shadow-3); font-weight: 600; font-size: var(--step-0);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.star-btn {
  background: none; border: 0; cursor: pointer; line-height: 0;
  color: var(--text-3); padding: var(--s1); border-radius: var(--r-sm);
}
.star-btn:hover { color: var(--accent); }
.star-btn[aria-pressed="true"] { color: var(--accent); }
.star-btn[aria-pressed="true"] .ico-svg { fill: currentColor; }

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

.math {
  font-family: var(--font-math); font-size: 1.5em; font-style: italic;
  letter-spacing: .01em; color: var(--text); line-height: 1.5;
}
.math sup { font-size: .62em; font-style: normal; }
.math .op { font-style: normal; padding-inline: .12em; }

.banner {
  display: flex; gap: var(--s4); align-items: center;
  padding: var(--s4) var(--s5); border-radius: var(--r-lg);
  background: var(--primary-tint); border: 1px solid var(--primary-light); color: var(--brand-ink);
}
.banner.warn { background: var(--accent-light); border-color: var(--accent); color: var(--warn-ink); }
.banner p { margin: 0; color: inherit; }

/* ============================== worksheet card ==============================
   The card leads with two real questions from the sheet. A worksheet is its
   questions; describing one without showing any asks the reader to take it on
   trust. */
.ex-card { display: flex; flex-direction: column; gap: var(--s3); height: 100%; }

.ex-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.ex-head-main { min-width: 0; }
.ex-card .ex-meta {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-2); font-size: var(--step--1); font-weight: 500;
  letter-spacing: .01em; margin-bottom: 4px;
}
.ex-card h3 { font-size: var(--step-1); margin: 0; line-height: 1.3; }
.ex-card .ex-title-link { color: var(--text); }
.ex-card .ex-title-link:hover { color: var(--link); text-decoration: none; }
.ex-card .ex-summary {
  margin: 0; font-size: var(--step--1); color: var(--text-2); line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.ex-preview {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s3) var(--s4) var(--s2);
}
.preview-sheet { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.preview-line { display: flex; gap: var(--s2); align-items: baseline; }
.preview-num {
  font-family: var(--font-head); font-weight: 700; font-size: var(--step--1);
  color: var(--text-3); min-width: 14px;
}
.preview-body { min-width: 0; display: grid; gap: 3px; }
.preview-prompt {
  font-size: var(--step--1); color: var(--text); line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preview-math {
  font-family: var(--font-math); font-style: italic; font-size: var(--step-0);
  color: var(--text); letter-spacing: .01em;
}
.preview-opts { display: grid; gap: 2px; }
.preview-opt {
  font-size: 11.5px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preview-answer { font-size: 11.5px; color: var(--text-3); }
.preview-rule { display: block; height: 1px; background: var(--border-strong); max-width: 130px; margin-top: 6px; }
.ex-preview-more {
  display: block; margin-top: var(--s3); padding-top: var(--s2);
  border-top: 1px dashed var(--border-strong);
  font-size: 11px; color: var(--text-3); font-weight: 600; letter-spacing: .02em;
}

.ex-card .ex-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.ex-card .ex-progress { margin-top: 2px; }
.ex-card .ex-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding-top: var(--s3); border-top: 1px solid var(--border);
}

.grade-card .grade-count { display: inline-flex; align-items: center; gap: 6px; }


.load-more { display: grid; justify-items: center; gap: var(--s3); padding: var(--s6) 0 var(--s3); }
.preview-opt { display: flex; gap: 7px; align-items: baseline; }
.preview-key {
  font-family: var(--font-head); font-weight: 700; font-size: 10px;
  color: var(--text-3); min-width: 9px; flex: none;
}

/* ============================== subject index ==============================
   A quiet, typographic list. The subject index is a table of contents, not a
   set of buttons, so it is set rather than decorated. */
.subject-index { border-top: 1px solid var(--border); }
.subject-row-card {
  display: block; color: inherit; text-decoration: none;
  padding: var(--s5) var(--s4) var(--s5) 0;
  border-bottom: 1px solid var(--border);
  transition: background .14s, padding-left .14s;
}
.subject-row-card:hover {
  text-decoration: none; background: var(--surface);
  padding-left: var(--s4); padding-right: var(--s4);
}
/* Wraps rather than overflowing: on a 320px screen the title and
   "99,579 worksheets" do not fit on one line, and the count belongs under the
   title rather than off the side of the phone. */
.subject-row-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s2) var(--s4); }
.subject-row-title {
  margin: 0; font-size: var(--step-2); font-weight: 600; letter-spacing: -.015em;
}
.subject-row-card:hover .subject-row-title { color: var(--link); }
.subject-row-count {
  font-size: var(--step--1); color: var(--text-3); font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.subject-row-blurb { margin: 6px 0 0; color: var(--text-2); font-size: var(--step-0); max-width: 68ch; }
.subject-row-topics {
  margin: var(--s3) 0 0; font-size: var(--step--1); color: var(--text-3);
  line-height: 1.7; max-width: 90ch;
}

/* Separators belong to the word before them, never to the line after — so the
   dot hangs off the end of the preceding chip, and the break opportunity (a
   zero-width space in the markup) comes after it. */
.subject-row-topics .topic-chip:not(:last-child)::after {
  content: '·'; color: var(--border-strong); margin: 0 .2em 0 .45em;
}

/* A grid rather than CSS columns: rows line up across the two tracks, and no
   entry can be split down the middle of a column break. */
@media (min-width: 900px) {
  .subject-index {
    /* minmax(0, 1fr), not 1fr: a bare 1fr track takes its minimum from its
       widest child, so one long topic name pushed the whole grid past the
       viewport. */
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: var(--s7); border-top: 0;
  }
  .subject-row-card:nth-child(-n+2) { border-top: 1px solid var(--border); }
}

/* ------------------------------ class cards ------------------------------ */
.class-card { display: grid; gap: var(--s3); }
.class-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3);
  padding: var(--s3) 0; border-block: 1px solid var(--border);
}
.class-stats > div { display: grid; gap: 2px; }
.class-stats strong { font-family: var(--font-head); font-size: var(--step-1); }
.class-stats span { font-size: var(--step--1); color: var(--text-2); }
.cell-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--border-strong);
}
.selected-strip {
  margin-top: var(--s4); padding: var(--s4);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.assigned-overdue { border-color: var(--danger); }

/* On the narrowest phones a button label is allowed to wrap. `nowrap` is right
   almost everywhere — a two-line button reads as a mistake — but at 320px
   "See a printable worksheet" is wider than the screen, and a button running
   off the side is worse than a button on two lines.
   This lives here, not in base.css, because components.css loads later and the
   two rules have the same specificity. */
@media (max-width: 380px) {
  .btn { white-space: normal; }
}
