/* ==========================================================================
   ColoryBoo — Design tokens
   Palette pulled straight from the crayon-box logo: sky blue, sunny yellow,
   vibrant green, orange and candy pink, all outlined in a deep "crayon ink"
   navy. Fredoka carries the bubbly display voice; Quicksand is the calmer
   body/UI face so long stretches of text stay easy for parents to read.
   ========================================================================== */
:root {
  --ink: #16324F;
  --paper: #FFFDF8;
  --paper-soft: #FBF7EE;
  --line: #E7E2D6;

  --sky: #3FA9E0;
  --yellow: #FFC93C;
  --green: #7ED957;
  --orange: #FF914D;
  --pink: #FF6FA5;
  --purple: #8B6FD6;

  --sky-deep: #2C86B8;
  --yellow-deep: #E0A800;

  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;

  --shadow-card: 0 6px 0 rgba(22, 50, 79, 0.10), 0 10px 24px rgba(22, 50, 79, 0.08);
  --shadow-pop: 0 10px 0 rgba(22, 50, 79, 0.12), 0 18px 34px rgba(22, 50, 79, 0.16);

  --font-display: 'Fredoka', 'Quicksand', system-ui, sans-serif;
  --font-body: 'Quicksand', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(63, 169, 224, 0.10), transparent 40%),
    radial-gradient(circle at 95% 10%, rgba(255, 201, 60, 0.12), transparent 40%),
    var(--paper);
  min-height: 100vh;
}

img, svg { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------------------------- Top bar ---------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 3px solid var(--ink);
}
.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  max-width: 1180px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex-shrink: 0; }
.brand__logo { height: 52px; width: auto; display: block; }
.topbar__right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.topbar__search { flex: 1; max-width: 480px; margin-left: auto; min-width: 0; }

@media (max-width: 480px) {
  .topbar__inner { gap: 8px; padding: 8px 14px; }
  .brand__logo { height: 40px; }
  .search-box input { padding: 10px 14px 10px 38px; font-size: 0.9rem; }
  .search-box__icon { left: 12px; width: 15px; height: 15px; }
}

/* ------------------------------ Search ---------------------------------- */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box input {
  width: 100%;
  padding: 12px 18px 12px 44px;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--ink);
  background: #fff;
  outline-offset: 2px;
}
.search-box input::placeholder { color: #93A0AE; font-weight: 500; }
.search-box__icon {
  position: absolute;
  left: 16px;
  width: 18px;
  height: 18px;
  pointer-events: none;
}
.search-box__clear {
  position: absolute;
  right: 8px;
  border: none;
  background: var(--paper-soft);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.9rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.search-box__clear.show { display: inline-flex; }

/* ------------------------------- Buttons -------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.95rem;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
.btn--primary { background: var(--yellow); }
.btn--sky { background: var(--sky); color: #fff; }
.btn--pink { background: var(--pink); color: #fff; }
.btn--ghost { background: var(--paper-soft); box-shadow: 0 4px 0 var(--line); border-color: var(--line); }
.btn--sm { padding: 7px 14px; font-size: 0.82rem; box-shadow: 0 3px 0 var(--ink); border-width: 2px; }
.btn--block { width: 100%; justify-content: center; }
.btn--icon-only { padding: 10px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------------------- Home / Browse Pages nav buttons --------------------
   A small icon "badge" on the left + bold label, with a friendlier hover
   lift than the plain flat buttons elsewhere. */
.btn--home, .btn--browse {
  padding: 6px 22px 6px 6px;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn--home:hover, .btn--browse:hover { transform: translateY(-2px); }
.btn--home:active, .btn--browse:active { transform: translateY(2px); }
.btn__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.05rem;
  flex-shrink: 0;
}
.btn--home {
  background: #fff;
  border-color: var(--sky-deep);
  color: var(--ink);
}
.btn--home .btn__icon { background: var(--sky); }
.btn--home:hover { box-shadow: 0 6px 0 var(--sky-deep); }

.btn--browse {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  border-color: var(--ink);
  color: var(--ink);
}
.btn--browse .btn__icon { background: #fff; }
.btn--browse:hover { box-shadow: 0 7px 0 var(--ink); }

@media (max-width: 480px) {
  .btn--home span.btn__label, .btn--browse span.btn__label { display: none; }
  .btn--home, .btn--browse { padding: 4px; }
}

/* ------------------------------ Language switch ----------------------------- */
.lang-switch {
  display: flex;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
  background: #fff;
}
.lang-switch button {
  border: none;
  background: transparent;
  padding: 9px 12px;
  font-weight: 800;
  font-size: 0.76rem;
  color: var(--ink);
  border-right: 2px solid var(--ink);
  letter-spacing: 0.3px;
}
.lang-switch button:last-child { border-right: none; }
.lang-switch button[aria-pressed="true"] { background: var(--ink); color: #fff; }
@media (max-width: 480px) { .lang-switch button { padding: 8px 9px; font-size: 0.7rem; } }

/* -------------------------------- Hero ----------------------------------- */
.hero {
  padding: 48px 0 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero__ghost { width: 168px; margin: 0 auto 6px; animation: bob 3.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .hero__ghost { animation: none; } }

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.1rem);
  margin: 4px 0 10px;
  line-height: 1.05;
}
.hero h1 .accent { color: var(--sky-deep); }
.hero p.sub {
  max-width: 560px;
  margin: 0 auto 26px;
  font-size: 1.05rem;
  font-weight: 600;
  color: #4A5A6A;
}
.hero .search-box { max-width: 520px; margin: 0 auto; }
.hero .search-box input { padding: 16px 20px 16px 50px; font-size: 1.05rem; }

.stats-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-top: 26px;
  flex-wrap: wrap;
}
.stat { text-align: center; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.6rem; }
.stat span { font-size: 0.82rem; font-weight: 700; color: #6B7A89; text-transform: none; }

/* --------------------------- Category page nav ---------------------------- */
.cat-nav {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 20px 16px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.cat-nav::-webkit-scrollbar { height: 6px; }
.cat-nav::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.nav-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
  background: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
  text-decoration: none;
}
.nav-link .emoji { font-size: 1.1rem; }
.nav-link--active {
  background: var(--sky);
  color: #fff;
  box-shadow: 0 4px 0 var(--ink);
}

/* ------------------------------ Home hub tiles ----------------------------- */
.tile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 8px 0 60px;
}
@media (min-width: 720px) { .tile-grid { grid-template-columns: repeat(3, 1fr); } }

.cat-tile {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.12s ease;
}
.cat-tile:hover { transform: translateY(-4px); }
.cat-tile__preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  background: var(--ink);
  aspect-ratio: 3 / 1.55;
}
.cat-tile__preview img { width: 100%; height: 100%; object-fit: cover; }
.cat-tile__body { padding: 18px 20px 22px; background: var(--tile-color, var(--sky)); flex: 1; }
.cat-tile__body h3 { font-family: var(--font-display); font-size: 1.25rem; margin: 4px 0 4px; color: #fff; }
.cat-tile__body p { margin: 0 0 12px; color: rgba(255,255,255,0.92); font-weight: 600; font-size: 0.9rem; }
.cat-tile__count { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.22); color: #fff; font-weight: 800; font-size: 0.8rem; padding: 6px 12px; border-radius: 999px; }

/* ------------------------------ Section header ---------------------------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 6px;
  flex-wrap: wrap;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0;
}
.section-head p { margin: 2px 0 0; color: #6B7A89; font-weight: 600; font-size: 0.92rem; }
.result-count { font-weight: 700; color: #6B7A89; font-size: 0.9rem; }

/* --------------------------------- Grid ----------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  padding: 8px 0 60px;
}
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1180px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #6B7A89;
  font-weight: 700;
}
.empty-state .emoji { font-size: 2.4rem; display: block; margin-bottom: 10px; }

/* --------------------------------- Card ------------------------------------ */
.card {
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.card__art {
  aspect-ratio: 864 / 1232;
  background: var(--paper-soft);
  border-bottom: 2.5px solid var(--ink);
  padding: 8px;
  position: relative;
}
.card__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.card__art img:hover { transform: scale(1.03); }
.card__badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 4px 9px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #fff;
}
.card__badge--Easy { background: var(--green); }
.card__badge--Medium { background: var(--yellow); }
.card__badge--Hard { background: var(--pink); color: #fff; }

.card__body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card__cat {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--cat-color, var(--sky-deep));
  text-transform: none;
}
.card__title {
  font-family: var(--font-display);
  font-size: 1.02rem;
  margin: 0;
  line-height: 1.2;
  flex: 1;
}
.card__actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.card__actions .btn {
  flex-direction: column;
  padding: 7px 2px;
  font-size: 0.66rem;
  gap: 3px;
  box-shadow: 0 3px 0 var(--ink);
  border-width: 2px;
  white-space: nowrap;
}
.card__actions .btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* -------------------------------- Footer ----------------------------------- */
footer {
  position: relative;
  background: var(--ink);
  padding: 0 0 26px;
  margin-top: 30px;
  overflow: hidden;
}
/* A little crayon-box stripe across the top of the footer, echoing the logo. */
footer::before {
  content: '';
  display: block;
  height: 7px;
  background: linear-gradient(90deg, var(--sky), var(--yellow), var(--green), var(--orange), var(--pink));
}
.footer__grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding-top: 40px;
}
.footer__brand img {
  height: 96px;
  width: auto;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}
footer p { color: rgba(255, 255, 255, 0.78); font-weight: 600; font-size: 0.92rem; max-width: 460px; margin: 0 auto; }
.footer__bottom {
  text-align: center;
  margin: 26px auto 0;
  padding: 18px 20px 0;
  max-width: 1180px;
  box-sizing: border-box;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 600;
}

/* ================================ MODALS ================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 50, 79, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-pop);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
}
.modal--sm { max-width: 420px; }
.modal--md { max-width: 620px; }
.modal--lg { max-width: 1120px; }
.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: #fff;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  z-index: 2;
}
.modal__header { padding: 22px 60px 4px 24px; }
.modal__header h3 { font-family: var(--font-display); font-size: 1.35rem; margin: 0 0 4px; }
.modal__header p { margin: 0; color: #6B7A89; font-weight: 600; font-size: 0.9rem; }
.modal__body { padding: 16px 24px 24px; }

/* ------------------------- Drawing preview lightbox ------------------------ */
.preview-image {
  display: block;
  width: 100%;
  max-height: 65vh;
  height: auto;
  object-fit: contain;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  border: 2.5px solid var(--ink);
  background: #fff;
}
.preview-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.preview-actions .btn {
  flex-direction: column;
  padding: 10px 4px;
  font-size: 0.78rem;
  gap: 4px;
  white-space: nowrap;
}

/* -------------------------- Color Studio modal -----------------------------
   Desktop: a narrow tool column on the left, a big canvas on the right.
   (Grid auto-placement follows `order`, so the column widths below and the
   `order` values on the two children must be read together: col 1 = 190px
   is given to whichever child has the lower order, col 2 = 1fr to the
   other. Tools get the low order → narrow left column; the canvas gets the
   high order → wide right column.) On mobile it's a single stacked column,
   tools above canvas, and `order` there is irrelevant to width.
   ========================================================================== */
.studio {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 720px) { .studio { grid-template-columns: 190px 1fr; align-items: start; } }

.studio__canvas-wrap {
  background: var(--paper-soft);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 8px;
  order: 2;
}
@media (min-width: 720px) { .studio__canvas-wrap { order: 2; } }
.studio__canvas-wrap canvas { width: 100%; height: auto; display: block; border-radius: var(--radius-sm); cursor: crosshair; touch-action: none; background: #fff; }

.studio__tools { order: 1; display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 720px) { .studio__tools { order: 1; } }

.studio__group h4 { font-family: var(--font-display); font-size: 0.95rem; margin: 0 0 8px; }
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
@media (min-width: 720px) { .palette { grid-template-columns: repeat(5, 1fr); } }
.swatch {
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 10px;
  border: 3px solid var(--ink);
  padding: 0;
  position: relative;
}
.swatch[aria-pressed="true"]::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  font-weight: 800;
}
.tool-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn {
  flex: 1;
  min-width: 90px;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 10px;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.tool-btn[aria-pressed="true"] { background: var(--yellow); }
.tool-btn svg { width: 20px; height: 20px; }
.studio__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------- misc ------------------------------------ */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 3px solid var(--sky-deep); outline-offset: 2px; }

.printable-only { display: none; }

/* Skip-link for keyboard users */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--yellow);
  padding: 10px 16px;
  border-radius: 0 0 10px 0;
  font-weight: 800;
  z-index: 200;
}
.skip-link:focus { left: 0; }

/* Print rules live in css/print.css (loaded with media="print") so the
   screen stylesheet stays screen-only and print output stays predictable. */
