/* Home page. Portrait canvas: 42 x 90 rem. Landscape canvas: 96 x 54 rem. */
html { font-size: clamp(5px, min(100vw / 42, 100vh / 90), 12px); }
@supports (height: 100dvh) {
  html { font-size: clamp(5px, min(100vw / 42, 100dvh / 90), 12px); }
}

body.home-page {
  padding: 1.2rem;
  display: flex;
  justify-content: center;
}

.home {
  width: 100%;
  max-width: 44rem;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 1.4rem;
}

.top { display: flex; flex-direction: column; gap: 1.2rem; }

.head-row { display: flex; align-items: center; justify-content: space-between; gap: 1.6rem; }
.theme-btn {
  flex: none;
  height: 3.2rem;
  padding: 0 1.1rem;
  border: 0.1rem solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.site-head h1 { margin: 0; font-size: 3.4rem; line-height: 1.2; letter-spacing: -0.02em; }
.site-head h1 span { color: var(--primary); }
.site-head p { margin: 0.3rem 0 0; color: var(--muted); font-size: 1.5rem; line-height: 1.35; }
.site-head p.fine { margin-top: 0.4rem; font-size: 1.15rem; line-height: 1.3; }

.grade-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.8rem; }
.grade-nav button {
  height: 4.2rem;
  padding: 0 0.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1.15;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  border: 0.15rem solid var(--border);
  border-radius: 1.2rem;
  cursor: pointer;
  white-space: nowrap;
}
.grade-nav button small { font-size: 0.95rem; font-weight: 600; opacity: 0.75; }
.grade-nav button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.card-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.ex-card {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  background: var(--card);
  border: 0.2rem solid transparent;
  border-radius: 1.6rem;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 0.4rem 1.2rem rgba(0,0,0,0.05);
  transition: transform 0.12s, border-color 0.12s;
}
.ex-card:hover, .ex-card:focus-visible { transform: translateY(-0.2rem); border-color: var(--primary); outline: none; }

.ex-head { display: flex; align-items: center; gap: 0.7rem; }
.ex-icon {
  flex: none;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 0.9rem;
  background: var(--icon-bg); /* stays pale in dark mode so dark emoji remain visible */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}
/* Titles are kept to two lines so the description and records always have room. */
.ex-title { min-width: 0; font-weight: 700; font-size: 1.45rem; line-height: 1.2; overflow-wrap: break-word; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.ex-blurb {
  flex: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.ex-status { margin-top: auto; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; font-weight: 700; color: var(--muted); white-space: nowrap; }
.ex-best { list-style: none; margin: auto 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.ex-best li { display: flex; align-items: center; gap: 0.5rem; font-size: 1.2rem; line-height: 1.3; font-weight: 600; white-space: nowrap; }
.ex-best .when { color: var(--muted); }
.ex-best .time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-best .score { min-width: 3.4rem; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
/* A card with records gives its blurb one line so the three rows always fit. */
.ex-card:has(.ex-best) .ex-blurb { -webkit-line-clamp: 1; }

.site-foot { min-width: 0; display: flex; align-items: center; justify-content: center; gap: 0.9rem; color: var(--muted); font-size: 1.2rem; white-space: nowrap; }
.site-foot a { color: var(--muted); text-decoration: none; }
.site-foot span a { text-decoration: underline; }
.site-foot a:hover { color: var(--primary); text-decoration: underline; }
.site-foot [hidden] { display: none; }

/* Page switcher that takes the last card slot when a grade has more than 8 exercises. */
.ex-pager { align-items: center; justify-content: center; gap: 0.6rem; text-align: center; background: var(--primary-light); }
.ex-pager:hover { transform: none; border-color: transparent; }
.pager-title { font-size: 1.55rem; font-weight: 700; }
.pager-page { font-size: 1.2rem; font-weight: 600; color: var(--muted); }
.pager-btns { display: flex; gap: 1rem; margin-top: 0.4rem; }
.pager-btns button {
  width: 5rem;
  height: 4.4rem;
  border: none;
  border-radius: 1.2rem;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1;
  padding: 0 0 0.3rem;
  cursor: pointer;
}
.pager-btns button:hover { background: var(--primary-dark); }
.ex-blurb.ex-resume { color: var(--primary); font-weight: 700; }

@media (orientation: landscape) {
  html { font-size: clamp(4px, min(100vw / 96, 100vh / 54), 12px); }
  @supports (height: 100dvh) {
    html { font-size: clamp(4px, min(100vw / 96, 100dvh / 54), 12px); }
  }
  .home { max-width: 94rem; gap: 1.2rem; }
  .top { flex-direction: row; align-items: center; justify-content: space-between; gap: 3rem; }
  .grade-nav { flex: none; width: 44rem; }
  .card-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 1.2rem; }
  .ex-card { padding: 1.4rem; gap: 0.8rem; }
  .ex-blurb { -webkit-line-clamp: 3; }
  .ex-card:has(.ex-best) .ex-blurb { -webkit-line-clamp: 2; }
}
