:root {
  --ink: #2b1d14;
  --paper: #fff6e8;
  --accent: #ff8a3d;
  --accent-dark: #d9621b;
  --muted: #8c7462;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
}

.hidden { display: none !important; }

button { font: inherit; cursor: pointer; }

/* HUD */
#hud {
  position: fixed;
  top: calc(8px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  right: calc(10px + var(--safe-r));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
}
.hud-left, .hud-mid, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(43, 29, 20, .72);
  color: var(--paper);
  padding: 6px 10px;
  border-radius: 14px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.hud-left { flex-direction: column; align-items: flex-start; gap: 4px; min-width: 150px; }
#hud-level { font-size: 13px; font-weight: 700; opacity: .9; }
.goal { display: flex; align-items: center; gap: 8px; }
.bar { width: 120px; height: 10px; border-radius: 6px; background: rgba(255,255,255,.18); overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd25e, var(--accent)); transition: width .25s; }
#hud-count { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-mid { gap: 12px; }
#hud-hearts { font-size: 18px; letter-spacing: 2px; }
#hud-noise { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.nbar { width: 80px; height: 8px; border-radius: 5px; background: rgba(255,255,255,.18); overflow: hidden; }
#noise-fill { height: 100%; width: 0; background: #7bd389; transition: width .15s, background .3s; }
#hud-noise.warn #noise-fill { background: #ff5a4a; }
#hud-noise.warn { animation: pulse .5s infinite alternate; }
@keyframes pulse { to { color: #ff8a7a; } }
#hud-score { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.icon-btn {
  pointer-events: auto;
  border: 0;
  background: rgba(255,255,255,.12);
  color: var(--paper);
  width: 34px; height: 34px;
  border-radius: 10px;
  font-size: 16px;
  display: grid; place-items: center;
  padding: 0;
}

/* Touch controls */
#touch { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#stick-zone {
  position: absolute;
  left: 0; top: 70px; bottom: 0;
  width: 50%;
  pointer-events: auto;
  touch-action: none;
}
#stick-base {
  position: absolute;
  width: 120px; height: 120px;
  margin: -60px 0 0 -60px;
  left: calc(110px + var(--safe-l));
  bottom: auto;
  top: calc(100% - 100px - var(--safe-b));
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: 2px solid rgba(255,255,255,.28);
  transition: opacity .2s;
  opacity: .55;
}
#stick-base.active { opacity: 1; transition: none; }
#stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255,246,232,.85);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.tbtn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  border: 2px solid rgba(255,255,255,.35);
  border-radius: 50%;
  color: var(--paper);
  display: grid; place-items: center;
  padding: 0;
  -webkit-user-select: none;
}
.tbtn.down { transform: scale(.92); filter: brightness(1.3); }
#btn-jump {
  width: 92px; height: 92px;
  right: calc(24px + var(--safe-r));
  bottom: calc(26px + var(--safe-b));
  background: rgba(255,138,61,.55);
  font-size: 40px;
  font-weight: 800;
}
#btn-paw {
  width: 74px; height: 74px;
  right: calc(132px + var(--safe-r));
  bottom: calc(18px + var(--safe-b));
  background: rgba(255,255,255,.18);
  font-size: 32px;
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
  background: rgba(30, 20, 14, .55);
  overflow-y: auto;
  touch-action: pan-y;
}
#menu { background: radial-gradient(circle at 50% 30%, #6b4a33, #2b1d14 75%); }
.card {
  background: var(--paper);
  border-radius: 24px;
  padding: 20px 26px 22px;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
h1 { margin: 4px 0 6px; font-size: clamp(26px, 5vw, 40px); line-height: 1.05; }
h1 span { color: var(--accent-dark); }
h2 { margin: 2px 0 10px; font-size: 26px; }
.lead { margin: 0 0 14px; color: var(--muted); }
.buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 8px 0 4px; }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 22px;
  font-size: 18px;
  font-weight: 800;
  background: #eadbc6;
  color: var(--ink);
  min-width: 140px;
}
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); }
.btn:active { transform: translateY(2px); }
.controls { margin-top: 14px; font-size: 14px; color: var(--muted); line-height: 1.7; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 5px;
  border-radius: 5px;
  background: #eadbc6;
  color: var(--ink);
  font: 600 12px/20px ui-monospace, Menlo, monospace;
  margin: 0 1px;
}
.best { margin-top: 10px; font-weight: 700; color: var(--accent-dark); min-height: 1em; }
body.touch .desktop-only { display: none; }
body:not(.touch) .touch-only { display: none; }

.cat-preview {
  width: 173px; height: 136px;
  margin: -6px auto -4px;
  background: url(assets/cat.png) 0 0 / 692px 544px no-repeat;
  animation: catwalk .9s steps(1) infinite;
  transform: scale(.8);
}
@keyframes catwalk {
  0%   { background-position: 0 -136px; }
  25%  { background-position: -173px -136px; }
  50%  { background-position: -346px -136px; }
  75%  { background-position: -519px -136px; }
}

#ov-body { color: var(--muted); font-size: 16px; line-height: 1.6; }
#ov-body .stats { display: grid; grid-template-columns: auto auto; gap: 2px 18px; justify-content: center; margin: 6px 0 10px; text-align: left; }
#ov-body .stats b { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }

#rotate-hint {
  display: none;
  position: fixed;
  left: 50%; bottom: calc(150px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(43,29,20,.85);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}
@media (orientation: portrait) {
  body.touch.playing #rotate-hint { display: block; }
}

@media (max-height: 430px) {
  .card { padding: 12px 18px 14px; }
  .cat-preview { margin: -18px auto -18px; transform: scale(.6); }
  .controls { margin-top: 8px; line-height: 1.5; font-size: 13px; }
  .lead { display: none; }
  h2 { font-size: 22px; margin-bottom: 6px; }
}
@media (max-width: 600px) {
  .hud-left { min-width: 0; padding: 5px 8px; }
  .bar { width: 70px; }
  #hud-level { font-size: 11px; }
  .nbar { width: 50px; }
  .hud-mid, .hud-right { padding: 5px 8px; }
}

/* Level select, stars, sound toggles */
.levels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0 2px;
}
.level-chip {
  border: 0;
  border-radius: 14px;
  background: #eadbc6;
  color: var(--ink);
  padding: 8px 4px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.level-chip .n { font-size: 18px; font-weight: 900; }
.level-chip .t { font-size: 12px; font-weight: 700; }
.level-chip .s { font-size: 13px; color: var(--accent-dark); letter-spacing: 1px; }
.level-chip.locked { opacity: .45; cursor: default; }
.level-chip:not(.locked):active { transform: translateY(2px); }
#ov-body .stars { font-size: 34px; color: #f4a623; letter-spacing: 4px; line-height: 1.1; margin-bottom: 4px; }
#ov-body .hint { font-size: 13px; margin-bottom: 6px; }
#btn-music.off { opacity: .4; text-decoration: line-through; }
@media (max-width: 420px) {
  .levels { grid-template-columns: repeat(2, 1fr); }
}

/* Bonus tasks */
#hud-tasks { font-size: 12px; font-weight: 700; color: #ffd25e; letter-spacing: .5px; white-space: nowrap; }
#hud-tasks:empty { display: none; }
#ov-body ul.tasks { list-style: none; padding: 0; margin: 6px auto 10px; text-align: left; display: inline-block; font-size: 15px; }
#ov-body ul.tasks li { margin: 2px 0; }
#ov-body ul.tasks li.ok { color: var(--ink); font-weight: 700; }
#ov-body ul.tasks li i { font-style: normal; opacity: .7; }

/* Overlay never taller than the screen: the body scrolls, buttons stay put. */
#overlay .card {
  max-height: calc(100dvh - 24px - var(--safe-t) - var(--safe-b));
  display: flex;
  flex-direction: column;
}
#ov-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
#ov-buttons { flex: 0 0 auto; }
.result-side p.next { margin: 4px 0 2px; font-size: 14px; }

/* Results side by side on short landscape screens. */
@media (orientation: landscape) and (max-height: 560px) {
  #overlay .card { max-width: 760px; padding: 12px 20px 14px; }
  #overlay h2 { font-size: 21px; margin: 0 0 4px; }
  .result { display: grid; grid-template-columns: auto 1fr; gap: 6px 22px; align-items: center; text-align: left; }
  #ov-body .stars { font-size: 26px; text-align: center; }
  #ov-body .stats { margin: 2px 0; font-size: 14px; gap: 0 14px; }
  #ov-body ul.tasks { margin: 0; font-size: 13px; display: block; }
  #ov-body { font-size: 14px; line-height: 1.45; }
  #ov-buttons .btn { padding: 9px 18px; font-size: 16px; }
}

/* Fullscreen */
.menu-fs {
  position: fixed;
  top: calc(10px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  z-index: 11;
  width: 42px; height: 42px;
  border: 0; border-radius: 12px;
  background: rgba(255,255,255,.15);
  color: var(--paper);
  font-size: 20px;
}
#fs-hint {
  position: fixed;
  left: 50%; top: calc(60px + var(--safe-t));
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(92vw, 460px);
  background: rgba(43,29,20,.94);
  color: var(--paper);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
}
