:root {
  color-scheme: light;
  --ink: #183c2d;
  --forest: #16392b;
  --deep: #102b25;
  --cream: #fff8e6;
  --cream-soft: #f1ebce;
  --lime: #d3eb83;
  --sage: #b7ce95;
  --amber: #f1c265;
  --edge: clamp(20px, 3.9vw, 64px);
  --frame: clamp(16px, 2.6vw, 40px);
  --text-font: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --title-font: "Avenir Next", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  font: 500 16px/1.35 var(--text-font);
}

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

body {
  margin: 0;
  min-width: 290px;
  color: var(--cream);
  background: #597b60;
  overflow: hidden;
  overscroll-behavior: none;
}

button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid #fffefa; outline-offset: 4px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
svg { display: block; }

#game-view {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  background: linear-gradient(#a4d4d8 0%, #afdad1 38%, #659553 72%, #415e31 100%);
  touch-action: none;
}

.color-wash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(13, 39, 32, .35), transparent 25%, transparent 76%, rgba(15, 40, 26, .38));
  transition: opacity .3s;
}

.color-wash::before {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(ellipse at 0 100%, rgba(11, 37, 25, .83) 1%, rgba(18, 58, 38, .52) 32%, transparent 72%),
    linear-gradient(90deg, rgba(14, 43, 35, .38), transparent 58%);
  opacity: 0;
  transition: opacity .45s ease;
}

[data-mode="menu"] .color-wash::before { opacity: 1; }

.top-bar {
  position: fixed;
  z-index: 4;
  inset: max(var(--frame), env(safe-area-inset-top)) max(var(--edge), env(safe-area-inset-right)) auto max(var(--edge), env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--cream);
  text-shadow: 0 2px 8px #17342980;
}

.brand-mark {
  width: 47px;
  height: 47px;
  display: grid;
  place-items: center;
  color: var(--forest);
  background: var(--cream);
  border: 1px solid #fffdf2;
  border-radius: 15px;
  box-shadow: 0 2px 0 #b9b689, 0 4px 13px #13271e2e;
  transform: rotate(-5deg);
}

.brand-mark svg { width: 37px; height: 37px; }

.brand-name {
  font-family: var(--title-font);
  font-size: 1.24rem;
  font-weight: 900;
  letter-spacing: -.046em;
  line-height: .92;
}

.brand-name span { display: block; }

.top-actions { display: flex; gap: 9px; pointer-events: auto; }

.utility-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 45px;
  min-height: 44px;
  padding: 8px 11px;
  color: var(--cream);
  background: rgba(24, 58, 47, .86);
  border: 1px solid rgba(255, 251, 229, .5);
  border-radius: 15px;
  box-shadow: 0 2px 0 #10251f5c;
  font-size: .9rem;
  font-weight: 700;
  transition: background .16s, transform .16s;
}

.utility-button:hover { background: #284e3c; transform: translateY(-2px); }
.utility-button:active { transform: translateY(1px); }
.utility-button svg { width: 22px; height: 22px; }
.guide-button { padding-right: 13px; }
.sound-cross, #sound-toggle[aria-pressed="true"] .sound-wave { display: none; }
#sound-toggle[aria-pressed="true"] .sound-cross { display: block; }

.menu {
  position: fixed;
  left: max(var(--edge), env(safe-area-inset-left));
  bottom: max(clamp(22px, 5.9vh, 72px), env(safe-area-inset-bottom));
  z-index: 2;
  width: min(530px, calc(100vw - var(--edge) * 2));
  animation: arrive .45s cubic-bezier(.16, .77, .2, 1) both;
}

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

.menu-copy h1, .modal h2 {
  font-family: var(--title-font);
  font-weight: 900;
  letter-spacing: -.067em;
}

.menu-copy h1 {
  margin: 0;
  font-size: clamp(3.6rem, min(6.5vw, 12vh), 7.2rem);
  line-height: .88;
  text-shadow: 0 3px 0 #18382766, 0 4px 21px #102c23a1;
}

.menu-copy h1 em {
  color: var(--lime);
  font-style: normal;
}

.menu-copy p {
  max-width: 325px;
  margin: clamp(11px, 2.5vh, 24px) 0 clamp(14px, 3.4vh, 30px);
  color: var(--cream);
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  line-height: 1.43;
  text-shadow: 0 1px 5px #0b2c21, 0 0 12px #0d2c22ba;
  text-wrap: pretty;
}

.breed-picker { margin: 0 0 17px; padding: 0; border: 0; min-width: 0; }

.breed-picker legend {
  margin-bottom: 10px;
  padding: 0;
  color: var(--cream-soft);
  font-size: .85rem;
  font-weight: 800;
  letter-spacing: .095em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px #102c23;
}

.breed-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.breed-radio { position: absolute; width: 1px; height: 1px; opacity: 0; }

.breed-card {
  display: flex;
  align-items: center;
  min-height: 60px;
  gap: 8px;
  padding: 7px 8px;
  color: var(--cream);
  background: rgba(20, 50, 37, .79);
  border: 1px solid #d5e5a86b;
  border-radius: 13px;
  box-shadow: 0 2px 0 #15362cd9;
  cursor: pointer;
  transition: background .18s, transform .18s, color .18s, border-color .18s;
}

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

.breed-radio:focus-visible + .breed-card { outline: 3px solid var(--cream); outline-offset: 3px; }

.breed-radio:checked + .breed-card {
  color: var(--ink);
  background: var(--cream);
  border-color: #fffdf4;
  box-shadow: 0 3px 0 #a6a55c;
}

.breed-copy { min-width: 0; }
.breed-copy strong { display: block; font-size: clamp(.78rem, 1.18vw, .91rem); font-weight: 800; line-height: 1.16; }
.breed-copy small { display: block; margin-top: 3px; font-size: .75rem; opacity: .84; line-height: 1.14; }

.dog-avatar {
  --coat: #263a36;
  --ear: #263a36;
  --patch: #fdf6df;
  --medal: #a6ce96;
  position: relative;
  isolation: isolate;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  background: var(--medal);
  border-radius: 10px;
  overflow: hidden;
}

.breed-kelpie .dog-avatar { --coat: #764431; --ear: #4f352b; --patch: #e8a164; --medal: #efbb71; }
.breed-pyrenees .dog-avatar { --coat: #fff5e0; --ear: #dfbe91; --patch: #fff9eb; --medal: #b3d7d2; }

.dog-avatar::before, .dog-avatar::after {
  position: absolute;
  z-index: 1;
  top: 5px;
  left: 8px;
  width: 9px;
  height: 15px;
  content: "";
  background: var(--ear);
  border-radius: 70% 23% 26% 40%;
  transform: rotate(-24deg);
}

.dog-avatar::after { left: auto; right: 8px; transform: scaleX(-1) rotate(-24deg); }
.breed-pyrenees .dog-avatar::before, .breed-pyrenees .dog-avatar::after { top: 13px; width: 10px; height: 12px; }
.breed-kelpie .dog-avatar::before, .breed-kelpie .dog-avatar::after { top: 3px; height: 17px; }

.dog-avatar i {
  position: absolute;
  z-index: 2;
  inset: 10px 8px 7px;
  background: var(--coat);
  border-radius: 44% 44% 40% 40% / 53% 53% 45% 45%;
}

.dog-avatar i::after {
  content: "";
  position: absolute;
  inset: 1px 2px 0;
  background: var(--patch);
  clip-path: polygon(49% 0, 60% 22%, 68% 46%, 86% 71%, 80% 95%, 53% 100%, 23% 95%, 15% 71%, 33% 49%);
}

.breed-kelpie .dog-avatar i::after { top: 9px; clip-path: polygon(18% 4%, 43% 25%, 59% 25%, 82% 4%, 96% 78%, 72% 100%, 25% 100%, 6% 78%); }

.dog-avatar b {
  position: absolute;
  z-index: 3;
  top: 17px;
  left: 13px;
  width: 4px;
  height: 4px;
  border-radius: 60%;
  background: #262c24;
  box-shadow: 10px 0 #262c24;
}

.breed-collie .dog-avatar b { background: #fff8df; box-shadow: 10px 0 #fff8df; }

.dog-avatar b::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 4px;
  width: 6px;
  height: 4px;
  border-radius: 40% 40% 60% 60%;
  background: #262c24;
}

.dog-avatar small {
  position: absolute;
  inset: 28px 8px 0;
  background: #e76042;
  border-radius: 60% 60% 0 0;
  transform: rotate(-8deg);
}

.primary-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 49px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 13px;
  font-weight: 800;
  transition: background .16s, transform .16s, box-shadow .16s;
}

.primary-button {
  color: var(--ink);
  background: var(--lime);
  border-color: #e6f5b1;
  box-shadow: 0 4px 0 #759347, 0 7px 16px #001f1933;
}

.primary-button:hover { background: #e0f4a3; transform: translateY(-2px); }
.primary-button:active { transform: translateY(2px); box-shadow: 0 1px 0 #759347; }
.primary-button svg { width: 19px; height: 19px; }
.start-button { padding-inline: 17px 24px; min-height: 54px; font-size: 1.09rem; }

.secondary-button {
  color: var(--ink);
  background: #f4edda;
  border-color: #c2c8a7;
}

.secondary-button:hover { background: #e6ebcd; transform: translateY(-2px); }
.secondary-button:active { transform: translateY(1px); }

.game-hud {
  position: fixed;
  z-index: 3;
  top: max(var(--frame), env(safe-area-inset-top));
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: max-content;
  transform: translateX(-50%);
  pointer-events: none;
}

.level-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  max-width: 90vw;
  padding: 4px 11px 4px 5px;
  color: var(--cream);
  background: #173c2fea;
  border: 1px solid #f2f0ca75;
  border-radius: 12px;
  box-shadow: 0 2px 6px #13281f38;
  font-size: .91rem;
  line-height: 1.05;
}

.level-number {
  min-width: 33px;
  padding: 4px 5px;
  color: var(--ink);
  background: #d9e7ae;
  border-radius: 7px;
  text-align: center;
  font-size: .75rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.level-chip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 186px;
  padding: 7px 12px 9px 7px;
  overflow: hidden;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid #fffdf0;
  border-radius: 14px;
  box-shadow: 0 3px 0 #9fa564, 0 6px 12px #193d2938;
}

.score-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--cream);
  background: #b5cb8d;
  border-radius: 9px;
}

.score-icon svg { width: 26px; height: 26px; }
.score-count { display: flex; flex-direction: column; min-width: 54px; line-height: .95; white-space: nowrap; }
.score-count strong { font-size: 1.35rem; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -.05em; }
.score-slash { margin: 0 1px; color: #65905f; }
.score-count > span { margin-top: 4px; color: #526d54; font-size: .7rem; font-weight: 800; }

.clock {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding-left: 8px;
  border-left: 1px solid #d8dcc2;
  color: #45634f;
  font-size: .87rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.clock svg { width: 17px; height: 17px; }

.score-meter {
  position: absolute;
  inset: auto auto 0 0;
  width: var(--progress, 0%);
  height: 4px;
  background: #719749;
  transition: width .27s ease;
}

.objectives {
  position: fixed;
  z-index: 3;
  top: max(calc(var(--frame) + 115px), calc(env(safe-area-inset-top) + 115px));
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(90vw, 480px);
  transform: translateX(-50%);
  pointer-events: none;
}

.objective, .threat {
  padding: 5px 12px;
  border-radius: 9px;
  font-size: .85rem;
  font-weight: 800;
  text-align: center;
}

.objective { background: #18362be8; color: var(--cream); }
.threat { background: #f2c170; color: #422e22; box-shadow: 0 2px 0 #ab7447; }

.control-strip {
  position: fixed;
  z-index: 3;
  right: max(var(--edge), env(safe-area-inset-right));
  bottom: max(var(--frame), env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 8px 11px;
  color: var(--cream);
  background: rgba(20, 48, 36, .87);
  border: 1px solid #f0eac658;
  border-radius: 13px;
  box-shadow: 0 2px 0 #173a2d96;
}

[data-mode="playing"] .control-strip { right: 50%; transform: translateX(50%); }
.binding, .arrow-keys { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.binding { gap: 7px; font-size: .81rem; font-weight: 800; }
.binding-divider { width: 1px; height: 20px; background: #f5eccc43; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  min-height: 23px;
  padding: 0 4px;
  color: var(--ink);
  background: #f9f2d8;
  border: 1px solid #fffae7;
  border-radius: 5px;
  box-shadow: 0 2px 0 #afab7e;
  font: 800 .72rem/1 var(--text-font);
  vertical-align: middle;
}

.bark-binding { position: relative; }
.bark-binding.is-cooling kbd { background: #e1d999; border-color: #e1d999; }
.bark-binding.is-cooling::after {
  position: absolute;
  inset: auto auto -5px 0;
  width: var(--charge, 0%);
  height: 2px;
  content: "";
  background: var(--lime);
  border-radius: 2px;
}

.touch-controls { display: none; }

.toast {
  position: fixed;
  z-index: 6;
  top: 31%;
  left: max(var(--edge), env(safe-area-inset-left));
  max-width: min(280px, 75vw);
  padding: 10px 14px;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid #fffef0;
  border-radius: 10px;
  box-shadow: 0 3px 0 #a6af79, 0 4px 14px #183b3250;
  font-size: .94rem;
  font-weight: 800;
  animation: arrive .2s both;
  pointer-events: none;
}

.toast[data-kind="warning"], .toast[data-kind="danger"] { background: #ffd48b; border-color: #ffe1a5; box-shadow: 0 3px 0 #ae7146; }
.toast[data-kind="success"] { background: #daf0a1; border-color: #f5ffe0; }

.overlay {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(13, 36, 31, .58);
  backdrop-filter: blur(5px);
}

.modal {
  width: min(100%, 460px);
  max-height: 100%;
  padding: clamp(22px, 4.5vw, 40px);
  overflow-y: auto;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid #fffef1;
  border-radius: 25px;
  box-shadow: 0 6px 0 #9aa56d, 0 17px 80px #091f1c70;
  animation: arrive .28s cubic-bezier(.16, .77, .2, 1) both;
}

.modal:focus { outline: 0; }
.modal button:focus-visible { outline-color: #4c6f46; }

.modal-tag {
  display: inline-block;
  padding: 4px 8px;
  color: #284733;
  background: #e9edc9;
  border-radius: 7px;
  font-size: .8rem;
  font-weight: 900;
  letter-spacing: .052em;
  text-transform: uppercase;
}

.modal h2 { margin: 12px 0 9px; font-size: clamp(2.1rem, 6vw, 3.5rem); line-height: 1; }
.modal p { margin: 0; color: #466352; text-wrap: pretty; }

.help-tips {
  display: grid;
  gap: 11px;
  margin: 18px 0 2px;
  padding: 0;
  list-style: none;
}

.help-tips li {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid #dce2c4;
  color: #344e3f;
  font-size: .9rem;
}

.help-tips li strong { font-weight: 900; }
.help-tips kbd { min-height: 19px; background: #e9edc8; border-color: #f5f8e5; }

.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.modal-stat { min-width: 0; padding: 8px 11px; background: #ecedcf; border-radius: 10px; }
.modal-stat span, .modal-stat strong { display: block; }
.modal-stat span { color: #4e6952; font-size: .8rem; font-weight: 750; }
.modal-stat strong { color: var(--ink); font-weight: 900; font-variant-numeric: tabular-nums; }

.modal-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 22px; }
.noscript { position: fixed; z-index: 11; top: 45%; left: 10%; padding: 18px; color: var(--ink); background: var(--cream); }

@media (pointer: coarse), (max-width: 650px) {
  .control-strip { display: none; }

  .touch-controls {
    position: fixed;
    z-index: 4;
    inset: auto max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    pointer-events: none;
  }

  .direction-pad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(2, 44px);
    gap: 4px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .direction-pad button, .touch-bark {
    display: grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid #fff4d48a;
    border-radius: 12px;
    box-shadow: 0 2px 0 #132f26b3;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    -webkit-touch-callout: none;
  }

  .direction-pad button {
    color: var(--cream);
    background: #1a4233dc;
    font: 800 1.35rem/1 var(--text-font);
  }

  .direction-pad button.is-pressed { color: var(--ink); background: var(--lime); }
  .direction-pad button:first-child { grid-column: 2; }
  .direction-pad button:nth-child(2) { grid-row: 2; grid-column: 1; }
  .direction-pad button:nth-child(3) { grid-row: 2; grid-column: 2; }
  .direction-pad button:nth-child(4) { grid-row: 2; grid-column: 3; }

  .touch-bark {
    min-width: 65px;
    min-height: 62px;
    padding: 6px;
    color: var(--ink);
    background: var(--lime);
    border-radius: 18px;
    font-weight: 900;
    line-height: 1;
  }

  .touch-bark.is-pressed { background: var(--cream); }
  .touch-bark.is-cooling { background: #f0ce80; }
  .touch-bark svg { width: 20px; height: 20px; }
}

@media (max-width: 700px) {
  :root { --edge: clamp(14px, 4vw, 25px); --frame: 15px; }

  .top-bar { inset-inline: max(var(--edge), env(safe-area-inset-left)) max(var(--edge), env(safe-area-inset-right)); }
  .brand-mark { width: 40px; height: 40px; border-radius: 13px; }
  .brand-mark svg { width: 32px; height: 32px; }
  .brand-name { font-size: 1.05rem; }
  .top-actions { gap: 6px; }
  .guide-button { padding-right: 11px; }
  .guide-button span { display: none; }
  .menu-copy h1 { font-size: clamp(3.4rem, 9.2vw, 5.4rem); }
  .menu-copy p { margin-bottom: 16px; }
  .breed-card { gap: 6px; padding-inline: 6px; }
  .breed-copy strong { font-size: .81rem; }
  .dog-avatar { flex-basis: 34px; width: 34px; height: 35px; }
  .dog-avatar::before { left: 5px; }
  .dog-avatar::after { right: 5px; }
  .dog-avatar i { inset: 8px 5px 5px; }
  .dog-avatar b { left: 9px; }
  .dog-avatar small { inset: 27px 6px 0; }
}

@media (max-width: 580px) {
  .color-wash::before { background: linear-gradient(0deg, rgba(13, 39, 28, .9), rgba(17, 55, 35, .78) 25%, rgba(22, 57, 38, .46) 54%, transparent 73%); }
  .menu { bottom: max(21px, calc(env(safe-area-inset-bottom) + 9px)); }
  .menu-copy h1 { font-size: clamp(3.15rem, 11.3vw, 4.35rem); }
  .breed-grid { gap: 5px; }
  .breed-card { min-height: 59px; }
  .start-button { width: 100%; }
  .game-hud { top: max(69px, calc(env(safe-area-inset-top) + 54px)); }
  .objectives { top: max(171px, calc(env(safe-area-inset-top) + 155px)); }
  .toast { top: 43%; }
}

@media (max-width: 420px) {
  .breed-card { flex-direction: column; align-items: center; gap: 4px; min-height: 81px; padding: 5px 4px 7px; text-align: center; }
  .dog-avatar { flex: 0 0 35px; }
  .breed-copy strong { font-size: .78rem; }
  .breed-copy small { font-size: .72rem; }
}

@media (max-height: 650px) and (min-width: 581px) {
  .menu { bottom: max(17px, env(safe-area-inset-bottom)); }
  .menu-copy h1 { font-size: clamp(3.2rem, 9.8vh, 5.2rem); }
  .menu-copy p { margin: 9px 0 14px; }
  .breed-picker { margin-bottom: 11px; }
  .breed-picker legend { margin-bottom: 7px; }
  .breed-card { min-height: 49px; padding-block: 4px; }
  .start-button { min-height: 47px; }
}

@media (max-height: 470px) and (min-width: 581px) {
  .menu { width: min(415px, calc(100vw - var(--edge) * 2)); }
  .menu-copy h1 { font-size: clamp(2.4rem, 11.9vh, 3.55rem); }
  .menu-copy h1 br { display: none; }
  .breed-copy strong { font-size: .76rem; }
  .breed-copy small { font-size: .7rem; }
  .menu-copy p { max-width: unset; }
  .brand { margin-top: -4px; }
  .brand-mark { width: 39px; height: 39px; }
  .brand-mark svg { width: 32px; height: 32px; }
  .brand-name { font-size: 1.02rem; }
  .help-tips { gap: 6px; }
  .modal { padding: 19px 23px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}
