:root {
  --cream: #fff8e7;
  --parchment: #f7eeda;
  --ink: #3a2f28;
  --grass: #58a34a;
  --grass-dark: #3e7c34;
  --sky: #7ec8f0;
  --barn: #c94f38;
  --gold: #f4b942;
  --gold-dark: #d89a26;
}

* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #6db6e8;
  font-family: "Baloo 2", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  color: var(--ink);
}

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

#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(31, 41, 20, 0.38) 100%);
}

#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

/* ============ screens ============ */
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.screen.visible { display: flex; }
.screen-dim { background: rgba(24, 38, 18, 0.55); backdrop-filter: blur(2px); }
.screen > * { pointer-events: auto; }

/* ============ buttons ============ */
.btn {
  font-family: inherit; font-weight: 800; font-size: 19px; letter-spacing: 0.4px;
  color: var(--ink);
  background: linear-gradient(#fffdf2, #f3e7c8);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 11px 34px;
  cursor: pointer;
  box-shadow: 0 5px 0 #b9a878, 0 8px 18px rgba(0,0,0,0.35);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s;
  text-shadow: 0 1px 0 #fff;
}
.btn:hover { transform: translateY(-2px) scale(1.02); filter: brightness(1.04); box-shadow: 0 7px 0 #b9a878, 0 12px 22px rgba(0,0,0,0.4); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b9a878, 0 4px 8px rgba(0,0,0,0.35); }
.btn-big {
  font-size: 26px; padding: 14px 52px;
  background: linear-gradient(#ffe066, #f4b942);
  border-color: #6b4b16;
  box-shadow: 0 6px 0 #a87a1e, 0 10px 22px rgba(0,0,0,0.4);
  color: #4a3205;
}
.btn-big:hover { box-shadow: 0 8px 0 #a87a1e, 0 14px 26px rgba(0,0,0,0.45); }
.btn-big:active { box-shadow: 0 2px 0 #a87a1e; }
.btn-small { font-size: 15px; padding: 8px 18px; opacity: 0.92; }
.btn:disabled { filter: grayscale(1) opacity(0.6); cursor: default; transform: none; }

/* ============ title ============ */
.title-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 26px;
  width: 100%; height: 100%;
  padding: 4vh 20px 3vh;
  background: linear-gradient(rgba(28, 60, 90, 0.10), rgba(28, 60, 90, 0.0) 35%, rgba(20, 46, 14, 0.30) 100%);
}
.title-logo { display: flex; flex-direction: column; align-items: center; transform: rotate(-2deg); }
.logo-sheep { width: 190px; filter: drop-shadow(0 8px 12px rgba(0,0,0,0.4)); animation: sheep-bob 2.6s ease-in-out infinite; }
@keyframes sheep-bob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-12px) rotate(2deg); }
}
.game-title {
  font-size: clamp(64px, 11vw, 118px);
  font-weight: 800; letter-spacing: 2px; line-height: 0.95;
  color: #fff8e7;
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 0 6px 0 var(--ink), 0 14px 34px rgba(0,0,0,0.45);
  margin-top: 6px;
}
.game-subtitle {
  margin-top: 10px;
  font-size: clamp(16px, 2.4vw, 24px); font-weight: 700; color: #fff3c8;
  text-shadow: 0 2px 0 var(--ink), 0 4px 10px rgba(0,0,0,0.5);
  letter-spacing: 4px; text-transform: lowercase;
}
.menu-col { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.title-foot {
  margin-top: auto; font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7); letter-spacing: 1px;
}

/* ============ panels ============ */
.panel {
  background:
    radial-gradient(ellipse at 50% -10%, #fffdf2 0%, transparent 60%),
    linear-gradient(#fbf3dc, #efe0bd);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 10px 0 rgba(58,47,40,0.85), 0 26px 60px rgba(0,0,0,0.5), inset 0 2px 0 #ffffff;
  padding: 26px 34px 24px;
  max-width: 560px; width: min(92vw, 560px);
  max-height: 92vh; overflow-y: auto;
  text-align: center;
}
.panel-wide { max-width: 860px; width: min(94vw, 860px); }
.panel-title {
  font-size: 34px; font-weight: 800; letter-spacing: 1px;
  color: var(--ink); margin-bottom: 10px;
}
.panel-foot { margin-top: 16px; display: flex; gap: 12px; justify-content: center; }

/* ============ how to ============ */
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 26px; text-align: left; }
.howto-block h3 { font-size: 17px; color: var(--grass-dark); text-transform: uppercase; letter-spacing: 1.5px; margin: 12px 0 4px; }
.howto-block p, .howto-block li { font-size: 15px; line-height: 1.38; font-weight: 600; color: #4c4038; }
.keys { list-style: none; }
.keys li { margin: 7px 0; display: flex; align-items: center; gap: 6px; }
.key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 8px;
  background: linear-gradient(#ffffff, #dcd2ba);
  border: 2px solid var(--ink); border-radius: 8px;
  box-shadow: 0 3px 0 #b9a878;
  font-weight: 800; font-size: 14px;
}
.key-wide { min-width: 64px; }
.danger-list { list-style: none; }
.danger-list li { display: flex; align-items: baseline; gap: 8px; margin: 5px 0; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); flex: none; transform: translateY(1px); }
.dot-fox { background: #e07b2a; }
.dot-stray { background: #8a8d92; }
.dot-wolf { background: #4c5866; }
.dot-bear { background: #6b4226; }

/* ============ breed select ============ */
.breed-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 8px; }
.breed-card {
  background: linear-gradient(#fffdf4, #efe3c2);
  border: 3px solid var(--ink); border-radius: 18px;
  padding: 12px 10px 14px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 5px 0 #c9b989;
  transition: transform 0.1s, box-shadow 0.1s;
  font-family: inherit;
}
.breed-card:hover { transform: translateY(-4px); box-shadow: 0 9px 0 #c9b989, 0 16px 26px rgba(0,0,0,0.35); }
.breed-card:active { transform: translateY(1px); box-shadow: 0 3px 0 #c9b989; }
.breed-name { font-size: 19px; font-weight: 800; }
.breed-title { font-size: 11px; font-weight: 700; color: #8a6d3b; text-transform: uppercase; letter-spacing: 1px; min-height: 26px; }
.breed-canvas { width: 120px; height: 96px; }
.stat { width: 100%; }
.stat-label { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; color: #5d5142; text-transform: uppercase; letter-spacing: 0.6px; }
.stat-bar { height: 9px; border-radius: 5px; background: #d9cba6; border: 1.5px solid var(--ink); overflow: hidden; margin-top: 2px; }
.stat-fill { height: 100%; background: linear-gradient(90deg, #79c25e, #3e7c34); border-radius: 4px; }
.breed-desc { font-size: 11.5px; font-weight: 600; color: #5d5142; line-height: 1.3; min-height: 46px; }

/* ============ level select ============ */
.level-sub { font-size: 14px; font-weight: 600; color: #5d5142; margin-bottom: 14px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.level-btn {
  position: relative; aspect-ratio: 1 / 1.05;
  border: 3px solid var(--ink); border-radius: 16px;
  background: linear-gradient(#cdeeb4, #8ccb62);
  cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 5px 0 #4c7a33, inset 0 2px 0 #ffffffaa;
  transition: transform 0.1s;
}
.level-btn:hover { transform: translateY(-3px) scale(1.03); }
.level-btn:active { transform: translateY(1px); }
.level-btn .lvl-num { font-size: 34px; font-weight: 800; color: var(--ink); line-height: 1; }
.level-btn .lvl-name { font-size: 9.5px; font-weight: 800; color: #2c4a1e; text-align: center; line-height: 1.15; padding: 0 4px; text-transform: uppercase; letter-spacing: 0.4px; }
.level-btn .lvl-stars { font-size: 13px; letter-spacing: 2px; color: #a87a1e; text-shadow: 0 1px 0 #fff8; }
.level-btn.locked { background: linear-gradient(#b9b3a4, #8f887a); box-shadow: 0 5px 0 #5e594e; cursor: default; }
.level-btn.locked .lvl-num, .level-btn.locked .lvl-name { color: #4e4a40; }
.level-btn.final { background: linear-gradient(#f6c8b0, #d98d63); box-shadow: 0 5px 0 #7e4a26, inset 0 2px 0 #ffffffaa; }
.level-total { margin-top: 14px; font-weight: 800; font-size: 15px; color: #5d5142; }

/* ============ HUD ============ */
#hud { pointer-events: none; }
.hud-top {
  position: absolute; top: 14px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.hud-box {
  background: rgba(30, 42, 22, 0.72);
  border: 3px solid rgba(255, 248, 231, 0.9);
  border-radius: 16px;
  padding: 8px 16px;
  color: #fff8e7;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  backdrop-filter: blur(3px);
}
.hud-level-num { font-size: 12px; font-weight: 800; letter-spacing: 2px; color: #ffd96b; }
.hud-level-name { font-size: 20px; font-weight: 800; line-height: 1.1; }
.hud-sheep { display: flex; align-items: center; gap: 12px; padding: 6px 20px; }
.hud-sheep-icon { width: 46px; height: 36px; }
#hud-sheep-count { font-size: 32px; font-weight: 800; }
.hud-right { text-align: right; min-width: 108px; }
.hud-timer { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-score { font-size: 14px; font-weight: 700; color: #ffd96b; }
.hud-lost {
  position: absolute; top: 84px; left: 16px;
  background: rgba(30, 42, 22, 0.6); color: #ffd9d0;
  font-size: 13px; font-weight: 700; padding: 5px 12px; border-radius: 10px;
  border: 2px solid rgba(255, 248, 231, 0.4);
}
.hud-bottom { position: absolute; bottom: 26px; left: 0; right: 0; display: flex; justify-content: center; }
.bark-indicator { display: flex; align-items: center; gap: 10px; background: rgba(30,42,22,0.66); border: 3px solid rgba(255,248,231,0.85); padding: 8px 14px; border-radius: 14px; }
.bark-label { font-size: 15px; font-weight: 800; letter-spacing: 3px; color: #ffd96b; }
.bark-bar { width: 150px; height: 14px; border-radius: 8px; background: #20301a; border: 2px solid #fff8e7; overflow: hidden; }
.bark-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffd96b, #ffef9e); transition: width 0.06s linear; }
.bark-indicator.ready .bark-fill { background: linear-gradient(90deg, #8affa0, #d6ffb0); }
.bark-indicator.ready .bark-label { color: #8affa0; }

#hurt-flash {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(190, 30, 20, 0.5) 100%);
}
#hurt-flash.flash { animation: hurt-flash 0.5s ease-out; }
@keyframes hurt-flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ============ toast ============ */
.toast {
  position: absolute; top: 16%; left: 50%; transform: translate(-50%, -18px);
  opacity: 0; pointer-events: none; text-align: center;
  background: rgba(28, 40, 20, 0.82); border: 3px solid #ffd96b; border-radius: 18px;
  padding: 12px 30px; transition: opacity 0.35s, transform 0.35s;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-title { font-size: 27px; font-weight: 800; color: #ffd96b; letter-spacing: 1px; }
.toast-hint { font-size: 16px; font-weight: 700; color: #fff8e7; margin-top: 2px; }

/* ============ result / fail / ending ============ */
.result-stars { display: flex; gap: 14px; justify-content: center; margin: 6px 0 14px; }
.star { font-size: 58px; color: #cbbd93; text-shadow: 0 3px 0 #8a7c52; transition: transform 0.2s; transform: scale(0.6); opacity: 0.5; }
.star.earned { color: #ffd83d; text-shadow: 0 4px 0 #a87a1e, 0 8px 18px rgba(255, 216, 61, 0.45); opacity: 1; transform: scale(1); animation: star-pop 0.45s cubic-bezier(0.2, 2.2, 0.4, 1); }
@keyframes star-pop { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.5) rotate(8deg); } 100% { transform: scale(1); } }
.result-stats { margin: 4px auto 16px; max-width: 360px; }
.result-row { display: flex; justify-content: space-between; font-size: 17px; font-weight: 700; color: #4c4038; padding: 4px 6px; border-bottom: 2px dashed #cdbd95; }
.result-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.result-total { border-bottom: none; font-size: 21px; color: var(--ink); }
.fail-title { color: #a03428; }
.fail-text { font-size: 17px; font-weight: 600; color: #4c4038; line-height: 1.45; margin: 6px 0 18px; }
.ending-title { color: #3e7c34; }
.ending-stars { font-size: 34px; font-weight: 800; color: #a87a1e; margin-bottom: 14px; }

/* ============ error box ============ */
.error-box {
  position: fixed; z-index: 999; left: 10px; bottom: 10px; max-width: 60ch;
  background: #400; color: #ffd9d0; font: 12px/1.4 monospace;
  padding: 10px 12px; border-radius: 8px; white-space: pre-wrap;
}

@media (max-width: 760px) {
  .breed-cards { grid-template-columns: repeat(2, 1fr); }
  .level-grid { grid-template-columns: repeat(3, 1fr); }
  .howto-grid { grid-template-columns: 1fr; }
  .game-title { -webkit-text-stroke-width: 2px; }
}
