/* ═══════════════════════════════════════════════════════════════════════════
   Hub magic — shared look for the Math Tools Hub and the Math Games Hub.
   Loaded by pages/tools.html (body.hm-tools) and pages/games.html (body.hm-games);
   behaviour lives in assets/js/hub-magic.js. Everything degrades to the plain
   cards when JS is off, and motion stops for prefers-reduced-motion.
   ═══════════════════════════════════════════════════════════════════════════ */

@property --hm-ang { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

/* ── Hero: live maths sky behind the title ── */
.hm-hero { position: relative; isolation: isolate; }
body.hm-games .hm-hero { --hm-a: #ffb347; --hm-b: #ff6a00; --hm-c: #ffd000; }
.hm-sky {
  position: absolute; inset: -40px -24px -10px; z-index: -1;
  width: calc(100% + 48px); height: calc(100% + 50px);
  pointer-events: none;
  /* faint behind the title and text, full strength towards the sides */
  -webkit-mask-image: radial-gradient(ellipse 36% 46% at 50% 42%, rgba(0,0,0,.14) 0%, rgba(0,0,0,.35) 55%, #000 100%);
          mask-image: radial-gradient(ellipse 36% 46% at 50% 42%, rgba(0,0,0,.14) 0%, rgba(0,0,0,.35) 55%, #000 100%);
}
.hm-hero h1 {
  background: linear-gradient(100deg, #fff 0%, var(--hm-a, #22d3ee) 30%, var(--hm-b, #a855f7) 55%, var(--hm-c, #ff8c00) 80%, #fff 100%) !important;
  background-size: 220% 100% !important;
  -webkit-background-clip: text !important; background-clip: text !important;
  -webkit-text-fill-color: transparent !important; color: transparent !important;
  animation: hmShimmer 9s ease-in-out infinite alternate;
}
@keyframes hmShimmer { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }

.hm-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }
.hm-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 999px;
  font: 600 .78rem 'Poppins', sans-serif; color: var(--text, #e8e8ff);
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1);
  backdrop-filter: blur(8px);
  opacity: 0; transform: translateY(8px); animation: hmChipIn .6s cubic-bezier(.2,.8,.2,1) forwards;
}
.hm-chip b { color: var(--hm-a, #22d3ee); font-weight: 700; }
.hm-chip:nth-child(2) { animation-delay: .1s; } .hm-chip:nth-child(3) { animation-delay: .2s; } .hm-chip:nth-child(4) { animation-delay: .3s; }
@keyframes hmChipIn { to { opacity: 1; transform: none; } }

/* ── Search ── */
.hm-search {
  position: relative; max-width: 560px; margin: 0 auto 26px;
}
.hm-search input {
  width: 100%; height: 52px; padding: 0 48px 0 50px; border-radius: 999px;
  font: 400 .95rem 'Poppins', sans-serif; color: var(--text, #e8e8ff);
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.12);
  outline: none; transition: border-color .2s, box-shadow .2s, background .2s;
}
.hm-search input::placeholder { color: var(--muted, #9999c0); }
.hm-search input:focus { border-color: var(--hm-a, #22d3ee); box-shadow: 0 0 0 4px rgba(34,211,238,.12), 0 10px 40px rgba(0,0,0,.35); background: rgba(255,255,255,.06); }
.hm-search svg { position: absolute; left: 18px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted, #9999c0); pointer-events: none; }
.hm-search .hm-count { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font: 600 .72rem 'Poppins', sans-serif; color: var(--muted, #9999c0); }
.hm-search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.hm-empty { display: none; text-align: center; padding: 36px 16px 48px; color: var(--muted, #9999c0); font-size: .95rem; }
.hm-empty.show { display: block; }
.hm-nomatch, .hm-label-hidden { display: none !important; }

/* ── Cards (both hubs) ── */
.hm-card {
  --mx: 50%; --my: 0%;
  position: relative; isolation: isolate;
  border-radius: 20px !important;
  border: 1px solid rgba(255,255,255,.07) !important;
  background:
    radial-gradient(420px circle at var(--mx) var(--my), color-mix(in srgb, var(--c1, #22d3ee) 14%, transparent), transparent 45%),
    linear-gradient(165deg, color-mix(in srgb, var(--card, #141428) 92%, #fff 8%), var(--card, #141428)) !important;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s, border-color .35s !important;
  transform-style: preserve-3d;
}
.hm-card::after {                                   /* animated gradient rim, shown on hover */
  content: ''; position: absolute; inset: -1px; z-index: 1; border-radius: inherit; padding: 1.5px; pointer-events: none;
  background: conic-gradient(from var(--hm-ang), transparent 0deg 70deg, var(--c1, #22d3ee) 140deg, var(--c2, #a855f7) 220deg, transparent 290deg 360deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0; transition: opacity .35s;
  animation: hmSpin 4.5s linear infinite;
}
@keyframes hmSpin { to { --hm-ang: 360deg; } }
@media (hover: hover) {
  .hm-card:hover {
    transform: translateY(-6px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) !important;
    border-color: transparent !important;
    box-shadow: 0 24px 60px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.04), 0 0 40px color-mix(in srgb, var(--c1, #22d3ee) 18%, transparent) !important;
  }
  .hm-card:hover::after { opacity: 1; }
}

/* Scroll-in reveal (added by JS, so cards stay visible without it) */
.hm-reveal { opacity: 0; translate: 0 22px; scale: .97; }
.hm-reveal.hm-in { opacity: 1; translate: 0 0; scale: 1; transition: opacity .6s ease, translate .7s cubic-bezier(.2,.8,.2,1), scale .7s cubic-bezier(.2,.8,.2,1); transition-delay: calc(var(--i, 0) * 55ms); }

/* ── Math Tools Hub cards ── */
body.hm-tools .teach-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)) !important; gap: 18px !important; }
body.hm-tools .teach-card { display: flex; flex-direction: column; padding: 24px 22px 20px !important; overflow: visible !important; }
body.hm-tools .teach-card::before { display: none !important; }
body.hm-tools .teach-card .tc-icon {
  width: 54px; height: 54px; display: flex !important; align-items: center; justify-content: center;
  font-size: 1.6rem !important; line-height: 1; margin-bottom: 16px !important; border-radius: 16px;
  background: linear-gradient(140deg, color-mix(in srgb, var(--c1) 30%, transparent), color-mix(in srgb, var(--c2) 22%, transparent));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c1) 35%, transparent), 0 8px 24px color-mix(in srgb, var(--c1) 18%, transparent);
  transition: transform .45s cubic-bezier(.34,1.56,.64,1);
}
body.hm-tools .teach-card:hover .tc-icon { transform: translateY(-3px) rotate(-8deg) scale(1.08); }
body.hm-tools .teach-card .tc-title {
  font-family: 'Poppins', sans-serif !important; font-size: 1.02rem !important; font-weight: 600 !important;
  letter-spacing: 0; color: var(--text, #fff) !important; margin-bottom: 8px !important;
}
body.hm-tools .teach-card .tc-desc { font-size: .84rem !important; line-height: 1.6 !important; margin-bottom: 14px !important; }
body.hm-tools .teach-card .tc-tags { margin-top: auto; }
body.hm-tools .teach-card .tc-tag {
  background: color-mix(in srgb, var(--c1) 10%, transparent) !important; color: color-mix(in srgb, var(--c1) 70%, #fff) !important;
  border-color: color-mix(in srgb, var(--c1) 26%, transparent) !important;
}
.hm-go {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 14px;
  font: 600 .8rem 'Poppins', sans-serif; color: var(--c1, #22d3ee);
}
.hm-go svg { width: 15px; height: 15px; transition: transform .25s; }
@media (hover: hover) {
  .hm-go { opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s; }
  .hm-card:hover .hm-go { opacity: 1; transform: none; }
  .hm-card:hover .hm-go svg { transform: translateX(3px); }
}
body.hm-tools .teach-section-label { font-size: .74rem !important; margin: 34px 0 18px !important; color: var(--text, #e8e8ff) !important; }
body.hm-tools .teach-section-label .hm-n { margin-left: 2px; padding: 2px 9px; border-radius: 999px; font-size: .66rem; letter-spacing: .04em; background: rgba(255,255,255,.07); color: var(--muted, #9999c0); }

/* ── Math Games Hub cards ── */
body.hm-games .games-grid { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px !important; }
body.hm-games .games-grid .game-card { min-width: 0 !important; }
body.hm-games .game-card { overflow: visible !important; }
body.hm-games .game-card-header { padding: 22px 22px 14px !important; gap: 16px !important; }
body.hm-games .game-icon {
  width: 60px !important; height: 60px !important; border-radius: 18px !important; font-size: 2rem !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 10px 26px rgba(0,0,0,.35);
  transition: transform .5s cubic-bezier(.34,1.56,.64,1);
}
@media (hover: hover) { body.hm-games .game-card:hover .game-icon { transform: translateY(-4px) rotate(-10deg) scale(1.1); } }
body.hm-games .game-card h3 { font-size: 1.06rem !important; line-height: 1.3; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
body.hm-games .game-card .desc {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
body.hm-games .outcome-line {
  margin-top: 10px !important; padding: 0 0 0 10px !important; background: none !important;
  border-left: 2px solid color-mix(in srgb, var(--c1) 60%, transparent) !important; border-radius: 0 !important;
  font-size: .74rem !important; color: var(--muted, #9999c0) !important;
}
body.hm-games .outcome-line b { color: var(--c1) !important; }
body.hm-games .game-meta { gap: 6px !important; padding: 0 22px 16px !important; }
body.hm-games .game-meta .badge-pill { font-size: .66rem !important; padding: 3px 9px !important; letter-spacing: .02em; }
body.hm-games .game-meta .hm-more { background: rgba(255,255,255,.06); color: var(--muted, #9999c0); border: 1px dashed rgba(255,255,255,.18); cursor: default; }
body.hm-games .game-card-body { padding: 0 22px 22px !important; }
body.hm-games .play-btn {
  position: relative; overflow: hidden; display: flex !important; align-items: center; justify-content: center; gap: 10px;
  height: 46px; padding: 0 18px !important; border-radius: 999px !important; font-size: .9rem !important; letter-spacing: .03em !important;
  background: linear-gradient(120deg, var(--c1, #ff8c00), var(--c2, #ff6600)) !important; color: #0d0d1a !important;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--c1, #ff8c00) 28%, transparent);
  transition: transform .2s, box-shadow .25s !important;
}
body.hm-games .play-btn::after {                      /* light sweep */
  content: ''; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.55), transparent); transform: skewX(-20deg);
  transition: left .6s ease;
}
@media (hover: hover) {
  body.hm-games .game-card:hover .play-btn { box-shadow: 0 12px 30px color-mix(in srgb, var(--c1, #ff8c00) 45%, transparent); }
  body.hm-games .game-card:hover .play-btn::after { left: 120%; }
}
body.hm-games .section-label { font-size: .78rem !important; margin-top: 18px; }
body.hm-games .section-label .hm-n { margin-left: 6px; padding: 2px 9px; border-radius: 999px; font-size: .66rem; letter-spacing: .04em; background: rgba(255,255,255,.07); color: var(--muted, #9999c0); }

/* Phones: no tilt / hover rim; keep it quick */
@media (max-width: 600px) {
  body.hm-tools .teach-grid, body.hm-games .games-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .hm-search input { height: 48px; font-size: .9rem; }
  .hm-sky { inset: -20px -14px -10px; width: calc(100% + 28px); }
}

/* Phones: each filter group becomes one swipeable row instead of a tall column of chips */
@media (max-width: 560px) {
  body.hm-games .hf-group {
    flex-direction: row !important; flex-wrap: nowrap !important; align-items: center !important;
    overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; margin-right: -24px; padding-right: 24px;
    -webkit-mask-image: linear-gradient(90deg, #000 80%, transparent); mask-image: linear-gradient(90deg, #000 80%, transparent);
  }
  body.hm-games .hf-group::-webkit-scrollbar { display: none; }
  body.hm-games .hf-label { flex-shrink: 0; min-width: 58px !important; }
  body.hm-games .hf-chip { flex-shrink: 0; white-space: nowrap; }
}

/* Light theme */
body.theme-light .hm-card { border-color: rgba(26,26,46,.1) !important; background: radial-gradient(420px circle at var(--mx) var(--my), color-mix(in srgb, var(--c1, #0891b2) 12%, transparent), transparent 45%), var(--card, #fffdf7) !important; }
body.theme-light .hm-search input { background: #fff; border-color: rgba(26,26,46,.15); }
body.theme-light .hm-chip { background: #fff; border-color: rgba(26,26,46,.12); }
body.theme-light.hm-games .play-btn { color: #fff !important; }

@media print { .hm-reveal { opacity: 1 !important; translate: none !important; scale: none !important; } .hm-sky { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .hm-hero h1, .hm-card::after, .hm-chip { animation: none !important; opacity: 1; transform: none; }
  .hm-reveal { opacity: 1; translate: none; scale: none; }
  .hm-card, .hm-card:hover { transform: none !important; }
}
