/* ============================================================
   Count and Color — Separate Button UI with Shadows
   Version: 3.9 (Updated Header & Layout to match Coloring Page)
   ============================================================ */
:root {
  --brand-blue: #2f5fee;
  --text-primary: #0e2770;
  --text-secondary: #334155;
  --border-color: #e2e8f0;
  --stage-pad: 0.85rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
body {
  background: #ffffff;
  font-family: var(--smw-font-stack);
  color: var(--text-secondary);
}

img { max-width: 100%; }

.ico {
  flex-shrink: 0;
}

.ico-ws {
  width: 1.35rem;
  height: 1.35rem;
}

/* Container & Main Grid Layout */
.main-col-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  /* Changed: Removed inner padding to align with outer wrapper like Coloring page */
  padding: 0; 
}

.main-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  padding: 1.75rem 0;
  border-bottom: 1px solid rgba(50, 53, 62, .11);
  min-width: 0;
  border-radius: 10px;
  box-shadow: 0 6px 5px -5px #8FABD9;
}

.main-col:first-of-type {
  padding-top: 0.5rem;
}

.main-col:last-child {
  border-bottom: none;
  padding-bottom: 0.5rem;
}

@media (min-width: 768px) {
  .main-col {
    grid-template-columns: 200px 1fr;
    align-items: start;
    gap: 1.5rem;
  }

  .viewer { justify-content: flex-start; }
  .stage { justify-content: flex-start; }
}

@media (min-width: 1024px) {
  .main-col {
    grid-template-columns: 240px 1fr;
    gap: 2rem;
    padding: 1rem 0;
  }
}

@media (min-width: 1280px) {
  .main-col-container {
    padding: 0;
  }

  .main-col {
    grid-template-columns: 260px 1fr;
  }
}

/* Breadcrumb & Header */
.counting-main .breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #64748b;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.counting-main .breadcrumb a {
  color: var(--brand-blue);
  font-weight: 600;
  text-decoration: none;
  border-radius: 4px;
}

.counting-main .breadcrumb a:hover {
  text-decoration: underline;
}

.counting-main .breadcrumb .current {
  color: #0f172a;
  font-weight: 600;
}

/* Topic navigation: breadcrumb on the left, Topics dropdown on the right.
   The wrapper only exists when the page has sibling topics. */
.counting-main .counting-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.counting-main .counting-topbar .breadcrumb {
  margin-bottom: 0;
}

.counting-main .topic-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  max-height: 20px;
}

.counting-main .topic-nav-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.counting-main .topic-nav-select {
  min-width: 0;
  max-width: min(100%, 22rem);
  height: 2.25rem;
  padding: 0 0.75rem;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  background: #F4F8FF;
  border: 1.5px solid #BFD8FF;
  border-radius: 0.6rem;
  cursor: pointer;
  text-overflow: ellipsis;
}

.counting-main .topic-nav-select:hover {
  background: #EBF3FF;
}

.counting-main .topic-nav-select:focus-visible {
  outline: 2px solid var(--brand-blue);
  outline-offset: 2px;
}

@media (max-width: 767px) {
  .counting-main .topic-nav {
    width: 100%;
  }

  .counting-main .topic-nav-select {
    flex: 1 1 auto;
    font-size: 16px; /* avoids iOS zoom-on-focus */
  }
}

/* ============================================================
   UPDATED HEADER STRIP (Matching Coloring Page .hero)
   ============================================================ */
.counting-main .page-header.counting-header-strip {
  /* Matches .hero padding */
  padding: 1.375rem 1.75rem;
  background: oklch(0.95 0.03 264);
  border: 2px solid oklch(0.75 0.12 264);
  border-radius: 1rem;
  /* Matches .hero bottom margin */
  margin: 0 0 1.5rem 0;
  box-sizing: border-box;
  /* Keeps content contained like the coloring page */
  overflow: hidden;
  position: relative;
  width: 100%;
  max-width: 100%;
}

/* Fallback for browsers without oklch() support */
@supports not (background: oklch(0.95 0.03 264)) {
  .counting-main .page-header.counting-header-strip {
    background: #EEF2FD;
    border-color: #9DB2EE;
    box-shadow: 0 6px 18px rgba(47, 95, 238, 0.06);
  }
}

.counting-main .counting-header-strip .title {
  font-family: var(--smw-font-stack);
  font-size: 1.875rem; /* Matches .hero-text h1 */
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #0e2770;
  text-align: center;
  margin: 0 0 0.5rem 0;
  overflow-wrap: break-word;
}

.counting-main .counting-header-strip .subtitle {
  font-size: 0.9375rem; /* 15px, matches .hero-text p */
  line-height: 1.5;
  color: #0b205f;
  font-weight: 500;
  margin: 0 0 1.25rem 0; /* Matches .hero-text p margin */
  width: 100%;
  max-width: 100%;
  text-align: left;
}

/* Responsive Header adjustments */
@media (min-width: 640px) {
  .counting-main .counting-header-strip .title {
    font-size: 2.125rem;
  }
}

@media (max-width: 767.98px) {
  .counting-main .page-header.counting-header-strip {
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 0.875rem;
    border-width: 2px;
  }

  .counting-main .counting-header-strip .title {
    font-size: 1.5rem;
    text-align: left;
  }

  .counting-main .counting-header-strip .subtitle {
    font-size: 0.875rem;
  }
}

@media (max-width: 480px) {
  .counting-main .page-header.counting-header-strip {
    padding: 0.875rem;
  }
  .counting-main .counting-header-strip .title {
    font-size: 22px;
  }
}

/* Left Thumbnail Section */
.viewer {
  display: flex;
  justify-content: center;
  width: 100%;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 220px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  padding: var(--stage-pad);
  border-radius: 14px;
}

@media (min-width: 768px) {
  .stage {
    max-width: 100%;
    margin: 0;
  }
}

.stage-preview-link {
  display: flex;
  justify-content: center;
  width: auto;
  text-decoration: none;
}

.stage img {
  box-shadow: 2px 2px 10px oklch(75.075% 0.1194 263.698 / 0.911), -2px -2px 10px oklch(75.075% 0.1194 263.698 / 0.911);
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
  width: 190px;
  height: 250px;
  max-width: 100%;
  object-fit: contain;
}

.stage img:hover {
  box-shadow: 2px 2px 10px #55BAFF, -2px -2px 10px #55BAFF;
}

.info {
  padding-top: var(--stage-pad);
  min-width: 0;
  max-width: 100%;
}

.worksheet-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
}

.worksheet-description {
  font-size: 16px;
  line-height: 1.6;
  color: #0b205f;
  margin: 0 0 1.1rem 0;
  max-width: 62ch;
  font-weight: 500;
}

/* Fluid Flex Container preventing grid item overflow */
.worksheet-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  justify-content: flex-start;
  align-items: center;
  max-width: 100%;
}

/* ============================================================
   EXACT MATCH DESIGN: Side-by-Side Floating Buttons with Shadows
   ============================================================ */
.ws-item {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem; /* Gap between the pill and key circle */
  width: fit-content;
  max-width: 100%;
}

/* Main Worksheet Pill Button */
.btn-ws-dl {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  height: 2.75rem; /* ~44px height — compact, still touch-friendly */
  padding: 0 1.1rem 0 0.85rem;
  background: #F4F8FF;
  color: #121052;
  border: 1.5px solid #BFD8FF;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(59, 114, 196, 0.12);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

.btn-ws-dl .ws-label {
  font-family: var(--smw-font-stack);
  letter-spacing: -0.01em;
}

.btn-ws-dl:hover {
  background: #EBF3FF;
  box-shadow: 0 8px 20px rgba(59, 114, 196, 0.18);
  transform: translateY(-2px);
}

.btn-ws-dl:active {
  transform: translateY(0);
}

/* Separate Right Answer Key Circle Button */
.btn-key-dl {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem; /* Exact same height as pill button */
  height: 2.75rem;
  border-radius: 50%;
  background: #FFF0F5;
  border: 1.5px solid #FDC2D6;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(244, 37, 82, 0.12);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

.btn-key-dl:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(244, 37, 82, 0.18);
  background: #FFE4ED;
}

.btn-key-dl:active {
  transform: translateY(0);
}

/* Key icon sits inside the circle at a fixed size (not full-bleed) */
.ico-key {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.ico-key path {
  fill: #EC2251;
}

/* Proportional size bump on larger screens — stays compact, never oversized */
@media (min-width: 768px) {
  .btn-ws-dl {
    height: 2.875rem;
    padding: 0 1.25rem 0 0.95rem;
    font-size: 1.05rem;
    gap: 0.6rem;
  }

  .btn-key-dl {
    width: 2.875rem;
    height: 2.875rem;
  }

  .ico-ws {
    width: 1.45rem;
    height: 1.45rem;
  }

  .ico-key {
    width: 1.2rem;
    height: 1.2rem;
  }
}

@media (min-width: 1024px) {
  .btn-ws-dl {
    height: 3rem;
    padding: 0 1.4rem 0 1rem;
    font-size: 1.1rem;
    gap: 0.65rem;
  }

  .btn-key-dl {
    width: 3rem;
    height: 3rem;
  }

  .ico-ws {
    width: 1.55rem;
    height: 1.55rem;
  }

  .ico-key {
    width: 1.3rem;
    height: 1.3rem;
  }
}

.print-layer { display: none; }

/* ============================================================
   TOPICS DROPDOWN (Counting) — same look as the Money country selector
   ============================================================ */
.counting-main .topic-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 12px;
}

.counting-main .topic-bar .breadcrumb {
  margin-bottom: 0;
  flex: 1 1 280px;
  min-width: 0;
}

.counting-main .breadcrumb .current {
  min-width: 0;
  overflow-wrap: anywhere;
}

.counting-main .topic-picker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
  min-width: 0;
  max-width: 100%;
}

.counting-main .topic-picker-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.counting-main .topic-dropdown {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.counting-main .topic-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  max-width: min(100%, 22rem);
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  background: #ffffff;
  border: 1.5px solid oklch(0.75 0.12 264);
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(47, 95, 238, 0.08);
  cursor: pointer;
  list-style: none;
  user-select: none;
  white-space: nowrap;
  transition: background-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.counting-main .topic-trigger::-webkit-details-marker { display: none; }
.counting-main .topic-trigger::marker { content: ""; }

.counting-main .topic-trigger:hover {
  background: oklch(0.95 0.03 264);
}

.counting-main .topic-trigger:focus-visible {
  outline: 2px solid var(--brand-blue);
  outline-offset: 2px;
}

.counting-main .topic-dropdown[open] > .topic-trigger {
  box-shadow: 0 0 0 3px rgba(47, 95, 238, 0.15);
}

.counting-main .topic-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counting-main .topic-chevron {
  flex-shrink: 0;
  transition: transform 0.2s var(--ease);
}

.counting-main .topic-dropdown[open] .topic-chevron {
  transform: rotate(180deg);
}

.counting-main .topic-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 100%;
  width: max-content;
  max-width: min(92vw, 26rem);
  max-height: 70vh;
  overflow-y: auto;
  margin: 0;
  padding: 0.4rem;
  list-style: none;
  background: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(20, 30, 60, 0.14);
}

.counting-main .topic-option {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: background-color 0.2s var(--ease);
}

.counting-main .topic-option:hover {
  background: oklch(0.95 0.03 264);
}

.counting-main .topic-option.is-current {
  background: oklch(0.93 0.05 264);
  color: var(--brand-blue);
  font-weight: 700;
}

.counting-main .topic-option:focus-visible {
  outline: 2px solid var(--brand-blue);
  outline-offset: -2px;
}

/* Phones: breadcrumb above, label above a full-width dropdown. */
@media (max-width: 767px) {
  .counting-main .topic-bar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.75rem;
    min-width: 0;
    width: 100%;
  }

  .counting-main .topic-bar .breadcrumb {
    flex: 0 0 auto;
    max-width: 100%;
  }

  .counting-main .topic-picker {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    margin-left: 0;
    width: 100%;
  }

  .counting-main .topic-dropdown {
    width: 100%;
  }

  .counting-main .topic-trigger {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 100%;
  }

  .counting-main .topic-list {
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 60vh;
  }
}

/* ============================================================
   Per-worksheet title + description list shown under the download
   buttons on database-driven listing pages.
   ============================================================ */
.ws-details {
  list-style: none;
  margin: 1rem 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 62ch;
}

.ws-detail {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 0.75rem;
  row-gap: 0.1rem;
  align-items: baseline;
  padding-left: 0.75rem;
  border-left: 3px solid #BFD8FF;
}

.ws-detail-num {
  grid-column: 1;
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-blue);
  white-space: nowrap;
}

.ws-detail-title {
  grid-column: 2;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
}

.ws-detail-desc {
  grid-column: 2;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 500;
  color: var(--text-secondary);
}

@media (max-width: 767px) {
  .ws-detail {
    grid-template-columns: 1fr;
  }

  .ws-detail-num,
  .ws-detail-title,
  .ws-detail-desc {
    grid-column: 1;
  }
}