/* ============================================================
   Capybara Dash — layout & UI chrome
   The game itself is drawn on <canvas>; this file styles the
   shell, the overlay screens and the touch controls.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #10121c;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

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

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;         /* keeps the chunky pixel-art feel */
  image-rendering: crisp-edges;
}

/* ---------------- Overlay screens ---------------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(12, 16, 34, 0.34);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
  animation: fadeIn .25s ease;
}

.screen.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.panel {
  width: min(560px, 94vw);
  max-height: 94vh;
  overflow: auto;
  text-align: center;
  padding: 26px 22px 22px;
  border-radius: 20px;
  background: linear-gradient(165deg, #fff6e0 0%, #ffe3b0 100%);
  color: #4a3218;
  border: 5px solid #7a4a1c;
  box-shadow: 0 14px 0 rgba(0, 0, 0, .28), 0 0 0 5px #ffd88a inset;
}

.title {
  font-size: clamp(34px, 9vw, 64px);
  line-height: 1;
  letter-spacing: 1px;
  color: #b3541e;
  text-shadow: 3px 3px 0 #ffd88a, 6px 6px 0 rgba(0, 0, 0, .18);
  animation: bob 2.2s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-1.2deg) }
  50%      { transform: translateY(-8px) rotate(1.2deg) }
}

.subtitle {
  margin: 6px 0 18px;
  font-size: clamp(13px, 3.4vw, 19px);
  font-weight: bold;
  color: #7a4a1c;
  letter-spacing: .5px;
}

.panel h2 {
  font-size: clamp(28px, 7vw, 44px);
  color: #b3541e;
  text-shadow: 2px 2px 0 #ffd88a;
}

.go-sub { margin: 4px 0 14px; font-size: 15px; color: #7a4a1c; }

/* ---------------- Buttons ---------------- */

.big-btn {
  display: block;
  width: min(300px, 80%);
  margin: 14px auto 10px;
  padding: 15px 20px;
  font: bold clamp(18px, 5vw, 26px)/1 "Trebuchet MS", sans-serif;
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(#7ec850, #4e9c2c);
  border: 4px solid #2f6a18;
  border-radius: 14px;
  box-shadow: 0 6px 0 #2f6a18;
  cursor: pointer;
  transition: transform .07s, box-shadow .07s, filter .15s;
}

.big-btn:hover   { filter: brightness(1.08); }
.big-btn:active  { transform: translateY(6px); box-shadow: 0 0 0 #2f6a18; }
.big-btn:focus-visible { outline: 3px dashed #b3541e; outline-offset: 4px; }

.icon-btn {
  position: absolute;
  top: 10px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
  color: #fff;
  background: rgba(20, 30, 55, .55);
  border: 2px solid rgba(255, 255, 255, .5);
  border-radius: 12px;
  cursor: pointer;
  z-index: 20;
}
.icon-btn:active { transform: scale(.92); }

#mute-btn  { right: 10px; }
#pause-btn { right: 62px; }

/* ---------------- Instructions ---------------- */

.controls-help {
  margin: 14px auto 6px;
  font-size: clamp(12px, 3.2vw, 15px);
  line-height: 1.75;
  color: #5c3d1c;
}
.controls-help b { color: #b3541e; }
.controls-help i { opacity: .8; font-size: .9em; }

.tip { font-size: clamp(11px, 3vw, 14px); color: #7a4a1c; margin-top: 8px; }

/* The premise needs to land before the player presses start, or the new
   hold-to-run mechanic reads as a broken auto-runner. */
.premise {
  margin: 0 auto 4px;
  max-width: 30em;
  font-size: clamp(13px, 3.4vw, 16px);
  line-height: 1.5;
  color: #6b3f14;
  background: rgba(255, 255, 255, .5);
  border: 2px dashed #d9a45b;
  border-radius: 12px;
  padding: 8px 10px;
}
.premise b { color: #b3541e; }

/* `b.key` is listed first so this beats `.controls-help b` on specificity —
   without it the keycap text inherits that rule's orange and vanishes against
   the orange keycap background. */
b.key, .key {
  display: inline-block;
  min-width: 1.4em;
  padding: 1px 6px;
  color: #fff;
  background: #b3541e;
  border-radius: 5px;
  box-shadow: 0 2px 0 #7a4a1c;
}

.rainbow {
  font-weight: bold;
  background: linear-gradient(90deg, #ff4d4d, #ffa63d, #ffe14d, #66e05e, #4dc3ff, #b06bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hiscore-line { margin-top: 10px; font-weight: bold; color: #b3541e; }

/* ---------------- Game over stats ---------------- */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px auto;
  max-width: 340px;
}
.stat-grid > div {
  background: rgba(255, 255, 255, .55);
  border: 2px solid #d9a45b;
  border-radius: 10px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: 11px; letter-spacing: 1.5px; color: #8a6533; }
.stat-val   { font-size: clamp(18px, 5vw, 24px); font-weight: bold; color: #b3541e; }

.new-best {
  font-weight: bold;
  color: #d18300;
  animation: pop .6s ease-in-out infinite alternate;
}
.new-best.hidden { display: none; }
@keyframes pop { from { transform: scale(1) } to { transform: scale(1.08) } }

/* ---------------- Touch controls ---------------- */

#touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  display: none;                    /* enabled from JS on touch devices */
  justify-content: space-between;
  padding: 0 14px 18px;
  z-index: 15;
  pointer-events: none;
}
#touch-controls.on { display: flex; }

.touch-group { display: flex; gap: 10px; align-items: flex-end; pointer-events: none; }

.touch-btn {
  pointer-events: auto;
  width: 96px;
  height: 72px;
  font: bold 17px/1.15 "Trebuchet MS", sans-serif;
  letter-spacing: 1px;
  color: #fff;
  background: rgba(30, 45, 80, .42);
  border: 3px solid rgba(255, 255, 255, .55);
  border-radius: 18px;
  cursor: pointer;
}
.touch-btn:active { background: rgba(120, 200, 255, .55); transform: scale(.95); }

/* RUN is the button that is held almost constantly, so it is the biggest
   target on screen and visually distinct from the two action buttons. */
.touch-btn.run {
  width: 122px;
  height: 92px;
  font-size: 19px;
  background: rgba(60, 150, 60, .5);
  border-color: rgba(190, 255, 190, .75);
}
.touch-btn.run:active { background: rgba(120, 240, 120, .62); }

@media (max-width: 420px) {
  .touch-btn { width: 78px; height: 64px; font-size: 15px; }
  .touch-btn.run { width: 104px; height: 82px; font-size: 17px; }
}

/* Hide touch buttons while an overlay screen is up */
#game-shell.overlay #touch-controls { display: none; }

@media (max-height: 430px) {
  .panel { padding: 14px 16px; }
  .controls-help { line-height: 1.5; margin: 8px auto 4px; }
  .big-btn { margin: 8px auto 6px; padding: 11px 16px; }
}
