/* Monty's Treasure Sort — Design System */

/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --primary: #0f766e;
  --primary-rgb: 15, 118, 110;
  --primary-container: #f6cf74;
  --on-primary: #f4fffd;
  --on-primary-container: #5a3d00;

  --surface: #fdf8ee;
  --surface-container-low: #f7f0e1;
  --surface-container-lowest: #fffdf8;
  --surface-container-high: #ece2cf;
  --surface-container-highest: #e3d7c0;
  /* Used by the fallback parental gate, which builds its UI inline. */
  --border: #cbbfa8;

  --secondary-container: #c7ece8;
  --on-secondary-container: #0b4f4a;
  --tertiary-container: #ffe1a8;
  --on-tertiary-container: #5a3d00;

  --on-surface: #2b2620;
  --on-surface-variant: #5f574c;
  --outline-variant: #a99c88;

  --font-headline: 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Be Vietnam Pro', sans-serif;

  --radius-md: 0.75rem;
  --radius-lg: 1.5rem;
  --radius-xl: 2rem;
  --radius-full: 9999px;

  --shadow-card: 0 4px 12px rgba(43, 38, 32, 0.07);
  --shadow-modal: 0 20px 40px rgba(43, 38, 32, 0.14);
}

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100vh; /* Fallback for browsers that do not support dynamic viewport units */
  height: 100dvh;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--on-surface);
  line-height: 1.5;
  overflow: hidden; /* The game is a contained surface, not a scrolling page. */
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  padding: 0;
}

/* ─── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-headline);
  letter-spacing: -0.02em;
  color: var(--on-surface);
}
h1 { font-size: clamp(1.25rem, 4vw, 2rem);    font-weight: 700; }
h2 { font-size: clamp(1.25rem, 3vw, 1.75rem); font-weight: 600; }
h3 { font-size: clamp(1rem, 2.5vw, 1.25rem);  font-weight: 600; }

/* ─── SVG sprite ─────────────────────────────────────────────── */
.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ─── Loading Overlay ────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  transition: opacity 0.5s ease-out, visibility 0.5s;
}
.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.loader-content {
  text-align: center;
  color: var(--on-primary-container);
  padding: 2rem;
}

.loader-title {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  margin-bottom: 2rem;
  color: var(--on-primary-container);
}

.spinner {
  font-size: clamp(2.5rem, 8vw, 4rem);
  margin-bottom: 1rem;
  color: var(--primary);
  animation: rotateScale 1.5s ease-in-out infinite;
  display: inline-block;
}

.spinner svg {
  width: 1em;
  height: 1em;
  display: block;
}

@keyframes rotateScale {
  0%   { transform: scale(1)   rotate(0deg); }
  50%  { transform: scale(1.2) rotate(180deg); }
  100% { transform: scale(1)   rotate(360deg); }
}

.loader-content p {
  font-family: var(--font-headline);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: clamp(0.75rem, 2vw, 1rem);
}

/* ─── Main Container ─────────────────────────────────────────── */
#game-container {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: calc(clamp(0.5rem, 1.5vh, 1.25rem) + var(--reserved-top, 0px))
           calc(clamp(1rem, 3vw, 2rem) + env(safe-area-inset-right))
           calc(clamp(0.5rem, 1.5vh, 1.25rem) + var(--reserved-bottom, 0px))
           calc(clamp(1rem, 3vw, 2rem) + env(safe-area-inset-left));
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

body[data-screen="game"] #game-container {
  max-width: 100vw;
  padding: calc(0.25rem + var(--reserved-top, 0px))
           calc(0.5rem + env(safe-area-inset-right))
           calc(0.5rem + var(--reserved-bottom, 0px) + env(safe-area-inset-bottom))
           calc(0.5rem + env(safe-area-inset-left));
  overflow: hidden;
}

body { --reserved-bottom: 0px; --reserved-top: 0px; }

/* ─── Screens ────────────────────────────────────────────────── */
.screen {
  display: none;
  animation: fadeIn 0.3s ease-out;
  height: 100%;
  min-height: 0;
}
.screen.active {
  display: flex;
  flex-direction: column;
}
#home-screen.active,
#difficulty-screen.active,
#settings-screen.active {
  justify-content: center;
}

#victory-screen.active {
  justify-content: flex-start;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Home Screen ────────────────────────────────────────────── */
.welcome-content {
  text-align: center;
  padding: clamp(0.5rem, 3vh, 2rem) clamp(1rem, 5vw, 3rem);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.hero-brand {
  margin-bottom: clamp(0.75rem, 2.5vh, 1.5rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  animation: fadeInDown 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

.hero-logo {
  width: clamp(2rem, 6vw, 3.5rem);
  height: clamp(2rem, 6vw, 3.5rem);
  color: var(--primary);
  filter: drop-shadow(0 4px 12px rgba(var(--primary-rgb), 0.22));
}

.hero-title {
  font-size: clamp(1.75rem, 6vw, 3rem);
  font-weight: 800;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--on-primary-container), var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--primary); /* fallback when background-clip is unsupported */
  text-shadow: 0 10px 30px rgba(var(--primary-rgb), 0.12);
  padding-bottom: 0.1em;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mascot-area {
  margin-bottom: clamp(0.5rem, 2.5vh, 1.5rem);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

.mascot-image-wrapper {
  width: clamp(140px, 35vw, 280px);
  height: clamp(140px, 35vw, 280px);
  max-width: 35vh;
  max-height: 35vh;
  position: relative;
  animation: float 4s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  overflow: visible;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-6px) rotate(-1.5deg); }
}

.mascot-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 40px rgba(43, 38, 32, 0.12));
  position: relative;
  z-index: 2;
}

.mascot-glow {
  position: absolute;
  width: 120%;
  height: 120%;
  background: radial-gradient(circle, var(--primary-container) 0%, transparent 70%);
  opacity: 0.6;
  filter: blur(40px);
  z-index: 1;
  animation: pulseGlow 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1);   opacity: 0.4; }
  50%      { transform: scale(1.1); opacity: 0.7; }
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.hero-tagline {
  color: var(--on-surface-variant);
  margin-bottom: clamp(0.75rem, 3vh, 1.75rem);
  font-weight: 500;
  font-size: clamp(1rem, 3vw, 1.25rem);
  opacity: 0.9;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius-full);
  padding: 0.875rem 2rem;
  font-size: clamp(0.9rem, 2.5vw, 1.125rem);
  font-weight: 600;
  font-family: var(--font-headline);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover  { background: var(--on-primary-container); transform: translateY(-2px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface-container-high);
  color: var(--on-surface);
  border: none;
  border-radius: var(--radius-full);
  padding: 0.75rem 1.5rem;
  font-size: clamp(0.875rem, 2vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-secondary:hover { background: var(--surface-container-highest); }
.btn-secondary:active { transform: scale(0.97); }

/* Shared inline icon sizing */
.btn-primary svg,
.btn-secondary svg,
.btn-back svg,
.btn-support svg {
  width: 1.25em;
  height: 1.25em;
  vertical-align: middle;
  margin-right: 0.45em;
}

/* ─── Touch Target Enforcement ───────────────────────────────── */
button,
[role="button"],
input[type="checkbox"],
.btn-primary,
.btn-secondary,
.btn-difficulty,
.btn-back {
  min-height: 56px;
  min-width: 56px;
}

.btn-link {
  min-height: 44px;
  min-width: 44px;
}

.btn-large {
  padding: 1rem 2.5rem;
  font-size: clamp(1rem, 3vw, 1.25rem);
}

.btn-settings {
  margin-top: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ─── Difficulty Screen ──────────────────────────────────────── */
.difficulty-content {
  text-align: center;
  padding: clamp(1rem, 3vw, 2rem);
  background: var(--surface-container-lowest);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  max-width: min(560px, 100%);
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.screen-title {
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  margin: 0;
}

.screen-title svg {
  width: 1.15em;
  height: 1.15em;
}

.screen-subtitle {
  color: var(--on-surface-variant);
  font-size: clamp(0.9rem, 2vw, 1rem);
  margin-bottom: clamp(0.5rem, 1.5vh, 1rem);
}

.difficulty-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 420px;
  margin: 0 auto clamp(0.75rem, 2vh, 1.25rem);
}

.btn-difficulty {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.85rem;
  align-items: center;
  text-align: left;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  border: none;
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.25rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-difficulty:hover {
  background: var(--tertiary-container);
  color: var(--on-tertiary-container);
}
.btn-difficulty:active { transform: scale(0.98); }

.difficulty-icon {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-full);
  background: var(--surface-container-lowest);
  color: var(--primary);
  font-size: 1.1rem;
}

.difficulty-name {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  line-height: 1.2;
}

.difficulty-meta {
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  opacity: 0.9;
}

/* ─── Game Screen ────────────────────────────────────────────── */
.game-header-bar {
  background: var(--surface-container-lowest);
  padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 1.5rem);
  border-radius: var(--radius-lg);
  margin-bottom: clamp(0.5rem, 2vw, 1rem);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  box-shadow: var(--shadow-card);
  gap: 1rem;
  flex-shrink: 0;
}

.game-header-bar .screen-title {
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  white-space: nowrap;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  background: var(--surface-container-high);
  color: var(--on-surface);
  border: none;
  border-radius: var(--radius-full);
  padding: 0.4rem 1rem;
  font-size: clamp(0.8rem, 2vw, 1rem);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-back:hover { background: var(--surface-container-highest); }

.header-right {
  justify-self: end;
}

/* The hoard, baskets and items are built by the game controller. */
.treasure-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.game-stage {
  --basket-size: min(28vw, 120px);
  --item-size: clamp(112px, 34vw, 190px);
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: clamp(0.5rem, 1.5vh, 1rem);
  touch-action: manipulation;
}

.item-slot {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
}

.basket-tray {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(0.5rem, 2vw, 1rem);
  padding: 0.25rem 0 0.5rem;
}

.round-progress {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: clamp(0.8rem, 2vw, 0.95rem);
  color: var(--on-surface-variant);
  background: var(--surface-container-low);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.7rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ─── Baskets ────────────────────────────────────────────────── */
.basket {
  position: relative;
  width: var(--basket-size);
  height: calc(var(--basket-size) * 0.92);
  min-width: 72px;
  min-height: 64px;
  border: none;
  padding: 0;
  background: linear-gradient(180deg, #f0c46a 0%, #e0a93f 55%, #c98f2c 100%);
  border-radius: 18% 18% 30% 30% / 16% 16% 32% 32%;
  box-shadow: inset 0 -8px 0 rgba(90, 61, 0, 0.12), 0 8px 18px rgba(43, 38, 32, 0.16);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s, box-shadow 0.18s, background 0.18s;
  touch-action: manipulation;
}

.basket::before {
  content: '';
  position: absolute;
  top: -8%;
  left: 6%;
  width: 88%;
  height: 20%;
  border-radius: var(--radius-full);
  background: linear-gradient(180deg, #f8d98d, #d9a43b);
  box-shadow: 0 2px 0 rgba(90, 61, 0, 0.18);
}

.basket::after {
  content: '';
  position: absolute;
  inset: 22% 10% 12%;
  border-radius: 12% 12% 22% 22%;
  background: repeating-linear-gradient(90deg,
    rgba(255, 255, 255, 0.16) 0 3px,
    transparent 3px 10px);
  pointer-events: none;
}

.basket[hidden] { display: none; }

.basket-icon {
  position: relative;
  z-index: 2;
  width: 58%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: var(--on-surface);
}

.basket-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.basket-shine {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

.basket:hover { transform: translateY(-2px); }

.basket:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.basket.is-target {
  transform: translateY(-6px) scale(1.05);
  box-shadow: 0 0 0 4px var(--primary-container), 0 12px 22px rgba(43, 38, 32, 0.2);
}

.basket.is-correct {
  animation: basketPop 0.45s ease-out;
  background: linear-gradient(180deg, #ffe6a8, #f2c14e 60%, #d99f2e);
}

.basket.is-wrong {
  animation: basketWobble 0.4s ease-in-out;
  background: linear-gradient(180deg, #e8dcc4, #d9c9a8 60%, #c4b391);
}

.basket.is-hint {
  animation: basketHint 0.75s ease-in-out 2;
}

.basket.is-relabelling .basket-icon {
  animation: basketRelabel 0.3s ease-out;
}

@keyframes basketPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.08) translateY(-4px); }
  100% { transform: scale(1); }
}

@keyframes basketWobble {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-1deg); }
  75% { transform: translateX(5px) rotate(1deg); }
}

@keyframes basketHint {
  0%, 100% { box-shadow: inset 0 -8px 0 rgba(90, 61, 0, 0.12), 0 8px 18px rgba(43, 38, 32, 0.16); }
  50% { box-shadow: 0 0 0 8px rgba(246, 207, 116, 0.65), 0 10px 22px rgba(43, 38, 32, 0.2); }
}

@keyframes basketRelabel {
  from { opacity: 0; transform: scale(0.8) rotate(-5deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

/* ─── Treasure items ─────────────────────────────────────────── */
.treasure-item {
  position: relative;
  z-index: 5;
  width: var(--item-size);
  aspect-ratio: 1;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  filter: drop-shadow(0 12px 18px rgba(43, 38, 32, 0.18));
  transition: filter 0.2s, transform 0.2s;
}

.treasure-item--small { width: calc(var(--item-size) * 0.66); }
.treasure-item--large { width: var(--item-size); }

.treasure-item:hover {
  filter: drop-shadow(0 16px 24px rgba(43, 38, 32, 0.22));
  transform: translateY(-2px) scale(1.02);
}

.treasure-item:focus-visible {
  outline: 4px solid var(--primary);
  outline-offset: 8px;
  border-radius: 28px;
}

.treasure-item.is-selected {
  outline: 4px solid var(--primary-container);
  outline-offset: 7px;
  border-radius: 28px;
  filter: drop-shadow(0 0 18px rgba(246, 207, 116, 0.8));
  transform: scale(1.05);
}

.treasure-item.is-pressed { cursor: grabbing; }

.treasure-item.is-dragging {
  transition: none;
  z-index: 40;
  cursor: grabbing;
  filter: drop-shadow(0 22px 26px rgba(43, 38, 32, 0.24));
}

.treasure-item.is-returning {
  transition: transform 0.34s cubic-bezier(0.2, 0.8, 0.3, 1), filter 0.2s;
}

.treasure-item.is-snapping {
  z-index: 30;
  pointer-events: none;
}

.treasure-item.is-fading {
  transition: opacity 0.16s ease-out;
}

.treasure-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

body.is-dragging-item {
  touch-action: none;
  overflow: hidden;
  cursor: grabbing;
}

/* ─── Rule banner ────────────────────────────────────────────── */
.rule-banner {
  position: absolute;
  top: 0.25rem;
  left: 50%;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: min(92%, 460px);
  padding: 0.45rem 0.9rem 0.45rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--primary-container);
  color: var(--on-primary-container);
  box-shadow: var(--shadow-modal);
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  pointer-events: none;
}

.rule-banner[hidden] { display: none; }

.rule-banner.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.rule-banner-monty {
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 50%;
  background: var(--surface-container-lowest);
  padding: 2px;
}

.rule-banner-text {
  margin: 0;
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  white-space: nowrap;
}

/* ─── Sparkles ───────────────────────────────────────────────── */
.sparkle-layer {
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
}

.sparkle {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--primary-container);
  box-shadow: 0 0 8px #fff3c4;
  animation: sparkleOut 0.62s ease-out forwards;
}

@keyframes sparkleOut {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

/* ─── Victory screen ─────────────────────────────────────────── */
.victory-panel {
  width: min(560px, 100%);
  padding: clamp(1rem, 3vw, 2rem);
  border-radius: var(--radius-xl);
  background: var(--surface-container-lowest);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.victory-monty {
  width: clamp(110px, 22vh, 200px);
  height: auto;
  object-fit: contain;
}

.victory-title {
  color: var(--primary);
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  margin: 0;
}

/* Focused programmatically so screen readers announce the result; it is a
   heading, not a control, so no visible ring is needed. */
.victory-title:focus { outline: none; }

.victory-difficulty {
  color: var(--on-surface-variant);
  font-weight: 600;
  margin: 0;
}

.victory-stars {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.25rem 0;
}

.victory-star {
  width: clamp(2.4rem, 8vw, 3.4rem);
  height: clamp(2.4rem, 8vw, 3.4rem);
  fill: none;
  stroke: var(--outline-variant);
  stroke-width: 1.5;
  opacity: 0.55;
}

.victory-star.is-earned {
  fill: var(--primary-container);
  stroke: #5a3d00;
  opacity: 1;
  animation: starPop 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.25) both;
  animation-delay: var(--star-delay, 0ms);
}

.victory-star.is-locked {
  fill: var(--surface-container-high);
  stroke: var(--outline-variant);
}

@keyframes starPop {
  0% { transform: scale(0.4) rotate(-16deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.victory-accuracy {
  margin: 0;
  color: var(--on-surface);
  font-weight: 600;
}

.victory-time {
  margin: 0;
  color: var(--on-surface-variant);
  font-size: 0.95rem;
}

.victory-best {
  margin: 0;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.9rem;
}

.victory-badges { width: 100%; }

.victory-badges[hidden] { display: none; }

.victory-badges-title {
  margin: 0.25rem 0 0.4rem;
  text-align: center;
  color: var(--on-secondary-container);
  font-family: var(--font-headline);
  font-weight: 700;
}

.victory-badges-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 0.5rem;
  width: 100%;
}

.victory-badges-list .badge-tile {
  padding: 0.5rem 0.35rem;
  background: var(--secondary-container);
}

.victory-badges-list .badge-medallion {
  width: clamp(38px, 10vw, 54px);
}

.victory-badges-list .badge-blurb { display: none; }

.victory-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* ─── Best scores (difficulty screen) ────────────────────────── */
.best-scores {
  width: 100%;
  max-width: 420px;
  margin: 0 auto clamp(0.5rem, 1.5vh, 0.9rem);
}

.best-scores-title {
  margin: 0 0 0.35rem;
  color: var(--on-surface-variant);
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.best-scores-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.best-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-md);
  background: var(--surface-container-low);
  font-size: 0.875rem;
}

.best-name {
  min-width: 4.5rem;
  text-align: left;
  font-weight: 600;
  color: var(--on-surface);
}

.best-stars {
  color: #8a5a00;
  letter-spacing: 0.12em;
}

.best-time {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--on-surface-variant);
}

.best-row.is-empty .best-time {
  font-size: 0.78rem;
  opacity: 0.75;
}

/* ─── Monty encouragement bubble ─────────────────────────────── */
.monty-bubble {
  position: absolute;
  left: clamp(0.5rem, 2vw, 1rem);
  bottom: calc(var(--basket-size) * 0.95 + 1.1rem);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: min(62%, 280px);
  padding: 0.35rem 0.75rem 0.35rem 0.35rem;
  border-radius: var(--radius-full);
  background: var(--surface-container-lowest);
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  pointer-events: none;
}

.monty-bubble[hidden] { display: none; }

.monty-bubble.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.monty-bubble-face {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 50%;
  background: var(--surface-container-low);
}

.monty-bubble-text {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--on-surface);
}

body[data-orientation="landscape"] .monty-bubble {
  bottom: 0.75rem;
  left: 0.75rem;
}

/* ─── Badges ─────────────────────────────────────────────────── */
.settings-badges {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--surface-container-high);
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.settings-section-head h3 {
  margin: 0;
  color: var(--primary);
  font-size: 1rem;
}

.badge-count {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--on-primary-container);
  background: var(--primary-container);
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
}

.badges-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 0.5rem;
  width: 100%;
}

.badge-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.55rem 0.4rem;
  border-radius: var(--radius-md);
  background: var(--surface-container-low);
  text-align: center;
  min-width: 0;
}

.badge-medallion {
  width: clamp(42px, 12vw, 58px);
  aspect-ratio: 1;
  display: block;
}

.badge-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.badge-name {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--primary);
  line-height: 1.2;
}

.badge-blurb {
  font-size: 0.68rem;
  line-height: 1.3;
  color: var(--on-surface-variant);
}

.badge-tile.locked .badge-svg {
  filter: grayscale(1);
  opacity: 0.55;
}

.badge-tile.locked .badge-name { color: var(--on-surface-variant); }

/* ─── Badge toast ────────────────────────────────────────────── */
.badge-toast {
  position: fixed;
  left: 50%;
  top: calc(1rem + env(safe-area-inset-top));
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: min(420px, 92vw);
  padding: 0.55rem 0.9rem 0.55rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--surface-container-lowest);
  box-shadow: var(--shadow-modal);
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
  pointer-events: none;
}

.badge-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.badge-toast-icon {
  width: 2.4rem;
  height: 2.4rem;
  flex-shrink: 0;
}

.badge-toast-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--on-surface-variant);
}

.badge-toast-copy strong {
  font-family: var(--font-headline);
  color: var(--primary);
  font-size: 0.9rem;
}

.badge-toast-copy span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-status {
  min-height: 1.2em;
  margin: 0.5rem 0 0;
  text-align: center;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ─── Reset control ──────────────────────────────────────────── */
.btn-reset {
  color: var(--primary);
  font-weight: 600;
  flex-shrink: 0;
}

/* ─── In-app reduced motion ──────────────────────────────────── */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

body.reduce-motion .sparkle { display: none; }

body.reduce-motion .basket.is-hint {
  box-shadow: 0 0 0 7px var(--primary-container), 0 8px 18px rgba(43, 38, 32, 0.16);
}

body.reduce-motion .victory-star.is-earned {
  animation: none;
  opacity: 1;
}

/* ─── Landscape game layout ──────────────────────────────────── */
body[data-orientation="landscape"] .game-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr);
  gap: clamp(0.5rem, 1.5vw, 1.25rem);
}

body[data-orientation="landscape"] .item-slot {
  grid-column: 1;
  grid-row: 1;
}

body[data-orientation="landscape"] .basket-tray {
  grid-column: 2;
  grid-row: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
}

body[data-orientation="landscape"] .rule-banner {
  left: 50%;
}

/* Short viewports: the header and banner give back vertical room. */
@media (max-height: 700px) {
  .game-header-bar {
    padding: 0.35rem 0.6rem;
    margin-bottom: 0.35rem;
  }
  .game-stage { gap: 0.35rem; }
  .basket-tray { padding-bottom: 0.25rem; gap: 0.4rem; }
  .rule-banner { padding: 0.3rem 0.6rem 0.3rem 0.35rem; }
  .rule-banner-monty { width: 1.8rem; height: 1.8rem; }
  .best-scores { margin-bottom: 0.35rem; }
  .best-scores-title { font-size: 0.7rem; margin-bottom: 0.2rem; }
  .best-row { padding: 0.15rem 0.45rem; font-size: 0.78rem; }
  .settings-badges { margin-top: 0.75rem; padding-top: 0.6rem; }
  .badge-tile { padding: 0.4rem 0.3rem; }
}

/* The blanket reduced-motion rule above shortens every animation; these
   remove the two decorative effects that do not have a useful static form. */
@media (prefers-reduced-motion: reduce) {
  .sparkle { display: none; }
  .treasure-item.is-selected,
  .treasure-item.is-returning { transition: none; }
  /* The pulse is an animation, so the blanket rule would erase the only
     persistent hint cue. Keep a static ring for its 1.6s lifetime. */
  .basket.is-hint {
    box-shadow: 0 0 0 7px var(--primary-container), 0 8px 18px rgba(43, 38, 32, 0.16);
  }
  .victory-star.is-earned {
    animation: none;
    opacity: 1;
  }
}

@media (forced-colors: active) {
  .basket,
  .treasure-item {
    border: 2px solid currentColor;
  }
}

/* ─── Victory Screen ─────────────────────────────────────────── */
.victory-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(0.5rem, 2vh, 1rem);
  text-align: center;
  padding: clamp(0.75rem, 2vh, 1.25rem);
  overflow-y: auto;
}

/* ─── Settings Screen ────────────────────────────────────────── */
.settings-content {
  text-align: left;
  background: var(--surface-container-lowest);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  padding: clamp(1.25rem, 3vw, 2rem);
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  margin: 0 auto;
}

.settings-content .screen-title {
  justify-content: flex-start;
  margin-bottom: 1rem;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--surface-container-high);
}
.setting-item:last-of-type { border-bottom: none; }
.setting-item label { font-weight: 500; color: var(--on-surface); }

.setting-text {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.setting-item small {
  display: block;
  color: var(--on-surface-variant);
  font-size: 0.75rem;
  line-height: 1.4;
}

.setting-item input[type="checkbox"] {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.modal-actions { margin-top: 1.5rem; text-align: center; }

.legal-links {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--surface-container-high);
  display: flex;
  gap: 1rem;
  justify-content: center;
  font-size: 0.875rem;
  flex-wrap: wrap;
}
.legal-links a { color: var(--on-surface-variant); text-decoration: none; }
.legal-links a:hover { color: var(--primary); }

/* ─── Footer ─────────────────────────────────────────────────── */
.game-footer {
  margin-top: auto;
  padding: clamp(0.5rem, 1.5vh, 1.25rem) clamp(1rem, 3vw, 2rem);
  background: var(--surface-container-low);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  flex-shrink: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

body[data-screen="game"] .game-footer,
body[data-screen="victory"] .game-footer,
body[data-screen="settings"] .game-footer {
  display: none;
}

.footer-content {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.footer-top {
  display: flex;
  justify-content: center;
  align-items: center;
}
.footer-top[hidden] { display: none; }

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.footer-links a,
.footer-links .btn-link {
  color: var(--on-surface-variant);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.2s;
}

.footer-links a:hover,
.footer-links .btn-link:hover { color: var(--primary); }
.footer-links span { color: var(--outline-variant); user-select: none; }

.footer-copyright p {
  color: var(--on-surface-variant);
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.8;
}
.footer-copyright[hidden] { display: none; }

/* ─── Legal / Support Buttons ────────────────────────────────── */
.btn-support {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius-full);
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-support:hover {
  background: var(--on-primary-container);
  transform: translateY(-2px);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-link:hover { color: var(--primary); }

/* ─── Install Prompt ─────────────────────────────────────────── */
.install-prompt {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-container-lowest);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  z-index: 9999;
  width: min(420px, 92vw);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  animation: slideUp 0.3s ease-out;
}

/* The prompt belongs on the home screen only. */
body:not([data-screen="home"]) .install-prompt { display: none; }

/* An author display rule beats the UA rule behind the hidden attribute. */
.install-prompt[hidden] { display: none; }

.install-steps {
  margin-top: 0.5rem;
  padding: 0.5rem 0.625rem;
  background: var(--surface-container-low);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--on-surface-variant);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.install-steps[hidden] { display: none; }
.install-step { display: flex; align-items: center; gap: 0.4rem; }
.install-step-sep { color: var(--outline-variant); }
.install-step-num {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-full);
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.75rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.install-content h3 {
  color: var(--primary);
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.install-content h3 svg { width: 1.1em; height: 1.1em; }
.install-content p { color: var(--on-surface-variant); font-size: 0.875rem; margin-top: 0.25rem; }

.install-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ─── Offline Banner ─────────────────────────────────────────── */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--on-surface);
  color: var(--surface-container-lowest);
  padding: 0.75rem 1rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.offline-banner:not([hidden]) { display: flex; }
.offline-banner svg { width: 1.25em; height: 1.25em; }

/* Reserve the banner's measured height so it cannot cover the header. */
body.offline-banner-visible { --reserved-top: 4.25rem; }

/* ─── Update Banner ──────────────────────────────────────────── */
.update-banner {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-container);
  color: var(--on-primary-container);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  z-index: 9999;
  width: min(400px, 90vw);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  animation: slideUp 0.3s ease-out;
}
.update-banner[hidden] { display: none; }
.update-banner svg { width: 1.25em; height: 1.25em; flex-shrink: 0; }

.update-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* ─── Accessibility ──────────────────────────────────────────── */
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

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

@media (prefers-contrast: high) {
  :root { --primary: #000; --on-primary: #fff; }
  .basket,
  .treasure-item { border: 3px solid #000; }
  .best-stars { color: #000; }
  .victory-star.is-earned { fill: #000; stroke: #000; }
}

/* High contrast mode overrides */
@media (forced-colors: active) {
  :root {
    --primary: #006400;
    --on-primary: #ffffff;
    --surface: #ffffff;
    --on-surface: #000000;
  }
  .btn-primary,
  .btn-secondary,
  .btn-difficulty,
  .btn-back,
  .btn-support {
    border: 2px solid currentColor;
  }
  .install-steps {
    border: 1px solid currentColor;
  }
}

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Short viewports ────────────────────────────────────────── */
@media (max-height: 700px) {
  .welcome-content { padding: 0.5rem 1rem; }
  .hero-logo { width: 1.75rem; height: 1.75rem; }
  .hero-brand { margin-bottom: 0.35rem; gap: 0.35rem; }
  .hero-title { font-size: clamp(1rem, 4vh, 1.4rem); }
  .mascot-image-wrapper {
    width: clamp(72px, 18vh, 140px);
    height: clamp(72px, 18vh, 140px);
    max-width: 20vh;
    max-height: 20vh;
    margin-bottom: 0.3rem;
  }
  .mascot-area { margin-bottom: 0.25rem; }
  .hero-tagline { display: none; }
  .btn-large { padding: 0.75rem 2rem; }
  .btn-settings { margin-top: 0.4rem; }
  .game-footer { padding: 0.35rem 1rem; }
  .footer-content { gap: 0.35rem; }
  .difficulty-content { padding: 0.75rem 1rem; }
  .difficulty-buttons { gap: 0.5rem; margin-bottom: 0.5rem; }
  .btn-difficulty { padding: 0.55rem 0.9rem; }
  .settings-content { padding: 1rem; }
  .setting-item { padding: 0.5rem 0; }
  .modal-actions { margin-top: 0.75rem; }
  .legal-links { margin-top: 0.75rem; font-size: 0.8rem; }
  .victory-content { padding: 0.5rem; gap: 0.5rem; }
}

/* Mid-height desktops: the full 35vh mascot plus footer is a few pixels
   taller than the container, which leaves a stray scrollbar on the home
   screen. Trim the mascot instead of letting the page scroll. */
@media (min-height: 701px) and (max-height: 900px) {
  .mascot-image-wrapper {
    width: clamp(130px, 28vh, 240px);
    height: clamp(130px, 28vh, 240px);
    max-width: 28vh;
    max-height: 28vh;
  }
  .hero-brand { margin-bottom: 0.5rem; }
  .hero-tagline { margin-bottom: 0.5rem; }
}

/* ─── Landscape welcome layout ───────────────────────────────── */
/* Short landscape phones only. A desktop window is also landscape, but it has
   the height for the centred stack and reads better that way. */
@media (orientation: landscape) and (max-height: 600px) {
  .welcome-content {
    display: grid;
    grid-template-columns: minmax(110px, 220px) 1fr;
    grid-template-rows: auto 1fr;
    gap: 0.4rem 1rem;
    align-items: center;
    justify-items: center;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
  }
  .hero-brand { grid-column: 1 / -1; margin-bottom: 0.25rem; }
  .mascot-area { grid-column: 1; grid-row: 2; margin-bottom: 0; }
  .hero-actions { grid-column: 2; grid-row: 2; }
  .mascot-image-wrapper {
    width: clamp(70px, 16vh, 150px);
    height: clamp(70px, 16vh, 150px);
    max-width: 18vh;
    max-height: 18vh;
  }
  .hero-tagline { margin-bottom: 0.35rem; display: block; }
  .btn-settings { margin-top: 0.4rem; }
}

@media (max-height: 480px) {
  body[data-screen="home"] #game-container,
  body[data-screen="difficulty"] #game-container {
    overflow-y: auto;
  }
  /* Keep the legal links reachable without letting the footer crowd the
     buttons out of a 375px-tall landscape viewport. */
  .footer-copyright { display: none; }
  .game-footer { padding: 0.3rem 1rem; }
  .footer-content { gap: 0.2rem; }
  .btn-support { min-height: 44px; padding: 0.4rem 1rem; }
}
