@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Nunito:wght@500;600;700;800;900&display=swap');

:root {
  color-scheme: light;
  font-family: 'Nunito', system-ui, sans-serif;
  --ink: #18372d;
  --ink-soft: #577064;
  --cream: #fffaf0;
  --yellow: #ffc83d;
  --orange: #d96a2b;
  --green: #257b56;
  --green-dark: #1e684d;
  --sky: #a8ddf2;
  --panel: rgba(255, 252, 240, 0.95);
  --shadow: 0 24px 70px rgba(29, 71, 54, 0.2), 0 3px 0 rgba(24, 55, 45, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body,
#game {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #9cd8ef;
  color: var(--ink);
  user-select: none;
}

button,
kbd {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 260ms ease, visibility 260ms ease;
  background: linear-gradient(180deg, rgba(121, 202, 232, 0.08), rgba(17, 72, 49, 0.2));
}

.screen--active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#start-screen {
  align-items: end;
  padding-bottom: clamp(24px, 5vh, 64px);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.38), transparent 31%),
    linear-gradient(180deg, rgba(96, 190, 229, 0.06), rgba(22, 73, 52, 0.24));
}

.panel {
  position: relative;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  border-radius: 28px;
  backdrop-filter: blur(14px);
}

.panel::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 20px;
  border: 1px solid rgba(29, 98, 70, 0.1);
  pointer-events: none;
}

.title-card {
  width: min(920px, 95vw);
  padding: clamp(24px, 4vw, 44px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  line-height: 0.94;
  letter-spacing: -0.035em;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.45rem, 6vw, 5rem);
  font-weight: 800;
}

h1 span {
  color: var(--orange);
  text-shadow: 0 4px 0 #ffd16e;
}

.lead {
  max-width: 670px;
  margin-bottom: 24px;
  color: var(--ink-soft);
  font-size: clamp(0.95rem, 1.8vw, 1.15rem);
  font-weight: 700;
}

.breed-section {
  padding-top: 19px;
  border-top: 1px solid rgba(36, 91, 68, 0.14);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.45rem;
}

.section-heading span {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.breed-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.breed-card {
  position: relative;
  min-width: 0;
  padding: 13px 14px 12px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: #f1efe1;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.breed-card:hover {
  transform: translateY(-2px);
  background: #fff8df;
}

.breed-card[aria-checked='true'] {
  border-color: var(--green);
  background: #f2ffe9;
  box-shadow: 0 7px 20px rgba(47, 149, 103, 0.13);
}

.breed-card[aria-checked='true']::after {
  content: '✓';
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  border-radius: 999px;
  color: white;
  background: var(--green);
  font-size: 0.72rem;
  font-weight: 900;
}

.breed-name {
  display: block;
  margin-bottom: 1px;
  padding-right: 17px;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.1;
}

.breed-role {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-row {
  display: grid;
  grid-template-columns: 45px 1fr;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 0.65rem;
  font-weight: 800;
}

.stat-bar {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(46, 96, 73, 0.12);
}

.stat-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--orange);
}

.start-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-top: 20px;
}

.controls-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 800;
}

.controls-preview span {
  display: flex;
  align-items: center;
  gap: 5px;
}

kbd {
  display: inline-grid;
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  place-items: center;
  border: 1px solid rgba(27, 67, 52, 0.17);
  border-bottom-width: 3px;
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font-size: 0.62rem;
  font-weight: 900;
}

.button {
  position: relative;
  z-index: 1;
  min-height: 48px;
  padding: 12px 21px;
  border: 0;
  border-radius: 15px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

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

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  filter: grayscale(0.45);
  transform: none;
}

.button--primary {
  color: #17362c;
  background: var(--yellow);
  box-shadow: 0 5px 0 #d89b25, 0 10px 22px rgba(154, 104, 21, 0.17);
}

.button--primary b {
  margin-left: 14px;
  font-size: 1.1rem;
}

.button--ghost {
  color: var(--ink);
  background: #eaf2e8;
  box-shadow: 0 3px 0 #ceddca;
}

.text-button {
  position: relative;
  z-index: 1;
  padding: 10px;
  border: 0;
  color: var(--ink-soft);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.loading-note {
  position: absolute;
  top: 18px;
  right: 20px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 800;
}

.compact-card,
.result-card {
  width: min(490px, 92vw);
  padding: 40px;
  text-align: center;
}

.compact-card h2,
.result-card h2 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 6vw, 3.2rem);
}

.compact-card > p:not(.eyebrow),
.result-card > p:not(.eyebrow) {
  color: var(--ink-soft);
  font-weight: 700;
}

.compact-card .button {
  display: block;
  width: 100%;
  margin-top: 12px;
}

.level-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  margin: 18px 0 22px;
}

.level-badges span {
  padding: 6px 10px;
  border-radius: 999px;
  background: #e9f3e4;
  color: var(--green-dark);
  font-size: 0.7rem;
  font-weight: 900;
}

.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.hud--active {
  opacity: 1;
  visibility: visible;
}

.panel-lite {
  background: rgba(255, 253, 242, 0.89);
  border: 1px solid rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 24px rgba(32, 68, 54, 0.12);
  backdrop-filter: blur(9px);
}

.hud-top {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
}

.level-chip,
.timer,
.score {
  display: flex;
  flex-direction: column;
  min-width: 104px;
  padding: 9px 14px;
  border-radius: 14px;
}

.level-chip {
  position: absolute;
  left: 0;
  min-width: 180px;
}

.level-chip span,
.timer span,
.score span,
.sheep-counter span {
  color: var(--ink-soft);
  font-size: 0.59rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.level-chip strong {
  font-size: 0.83rem;
}

.timer,
.score {
  align-items: center;
  padding-inline: 19px;
}

.timer strong,
.score strong {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.2rem;
  line-height: 1;
}

.timer--urgent {
  color: #a53c2f;
  animation: urgent 800ms ease-in-out infinite alternate;
}

@keyframes urgent {
  to { transform: scale(1.05); }
}

.sheep-counter {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: 41px auto;
  align-items: center;
  gap: 9px;
  min-width: 205px;
  padding: 10px 13px;
  border-radius: 16px;
}

.sheep-counter strong {
  display: block;
  font-size: 1rem;
  line-height: 1;
}

.sheep-counter strong b {
  font: inherit;
}

.sheep-icon {
  position: relative;
  display: grid;
  width: 39px;
  height: 34px;
  place-items: center;
  border: 3px dotted #d7cdb1;
  border-radius: 50%;
  background: #fffdf5;
  color: #413a32;
  font-size: 0.7rem;
}

.progress-track {
  grid-column: 1 / -1;
  height: 5px;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(48, 102, 75, 0.12);
}

.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 280ms ease;
}

.bark-widget {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 175px;
  padding: 8px 12px 8px 8px;
  border-radius: 16px;
}

.bark-widget > div:last-child {
  display: flex;
  flex-direction: column;
}

.bark-widget strong {
  font-size: 0.75rem;
}

.bark-widget > div:last-child span {
  color: var(--ink-soft);
  font-size: 0.63rem;
  font-weight: 800;
}

.bark-ring {
  position: relative;
  display: grid;
  width: 45px;
  height: 45px;
  overflow: hidden;
  place-items: center;
  border: 3px solid var(--green);
  border-radius: 50%;
  background: white;
}

.bark-ring span {
  position: relative;
  z-index: 2;
  font-size: 0.49rem;
  font-weight: 900;
}

.bark-ring i {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform: translateY(100%);
  background: #a9ddb5;
}

.mission-tip {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(410px, 45vw);
  padding: 9px 12px;
  border-radius: 14px;
  transform: translateX(-50%);
  transition: opacity 300ms ease, transform 300ms ease;
}

.mission-tip--hidden {
  opacity: 0;
  transform: translate(-50%, 10px);
}

.mission-tip p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.2;
}

.tip-icon {
  display: grid;
  flex: 0 0 25px;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  font-weight: 900;
}

.toast {
  position: absolute;
  top: 90px;
  left: 50%;
  padding: 9px 15px;
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, -10px);
  color: #fff;
  background: rgba(24, 55, 45, 0.86);
  box-shadow: 0 8px 23px rgba(20, 47, 37, 0.2);
  font-size: 0.75rem;
  font-weight: 900;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.baa-caption {
  position: absolute;
  z-index: 11;
  opacity: 0;
  color: white;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.2rem;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(27, 54, 44, 0.55);
  transition: opacity 100ms ease;
}

.baa-caption--show {
  animation: baa 900ms ease-out forwards;
}

@keyframes baa {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.7) rotate(-4deg); }
  25% { opacity: 1; transform: translate(-50%, 0) scale(1.08) rotate(2deg); }
  100% { opacity: 0; transform: translate(-50%, -26px) scale(1) rotate(-2deg); }
}

.result-card .button {
  width: 100%;
  margin-top: 10px;
}

.result-badge {
  display: grid;
  width: 67px;
  height: 67px;
  margin: -70px auto 15px;
  place-items: center;
  border: 5px solid var(--cream);
  border-radius: 50%;
  color: white;
  background: var(--green);
  box-shadow: 0 8px 25px rgba(34, 110, 77, 0.25);
  font-size: 2rem;
  font-weight: 900;
}

.result-badge--fail {
  background: var(--orange);
}

.stars {
  margin: 9px 0 16px;
  color: var(--yellow);
  font-size: 2.4rem;
  letter-spacing: 0.08em;
  line-height: 1;
  text-shadow: 0 2px 0 #c68820;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 13px;
}

.result-stats div {
  display: flex;
  flex-direction: column;
  padding: 10px 6px;
  border-radius: 13px;
  background: #eef4e9;
}

.result-stats span {
  color: var(--ink-soft);
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-stats strong {
  font-size: 0.9rem;
}

noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  padding: 24px;
  place-items: center;
  color: var(--ink);
  background: var(--cream);
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
}

@media (max-width: 680px) {
  .screen { padding: 12px; }
  #start-screen { align-items: center; padding-bottom: 12px; }
  .title-card { padding: 22px 18px; }
  h1 { font-size: 2.3rem; }
  .lead { margin-bottom: 14px; font-size: 0.82rem; }
  .breed-section { padding-top: 12px; }
  .breed-list { gap: 6px; }
  .breed-card { padding: 10px 8px; }
  .breed-role { min-height: 24px; font-size: 0.55rem; }
  .stat-row { grid-template-columns: 1fr; gap: 2px; }
  .start-footer { align-items: stretch; flex-direction: column; margin-top: 13px; }
  .controls-preview { display: none; }
  .button { min-height: 45px; }
  .section-heading span { display: none; }
  .loading-note { display: none; }
  .level-chip { min-width: 135px; }
  .level-chip strong { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .score { display: none; }
  .timer { margin-left: auto; }
  .mission-tip { bottom: 84px; width: calc(100vw - 36px); }
  .compact-card, .result-card { padding: 31px 22px; }
  .sheep-counter,
  .bark-widget {
    bottom: 12px;
    min-width: 0;
    width: calc(50vw - 18px);
  }
  .sheep-counter { left: 12px; }
  .bark-widget { right: 12px; }
  .sheep-counter span { font-size: 0.54rem; }
}

@media (max-width: 380px) {
  .sheep-counter { grid-template-columns: 33px auto; gap: 6px; padding-inline: 8px; }
  .sheep-icon { width: 33px; height: 31px; }
  .bark-widget { gap: 6px; padding-right: 7px; }
  .bark-ring { width: 39px; height: 39px; }
  .bark-widget strong { font-size: 0.66rem; }
  .bark-widget > div:last-child span { font-size: 0.56rem; }
}

@media (max-height: 600px) {
  .screen { place-items: start center; }
  .title-card,
  .compact-card,
  .result-card { margin-block: 8px; }
}

@media (max-height: 690px) and (min-width: 681px) {
  .title-card { padding: 22px 30px; }
  h1 { font-size: 3rem; }
  .lead { margin-bottom: 13px; }
  .breed-section { padding-top: 12px; }
  .breed-card { padding-block: 9px; }
  .start-footer { margin-top: 12px; }
}

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