/* Bark & Baa — UI styles. Sunny, chunky, rounded, with bold navy outlines and bouncy transitions.
   Sizing: everything is in rem; the root font size scales with the viewport (960×600 … 4K). */

:root {
  --navy: #1d2b53;
  --navy-2: #2c3d6e;
  --navy-a: rgba(29, 43, 83, 0.55);
  --sun: #ffcc33;
  --sun-2: #ffb020;
  --sun-3: #ff9a1f;
  --sun-light: #ffe483;
  --grass: #6cc24a;
  --grass-2: #3f9a36;
  --grass-light: #a6e05a;
  --sky: #5ec3f2;
  --sky-2: #2f8fd6;
  --sky-light: #bfe9ff;
  --cream: #fffaf0;
  --paper: #fff7e6;
  --red: #ff5a4a;
  --red-2: #d93a2c;
  --pink: #ff6fa8;
  --purple: #9b6bff;
  --good: #5fd35f;
  --shadow: 0 0.45rem 0 rgba(29, 43, 83, 0.35);
  --font: 'Fredoka', 'Baloo 2', 'Nunito', ui-rounded, 'SF Pro Rounded', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --r-card: 1.6rem;
  --bw: 0.22rem; /* standard navy border width */
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  font-size: clamp(13px, calc(0.5vw + 0.9vh), 40px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #8fd3f5; color: var(--navy);
  font-family: var(--font); font-weight: 500;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; }
svg { display: block; }

/* Outlined display text: thick navy stroke painted under the fill + a chunky drop shadow. */
.ol {
  -webkit-text-stroke: calc(var(--ow, 0.16em)) var(--oc, var(--navy));
  paint-order: stroke fill;
  text-shadow: 0 var(--od, 0.09em) 0 var(--oc, var(--navy));
}

#stage { position: fixed; inset: 0; z-index: 0; transition: opacity 0.35s ease, filter 0.35s ease; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; }
#stage.is-dim { opacity: 0; }
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

/* ------------------------------------------------------------------ boot / loading */
.boot {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #d8f3ff 0%, #8fd3f5 45%, #5ec3f2 100%);
  transition: opacity 0.5s ease, visibility 0.5s;
}
.boot::after { /* rolling hill */
  content: ''; position: absolute; left: -10%; right: -10%; bottom: -35vh; height: 60vh; border-radius: 50%;
  background: linear-gradient(#8ad65a, #5fb843); box-shadow: 0 -0.4rem 0 #a6e05a inset;
}
.boot.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-card { position: relative; z-index: 1; text-align: center; padding: 2rem 3rem; }
.boot-sheep { width: 7rem; height: auto; margin: 0 auto 0.6rem; animation: bootHop 0.7s var(--ease-out) infinite alternate; }
.boot-title {
  font-size: 4rem; font-weight: 700; color: var(--sun); letter-spacing: 0.02em;
  -webkit-text-stroke: 0.55rem var(--navy); paint-order: stroke fill; text-shadow: 0 0.4rem 0 var(--navy);
}
.boot-title span { color: var(--pink); }
.boot-msg { margin-top: 0.8rem; font-size: 1.25rem; font-weight: 600; color: var(--navy); }
.boot-msg small { font-weight: 500; opacity: 0.8; }
.boot-msg .btn { margin-top: 1rem; }
.boot-bar { width: 16rem; height: 0.9rem; margin: 1rem auto 0; border: var(--bw) solid var(--navy); border-radius: 1rem; background: #fff; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 5%; background: repeating-linear-gradient(-45deg, var(--sun) 0 0.5rem, var(--sun-2) 0.5rem 1rem); transition: width 0.3s ease; }
.boot-error .boot-bar { display: none; }
.boot-error .boot-sheep { animation: none; transform: rotate(-12deg); }
.boot-noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; background: #8fd3f5; z-index: 200; }
@keyframes bootHop { from { transform: translateY(0) scale(1.04, 0.96); } to { transform: translateY(-0.9rem) scale(0.97, 1.03); } }

/* ------------------------------------------------------------------ generic screen */
.scr {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center;
  pointer-events: none;
}
.scr.is-on { display: flex; animation: scrIn 0.45s var(--ease-out) both; }
.scr > * { pointer-events: auto; }
.scr-dim { background: radial-gradient(ellipse at 50% 45%, rgba(20, 40, 90, 0.08) 0%, rgba(20, 40, 90, 0.52) 100%); }
@keyframes scrIn { from { opacity: 0; } to { opacity: 1; } }

.scr-heading {
  margin: 4.5vh 0 0; font-size: 3rem; font-weight: 700; color: #fff; letter-spacing: 0.01em;
  --ow: 0.14em; --od: 0.1em; animation: dropIn 0.6s var(--ease-back) both;
}
.scr-heading small { display: block; font-size: 0.42em; color: var(--sun-light); margin-top: 0.2em; --ow: 0.2em; }

.hint-bar {
  display: flex; gap: 1.2rem; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 0.5rem 1.2rem; border-radius: 99rem; background: rgba(29, 43, 83, 0.72); color: #fff;
  font-size: 1rem; font-weight: 500;
}
.hint-bar span { white-space: nowrap; }
kbd {
  display: inline-block; min-width: 1.7em; padding: 0.05em 0.45em; margin: 0 0.12em; border-radius: 0.45em;
  background: #fff; color: var(--navy); border: 0.12rem solid var(--navy); box-shadow: 0 0.16rem 0 var(--navy);
  font-family: inherit; font-weight: 700; font-size: 0.9em; text-align: center; line-height: 1.35; text-shadow: none;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  padding: 0.55em 1.5em; min-width: 9em; border: var(--bw) solid var(--navy); border-radius: 99rem;
  background: linear-gradient(#ffe066, var(--sun) 55%, var(--sun-2));
  color: var(--navy); font-size: 1.35rem; font-weight: 700; letter-spacing: 0.01em; cursor: pointer;
  box-shadow: 0 0.38rem 0 var(--navy), inset 0 0.22rem 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.14s var(--ease-back), box-shadow 0.14s ease, filter 0.14s ease;
  outline: none;
}
.btn svg { width: 1.2em; height: 1.2em; }
.btn:hover { filter: brightness(1.05); }
.btn:active, .btn.is-press { transform: translateY(0.3rem) scale(0.98); box-shadow: 0 0.08rem 0 var(--navy), inset 0 0.22rem 0 rgba(255, 255, 255, 0.55); }
.btn.is-sel {
  transform: scale(1.07);
  box-shadow: 0 0.38rem 0 var(--navy), 0 0 0 0.35rem #fff, 0 0 0 0.6rem var(--navy), inset 0 0.22rem 0 rgba(255, 255, 255, 0.55);
  animation: selBob 1.1s ease-in-out infinite;
}
.btn.is-sel:active, .btn.is-sel.is-press { transform: translateY(0.3rem) scale(1.02); animation: none; }
.btn-green { background: linear-gradient(#9be86b, var(--grass) 55%, var(--grass-2)); color: #fff; }
.btn-green, .btn-blue, .btn-red { text-shadow: 0 0.12rem 0 rgba(29, 43, 83, 0.6); }
.btn-blue { background: linear-gradient(#8fdcff, var(--sky) 55%, var(--sky-2)); color: #fff; }
.btn-red { background: linear-gradient(#ff8f7d, var(--red) 55%, var(--red-2)); color: #fff; }
.btn-white { background: linear-gradient(#fff, #f2f6ff); }
.btn-big { font-size: 2rem; padding: 0.5em 1.6em; }
.btn-small { font-size: 1rem; min-width: 0; padding: 0.4em 1.1em; }
@keyframes selBob { 0%, 100% { transform: scale(1.07) translateY(0); } 50% { transform: scale(1.07) translateY(-0.18rem); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 3.2rem; height: 3.2rem; padding: 0;
  border: var(--bw) solid var(--navy); border-radius: 50%; background: #fff; color: var(--navy); cursor: pointer;
  box-shadow: 0 0.3rem 0 var(--navy); transition: transform 0.14s var(--ease-back), box-shadow 0.14s ease; outline: none;
}
.icon-btn svg { width: 58%; height: 58%; }
.icon-btn:hover { transform: scale(1.08); }
.icon-btn:active { transform: translateY(0.25rem); box-shadow: 0 0.05rem 0 var(--navy); }

.card {
  background: var(--cream); border: var(--bw) solid var(--navy); border-radius: var(--r-card);
  box-shadow: 0 0.55rem 0 var(--navy), 0 1.4rem 2.4rem rgba(20, 30, 70, 0.3);
}

/* ------------------------------------------------------------------ title */
.scr-title { justify-content: space-between; padding: 5vh 1rem 5.5vh; background: linear-gradient(rgba(255, 255, 255, 0.05), rgba(20, 50, 100, 0) 40%, rgba(20, 40, 90, 0.25)); }
.logo { position: relative; display: flex; flex-direction: column; align-items: center; line-height: 0.86; margin-top: 1vh; }
.logo-row { display: flex; align-items: flex-end; font-size: 7.6rem; font-weight: 700; letter-spacing: 0.01em; }
.logo-row span {
  display: inline-block; --ow: 0.13em; --od: 0.075em;
  -webkit-text-stroke: var(--ow) var(--navy); paint-order: stroke fill;
  text-shadow: 0 0.075em 0 var(--navy), 0 0.13em 0 rgba(20, 30, 70, 0.22);
  animation: logoDrop 0.8s var(--ease-back) both, letterBob 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.07s), calc(0.9s + var(--i) * 0.13s);
}
.logo-row .w1 { color: var(--sun); }
.logo-row .w2 { color: #fff; }
.logo-row .amp { color: var(--pink); font-size: 0.62em; margin: 0 0.18em 0.12em; transform-origin: 50% 80%; }
.logo-row .amp { animation: logoDrop 0.8s var(--ease-back) both, ampWiggle 2.2s ease-in-out infinite; animation-delay: 0.35s, 1s; }
.logo-deco { position: absolute; width: 6.2rem; height: auto; }
.logo-deco.sheep { right: -5.4rem; bottom: -0.6rem; animation: decoHop 1.6s ease-in-out infinite; }
.logo-deco.paw { left: -4.6rem; top: 0.8rem; width: 3.6rem; transform: rotate(-18deg); animation: pawTap 2.4s ease-in-out infinite; }
.tagline {
  margin-top: 1.2rem; padding: 0.35rem 1.4rem; border-radius: 99rem; background: var(--navy); color: #fff;
  font-size: 1.35rem; font-weight: 600; letter-spacing: 0.04em; box-shadow: 0 0.3rem 0 rgba(0, 0, 0, 0.2);
  animation: dropIn 0.7s var(--ease-back) 0.7s both;
}
.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 1.3rem; }
.title-bottom .btn-big { animation: pulseBtn 1.3s ease-in-out infinite, dropIn 0.7s var(--ease-back) 1s both; }
.title-bottom .btn-big.is-sel { animation: pulseBtn 1.3s ease-in-out infinite, dropIn 0.7s var(--ease-back) 1s both; }
.title-meta { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; justify-content: center; }
.title-meta .btn-small { box-shadow: 0 0.26rem 0 var(--navy), inset 0 0.22rem 0 rgba(255, 255, 255, 0.55); }
.title-meta .btn-small kbd { font-size: 0.8em; }
/* 'How to play' overlay on the title (click / Esc / Enter / H closes it) */
.howto {
  position: absolute; inset: 0; z-index: 4; display: none; align-items: center; justify-content: center; padding: 1rem;
  background: rgba(20, 35, 80, 0.5); cursor: pointer;
}
.howto.is-on { display: flex; animation: scrIn 0.25s ease both; }
.howto-card { width: min(31rem, 94vw); max-height: calc(100vh - 2rem); overflow-y: auto; padding: 1.2rem 1.8rem 1.3rem; animation: riseIn 0.4s var(--ease-back) both; }
.howto-card h3 { margin: 0 0 0.35rem; text-align: center; font-size: 2.3rem; color: var(--sun); --ow: 0.14em; --od: 0.08em; }
.howto-goal { margin: 0 0 0.9rem; text-align: center; font-size: 1.1rem; font-weight: 600; line-height: 1.3; color: var(--navy-2); text-wrap: balance; }
.howto-foot { margin-top: 0.9rem; text-align: center; font-size: 0.95rem; opacity: 0.75; }
.title-corner { position: absolute; top: 1.3rem; right: 1.3rem; display: flex; gap: 0.7rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.4em; padding: 0.3em 0.9em; border-radius: 99rem;
  background: rgba(255, 255, 255, 0.92); border: 0.16rem solid var(--navy); font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 0.2rem 0 var(--navy);
}
.chip svg { width: 1.25em; height: 1.25em; }
.chip svg.ic-sheep { width: 1.7em; height: auto; }
@keyframes logoDrop { 0% { transform: translateY(-120%) scale(0.6); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; opacity: 1; } }
@keyframes letterBob { 0%, 100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-0.07em) rotate(-2deg); } 50% { transform: translateY(0) rotate(0); } 75% { transform: translateY(0.02em) rotate(1.5deg); } }
@keyframes ampWiggle { 0%, 100% { transform: rotate(-8deg) scale(1); } 50% { transform: rotate(10deg) scale(1.12); } }
@keyframes decoHop { 0%, 100% { transform: translateY(0) rotate(0); } 30% { transform: translateY(-1rem) rotate(-6deg); } 55% { transform: translateY(0) rotate(2deg); } }
@keyframes pawTap { 0%, 100% { transform: rotate(-18deg) translateY(0); } 45% { transform: rotate(-26deg) translateY(-0.3rem); } }
@keyframes pulseBtn { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes dropIn { from { transform: translateY(-1.8rem) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes riseIn { from { transform: translateY(2.2rem) scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------------ breed select */
.scr-breeds { justify-content: space-between; padding-bottom: 3vh; }
.breed-row { display: flex; align-items: center; gap: 1.2rem; }
.breed-main { /* 100vw − 11rem leaves room for the two arrow buttons and the row gaps */
  display: flex; align-items: stretch; gap: 1.6rem; width: min(calc(100vw - 11rem), 58rem); padding: 1.3rem 1.8rem 1.3rem 1.3rem;
  animation: riseIn 0.55s var(--ease-back) 0.05s both;
}
.breed-stage {
  position: relative; flex: 0 0 auto; width: 19rem; height: 19rem; border-radius: 1.2rem; overflow: hidden;
  border: var(--bw) solid var(--navy);
  background: radial-gradient(circle at 50% 38%, #e9f8ff 0%, #bfe9ff 45%, #7fcdf2 100%);
}
.breed-stage::before { /* hill behind the dog */
  content: ''; position: absolute; left: -20%; right: -20%; bottom: -46%; height: 80%; border-radius: 50%;
  background: linear-gradient(#9be06a, #62b845);
}
.breed-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.breed-stage .breed-tag {
  position: absolute; left: 0.7rem; top: 0.7rem; padding: 0.2rem 0.8rem; border-radius: 99rem; background: var(--c, var(--red));
  color: #fff; font-weight: 700; font-size: 0.95rem; border: 0.16rem solid var(--navy); z-index: 2;
}
.breed-info { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.breed-title-pill {
  align-self: flex-start; padding: 0.15rem 0.9rem; border-radius: 99rem; background: var(--c, var(--red)); color: #fff;
  font-weight: 700; font-size: 1.05rem; letter-spacing: 0.05em; text-transform: uppercase; border: 0.16rem solid var(--navy);
}
.breed-name { margin-top: 0.35rem; font-size: 2.4rem; font-weight: 700; color: #fff; line-height: 1.05; --ow: 0.13em; --od: 0.08em; }
.breed-blurb { margin: 0.5rem 0 0; font-size: 1.12rem; line-height: 1.35; color: var(--navy-2); }
.breed-trait {
  display: flex; align-items: center; gap: 0.5rem; margin-top: 0.7rem; padding: 0.45rem 0.8rem; border-radius: 0.9rem;
  background: #fff; border: 0.16rem dashed var(--c, var(--red)); font-weight: 600; font-size: 1.02rem;
}
.breed-trait svg { flex: 0 0 auto; width: 1.4rem; height: 1.4rem; color: var(--c, var(--red)); }
.stats { margin-top: auto; padding-top: 0.8rem; display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.9rem; align-items: center; }
.stat-label { font-weight: 700; font-size: 1.02rem; }
.stat-pips { display: flex; gap: 0.3rem; }
.stat-pips i {
  flex: 1 1 0; height: 0.95rem; border-radius: 0.5rem; background: #e4e0d6; border: 0.14rem solid var(--navy);
  transition: background-color 0.25s ease, transform 0.25s var(--ease-back);
}
.stat-pips i.on { background: var(--c, var(--red)); transform: scaleY(1.12); }
.breed-arrow { width: 3.8rem; height: 3.8rem; }
.breed-arrow svg { width: 55%; height: 55%; }
.breed-chips { display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; }
.breed-chip {
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem; width: 8.2rem; padding: 0.5rem 0.4rem 0.55rem;
  border: var(--bw) solid var(--navy); border-radius: 1.2rem; background: #fff; cursor: pointer; color: var(--navy);
  box-shadow: 0 0.3rem 0 var(--navy); transition: transform 0.18s var(--ease-back), background-color 0.18s ease; outline: none;
  font-size: 0.95rem; font-weight: 700;
}
.breed-chip svg { width: 3.1rem; height: 3.1rem; }
.breed-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.breed-chip:hover { transform: translateY(-0.2rem); }
.breed-chip.is-sel { background: var(--c); color: #fff; transform: translateY(-0.45rem) scale(1.06); box-shadow: 0 0.3rem 0 var(--navy), 0 0 0 0.3rem #fff, 0 0 0 0.52rem var(--navy); }
.breed-chip.is-sel span { text-shadow: 0 0.1rem 0 var(--navy); }

/* ------------------------------------------------------------------ level select */
.scr-levels { justify-content: space-between; padding-bottom: 3vh; }
.level-grid { display: grid; grid-template-columns: repeat(5, 11.2rem); gap: 1.1rem; animation: riseIn 0.55s var(--ease-back) both; }
.lvl-card {
  position: relative; display: flex; flex-direction: column; align-items: stretch; height: 11rem; padding: 0; overflow: hidden;
  border: var(--bw) solid var(--navy); border-radius: 1.3rem; background: #fff; color: var(--navy); cursor: pointer; text-align: left;
  box-shadow: 0 0.35rem 0 var(--navy); transition: transform 0.18s var(--ease-back), box-shadow 0.18s ease; outline: none;
  animation: riseIn 0.5s var(--ease-back) both; animation-delay: calc(var(--i) * 0.035s);
}
.lvl-card:hover { transform: translateY(-0.2rem); }
.lvl-card.is-sel { transform: translateY(-0.4rem) scale(1.06); box-shadow: 0 0.35rem 0 var(--navy), 0 0 0 0.3rem #fff, 0 0 0 0.55rem var(--navy); z-index: 2; }
.lvl-sky { position: relative; height: 4.6rem; background: var(--tod, linear-gradient(#bfe9ff, #7fcdf2)); overflow: hidden; }
.lvl-sky::before { content: ''; position: absolute; left: -15%; right: 25%; bottom: -2.2rem; height: 3.6rem; border-radius: 50%; background: #8ed35a; }
.lvl-sky::after { content: ''; position: absolute; left: 35%; right: -20%; bottom: -2.4rem; height: 3.8rem; border-radius: 50%; background: #69bf47; }
.lvl-mtn { position: absolute; left: 20%; bottom: 0.9rem; width: 0; height: 0; border-left: 2.4rem solid transparent; border-right: 2.4rem solid transparent; border-bottom: 2.6rem solid rgba(110, 130, 180, 0.75); }
.lvl-mtn::after { content: ''; position: absolute; left: -0.8rem; top: 0; border-left: 0.8rem solid transparent; border-right: 0.8rem solid transparent; border-bottom: 0.85rem solid #fff; }
.lvl-num {
  position: absolute; left: 0.55rem; top: 0.45rem; z-index: 2; font-size: 2.1rem; font-weight: 700; color: #fff; line-height: 1;
  --ow: 0.16em; --od: 0.08em;
}
.lvl-tag {
  position: absolute; right: 0.5rem; top: 0.5rem; z-index: 2; padding: 0.1rem 0.5rem; border-radius: 99rem; background: var(--red);
  color: #fff; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; border: 0.14rem solid var(--navy);
}
.lvl-body { flex: 1 1 auto; display: flex; flex-direction: column; padding: 0.35rem 0.7rem 0.5rem; }
/* names wrap to (at most) two lines instead of ellipsizing when Fredoka is unavailable and a fallback font is wider */
.lvl-name {
  font-size: 1.12rem; font-weight: 700; line-height: 1.05; white-space: normal; min-height: 2.1em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.lvl-stars { display: flex; gap: 0.15rem; margin-top: 0.3rem; }
.lvl-stars svg { width: 1.45rem; height: 1.45rem; }
.lvl-best { margin-top: auto; font-size: 0.85rem; font-weight: 600; color: var(--navy-2); opacity: 0.85; }
.lvl-card.is-locked { background: #d9dde8; cursor: default; }
.lvl-card.is-locked .lvl-sky { filter: grayscale(0.85) brightness(0.8); }
.lvl-card.is-locked .lvl-body { opacity: 0.55; }
.lvl-lock {
  position: absolute; left: 0; right: 0; top: 0; height: 4.6rem; display: none; align-items: center; justify-content: center; z-index: 3;
}
.lvl-lock svg { width: 3.4rem; height: 3.4rem; filter: drop-shadow(0 0.25rem 0 rgba(29, 43, 83, 0.4)); }
.lvl-card.is-locked .lvl-lock { display: flex; }
.lvl-card.is-shake { animation: shake 0.4s ease; }
.levels-foot { display: flex; flex-direction: column; gap: 0.8rem; align-items: center; }
.levels-info { display: flex; gap: 0.8rem; align-items: center; }
.levels-info .chip { cursor: pointer; }
.dog-dot { width: 1.1em; height: 1.1em; border-radius: 50%; background: var(--c); border: 0.14rem solid var(--navy); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-0.5rem) rotate(-2deg); } 40% { transform: translateX(0.5rem) rotate(2deg); } 60% { transform: translateX(-0.35rem); } 80% { transform: translateX(0.25rem); } }

/* ------------------------------------------------------------------ intro */
.scr-intro { align-items: flex-start; justify-content: center; padding-left: 3vw; background: linear-gradient(90deg, rgba(20, 40, 90, 0.45), rgba(20, 40, 90, 0) 55%); }
.intro-card { width: min(34rem, 44vw); padding: 1.5rem 1.7rem 1.6rem; animation: slideInL 0.6s var(--ease-back) both; }
.intro-lvl {
  display: inline-block; padding: 0.15rem 0.9rem; border-radius: 99rem; background: var(--sky-2); color: #fff; font-weight: 700;
  font-size: 1.05rem; letter-spacing: 0.08em; text-transform: uppercase; border: 0.16rem solid var(--navy);
}
.intro-name { margin-top: 0.4rem; font-size: 2.9rem; font-weight: 700; color: var(--sun); line-height: 1.05; --ow: 0.13em; --od: 0.08em; }
.intro-obj { margin: 0.6rem 0 0; font-size: 1.28rem; font-weight: 600; line-height: 1.3; }
.intro-facts { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.9rem; }
.intro-facts .chip { background: #fff; font-size: 1.1rem; }
.intro-tips { list-style: none; margin: 0.9rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.intro-tips li { display: flex; gap: 0.55rem; align-items: flex-start; font-size: 1.1rem; line-height: 1.3; color: var(--navy-2); }
.intro-tips li svg { flex: 0 0 auto; width: 1.3rem; height: 1.3rem; margin-top: 0.08rem; color: var(--sun-3); }
.intro-go { margin-top: 1.2rem; display: flex; align-items: center; gap: 1rem; }
.intro-go .btn { animation: pulseBtn 1.3s ease-in-out infinite; }
.intro-skip { font-size: 0.95rem; opacity: 0.7; }
@keyframes slideInL { from { transform: translateX(-120%) rotate(-4deg); } to { transform: none; } }

/* ------------------------------------------------------------------ HUD */
.hud { position: absolute; inset: 0; display: none; pointer-events: none; }
.hud.is-on { display: block; animation: scrIn 0.4s ease both; }
.hud .pill {
  display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.35rem 1rem 0.35rem 0.6rem; border-radius: 99rem;
  background: rgba(255, 255, 255, 0.93); border: var(--bw) solid var(--navy); box-shadow: 0 0.3rem 0 rgba(29, 43, 83, 0.55);
  font-weight: 700; font-size: 1.5rem; line-height: 1; color: var(--navy);
}
.hud-tl { position: absolute; left: 1.2rem; top: 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start; }
.sheep-pill svg.ic-sheep { width: 2.5rem; height: auto; margin: -0.2rem 0; }
.sheep-pill .n-pen { font-size: 1.9rem; min-width: 1.2ch; text-align: right; display: inline-block; }
.sheep-pill .n-sep { opacity: 0.45; }
.sheep-pill .n-req { color: var(--grass-2); }
.sheep-pill .n-tot { font-size: 1.05rem; opacity: 0.6; font-weight: 600; }
.sheep-pill.is-met .n-pen { color: var(--grass-2); }
.lost-pill { font-size: 1.15rem !important; color: var(--red-2) !important; padding: 0.25rem 0.8rem 0.25rem 0.5rem !important; }
.lost-pill svg { width: 1.7rem; height: auto; }
.lost-pill.is-zero { display: none !important; }
.pop { animation: pop 0.45s var(--ease-back); }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.35); } 100% { transform: scale(1); } }
.pop-red { animation: popRed 0.6s ease; }
@keyframes popRed { 0% { transform: scale(1); background: #fff; } 30% { transform: scale(1.3) rotate(-4deg); background: #ffd2cc; } 100% { transform: scale(1); } }

.hud-tc { position: absolute; left: 50%; top: 1.1rem; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.timer { font-variant-numeric: tabular-nums; font-size: 1.8rem !important; padding-right: 1.15rem !important; }
.timer svg { width: 1.7rem; height: 1.7rem; }
.timer.is-low { background: var(--red) !important; color: #fff !important; animation: timerPulse 1s ease-in-out infinite; }
.timer.is-low svg { color: #fff; --clock-face: var(--red-2); }
@keyframes timerPulse { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.14); } 40% { transform: scale(1); } }

.boss-bar {
  display: none; flex-direction: column; align-items: center; gap: 0.25rem; padding: 0.4rem 1rem 0.5rem; border-radius: 1rem;
  background: rgba(29, 43, 83, 0.82); border: var(--bw) solid var(--navy); box-shadow: 0 0.3rem 0 rgba(0, 0, 0, 0.25);
}
.boss-bar.is-on { display: flex; animation: dropIn 0.5s var(--ease-back) both; }
.boss-name { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: 0.06em; text-transform: uppercase; }
.boss-name b { color: var(--red); margin-right: 0.35em; }
.boss-hearts { display: flex; gap: 0.2rem; }
.boss-hearts svg { width: 1.5rem; height: 1.5rem; transition: transform 0.25s var(--ease-back), opacity 0.25s ease; }
.boss-hearts svg.off { opacity: 0.3; transform: scale(0.75); }
.boss-hearts svg.hit { animation: pop 0.45s var(--ease-back); }

.hud-tr { position: absolute; right: 1.2rem; top: 1.1rem; display: flex; gap: 0.6rem; align-items: flex-start; }
.badge {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.9rem 0.45rem 0.45rem; border-radius: 99rem;
  background: rgba(255, 255, 255, 0.93); border: var(--bw) solid var(--navy); box-shadow: 0 0.3rem 0 rgba(29, 43, 83, 0.55);
}
.badge-icon {
  position: relative; width: 3.3rem; height: 3.3rem; border-radius: 50%; background: var(--c); border: var(--bw) solid var(--navy);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.badge-icon svg { width: 82%; height: 82%; position: relative; z-index: 1; }
.badge-icon .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(29, 43, 83, 0.45); z-index: 2; }
.badge.is-ready .badge-icon { animation: readyFlash 0.5s ease; }
@keyframes readyFlash { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 1); transform: scale(1); } 40% { box-shadow: 0 0 0 0.6rem rgba(255, 204, 51, 0.7); transform: scale(1.14); } 100% { box-shadow: 0 0 0 1rem rgba(255, 204, 51, 0); transform: scale(1); } }
.badge-meters { display: flex; flex-direction: column; gap: 0.25rem; width: 10.5rem; }
.mrow { display: flex; align-items: center; gap: 0.4rem; }
.mrow > span { flex: 0 0 2.4rem; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; opacity: 0.9; } /* ≥ 10.4 px at the 13 px root */
.mrow .meter { flex: 1 1 auto; }
.badge-name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { position: relative; height: 0.8rem; border-radius: 0.6rem; background: #e4e0d6; border: 0.14rem solid var(--navy); overflow: hidden; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; border-radius: 0.4rem; transform-origin: 0 50%; }
.meter.bark i { background: var(--c); }
.meter.bark.is-ready i { background: linear-gradient(90deg, var(--c) 0 42%, rgba(255, 255, 255, 0.9) 50%, var(--c) 58% 100%) var(--c); background-size: 250% 100%; animation: shimmer 1.6s linear infinite; }
/* stamina: a fixed gold no breed colour uses, plus three navy segment ticks, so RUN never looks like the BARK bar
   (the Old English Sheepdog's bark bar is green, the Huntaway's orange) */
.meter.stam i { background: linear-gradient(90deg, #ffe066, #ffcc33); }
.meter.stam::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; /* on the track, so the ticks stay put while the fill scales */
  background: linear-gradient(90deg,
    transparent calc(25% - 0.06rem), var(--navy) 0 calc(25% + 0.06rem),
    transparent 0 calc(50% - 0.06rem), var(--navy) 0 calc(50% + 0.06rem),
    transparent 0 calc(75% - 0.06rem), var(--navy) 0 calc(75% + 0.06rem), transparent 0);
}
.meter.stam.is-low i { background: var(--red); }
.meter-label { display: flex; justify-content: space-between; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; opacity: 0.7; margin-bottom: -0.15rem; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.hud-btn { width: 2.9rem; height: 2.9rem; pointer-events: auto; }

.banners { position: absolute; left: 0; right: 0; top: max(18vh, 9.6rem); display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.banner {
  padding: 0.35rem 1.6rem 0.45rem; border-radius: 1.2rem; font-size: 1.9rem; font-weight: 700; color: #fff; text-align: center;
  background: var(--sky-2); border: var(--bw) solid var(--navy); box-shadow: 0 0.4rem 0 var(--navy);
  text-shadow: 0 0.14rem 0 var(--navy); animation: bannerIn 0.5s var(--ease-back) both; max-width: 80vw;
}
.banner.b-danger { background: var(--red); }
.banner.b-boss { background: linear-gradient(#ff6a55, #c92a3a); font-size: 2.3rem; padding: 0.5rem 2rem; }
.banner.b-good { background: var(--grass); }
.banner.b-gold { background: linear-gradient(#ffd84d, var(--sun-2)); color: var(--navy); text-shadow: 0 0.12rem 0 rgba(255, 255, 255, 0.6); }
.banner.b-small { font-size: 1.3rem; padding: 0.25rem 1.1rem 0.3rem; }
.banner.b-go {
  background: none; border: none; box-shadow: none; font-size: 7rem; color: var(--sun); padding: 0;
  -webkit-text-stroke: 0.17em var(--navy); paint-order: stroke fill; text-shadow: 0 0.1em 0 var(--navy);
  animation: goIn 1s var(--ease-back) both;
}
.banner.is-out { animation: bannerOut 0.35s ease forwards; }
@keyframes bannerIn { from { transform: translateY(-1.5rem) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bannerOut { to { transform: translateY(-0.8rem) scale(0.9); opacity: 0; } }
@keyframes goIn { 0% { transform: scale(0.2) rotate(-12deg); opacity: 0; } 55% { transform: scale(1.15) rotate(3deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

/* max-width: 40vw, but never reaching the bottom-centre hints (gate hint ~23.4rem wide, L1 pause pill) on screens ≤ 1024 px */
.toasts { position: absolute; left: 1.2rem; bottom: 1.2rem; display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; max-width: min(40vw, calc(50vw - 13.5rem)); z-index: 2; }
.toast { display: flex; align-items: flex-end; gap: 0.5rem; animation: toastIn 0.45s var(--ease-back) both; }
.toast-face { flex: 0 0 auto; width: 3.4rem; height: 3.4rem; border-radius: 50%; background: #ffe0b8; border: var(--bw) solid var(--navy); overflow: hidden; }
.toast-face svg { width: 100%; height: 100%; }
.toast-bubble {
  position: relative; padding: 0.5rem 0.95rem; border-radius: 1rem; background: #fff; border: var(--bw) solid var(--navy);
  font-weight: 600; font-size: 1.1rem; line-height: 1.25; box-shadow: 0 0.25rem 0 rgba(29, 43, 83, 0.5); margin-bottom: 0.9rem;
}
.toast-bubble::before { content: ''; position: absolute; left: -0.62rem; bottom: 0.45rem; width: 0.9rem; height: 0.9rem; background: #fff; border-left: var(--bw) solid var(--navy); border-bottom: var(--bw) solid var(--navy); transform: rotate(45deg); }
.toast-bubble b { display: block; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--grass-2); }
.toast.is-out { animation: bannerOut 0.35s ease forwards; }
@keyframes toastIn { from { transform: translateX(-2rem) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }

.gate-hint {
  position: absolute; left: 50%; bottom: 1.4rem; transform: translateX(-50%); display: none !important;
  font-size: 1.3rem !important; background: linear-gradient(#ffe066, var(--sun)) !important; padding: 0.45rem 1.2rem !important;
}
.gate-hint.is-on { display: inline-flex !important; animation: hintBob 1.2s ease-in-out infinite; }
.gate-hint { white-space: nowrap; }
.gate-hint svg { width: 1.5em; height: 1.5em; flex: 0 0 auto; }
.gate-hint kbd { font-size: 0.85em; }
@keyframes hintBob { 0%, 100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-0.3rem); } }

/* level 1: 'Esc: pause & controls' for the first seconds (ui.js hudUpdate) */
.pause-hint {
  position: absolute; left: 50%; bottom: 1.4rem; transform: translateX(-50%); white-space: nowrap;
  font-size: 1.05rem !important; padding: 0.3rem 0.95rem !important; gap: 0.3rem !important;
  opacity: 0; visibility: hidden; transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}
.pause-hint.is-on { opacity: 1; visibility: visible; transition: opacity 0.4s ease; }
.pause-hint kbd { font-size: 0.85em; }

.arrows { position: absolute; inset: 0; overflow: hidden; z-index: 3; } /* above the minimap / toasts if an arrow touches them */
.t-arrow { position: absolute; left: 0; top: 0; width: 3.2rem; height: 3.2rem; margin: -1.6rem 0 0 -1.6rem; display: none; will-change: transform; }
.t-arrow.is-on { display: block; }
.t-arrow .t-rot { width: 100%; height: 100%; }
.t-arrow svg { width: 100%; height: 100%; animation: arrowPulse 0.8s ease-in-out infinite; }
.t-arrow.is-boss svg { animation-duration: 0.5s; }
/* gold "home" pointer to the pen: 0.8 × the threat arrow, a calmer pulse, an upright star on the badge */
.t-arrow.is-pen { width: 2.56rem; height: 2.56rem; margin: -1.28rem 0 0 -1.28rem; }
.t-arrow.is-pen svg { animation-duration: 1.4s; overflow: visible; } /* the pointer tip pokes past the viewBox */
.t-arrow .t-glyph { position: absolute; left: 27%; top: 27%; width: 46%; height: 46%; pointer-events: none; }
@keyframes arrowPulse { 0%, 100% { transform: scale(0.9); opacity: 0.85; } 50% { transform: scale(1.12); opacity: 1; } }

.minimap {
  position: absolute; right: 1.2rem; bottom: 1.2rem; width: 13.5rem; height: 13.5rem; border-radius: 1.6rem; overflow: hidden;
  border: var(--bw) solid var(--navy); background: #5fb843; box-shadow: 0 0.35rem 0 rgba(29, 43, 83, 0.55);
}
/* the canvas turns in quarter steps with the camera (ui.js turnMinimap), so screen-up is map-up */
.minimap canvas { display: block; width: 100%; height: 100%; transition: transform 0.35s var(--ease-out); }
.minimap-n {
  position: absolute; top: 0.3rem; left: 50%; transform: translateX(-50%); font-size: 0.8rem; font-weight: 700; color: #fff;
  -webkit-text-stroke: 0.2em var(--navy); paint-order: stroke fill; pointer-events: none;
}
/* … and the upright N badge sits on the rim where north now is */
.minimap-n[data-side="right"] { top: 50%; left: auto; right: 0.45rem; transform: translateY(-50%); }
.minimap-n[data-side="bottom"] { top: auto; bottom: 0.3rem; }
.minimap-n[data-side="left"] { top: 50%; left: 0.45rem; transform: translateY(-50%); }

/* ------------------------------------------------------------------ pause / controls */
.scr-pause { justify-content: center; background: rgba(20, 35, 80, 0.5); z-index: 5; }
.pause-card { display: flex; gap: 1.6rem; padding: 1.6rem 2rem 1.8rem; animation: riseIn 0.4s var(--ease-back) both; }
.pause-main { display: flex; flex-direction: column; align-items: stretch; gap: 0.9rem; min-width: 16rem; }
.pause-main h2 { margin: 0 0 0.3rem; text-align: center; font-size: 2.6rem; color: var(--sun); --ow: 0.14em; --od: 0.08em; }
.pause-main .btn { width: 100%; }
.controls-panel { display: none; min-width: 20rem; padding-left: 1.6rem; border-left: 0.2rem dashed rgba(29, 43, 83, 0.25); }
.controls-panel.is-on { display: block; animation: scrIn 0.3s ease both; }
.controls-panel h3 { margin: 0.2rem 0 0.8rem; font-size: 1.5rem; }
.ctrl-list { display: grid; grid-template-columns: auto 1fr; gap: 0.55rem 1rem; align-items: center; font-size: 1.08rem; }
.ctrl-list .keys { text-align: right; white-space: nowrap; }

/* ------------------------------------------------------------------ result */
/* the card sits near the top so the win camera's pen (lower third, confetti, shepherd) stays visible below it */
.scr-result { justify-content: flex-start; padding-top: 5vh; background: radial-gradient(ellipse at center, rgba(20, 40, 90, 0.25), rgba(20, 40, 90, 0.6)); }
.result-card { width: min(40rem, 92vw); padding: 1.3rem 2rem 1.6rem; text-align: center; animation: riseIn 0.55s var(--ease-back) both; }
.result-kicker { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--sky-2); }
.result-title { font-size: 3.2rem; font-weight: 700; color: var(--sun); line-height: 1.05; margin-top: 0.1rem; --ow: 0.13em; --od: 0.08em; }
.result-card.is-fail .result-title { color: var(--red); }
.result-reason { margin-top: 0.3rem; font-size: 1.3rem; font-weight: 600; }
.result-stars { display: flex; justify-content: center; align-items: flex-end; gap: 0.6rem; margin: 0.8rem 0 0.4rem; }
.result-stars .rs { position: relative; width: 5rem; height: 5rem; }
.result-stars .rs:nth-child(2) { width: 6.2rem; height: 6.2rem; margin-bottom: 0.6rem; }
.result-stars .rs svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.result-stars .rs .full { opacity: 0; }
.result-stars .rs.is-on .full { opacity: 1; animation: starIn 0.55s var(--ease-back) both; }
@keyframes starIn { 0% { transform: scale(2.2) rotate(-40deg); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
.score-rows { margin: 0.6rem auto 0; max-width: 26rem; display: flex; flex-direction: column; gap: 0.3rem; }
.score-row { display: flex; justify-content: space-between; align-items: center; padding: 0.25rem 0.8rem; border-radius: 0.7rem; background: rgba(29, 43, 83, 0.06); font-size: 1.12rem; font-weight: 600; animation: riseIn 0.4s var(--ease-out) both; }
.score-row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.score-row.total { background: var(--navy); color: #fff; font-size: 1.45rem; padding: 0.35rem 0.9rem; margin-top: 0.2rem; }
.score-row.total span:last-child { color: var(--sun); }
.new-best { display: inline-block; margin-top: 0.6rem; padding: 0.15rem 0.9rem; border-radius: 99rem; background: var(--pink); color: #fff; font-weight: 700; border: 0.16rem solid var(--navy); animation: pulseBtn 1s ease-in-out infinite; }
.result-btns { display: flex; justify-content: center; gap: 1rem; margin-top: 1.2rem; flex-wrap: wrap; }
.result-btns .btn { min-width: 0; padding: 0.5em 1.15em; font-size: 1.2rem; }

/* ------------------------------------------------------------------ ending */
.scr-ending { justify-content: center; background: radial-gradient(circle at 50% 40%, rgba(255, 230, 120, 0.35), rgba(20, 40, 90, 0.55)); overflow: hidden; }
.ending-card { position: relative; z-index: 2; width: min(40rem, 90vw); padding: 1.8rem 2.2rem 2rem; text-align: center; animation: riseIn 0.7s var(--ease-back) both; }
.ending-trophy { width: 7rem; height: 7rem; margin: -5rem auto 0.4rem; animation: decoHop 1.4s ease-in-out infinite; }
.ending-title { font-size: 3rem; font-weight: 700; color: var(--sun); line-height: 1.08; --ow: 0.13em; --od: 0.08em; }
.ending-text { margin: 0.8rem 0 0; font-size: 1.25rem; line-height: 1.4; }
.ending-stars { display: inline-flex; align-items: center; gap: 0.5rem; margin-top: 1rem; font-size: 2rem; font-weight: 700; padding: 0.3rem 1.2rem; border-radius: 99rem; background: var(--navy); color: #fff; }
.ending-stars svg { width: 2.2rem; height: 2.2rem; }
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.confetti i { position: absolute; top: -5vh; width: 0.8rem; height: 1.2rem; border-radius: 0.2rem; animation: confFall linear infinite; }
@keyframes confFall { 0% { transform: translateY(0) rotate(0); } 100% { transform: translateY(115vh) rotate(720deg); } }

/* ------------------------------------------------------------------ iris transition
   A navy sheet with a circular hole (radial mask); the hole radius is an animatable registered property. */
@property --iris { syntax: '<length>'; inherits: false; initial-value: 0px; }
.iris-wrap {
  position: fixed; inset: 0; z-index: 50; pointer-events: none; visibility: hidden; background: var(--navy);
  --iris: 150vmax;
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent var(--iris), #000 calc(var(--iris) + 1px));
  mask-image: radial-gradient(circle at 50% 50%, transparent var(--iris), #000 calc(var(--iris) + 1px));
  transition: --iris 0.55s cubic-bezier(0.3, 0.6, 0.4, 1), visibility 0s linear 0.55s;
}
.iris-wrap.is-closed {
  visibility: visible; pointer-events: auto; --iris: 0px;
  transition: --iris 0.42s cubic-bezier(0.55, 0, 0.8, 0.4), visibility 0s;
}
.iris-paw { position: absolute; left: 50%; top: 50%; width: 5rem; height: 5rem; margin: -2.5rem; opacity: 0; transition: opacity 0.2s ease; color: var(--sun); }
.iris-wrap.is-closed .iris-paw { opacity: 1; transition-delay: 0.3s; animation: pawTap 0.8s ease-in-out infinite; }

/* ------------------------------------------------------------------ debug overlay */
.debug-box {
  position: fixed; left: 0.5rem; bottom: 0.5rem; z-index: 60; padding: 0.4rem 0.6rem; border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.62); color: #bff7a8; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre;
  pointer-events: none; max-width: 46vw; overflow: hidden;
}
.debug-box .err { color: #ff9c8c; }

/* ------------------------------------------------------------------ difficulty (level select, intro, HUD, result) */
.diff-bar {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.4rem 0.8rem; max-width: 94vw;
  padding: 0.35rem 1.2rem 0.35rem 0.5rem; border-radius: 99rem; background: rgba(255, 255, 255, 0.94);
  border: var(--bw) solid var(--navy); box-shadow: 0 0.3rem 0 var(--navy);
  animation: riseIn 0.5s var(--ease-back) 0.15s both;
}
.diff-label { padding-left: 0.6rem; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.75; }
.diff-seg { display: flex; gap: 0.18rem; padding: 0.18rem; border-radius: 99rem; background: #e9e4d8; border: 0.16rem solid var(--navy); }
.diff-opt {
  min-width: 5.8rem; padding: 0.28em 1em; border: 0.16rem solid transparent; border-radius: 99rem; background: transparent;
  color: var(--navy); font-size: 1.08rem; font-weight: 700; cursor: pointer; outline: none;
  transition: background-color 0.15s ease, transform 0.15s var(--ease-back), box-shadow 0.15s ease;
}
.diff-opt:hover { background: rgba(255, 255, 255, 0.85); }
.diff-opt.is-on { background: var(--dc); border-color: var(--navy); box-shadow: 0 0.18rem 0 var(--navy); transform: translateY(-0.08rem); }
.diff-blurb { max-width: 25rem; font-size: 0.98rem; font-weight: 600; line-height: 1.2; color: var(--navy-2); }
.is-bump { animation: bump 0.35s var(--ease-back); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }
/* level cards: the clock for the chosen difficulty (bottom-right of the sky) + the hardest difficulty won */
.lvl-time {
  position: absolute; right: 0.45rem; bottom: 0.4rem; z-index: 2; display: inline-flex; align-items: center; gap: 0.2rem;
  padding: 0.05rem 0.45rem 0.05rem 0.25rem; border-radius: 99rem; background: rgba(255, 255, 255, 0.92); border: 0.14rem solid var(--navy);
  font-size: 0.82rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums;
}
.lvl-time svg { width: 1.05rem; height: 1.05rem; }
.lvl-card.is-locked .lvl-lock { padding-right: 3rem; } /* the lock sits a little left of centre, clear of the clock */
.lvl-bdiff .short { display: none; }
.lvl-bdiff {
  display: inline-block; margin-left: 0.35rem; padding: 0 0.4rem; border-radius: 99rem; background: var(--dc); border: 0.12rem solid var(--navy);
  color: var(--navy); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; line-height: 1.35; text-transform: uppercase; vertical-align: 0.05em;
}
.diff-pill {
  display: inline-block; vertical-align: 0.1em; padding: 0.1rem 0.75rem; border-radius: 99rem; background: var(--dc, var(--good));
  color: var(--navy); border: 0.16rem solid var(--navy); box-shadow: 0 0.16rem 0 var(--navy);
  font-size: 1rem; font-weight: 700; letter-spacing: 0.08em; line-height: 1.3; text-transform: uppercase;
}
.intro-card .diff-pill { margin-left: 0.35rem; }
.result-kicker .diff-pill { margin-left: 0.35rem; font-size: 0.85rem; }
.timer-wrap { position: relative; display: flex; }
.hud-diff { /* beside the clock, outside its box so the timer stays centred */
  position: absolute; left: calc(100% + 0.5rem); top: 50%; transform: translateY(-50%); white-space: nowrap;
  padding: 0.12rem 0.6rem; border-radius: 99rem; background: var(--dc, var(--good)); color: var(--navy); opacity: 0.92;
  border: 0.16rem solid var(--navy); box-shadow: 0 0.2rem 0 rgba(29, 43, 83, 0.55);
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; line-height: 1.25; text-transform: uppercase;
}
.score-row.mul { background: rgba(255, 204, 51, 0.25); background: color-mix(in srgb, var(--dc, var(--sun)) 30%, transparent); }

/* ------------------------------------------------------------------ sound settings panel (title & pause) */
.snd-overlay {
  position: absolute; inset: 0; z-index: 8; display: none; align-items: center; justify-content: center; padding: 1rem;
  background: rgba(20, 35, 80, 0.5); pointer-events: auto;
}
.snd-overlay.is-on { display: flex; animation: scrIn 0.25s ease both; }
.snd-card { width: min(34rem, 94vw); max-height: calc(100vh - 2rem); overflow-y: auto; padding: 1.2rem 1.6rem 1.1rem; animation: riseIn 0.4s var(--ease-back) both; }
.snd-card h3 { margin: 0 0 0.6rem; text-align: center; font-size: 2.3rem; color: var(--sun); --ow: 0.14em; --od: 0.08em; }
.snd-rows { display: flex; flex-direction: column; gap: 0.35rem; transition: opacity 0.2s ease; }
.snd-card.is-muted .snd-rows { opacity: 0.5; }
.snd-row {
  display: grid; grid-template-columns: 8rem 1fr 3.6rem; align-items: center; gap: 0.6rem;
  padding: 0.25rem 0.8rem; border-radius: 1rem; border: 0.16rem solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.snd-row.is-sel { background: #fff; border-color: var(--navy); box-shadow: 0 0.22rem 0 var(--navy); }
.snd-label { display: flex; align-items: center; gap: 0.5rem; font-size: 1.15rem; font-weight: 700; }
.snd-label svg { flex: 0 0 auto; width: 1.5rem; height: 1.5rem; color: var(--sc); }
.snd-slider { position: relative; padding: 0.7rem 0.9rem; cursor: pointer; touch-action: none; }
.snd-track { position: relative; height: 1rem; border-radius: 99rem; background: #e4e0d6; border: 0.16rem solid var(--navy); }
.snd-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; border-radius: 99rem; background: var(--sc); box-shadow: inset 0 0.18rem 0 rgba(255, 255, 255, 0.35); }
.snd-knob {
  position: absolute; left: 100%; top: 50%; width: 1.7rem; height: 1.7rem; margin: -0.85rem 0 0 -0.85rem; border-radius: 50%;
  background: #fff; border: var(--bw) solid var(--navy); box-shadow: 0 0.2rem 0 var(--navy); transition: transform 0.15s var(--ease-back);
}
.snd-row.is-sel .snd-knob { transform: scale(1.18); }
.snd-val { text-align: right; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.snd-row.is-zero .snd-val { color: var(--red-2); }
.snd-btns { display: flex; justify-content: center; gap: 1rem; margin-top: 0.9rem; }
.snd-btns .btn-small { font-size: 1.1rem; }
.snd-btns .btn-small kbd { font-size: 0.8em; }
.ctrl-sep { grid-column: 1 / -1; height: 0; margin: 0.15rem 0; border-top: 0.16rem dashed rgba(29, 43, 83, 0.25); }
/* over the pause menu: the pause backdrop already dims the game, and the pause card steps aside */
.snd-overlay.from-pause { background: none; }
.scr-pause.is-snd .pause-card { visibility: hidden; }

/* ------------------------------------------------------------------ small screens */
@media (max-aspect-ratio: 4/3) {
  .level-grid { grid-template-columns: repeat(5, 9.6rem); }
  /* narrow cards: the best-difficulty badge shrinks to its initial so 'Best 1,500' + badge stay on one line */
  .lvl-bdiff { min-width: 1.35em; padding: 0 0.3rem; text-align: center; }
  .lvl-bdiff .full { display: none; }
  .lvl-bdiff .short { display: inline; }
  .breed-stage { width: 15rem; height: 15rem; }
}
@media (max-width: 900px) { /* breed select: stage + arrows shrink so the row fits (after the 4:3 rule on purpose) */
  .breed-stage { width: 13rem; height: 13rem; }
  .breed-arrow { width: 3rem; height: 3rem; }
}
@media (max-height: 640px) {
  .scr-heading { margin-top: 2.5vh; font-size: 2.5rem; }
  .lvl-card { height: 10.6rem; } /* room for a two-line name (.lvl-name min-height 2.1em) + stars + best */
  /* compact result card, so the pen still shows below it on short screens */
  .scr-result { padding-top: 3vh; }
  .result-card { padding: 1rem 1.8rem 1.2rem; }
  .result-title { font-size: 2.7rem; }
  .result-stars { margin: 0.4rem 0 0.2rem; }
  .result-stars .rs { width: 4rem; height: 4rem; }
  .result-stars .rs:nth-child(2) { width: 5rem; height: 5rem; margin-bottom: 0.45rem; }
  .score-row { padding: 0.15rem 0.8rem; font-size: 1.05rem; }
  .score-row.total { font-size: 1.3rem; padding: 0.25rem 0.9rem; }
  .result-btns { margin-top: 0.9rem; }
}
@media (max-height: 520px) { /* last resort: never let the card run off the screen */
  .result-card { max-height: calc(100vh - 6vh); overflow-y: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
