/* hub.css: styles for the kids hub (index.html) and the grown-ups page (grownups.html).
   Sits on top of kids.css (tokens, buttons, cards, chips, sheet). Class prefixes:
   .hub-  the hub page: top bar, parent-gate button, topic sections, activity cards, player sheet
   .pick- avatar and age pickers (real radio inputs, visually hidden, shared by both pages)
   .opt-  skill-level option cards (real radio inputs, shared by both pages)
   .gu-   the grown-ups page: children panels, switches, help text, credits */

:root {
  --sun-soft: #FFF3C2;
}

/* Avatars: a round face holding an OpenMoji picture */

.avatar {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: var(--av, 48px);
  height: var(--av, 48px);
  overflow: hidden;
  border-radius: 50%;
  background: var(--sun-soft);
  box-shadow: inset 0 0 0 3px var(--line);
}

.avatar img {
  width: 86%;
  height: 86%;
  object-fit: contain;
}

.avatar.is-missing img { display: none; }

.avatar.is-missing::after {
  content: attr(data-initial);
  font-size: calc(var(--av, 48px) * 0.5);
  font-weight: 700;
  line-height: 1;
}

/* Hub top bar: wordmark left, player chip and the grown-ups gate right */

.hub-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--paper);
  border-bottom: 3px solid var(--line);
}

.hub-bar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: var(--max);
  min-height: 84px;
  margin: 0 auto;
  padding: 8px 12px;
}

.hub-wordmark {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font: 700 30px/1 var(--font-ui);
  text-decoration: none;
}

.hub-mark {
  width: 42px;
  height: 42px;
}

.hub-bar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 auto;
  gap: 10px;
  min-width: 0;
}

.hub-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 64px;
  max-width: 100%;
  min-height: 64px;
  padding: 0 14px 0 8px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  font: 600 20px/1.1 var(--font-ui);
  text-align: left;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.hub-chip:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.hub-chip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hub-caret {
  width: 16px;
  height: 16px;
  color: var(--ink-2);
}

/* The grown-ups gate: press and hold; a ring fills while held. The label shows on wider screens. */

.hub-gate {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-width: 64px;
  min-height: 64px;
  padding: 0 8px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  font: 600 20px/1 var(--font-ui);
  touch-action: none;
  -webkit-touch-callout: none;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, border-color 0.08s ease-out;
}

.hub-gate.is-holding {
  border-color: var(--grape);
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.hub-gate-label { display: none; }

@media (min-width: 560px) {
  .hub-gate { padding: 0 20px 0 8px; }
  .hub-gate-label { display: inline; }
}

.hub-ring {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
}

.hub-ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hub-ring-track, .hub-ring-fill {
  fill: none;
  stroke-width: 5;
}

.hub-ring-track { stroke: var(--line); }

.hub-ring-fill {
  stroke: var(--grape);
  stroke-linecap: round;
}

.hub-lock {
  width: 22px;
  height: 22px;
  color: var(--ink-2);
}

/* The YKYMF logo at the start of the bar: the same press-and-hold ring, with the studio badge inside it. */

.hub-studio,
.hub-studio.hub-gate { padding: 0 6px; }

.hub-studio .hub-ring {
  width: 60px;
  height: 60px;
}

.hub-studio-logo {
  position: relative;
  width: 42px;
  height: 42px;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Hub body */

.hub-main {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

.hub-note {
  margin: 0 0 14px;
  color: var(--ink-2);
}

.hub-jump {
  display: flex;
  gap: 10px;
  margin: 0 -16px;
  padding: 2px 16px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 720px) {
  .hub-jump {
    flex-wrap: wrap;
    justify-content: center;
    margin: 0;
    padding: 2px 0 10px;
  }
}

.hub-jump-link {
  display: grid;
  flex: none;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 3px solid rgba(30, 34, 53, 0.14);
  border-radius: 50%;
  background: var(--c, var(--sky));
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.14);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.hub-jump-link:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14);
}

.hub-jump-link .pic {
  --pic-size: 42px;
  border-radius: 50%;
  box-shadow: none;
}

.hub-topic { scroll-margin-top: 100px; }

.hub-topic-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 8px 18px 8px 8px;
  border-radius: var(--radius);
  background: var(--c, var(--sky));
}

.hub-topic-head h2 {
  margin: 0;
  font-size: clamp(24px, 5.5vw, 30px);
}

.hub-topic-head .pic { --pic-size: 56px; }

.hub-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hub-grid > li { display: flex; }

@media (min-width: 720px) {
  .hub-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
  }
}

/* Play again: one scrolling row of smaller cards */

.hub-again {
  display: flex;
  gap: 14px;
  margin: 0 -16px;
  padding: 2px 16px 14px;
  overflow-x: auto;
  list-style: none;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.hub-again > li {
  display: flex;
  flex: 0 0 156px;
  scroll-snap-align: start;
}

@media (min-width: 720px) {
  .hub-again {
    margin: 0;
    padding-left: 0;
    padding-right: 0;
  }
}

/* Activity cards */

.hub-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  content-visibility: auto; /* cards far below the fold are not laid out or painted until scrolled near */
  contain-intrinsic-size: auto 160px;
}

.hub-card-art {
  position: relative;
  display: grid;
  place-items: center;
  padding: 14px 10px;
  isolation: isolate;
}

.hub-card-art::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--c, var(--sky));
  opacity: 0.22;
}

.hub-card-art .pic { --pic-size: 84px; }
.hub-card-art .flag { --flag-size: 104px; }

.hub-again .hub-card-art .pic { --pic-size: 68px; }
.hub-again .hub-card-art .flag { --flag-size: 88px; }

.hub-card-title {
  display: block;
  padding: 10px 14px 4px;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.hub-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: auto;
  padding: 2px 14px 14px;
}

.hub-kind {
  color: var(--ink-2);
  font-size: 18px;
}

.hub-badge { background: var(--tangerine); }

/* Notes and error cards */

.hub-error { max-width: 560px; margin: 24px auto; }

.hub-warn {
  padding: 12px 16px;
  border: 3px solid var(--tangerine);
  border-radius: var(--radius-sm);
  background: var(--sun-soft);
}

.hub-warn p { margin: 0; }

/* Form fields (the grown-ups page's Add a child form and name boxes) */

.hub-field {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.hub-label {
  font-size: 22px;
  font-weight: 600;
}

.hub-input {
  width: 100%;
  min-height: 72px;
  padding: 0 20px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font: 600 30px/1.2 var(--font-ui);
}

.hub-input:focus { border-color: var(--sky); }

.hub-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.hub-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 160px;
  padding: 16px 10px;
  text-align: center;
}

.hub-player.is-active {
  border-color: var(--ink);
  background: var(--sun-soft);
}

.hub-player-name {
  max-width: 100%;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.hub-player-add {
  border-style: dashed;
  color: var(--ink-2);
}

.hub-plus {
  width: 48px;
  height: 48px;
}

/* Pickers: real radio inputs (hidden) inside labels, so keyboards and screen readers work */

.pick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.pick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pick { display: block; cursor: pointer; }

.pick-face {
  display: grid;
  place-items: center;
  min-height: 64px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.pick-grid .pick-face { aspect-ratio: 1 / 1; }

.pick-chips .pick-face {
  min-width: 64px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 24px;
  font-weight: 600;
}

.pick:active .pick-face {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.pick input:checked + .pick-face {
  border-color: var(--ink);
  background: var(--sun);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

.pick input:focus-visible + .pick-face {
  outline: 4px solid var(--ink);
  outline-offset: 3px;
}

/* Skill-level option cards */

.opt-list {
  display: grid;
  gap: 12px;
}

.opt { display: block; cursor: pointer; }

.opt-body {
  position: relative;
  display: block;
  min-height: 64px;
  padding: 14px 18px 14px 62px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.opt-body::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 50%;
  width: 28px;
  height: 28px;
  margin-top: -14px;
  border: 3px solid var(--ink-3);
  border-radius: 50%;
  background: #fff;
}

.opt:active .opt-body {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.opt input:checked + .opt-body {
  border-color: var(--ink);
  background: var(--sun-soft);
}

.opt input:checked + .opt-body::before {
  border-color: var(--ink);
  background: radial-gradient(circle, var(--ink) 0 7px, #fff 8px);
}

.opt input:focus-visible + .opt-body {
  outline: 4px solid var(--ink);
  outline-offset: 3px;
}

.opt-label {
  display: block;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
}

.opt-hint {
  display: block;
  margin-top: 2px;
  color: var(--ink-2);
  font-size: 18px;
  line-height: 1.35;
}

/* Grown-ups page */

.gu-page {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 760px;
  padding-top: 20px;
  padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
}

.gu-section .card-header { margin: 0; }

.gu-section .card-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.gu-section p { margin: 0; }

.gu-section h3 {
  margin: 0;
  font-size: 22px;
}

.gu-lead { color: var(--ink-2); }

.gu-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding-left: 1.3em;
}

.gu-status {
  min-height: 1.5em;
  font-weight: 600;
}

.gu-status.is-bad { color: #B3261E; }

.gu-player {
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.gu-player[open] { border-color: var(--ink); }

.gu-player-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 80px;
  padding: 8px 16px 8px 10px;
  list-style: none;
  cursor: pointer;
}

.gu-player-head::-webkit-details-marker { display: none; }

.gu-player-head::after {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  margin: 0 4px 0 auto;
  border-right: 4px solid var(--ink-2);
  border-bottom: 4px solid var(--ink-2);
  transform: translateY(-3px) rotate(45deg);
}

.gu-player[open] > .gu-player-head::after { transform: translateY(3px) rotate(-135deg); }

.gu-player-name {
  display: block;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.gu-player-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 4px;
  color: var(--ink-2);
  font-size: 18px;
}

.gu-player-body {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 6px 16px 20px;
}

.gu-fine {
  border: 3px solid var(--line);
  border-radius: var(--radius-sm);
}

.gu-fine[open] { border-color: var(--ink-2); }

.gu-fine > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 0 16px;
  font-size: 20px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.gu-fine > summary::-webkit-details-marker { display: none; }

.gu-fine > summary::after {
  content: "";
  flex: none;
  width: 12px;
  height: 12px;
  margin: 0 4px 0 auto;
  border-right: 4px solid var(--ink-2);
  border-bottom: 4px solid var(--ink-2);
  transform: translateY(-3px) rotate(45deg);
}

.gu-fine[open] > summary::after { transform: translateY(3px) rotate(-135deg); }

.gu-fine-tag {
  color: var(--ink-2);
  font-size: 18px;
  font-weight: 400;
}

.gu-fine-body {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 4px 16px 20px;
}

.gu-add-form {
  padding: 16px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
}

.gu-add-form .row .btn { flex: 1 1 0; }

.gu-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gu-group h4 {
  margin: 0;
  font-size: 22px;
}

.gu-help {
  margin: 0;
  color: var(--ink-2);
  font-size: 18px;
}

.gu-select {
  width: 100%;
  min-height: 64px;
  padding: 0 16px;
  border: 3px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 20px;
}

.gu-switch {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 76px;
  padding: 10px 16px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
  text-align: left;
}

.gu-switch-text {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.gu-switch-label {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
}

.gu-switch-hint {
  color: var(--ink-2);
  font-size: 18px;
  line-height: 1.3;
}

.gu-switch-state {
  flex: none;
  min-width: 2.2em;
  font-size: 20px;
  font-weight: 600;
  text-align: right;
}

.gu-switch-track {
  position: relative;
  flex: none;
  width: 68px;
  height: 40px;
  border-radius: 999px;
  background: var(--ink-3);
  transition: background 0.15s ease-out;
}

.gu-switch-knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease-out;
}

.gu-switch[aria-checked="true"] .gu-switch-track { background: var(--mint); }
.gu-switch[aria-checked="true"] .gu-switch-knob { transform: translateX(28px); }

.gu-credits {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding-left: 1.3em;
}

.gu-more summary {
  display: flex;
  align-items: center;
  min-height: 64px;
  font-weight: 600;
  cursor: pointer;
}

.gu-more ul {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding-left: 1.3em;
  font-size: 18px;
}

/* Wordmark circle mark (colours come from the tokens) */

.hub-mark-disc { fill: var(--sun); }
.hub-mark-ring, .hub-mark-smile {
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
}
.hub-mark-ring { stroke-width: 3.6; }
.hub-mark-smile { stroke-width: 3; }
.hub-mark-eye { fill: var(--ink); }

/* Adventure runs. Hub: the "Surprise me!" block. Play pages (loaded by shell.js when a run is on): the top bar
   position and Next button, and the full-screen "Challenge done!" panel. */

.run-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.run-surprise {
  width: 100%;
  max-width: 640px;
  min-height: 112px;
  gap: 16px;
  border-radius: 34px;
  font-size: clamp(34px, 9vw, 46px);
  font-weight: 700;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}

.run-surprise:active, .run-surprise.is-going {
  transform: translateY(6px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}

.run-surprise.is-going { pointer-events: none; }

.run-surprise .run-spark {
  width: 1.1em;
  height: 1.1em;
  animation: run-twinkle 2.4s ease-in-out infinite;
}

.run-caption {
  margin: 0;
  color: var(--ink-2);
  font-size: 20px;
  font-weight: 600;
}

@keyframes run-twinkle {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.18) rotate(14deg); }
}

/* Top bar during a run: the title gets a second line, "2 of 6" */

.run-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  line-height: 1.05;
}

.run-title-name, .run-pos {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-title-name { font-size: 22px; }

.run-pos {
  color: var(--ink-2);
  font-size: 16px;
  font-weight: 600;
}

.run-flip { transform: scaleX(-1); }

/* "Challenge done!" */

.run-done {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(circle at 50% 16%, var(--sun-soft, #FFF3C2) 0%, var(--paper) 64%);
  animation: kids-fade 0.25s ease-out;
}

.run-done:focus { outline: none; }

.run-done-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
}

.run-done-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(100%, 460px);
  margin: auto;
  text-align: center;
}

.run-done-title {
  margin: 0;
  font-size: clamp(38px, 11vw, 54px);
  line-height: 1.05;
  animation: kids-pop 0.5s ease-out;
}

.run-done-stars { --star-size: clamp(56px, 18vw, 84px); }

.run-done-count {
  margin: 0;
  color: var(--ink-2);
  font-size: 22px;
  font-weight: 600;
}

.run-dots {
  display: flex;
  gap: 10px;
}

.run-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--line);
}

.run-dot.is-done { background: var(--mint); }
.run-dot.is-next { background: var(--sun); box-shadow: 0 0 0 3px var(--ink); }

.run-done-actions {
  --gap: 14px;
  width: 100%;
  margin-top: 8px;
}

/* A moment of grace so a last excited tap on the activity cannot skip past this panel */
.run-done.is-arming .run-done-actions { pointer-events: none; }
