/* ==========================================================================
   Find Mr. Wiggles: storybook patchwork theme
   Cream paper, ink outlines, stitched patches in Mr. Wiggles' own colours.
   ========================================================================== */

@font-face {
  font-family: 'Grandstander';
  src: url('../assets/fonts/Grandstander-variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../assets/fonts/AtkinsonHyperlegible-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../assets/fonts/AtkinsonHyperlegible-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #f7f0df;
  --paper-deep: #efe3c8;
  --ink: #2a2230;
  --ink-soft: #5b4e5f;
  --teal: #2f9c9a;
  --teal-deep: #1f6f6d;
  --orange: #e98a3a;
  --mustard: #f2cd4b;
  --green: #9cc75a;
  --purple: #8b5cc7;
  --pink: #f08a9a;
  --danger: #c0392b;
  --radius: 18px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --stitch: 2px dashed rgba(42, 34, 48, 0.35);
  --shadow: 0 4px 0 var(--ink), 0 10px 24px rgba(42, 34, 48, 0.18);
  --font-display: 'Grandstander', 'Comic Sans MS', 'Chalkboard SE', cursive;
  --font-body: 'Atkinson Hyperlegible', 'Segoe UI', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  /* Paper grain + soft patchwork confetti, no image requests. */
  background-image:
    radial-gradient(circle at 12% 18%, rgba(47, 156, 154, 0.16) 0 90px, transparent 91px),
    radial-gradient(circle at 88% 12%, rgba(233, 138, 58, 0.16) 0 120px, transparent 121px),
    radial-gradient(circle at 80% 86%, rgba(139, 92, 199, 0.14) 0 110px, transparent 111px),
    radial-gradient(circle at 8% 90%, rgba(242, 205, 75, 0.22) 0 80px, transparent 81px),
    repeating-linear-gradient(45deg, rgba(42, 34, 48, 0.025) 0 2px, transparent 2px 6px);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 0.4em;
}

button {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  --btn-bg: #fff;
  --btn-fg: var(--ink);
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 48px;
  padding: 0.55em 1.2em;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.2s;
  touch-action: manipulation;
}
.btn:hover {
  transform: translateY(-1px) rotate(-0.6deg);
  box-shadow: 0 4px 0 var(--ink);
}
.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}
.btn-primary {
  --btn-bg: var(--orange);
  --btn-fg: var(--ink);
  font-size: 1.2rem;
  padding-inline: 1.6em;
}
.btn-ghost {
  --btn-bg: transparent;
  box-shadow: none;
  border-style: dashed;
  border-width: 2px;
}
.btn-ghost:hover {
  box-shadow: none;
  background: rgba(255, 255, 255, 0.6);
}
.btn-danger {
  --btn-bg: #fbe3df;
  --btn-fg: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 3px 0 var(--danger);
}
.btn-icon {
  min-width: 48px;
  padding: 0;
  font-size: 1.4rem;
}
.link-btn {
  border: 0;
  background: none;
  padding: 0.25em 0.4em;
  color: var(--teal-deep);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.25rem;
}
.actions-small {
  margin-top: 0.9rem;
  gap: 0.5rem;
}
.actions-small .btn {
  font-size: 0.95rem;
  min-height: 44px;
  padding-inline: 1em;
}
.actions-col {
  flex-direction: column;
  align-items: stretch;
}

/* ------------------------------------------------------------------ screens */
.screen {
  min-height: 100dvh;
}

.screen-home {
  display: grid;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) 1rem calc(1.5rem + var(--safe-bottom));
}

.home-card {
  position: relative;
  width: min(560px, 100%);
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 28px;
  box-shadow: var(--shadow);
  animation: drop-in 0.7s var(--ease-out) both;
}
.home-card::before {
  content: '';
  position: absolute;
  inset: 9px;
  border: var(--stitch);
  border-radius: 20px;
  pointer-events: none;
}

.logo {
  font-size: clamp(2.6rem, 9vw, 4.2rem);
  margin: 0;
  letter-spacing: -0.01em;
  transform: rotate(-2deg);
}
.logo-name {
  display: block;
  font-size: 1.15em;
  /* Sticker lettering in his hat colours */
  color: var(--teal);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--orange), 6px 6px 0 var(--ink);
  animation: wiggle 3.2s ease-in-out 1s infinite;
  transform-origin: 50% 80%;
}

.portrait {
  display: block;
  margin: 0.5rem auto 0;
  max-width: 100%;
  height: auto;
}

.tagline {
  max-width: 34ch;
  margin: 0.25rem auto 0;
  font-size: 1.1rem;
  color: var(--ink-soft);
}

.home-meta {
  margin: 1.1rem 0 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.screen-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.75rem + var(--safe-top)) calc(1rem + var(--safe-right)) 0.75rem calc(1rem + var(--safe-left));
  background: linear-gradient(var(--paper) 70%, transparent);
}
.screen-header h2 {
  flex: 1;
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
}

.scene-grid {
  list-style: none;
  margin: 0 auto;
  padding: 0.5rem 1rem 1rem;
  max-width: 1100px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 360px));
  justify-content: center;
  gap: 1.5rem;
}

.scene-card {
  --tilt: -1deg;
  --patch: var(--teal);
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 0.75rem 0.75rem 1rem;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #fffaf0;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transform: rotate(var(--tilt));
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s;
  animation: drop-in 0.6s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}
.scene-grid li:nth-child(even) .scene-card {
  --tilt: 1.2deg;
}
.scene-card:hover:not([aria-disabled='true']) {
  transform: rotate(0deg) translateY(-4px) scale(1.01);
}
.scene-card::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: var(--stitch);
  border-radius: 13px;
  pointer-events: none;
}
.scene-card[aria-disabled='true'] {
  cursor: not-allowed;
  background: var(--paper-deep);
}
.scene-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  overflow: hidden;
  background: var(--patch);
}
.scene-thumb canvas,
.scene-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scene-card[aria-disabled='true'] .scene-thumb canvas {
  filter: grayscale(1) blur(3px) brightness(0.9);
}
.scene-lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  text-shadow: 0 2px 0 #fff;
}
.scene-kind {
  margin: 0.8rem 0.25rem 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal-deep);
}
.scene-name {
  margin: 0.1rem 0.25rem 0.2rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1.15;
}
.scene-blurb {
  margin: 0 0.25rem;
  color: var(--ink-soft);
  font-size: 0.97rem;
}
.scene-status {
  margin: auto 0.25rem 0;
  padding-top: 0.7rem;
  font-weight: 700;
  font-size: 0.95rem;
}
.badge {
  display: inline-block;
  padding: 0.15em 0.65em;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 0.85rem;
  transform: rotate(-2deg);
}
.badge-new {
  background: var(--mustard);
}
.badge-done {
  background: var(--green);
}
.badge-locked {
  background: #fff;
}

.coming-soon {
  max-width: 60ch;
  margin: 1rem auto 2rem;
  padding: 0 1rem calc(1rem + var(--safe-bottom));
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
}

/* ------------------------------------------------------------------ game */
.screen-game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #1d1a22;
  overscroll-behavior: none;
}
.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
.game-canvas:active {
  cursor: grabbing;
}
.game-canvas:focus-visible {
  outline: 4px solid var(--mustard);
  outline-offset: -4px;
}

.hud {
  position: absolute;
  top: calc(0.6rem + var(--safe-top));
  left: calc(0.6rem + var(--safe-left));
  right: calc(0.6rem + var(--safe-right));
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}
.hud > * {
  pointer-events: auto;
}
.hud-btn {
  --btn-bg: var(--paper);
}
.hud-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0.3rem 0.9rem;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-1deg);
}
.hud-scene {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-diff {
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.hud-timer {
  margin-left: auto;
  min-width: 4.6ch;
  padding: 0.35rem 0.8rem;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--mustard);
  box-shadow: 0 3px 0 var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.hud-tools {
  position: absolute;
  right: calc(0.75rem + var(--safe-right));
  bottom: calc(0.9rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
}
.target-btn {
  width: 64px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  --btn-bg: #fffaf0;
}
.target-btn canvas {
  width: 56px;
  height: 56px;
}
#btn-hint {
  --btn-bg: var(--teal);
  color: #fff;
  text-shadow: 0 1px 0 var(--ink);
}
#btn-hint[aria-disabled='true'] {
  opacity: 0.6;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-bottom));
  max-width: min(80vw, 420px);
  padding: 0.55rem 1.1rem;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--ink);
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, 160%);
  opacity: 0;
  transition: transform 0.3s var(--ease-out), opacity 0.2s;
  pointer-events: none;
}
.toast.show {
  transform: translate(-50%, 0) rotate(-1deg);
  opacity: 1;
}

/* ------------------------------------------------------------------ dialogs */
.dialog {
  width: min(520px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 1.6rem 1.4rem 1.3rem;
  border: 3px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
}
.dialog[open] {
  animation: pop-in 0.35s var(--ease-out) both;
}
.dialog::backdrop {
  background:
    repeating-linear-gradient(115deg, rgba(47, 156, 154, 0.55) 0 28px, rgba(233, 138, 58, 0.55) 28px 56px),
    rgba(29, 26, 34, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.dialog h2 {
  font-size: 1.9rem;
  text-align: center;
}
.dialog p {
  margin: 0.4rem 0;
}
.eyebrow {
  margin: 0 !important;
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-deep);
}
#start-blurb {
  text-align: center;
  color: var(--ink-soft);
}
.start-body,
.meet-body {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.8rem 0;
  padding: 0.75rem;
  border: var(--stitch);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
}
.portrait-small {
  flex: 0 0 auto;
  width: 120px;
  margin: 0;
}
.meet-body .portrait {
  flex: 0 0 auto;
  width: 140px;
  margin: 0;
}
.traits {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.97rem;
}
.traits li + li {
  margin-top: 0.25rem;
}
.traits li::marker {
  content: '✦ ';
  color: var(--orange);
}
.start-diff {
  text-align: center;
}
.reference {
  margin-top: 0.6rem;
}
.reference summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--teal-deep);
}
.reference img {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 0.6rem;
  border: 2px solid var(--ink);
  border-radius: 12px;
}

.dialog-found {
  margin-bottom: calc(1rem + var(--safe-bottom));
  margin-top: auto;
}
.dialog-found::backdrop {
  background: rgba(29, 26, 34, 0.35);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.dialog-found h2 {
  font-size: 2.1rem;
  transform: rotate(-1.5deg);
}
.stars {
  margin: 0 !important;
  text-align: center;
  font-size: 2.4rem;
  letter-spacing: 0.15em;
  color: var(--mustard);
  -webkit-text-stroke: 1.5px var(--ink);
}
.stars span {
  display: inline-block;
  animation: star-pop 0.5s var(--ease-out) both;
}
.stars span:nth-child(2) {
  animation-delay: 0.15s;
}
.stars span:nth-child(3) {
  animation-delay: 0.3s;
}
.stars .dim {
  color: #fff;
}
.found-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.8rem 0 0.4rem;
}
.found-stats div {
  padding: 0.5rem;
  border: var(--stitch);
  border-radius: 12px;
  text-align: center;
  background: rgba(255, 255, 255, 0.6);
}
.found-stats dt {
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.found-stats dd {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
}
.found-best {
  text-align: center;
  font-weight: 700;
  color: var(--teal-deep);
}

.difficulty {
  margin: 0.5rem 0 1rem;
  padding: 0;
  border: 0;
}
.difficulty legend {
  margin-bottom: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
}
.difficulty-options {
  display: grid;
  gap: 0.45rem;
}
.diff-option {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.7rem;
  align-items: center;
  padding: 0.55rem 0.8rem;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
}
.diff-option input {
  grid-row: span 2;
  width: 1.3rem;
  height: 1.3rem;
  margin: 0;
  accent-color: var(--teal);
}
.diff-option strong {
  font-family: var(--font-display);
}
.diff-option small {
  color: var(--ink-soft);
}
.diff-option:has(input:checked) {
  background: var(--mustard);
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-0.6deg);
}
.diff-dots {
  letter-spacing: 0.1em;
  color: var(--orange);
}
.toggle {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 44px;
  font-weight: 700;
  cursor: pointer;
}
.toggle input {
  width: 1.3rem;
  height: 1.3rem;
  accent-color: var(--teal);
}
.danger-zone {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: var(--stitch);
  text-align: center;
}
.howto {
  padding-left: 1.3rem;
}
.howto li + li {
  margin-top: 0.4rem;
}
kbd {
  padding: 0.05em 0.4em;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: #fff;
  font-family: var(--font-body);
  font-size: 0.9em;
}

.noscript {
  padding: 2rem;
  text-align: center;
}

/* ------------------------------------------------------------------ motion */
@keyframes drop-in {
  from {
    opacity: 0;
    transform: translateY(-24px) rotate(-4deg) scale(0.96);
  }
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.85) rotate(-2deg);
  }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  6% { transform: rotate(-3deg); }
  12% { transform: rotate(3deg); }
  18% { transform: rotate(-2deg); }
  24% { transform: rotate(0); }
}
@keyframes star-pop {
  from {
    opacity: 0;
    transform: scale(0.2) rotate(-40deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 480px) {
  .home-card {
    padding: 1.6rem 1rem 1.2rem;
  }
  .start-body,
  .meet-body {
    flex-direction: column;
  }
  .hud-diff {
    display: none;
  }
  .found-stats dd {
    font-size: 1.15rem;
  }
}

@media (forced-colors: active) {
  .logo-name {
    color: CanvasText;
    -webkit-text-stroke: 0;
    text-shadow: none;
  }
}
