/* ---------------------------------------------------------------------------
   Activity dock, HUD and activity controls (js/activities.js)
   Layering (contract): dock button, HUD, tools and play boards z4; the
   activity picker sheet and toasts z5.
   --------------------------------------------------------------------------- */
:root {
  --px-ui-font: 'Fredoka', 'Nunito', 'Segoe UI Rounded', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --px-glass: rgba(22, 8, 26, 0.78);
  --px-glass-strong: rgba(18, 6, 22, 0.94);
  --px-line: rgba(255, 190, 225, 0.28);
  --px-card: rgba(255, 255, 255, 0.06);
  --px-card-hover: rgba(255, 255, 255, 0.13);
  --px-accent-ink: #2a0718;
}

/* Declared on body so each theme's --ink and --accent (set on body) apply. */
body {
  --px-text: var(--ink, #ffe3f0);
  --px-accent: var(--accent, #ff5fa2);
}

body.theme-aubrey {
  --px-glass: rgba(6, 42, 99, 0.80);
  --px-glass-strong: rgba(5, 34, 82, 0.95);
  --px-line: rgba(255, 240, 160, 0.38);
  --px-card: rgba(255, 255, 255, 0.08);
  --px-card-hover: rgba(255, 255, 255, 0.16);
  --px-accent-ink: #062a63;
}

.px-hidden { display: none !important; }

/* ---------------------------------------------------------------- Play button */
.px-play {
  position: fixed;
  left: calc(12px + env(safe-area-inset-left, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  min-width: 50px;
  padding: 0 18px 0 14px;
  border-radius: 999px;
  border: 1px solid var(--px-line);
  background: var(--px-glass);
  color: var(--px-text);
  font: 600 16px/1 var(--px-ui-font);
  letter-spacing: 0.02em;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35), 0 0 0 0 var(--px-accent);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s ease, background 0.25s ease, box-shadow 0.25s ease;
}
.px-play .px-play-emoji { font-size: 22px; line-height: 1; }
.px-play:hover, .px-play:focus-visible { transform: translateY(-2px); background: var(--px-glass-strong); outline: none; box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4), 0 0 0 2px var(--px-accent); }
.px-play:active { transform: scale(0.95); }
.px-play.is-playing { box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35), 0 0 0 2px var(--px-accent); }
.px-play.is-waiting { opacity: 0.6; }
.px-play-hello { animation: px-wiggle 1.2s ease-in-out 2.2s 2; }

@keyframes px-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-8deg) scale(1.05); }
  40% { transform: rotate(7deg) scale(1.05); }
  60% { transform: rotate(-4deg); }
  80% { transform: rotate(2deg); }
}

/* Phones: sit beside the "next" button, above the hint line. */
@media (max-width: 480px) {
  .px-play { bottom: calc(46px + env(safe-area-inset-bottom, 0px)); padding: 0; width: 50px; justify-content: center; }
  .px-play .px-play-label { display: none; }
}
@media (max-height: 460px) and (min-width: 481px) {
  .px-play { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); height: 44px; }
}

/* --------------------------------------------------------------- Top HUD */
.px-top {
  position: fixed;
  left: 50%;
  top: calc(62px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  z-index: 4;
  width: min(620px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  font-family: var(--px-ui-font);
  color: var(--px-text);
}
.px-hud, .px-tools > *, .px-toast { pointer-events: auto; }

.px-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 5px 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--px-line);
  background: var(--px-glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  font-size: 15px;
  white-space: nowrap;
  animation: px-drop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.px-hud-emoji { font-size: 18px; }
.px-hud-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.px-hud-text { opacity: 0.85; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.px-hud-score, .px-hud-timer {
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-variant-numeric: tabular-nums;
}
.px-hud-timer.is-low { background: var(--px-accent); color: var(--px-accent-ink); }
.px-hud-score.is-bump { animation: px-bump 0.3s ease; }
.px-stop {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  font: 600 14px/1 var(--px-ui-font);
  cursor: pointer;
  flex: none;
}
.px-stop:hover, .px-stop:focus-visible { background: var(--px-accent); color: var(--px-accent-ink); outline: none; }

@keyframes px-drop { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes px-bump { 50% { transform: scale(1.25); } }

/* Activity controls under the HUD. */
.px-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
}
.px-tools:empty { display: none; }
.px-btn, .px-chip {
  appearance: none;
  border: 1px solid var(--px-line);
  background: var(--px-glass);
  color: var(--px-text);
  font: 600 14px/1 var(--px-ui-font);
  padding: 9px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, transform 0.15s ease;
}
.px-btn:hover, .px-btn:focus-visible, .px-chip:hover, .px-chip:focus-visible { background: var(--px-glass-strong); outline: 2px solid var(--px-accent); outline-offset: 1px; }
.px-btn:active, .px-chip:active { transform: scale(0.95); }
.px-btn.is-on, .px-chip.is-on { background: var(--px-accent); color: var(--px-accent-ink); border-color: transparent; }
.px-btn-big { font-size: 17px; padding: 12px 20px; }

.px-field {
  display: flex;
  gap: 6px;
  width: min(460px, 100%);
}
.px-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--px-line);
  background: var(--px-glass-strong);
  color: var(--px-text);
  font: 500 16px/1.2 var(--px-ui-font);  /* 16px stops iOS zooming */
  padding: 10px 14px;
  border-radius: 999px;
  outline: none;
}
.px-input:focus { border-color: var(--px-accent); box-shadow: 0 0 0 2px var(--px-accent); }
.px-input::placeholder { color: var(--px-text); opacity: 0.5; }

.px-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--px-line);
  background: var(--px-glass);
  font-size: 18px;
  width: min(420px, 100%);
}
.px-slider input { flex: 1; min-width: 0; accent-color: var(--px-accent); height: 28px; }
.px-slider output { font: 600 14px/1 var(--px-ui-font); min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }

.px-meter {
  width: min(420px, 100%);
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--px-line);
  background: var(--px-glass);
  overflow: hidden;
  position: relative;
}
.px-meter-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #ff9ac6, #ff3d8c, #ff2978);
  border-radius: inherit;
}
.px-meter-label {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font: 600 13px/1 var(--px-ui-font);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.px-toast {
  max-width: 100%;
  padding: 9px 16px;
  border-radius: 16px;
  background: var(--px-glass-strong);
  border: 1px solid var(--px-line);
  font: 600 15px/1.25 var(--px-ui-font);
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(-6px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.px-toast.is-shown { opacity: 1; transform: none; }

/* ------------------------------------------------------- Centre play boards */
.px-center {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(110px + env(safe-area-inset-top, 0px)) 12px calc(118px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
  font-family: var(--px-ui-font);
  color: var(--px-text);
}
.px-center:empty { display: none; }
.px-center > * { pointer-events: auto; }

/* Tic-tac-toe */
.px-ttt {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  /* --px-avail-h is the measured free height between the HUD and the Play button. */
  width: min(330px, 76vw, 58vh, var(--px-avail-h, 58vh));
  aspect-ratio: 1;
  max-width: 100%;
  padding: 10px;
  border-radius: 24px;
  background: var(--px-glass);
  border: 1px solid var(--px-line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.35);
}
.px-ttt-cell {
  appearance: none;
  border: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: min(54px, 13vw, 10vh);
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, transform 0.15s ease;
}
.px-ttt-cell:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18); outline: none; }
.px-ttt-cell:focus-visible { background: rgba(255, 255, 255, 0.18); outline: 3px solid var(--px-accent); outline-offset: -3px; }
.px-ttt-cell:disabled { cursor: default; }
.px-ttt-cell.is-placed span { display: inline-block; animation: px-pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
.px-ttt-cell.is-win { background: var(--px-accent); }

/* Pop Rhythm pads */
.px-pads {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(420px, 92vw);
  max-width: 100%;
}
.px-pad {
  appearance: none;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 22px;
  aspect-ratio: 1.25;
  max-height: min(18vh, calc(var(--px-avail-h, 100vh) / 2 - 6px));
  width: 100%;
  background: var(--pad, #ff5fa2);
  color: #fff;
  font: 600 min(30px, 8vw)/1 var(--px-ui-font);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 6px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  opacity: 0.82;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}
.px-pad:focus-visible { outline: 3px solid #fff; outline-offset: 2px; opacity: 1; }
.px-pad.is-hit { transform: scale(0.92); opacity: 1; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18), 0 0 28px var(--pad, #fff); }
.px-pad.is-cue { opacity: 1; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 0 0 4px #fff, 0 0 30px var(--pad, #fff); }

/* Compliment jar */
.px-jar {
  appearance: none;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: min(84px, 20vw, 16vh);
  line-height: 1;
  filter: drop-shadow(0 8px 20px rgba(255, 80, 160, 0.45));
  -webkit-tap-highlight-color: transparent;
  animation: px-float 3s ease-in-out infinite;
  align-self: flex-end;
}
.px-jar:focus-visible { outline: 2px solid var(--px-accent); border-radius: 20px; }
.px-jar.is-shake { animation: px-wiggle 0.6s ease; }

@keyframes px-pop { from { transform: scale(0.2) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes px-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* Shake It: jiggle the particle stage for a moment. */
body.px-shaking #stage, body.px-shaking #overlay { animation: px-shake 0.45s linear; }
@keyframes px-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-9px, 4px) rotate(-0.6deg); }
  30% { transform: translate(8px, -5px) rotate(0.5deg); }
  45% { transform: translate(-6px, -3px); }
  60% { transform: translate(5px, 4px) rotate(-0.3deg); }
  80% { transform: translate(-2px, 1px); }
}

/* Fade the cursor hint while an activity is running. */
body.px-playing .hint { opacity: 0 !important; }

/* While a board is shown (js sets body.px-board and sizes .px-center), the
   caption and "next" button step aside so they are never covered. */
.ui { transition: opacity 0.25s ease, visibility 0s linear 0s; }
body.px-board .ui { opacity: 0; visibility: hidden; transition: opacity 0.25s ease, visibility 0s linear 0.25s; }

/* ----------------------------------------------------------- Activity sheet */
.px-dock {
  position: fixed;
  inset: 0;
  z-index: 5;
  font-family: var(--px-ui-font);
  color: var(--px-text);
}
.px-dock-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.px-dock.is-open .px-dock-backdrop { opacity: 1; }

.px-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(80vh, 680px);
  display: flex;
  flex-direction: column;
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--px-line);
  border-bottom: 0;
  background: var(--px-glass-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45);
  padding: 8px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  transform: translateY(104%);
  transition: transform 0.32s cubic-bezier(.2, .9, .3, 1);
  outline: none;
}
.px-dock.is-open .px-sheet { transform: none; }
.px-grabber { width: 42px; height: 5px; border-radius: 5px; background: var(--px-line); margin: 2px auto 8px; flex: none; }

.px-sheet-head { display: flex; align-items: center; gap: 10px; flex: none; }
.px-sheet-title { margin: 0; font: 600 20px/1.1 var(--px-ui-font); flex: 1; }
.px-sheet-title small { display: block; font-size: 12px; font-weight: 400; opacity: 0.7; margin-top: 3px; }
.px-close {
  appearance: none; border: 0; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1); color: inherit; font: 600 18px/1 var(--px-ui-font); cursor: pointer; flex: none;
}
.px-close:hover, .px-close:focus-visible { background: var(--px-accent); color: var(--px-accent-ink); outline: none; }

.px-search { margin: 10px 0 8px; width: 100%; flex: none; }
.px-cats {
  display: flex; gap: 6px; overflow-x: auto; flex: none;
  padding: 2px 2px 8px; margin: 0 -2px;
  scrollbar-width: none;
}
.px-cats::-webkit-scrollbar { display: none; }
.px-cats .px-chip { flex: none; padding: 8px 12px; font-size: 13px; backdrop-filter: none; -webkit-backdrop-filter: none; }

.px-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 4px;
  min-height: 0;
}
.px-card {
  appearance: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 12px 12px;
  border-radius: 16px;
  border: 1px solid transparent;
  background: var(--px-card);
  color: inherit;
  font-family: var(--px-ui-font);
  cursor: pointer;
  min-height: 104px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.18s ease, transform 0.15s ease, border-color 0.18s ease;
}
.px-card:hover, .px-card:focus-visible { background: var(--px-card-hover); border-color: var(--px-line); outline: none; transform: translateY(-2px); }
.px-card:active { transform: scale(0.97); }
.px-card.is-active { border-color: var(--px-accent); box-shadow: inset 0 0 0 1px var(--px-accent); }
.px-card > * { flex: none; }
.px-card-emoji { font-size: 28px; line-height: 1.1; }
.px-card-label { font-size: 15px; font-weight: 600; line-height: 1.15; }
.px-card-desc {
  font-size: 12px; line-height: 1.3; opacity: 0.72;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.px-card-badge {
  align-self: flex-start; font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 999px; background: var(--px-accent); color: var(--px-accent-ink);
}
.px-empty { grid-column: 1 / -1; text-align: center; opacity: 0.7; padding: 24px 8px; font-size: 15px; }

/* Wider screens: a floating panel above the Play button. */
@media (min-width: 700px) {
  .px-sheet {
    left: calc(12px + env(safe-area-inset-left, 0px));
    right: auto;
    bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    width: 460px;
    max-height: min(640px, calc(100vh - 170px));
    border-radius: 22px;
    border-bottom: 1px solid var(--px-line);
    padding-bottom: 12px;
    transform: translateY(24px) scale(0.97);
    transform-origin: 0 100%;
    opacity: 0;
    transition: transform 0.25s cubic-bezier(.2, .9, .3, 1), opacity 0.2s ease;
  }
  .px-dock.is-open .px-sheet { opacity: 1; }
  .px-grabber { display: none; }
}
/* Landscape phones: use the full height. */
@media (max-height: 500px) and (min-width: 481px) {
  .px-sheet { top: 8px; bottom: 8px; max-height: none; border-radius: 20px; border-bottom: 1px solid var(--px-line); width: min(560px, calc(100vw - 24px)); left: calc(12px + env(safe-area-inset-left, 0px)); right: auto; }
  .px-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .px-card { min-height: 88px; }
  .px-grabber { display: none; }
  .px-top { top: calc(56px + env(safe-area-inset-top, 0px)); gap: 5px; }
  .px-hud { font-size: 13px; padding: 3px 3px 3px 10px; }
  .px-btn { padding: 7px 10px; font-size: 13px; }
  .px-center { padding-top: 96px; padding-bottom: 70px; }
  .px-pad { max-height: min(22vh, calc(var(--px-avail-h, 100vh) / 2 - 6px)); aspect-ratio: 1.8; }
}
@media (max-width: 360px) {
  .px-hud { font-size: 13px; gap: 6px; padding-left: 10px; }
  .px-hud-text { display: none; }
  .px-btn { padding: 8px 10px; font-size: 13px; }
  .px-grid { grid-template-columns: repeat(2, 1fr); }
  .px-card { padding: 9px 10px 10px; min-height: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .px-play-hello, .px-jar, .px-hud, .px-hud-score.is-bump,
  .px-ttt-cell.is-placed span, body.px-shaking #stage, body.px-shaking #overlay { animation: none !important; }
  .px-sheet, .px-dock-backdrop, .px-toast, .px-card, .px-play, .ui, body.px-board .ui { transition: none !important; }
}
