/* Base homepage layout */
.page-main.home-shell {
  display: grid;
  grid-template-columns: minmax(210px, 250px) minmax(0, 1fr);
  gap: clamp(1.5rem, 2.5vw, 2.5rem);
  width: min(100% - 3rem, 1600px);
  max-width: none;
  margin-inline: auto;
  box-sizing: border-box;
  align-items: start;
}

.home-sidebar {
  position: sticky;
  top: 1.25rem;
  max-height: calc(100vh - 2.5rem);
  overflow-y: auto;
  padding: 1rem 0.75rem 1rem 0;
  border-right: 1px solid #e5e9f0;
}

.home-sidebar > h2 {
  margin: 0 0 0.75rem;
  padding: 0 0.75rem;
  color: #647084;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.home-sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-group {
  color: #39465b;
}

.sidebar-group summary {
  position: relative;
  padding: 0.55rem 0.65rem 0.55rem 1.65rem;
  border-radius: 7px;
  cursor: pointer;
  list-style: none;
}

.sidebar-group summary::-webkit-details-marker {
  display: none;
}

.sidebar-group summary::before {
  position: absolute;
  left: 0.7rem;
  content: "›";
  color: #7a8494;
  transition: transform 120ms ease;
}

.sidebar-group[open] summary::before {
  transform: rotate(90deg);
}

.sidebar-group summary > a {
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}

.sidebar-group summary:hover,
.sidebar-group summary:focus-within {
  background: #f3f5f8;
}

.sidebar-group ul {
  margin: 0.15rem 0 0.35rem 1.05rem;
  padding: 0 0 0 0.65rem;
  border-left: 1px solid #e5e9f0;
  list-style: none;
}

.sidebar-group li a {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  color: #596579;
  font-size: 0.92rem;
  line-height: 1.35;
  text-decoration: none;
}

.sidebar-group li a:hover,
.sidebar-group li a:focus-visible {
  background: #f3f5f8;
  color: #172033;
  outline: none;
}

.sidebar-group li a[aria-current="location"] {
  background: #eef4ff;
  color: #1f5fbf;
  font-weight: 600;
}

.home-content {
  min-width: 0;
}

.subject-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 1rem;
  min-width: 0;
}

.subject-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  min-height: 180px;
  padding: 1.25rem 1.15rem;
  border: 1px solid #e5e9f0;
  border-radius: 16px;
  background: #fff;
  color: #172033;
  text-decoration: none;
  box-shadow: 0 4px 18px rgba(23, 32, 51, 0.04);
  scroll-margin-top: 1.5rem;
  overflow-wrap: anywhere;
}

.subject-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
}

.subject-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.subject-card p {
  margin: 0.6rem 0 0;
  color: #647084;
}

.card-bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 1.1rem;
  padding-top: 0.7rem;
  border-top: 1px solid #edf1f5;
  color: #39465b;
  font-size: 0.9rem;
}

.topics-index {
  margin-top: 2rem;
}

.subject-topics + .subject-topics {
  margin-top: 2.25rem;
}

.subject-topics > h2 {
  margin-bottom: 1rem;
  font-size: 1.35rem;
}

.home-topic {
  scroll-margin-top: 1.25rem;
}

.home-topic + .home-topic {
  margin-top: 1.25rem;
}

.home-topic > h3 {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
}

.home-topic h4 {
  margin: 0;
  font-size: 1rem;
}

.exercise-list {
  min-width: 0;
}

.exercise-row {
  overflow-wrap: anywhere;
}

@media (min-width: 1500px) {
  .subject-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .page-main.home-shell {
    width: min(100% - 2rem, 760px);
    grid-template-columns: minmax(0, 1fr);
  }

  .home-sidebar {
    position: sticky;
    z-index: 5;
    top: 0;
    max-height: min(45vh, 360px);
    margin: 0 -1rem;
    padding: 0.75rem 1rem;
    border: 1px solid #e5e9f0;
    border-radius: 0 0 12px 12px;
    background: rgba(251, 252, 254, 0.97);
    backdrop-filter: blur(8px);
  }

  .home-sidebar nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.15rem 0.5rem;
  }
}

@media (max-width: 520px) {
  .page-main.home-shell {
    width: calc(100% - 2rem);
  }

  .subject-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .home-sidebar nav {
    grid-template-columns: minmax(0, 1fr);
  }

  .exercise-row {
    min-width: 0;
  }
}
