:root {
  --ink: #5a341c;
  --ink-soft: #7a5133;
  --card: #fffaf2;
  --line: #6b3e22;
  --orange: #ff8a2a;
  --orange-deep: #d86512;
  --sky: #49b7f5;
  --good: #7bcf4a;
  --warn: #ffb703;
  --low: #ff6b6b;
  --shadow: 0 8px 0 var(--line);
  font-family: Nunito, "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #67b85a;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
  z-index: 0;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}

.panel, .score, #goal, .icon-btn, .pad, #bark, .card, .settings-panel {
  background: var(--card);
  border: 4px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.meters {
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ico, .score-ico {
  font-size: 34px;
  line-height: 1;
  width: 42px;
  text-align: center;
  filter: drop-shadow(0 2px 0 rgba(90, 52, 28, 0.15));
}

.meter-name, .score-label, #hint {
  font-weight: 800;
  color: var(--ink-soft);
}

.meter-name { font-size: 16px; line-height: 1; margin-bottom: 4px; }

.track {
  width: 168px;
  height: 20px;
  border-radius: 999px;
  background: #f3e7d4;
  border: 3px solid var(--line);
  overflow: hidden;
  position: relative;
}

.fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  position: relative;
  transition: width 0.18s linear;
}

.fill.hunger { background: linear-gradient(180deg, #ffd166, #ff9f1c); }
.fill.thirst { background: linear-gradient(180deg, #8be0ff, #3aa0f5); }
.fill.low { background: linear-gradient(180deg, #ffd0d0, #ff6b6b); }

.fill::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 3px;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.55);
}

.meter.low .ico { animation: wiggle 0.45s ease-in-out infinite; }
.meter.low .meter-name { color: #e3503a; }

.carry {
  font-weight: 900;
  font-size: 18px;
  color: var(--ink);
  background: #fff1d2;
  border-radius: 14px;
  padding: 6px 10px;
}

.scores {
  display: flex;
  gap: 8px;
}

.score {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 10px 10px;
  min-width: 168px;
}

.score-num {
  font-weight: 900;
  font-size: 40px;
  line-height: 0.9;
  color: var(--ink);
}

.score-num.pop { animation: numpop 0.35s ease; }

.score-label { font-size: 15px; line-height: 1.1; }

.hud-actions {
  position: relative;
  margin-left: auto;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 4;
  width: max-content;
  min-width: 196px;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  pointer-events: auto;
  text-align: left;
}

.settings-panel[hidden] { display: none; }

.settings-title {
  margin: 0 0 2px;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.settings-label {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  color: var(--ink-soft);
}

.settings-sound {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#settings.is-open {
  background: var(--orange);
  color: #fff;
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--orange-deep);
}

.icon-btn {
  pointer-events: auto;
  width: 58px;
  height: 58px;
  border-radius: 20px;
  padding: 0;
  cursor: pointer;
  color: var(--ink);
  display: grid;
  place-items: center;
}

.icon-btn svg { width: 32px; height: 32px; display: block; }
#mute .icon-off, #full .icon-exit { display: none; }
#mute.is-muted .icon-on { display: none; }
#mute.is-muted .icon-off { display: block; }
#full.is-full .icon-enter { display: none; }
#full.is-full .icon-exit { display: block; }

.icon-btn:active, .pad:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--line); }

#pad {
  display: none;
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(176px, 46vw);
  height: min(176px, 46vw);
  pointer-events: none;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 6px;
}

.pad {
  pointer-events: auto;
  border-radius: 22px;
  padding: 0;
  cursor: pointer;
  position: relative;
  touch-action: none;
}

.pad::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-style: solid;
}

.pad.up { grid-column: 2; grid-row: 1; }
.pad.down { grid-column: 2; grid-row: 3; }
.pad.left { grid-column: 1; grid-row: 2; }
.pad.right { grid-column: 3; grid-row: 2; }

.pad.up::before { border-width: 0 10px 16px; border-color: transparent transparent var(--ink) transparent; transform: translate(-50%, -60%); }
.pad.down::before { border-width: 16px 10px 0; border-color: var(--ink) transparent transparent transparent; transform: translate(-50%, -40%); }
.pad.left::before { border-width: 10px 16px 10px 0; border-color: transparent var(--ink) transparent transparent; transform: translate(-60%, -50%); }
.pad.right::before { border-width: 10px 0 10px 16px; border-color: transparent transparent transparent var(--ink); transform: translate(-40%, -50%); }

body.touch #pad { display: grid; }

#goal {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 12px 28px;
  font-size: 30px;
  font-weight: 900;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  text-align: center;
}

#hint {
  position: absolute;
  right: 112px;
  bottom: max(28px, env(safe-area-inset-bottom));
  font-size: 13px;
  background: rgba(255, 250, 242, 0.82);
  border-radius: 999px;
  padding: 6px 10px;
}

#bark {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border-radius: 28px;
  pointer-events: auto;
  cursor: pointer;
  color: white;
  background: var(--orange);
  font: 900 26px/1 Nunito, "Segoe UI", sans-serif;
  text-shadow: 0 2px 0 rgba(120, 50, 10, 0.25);
  touch-action: none;
}

#bark:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--orange-deep); }

#toast {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  font-size: 46px;
  font-weight: 900;
  color: var(--ink);
  background: #fffef8;
  border: 4px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 10px 26px;
  opacity: 0;
}

#toast.show { animation: toast 1.7s ease; }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 16px 16px;
  background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.05), rgba(36, 90, 40, 0.28));
  transition: opacity 0.35s ease;
  overflow: auto;
}

#overlay.hide {
  opacity: 0;
  pointer-events: none;
}

.card {
  width: min(640px, 100%);
  padding: 26px 28px 24px;
  text-align: center;
}

.eyebrow {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #e07a2f;
  font-size: 14px;
}

h1 {
  margin: 2px 0 4px;
  font-size: 40px;
  line-height: 0.95;
  font-weight: 900;
}

#pup {
  width: 168px;
  height: 128px;
  display: block;
  margin: 0 auto;
}

.pick-label {
  margin: 2px 0 6px;
  font-size: 16px;
  font-weight: 900;
}

.swatches, .langs, .lang-mini {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.langs { margin-bottom: 8px; flex-wrap: wrap; }

.lang-btn, .swatch {
  pointer-events: auto;
  cursor: pointer;
  border: 4px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: 900 16px/1 Nunito, "Segoe UI", sans-serif;
}

.lang-btn {
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 0 4px 0 var(--line);
}

.lang-btn.on {
  background: var(--orange);
  color: #fff;
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--orange-deep);
}

.swatch.on {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--orange-deep);
  outline: 4px solid var(--orange);
  outline-offset: 3px;
}

.swatch {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--line);
  padding: 0;
  display: grid;
  place-items: center;
}

.lang-mini { pointer-events: auto; gap: 4px; }
.settings-panel .lang-mini { justify-content: flex-start; }
.settings-panel .icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  flex: none;
}
.settings-panel .icon-btn svg { width: 26px; height: 26px; }
.lang-mini .lang-btn {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 16px;
}

#play { margin-top: 8px; }

.lead {
  margin: 12px auto 10px;
  max-width: 520px;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink-soft);
}

.tips {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.tips li {
  display: flex;
  gap: 12px;
  align-items: center;
  background: #fff4e2;
  border-radius: 18px;
  padding: 8px 12px;
  font-size: 18px;
  font-weight: 800;
}

.tips span {
  font-size: 28px;
  width: 40px;
  text-align: center;
  flex: none;
}

#play {
  pointer-events: auto;
  appearance: none;
  border: 4px solid var(--line);
  background: var(--orange);
  color: white;
  font: 900 40px/1 Nunito, "Segoe UI", sans-serif;
  padding: 16px 28px;
  border-radius: 999px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 8px 0 var(--orange-deep);
  animation: bob 1.5s ease-in-out infinite;
  text-shadow: 0 2px 0 rgba(120, 50, 10, 0.25);
}

#play:hover { filter: brightness(1.05); }
#play:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 var(--orange-deep);
  animation: none;
}

#err {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  background: #fff;
  color: #8d2b2b;
  border: 3px solid #8d2b2b;
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 800;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

@keyframes numpop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes toast {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.9); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(0.98); }
}

@media (max-width: 980px) {
  h1 { font-size: 40px; }
  #goal { font-size: 22px; white-space: normal; padding: 8px 16px; }
  .score-num { font-size: 30px; }
  .score { min-width: 0; padding: 6px 10px 8px 8px; }
  #hint { display: none; }
  .track { width: 120px; }
  .ico, .score-ico { font-size: 26px; width: 30px; }
  .card { padding: 18px 16px 16px; }
  .lead, .tips li { font-size: 16px; }
  #play { font-size: 32px; padding: 14px 20px; }
}

body.touch #goal {
  left: auto;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(108px, calc(env(safe-area-inset-bottom) + 100px));
  transform: none;
  max-width: min(280px, calc(100% - 196px));
  font-size: 20px;
  padding: 10px 14px;
}

body.touch .icon-btn {
  width: 64px;
  height: 64px;
}

body.touch .lang-mini .lang-btn { width: 52px; height: 52px; font-size: 15px; }
body.touch .settings-panel .icon-btn { width: 52px; height: 52px; }
body.touch .swatch { width: 64px; height: 64px; }

@media (orientation: landscape) and (max-height: 520px) {
  body.touch #pad { width: 128px; height: 128px; }
  body.touch #goal { font-size: 16px; max-width: min(220px, calc(100% - 160px)); bottom: max(84px, calc(env(safe-area-inset-bottom) + 76px)); }
  #bark { width: 68px; height: 68px; font-size: 20px; }
  .topbar { gap: 6px; }
  .score-num { font-size: 26px; }
}
