/* Bluey Brick Adventure — UI styling */
:root {
  --blue: #3d78d8;
  --blue-dark: #2a4a8c;
  --blue-light: #82b9ec;
  --red: #d5443c;
  --orange: #f08026;
  --yellow: #f5c542;
  --green: #4faf46;
  --cream: #fdf6e4;
  --ink: #25305a;
  --shadow: 0 6px 0 rgba(37, 48, 90, .28);
  --radius: 18px;
  font-size: clamp(14px, 1.6vmin + 9px, 19px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #7cc4ef;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: none; }

/* ---------------------------------------------------------------- HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: none;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
  align-items: flex-start; justify-content: space-between;
  gap: 8px;
}
#hud.show { display: flex; }
.hud-left, .hud-center, .hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hud-right { justify-content: flex-end; }

.hud-pill {
  display: flex; align-items: center; gap: 6px;
  background: rgba(253, 246, 228, .94);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 800;
  font-size: 1rem;
  box-shadow: 0 3px 0 rgba(37, 48, 90, .3);
}
.hud-pill .ic { width: 1.15em; height: 1.15em; }
.hud-pill.bones { color: #a06a00; }
.hud-pill.bones .ic { color: #e8a812; }
.hud-pill.stickers .ic { color: #f2b705; }
.hud-pill .quota { opacity: .55; font-weight: 700; }
.hud-pill.timer { font-variant-numeric: tabular-nums; min-width: 7ch; justify-content: center; }
.hud-pill .paw { font-size: 1rem; line-height: 1; }

/* ---------------------------------------------------------------- screens */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.2rem;
  padding: 2rem 1rem;
  pointer-events: auto;
}
.screen.show { display: flex; animation: screenIn .35s ease both; }
@keyframes screenIn { from { opacity: 0; transform: scale(1.03); } to { opacity: 1; transform: none; } }

.screen-title {
  font-size: clamp(1.5rem, 4vmin, 2.4rem);
  color: #fff;
  text-shadow: 0 3px 0 var(--blue-dark), 0 6px 14px rgba(0,0,0,.25);
  letter-spacing: .02em;
}

.panel {
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 24px 50px rgba(20, 40, 90, .35);
  padding: 1.6rem 1.8rem;
  display: flex; flex-direction: column; gap: 1rem;
  align-items: stretch;
  min-width: min(30rem, 92vw);
  max-height: 88vh;
  overflow: auto;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  pointer-events: auto;
  font: inherit;
  font-weight: 900;
  font-size: 1.05rem;
  color: #fff;
  background: var(--blue);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: .7em 1.6em;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--blue-dark);
  transition: transform .08s, box-shadow .08s, filter .15s;
  letter-spacing: .02em;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.btn.big { font-size: 1.35rem; padding: .75em 2.2em; background: var(--orange); box-shadow: 0 6px 0 #a34f0e; border-radius: 16px; }
.btn.big:active { box-shadow: 0 1px 0 #a34f0e; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #b9b09a; }
.btn.ghost:active { box-shadow: 0 1px 0 #b9b09a; }
.btn.danger { background: var(--red); box-shadow: 0 5px 0 #7c1f1a; }
.btn.danger:active { box-shadow: 0 1px 0 #7c1f1a; }
.btn.small { font-size: .9rem; }
.menu-col { display: flex; flex-direction: column; gap: .8rem; align-items: center; }
.menu-row { display: flex; gap: .8rem; flex-wrap: wrap; justify-content: center; }

/* ---------------------------------------------------------------- title */
#screen-title { justify-content: space-between; padding: 8vh 1rem 6vh; }
.logo-wrap { text-align: center; }
.logo-studs { display: flex; gap: 14px; justify-content: center; margin-bottom: 10px; }
.logo-studs i {
  width: 26px; height: 14px; border-radius: 7px;
  background: linear-gradient(#ffe289, #f2b705);
  border: 2px solid var(--ink);
  animation: studBob 2.4s ease-in-out infinite;
}
.logo-studs i:nth-child(2) { animation-delay: .12s; }
.logo-studs i:nth-child(3) { animation-delay: .24s; }
.logo-studs i:nth-child(4) { animation-delay: .36s; }
.logo-studs i:nth-child(5) { animation-delay: .48s; }
@keyframes studBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.logo {
  font-size: clamp(2.6rem, 9.5vmin, 5.4rem);
  line-height: .95;
  color: #fff;
  letter-spacing: .04em;
  text-align: center;
  text-shadow:
    0 4px 0 var(--blue-dark),
    0 8px 0 rgba(42, 74, 140, .45),
    0 16px 30px rgba(0, 0, 0, .3);
  animation: logoBounce 3s ease-in-out infinite;
}
.logo .logo-sub {
  display: block;
  font-size: .48em;
  color: var(--yellow);
  text-shadow: 0 3px 0 #9c6d00, 0 8px 18px rgba(0,0,0,.3);
  letter-spacing: .35em;
  margin: .1em 0;
}
@keyframes logoBounce { 0%, 100% { transform: translateY(0) rotate(-.6deg); } 50% { transform: translateY(-8px) rotate(.6deg); } }
.tagline { color: #fff; font-weight: 700; text-shadow: 0 2px 0 rgba(42, 74, 140, .6); margin-top: .6rem; font-size: 1.05rem; }
.controls-hint {
  color: rgba(255, 255, 255, .92);
  font-size: .85rem;
  background: rgba(37, 48, 90, .45);
  padding: .5em 1em; border-radius: 999px;
  backdrop-filter: blur(2px);
}
.controls-hint b { color: var(--yellow); }

/* ---------------------------------------------------------------- character select */
.char-row { display: flex; gap: 1.4rem; flex-wrap: wrap; justify-content: center; }
.char-card {
  pointer-events: auto;
  font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  width: 13.5rem;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(37, 48, 90, .3);
  transition: transform .12s, box-shadow .12s;
}
.char-card:hover { transform: translateY(-4px); }
.char-card .face { width: 7.5rem; height: 7.5rem; }
.char-card .char-name { font-size: 1.5rem; font-weight: 900; }
.char-card .char-blurb { font-size: .8rem; opacity: .75; text-align: center; font-weight: 600; }
.char-card.bluey .char-name { color: var(--blue); }
.char-card.bingo .char-name { color: var(--orange); }
.char-card.selected { outline: 5px solid var(--yellow); transform: translateY(-6px) scale(1.04); }
.char-card.selected::after {
  content: "✓ Picked!";
  position: absolute; margin-top: -2.6rem;
  background: var(--yellow); color: var(--ink);
  font-weight: 900; font-size: .75rem;
  padding: .2em .8em; border-radius: 999px; border: 2px solid var(--ink);
}
.char-card { position: relative; }

/* ---------------------------------------------------------------- level map */
#screen-map .screen-title { margin-bottom: .2rem; }
.map-vignette { position: absolute; inset: 0; background: radial-gradient(transparent 55%, rgba(20, 40, 90, .28)); pointer-events: none; }
.map-node {
  pointer-events: auto;
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: .55rem .9rem;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(37, 48, 90, .3);
  transition: transform .12s;
  min-width: 8.5rem;
}
.map-node:hover { transform: translate(-50%, -50%) scale(1.08); z-index: 5; }
.map-node:active { transform: translate(-50%, -50%) scale(.97); }
.map-node .node-ic { font-size: 1.7rem; line-height: 1.1; }
.map-node .node-name { font-weight: 900; font-size: .85rem; white-space: nowrap; }
.map-node .node-best { font-size: .65rem; font-weight: 700; opacity: .7; }
.map-node .node-stars { display: flex; gap: 2px; }
.map-node.bonus { background: #ffe9f1; border-color: #b0446e; }
.map-node.locked { filter: grayscale(.85) brightness(.92); cursor: not-allowed; }
.map-node .node-lock { display: none; font-size: 1rem; }
.map-node.locked .node-lock { display: block; position: absolute; top: -10px; right: -8px; }
.map-actions { margin-top: auto; align-self: flex-end; padding-bottom: 2vh; }

.star {
  display: inline-block;
  width: 1rem; height: 1rem;
  background: #d8d2c2;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transition: background .2s, transform .2s;
}
.star.earned { background: var(--yellow); filter: drop-shadow(0 1px 0 #a06a00); }
.star.big { width: 3rem; height: 3rem; }
.star.pop { animation: starPop .5s cubic-bezier(.2, 2.2, .4, 1) both; }
@keyframes starPop { from { transform: scale(0) rotate(-120deg); } to { transform: scale(1) rotate(0); } }

/* ---------------------------------------------------------------- settings */
.settings-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .7rem 1.2rem;
  align-items: center;
  font-weight: 700;
}
.settings-grid input[type="range"] {
  pointer-events: auto;
  width: 100%;
  accent-color: var(--orange);
  height: 1.4rem;
}
.settings-grid .switch { width: 1.5rem; height: 1.5rem; accent-color: var(--green); justify-self: start; }

/* ---------------------------------------------------------------- results */
#results-stars { justify-content: center; gap: .8rem; display: flex; }
.results-stats { display: flex; flex-direction: column; gap: .45rem; }
.res-row {
  display: flex; justify-content: space-between; gap: 2rem;
  background: #fff;
  border: 2px solid #d8d2c2;
  border-radius: 10px;
  padding: .45rem .9rem;
  font-weight: 700;
}
.res-row b { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- intro + toast */
#intro {
  position: absolute; top: 18%; left: 50%;
  transform: translate(-50%, 0) scale(.9);
  background: rgba(253, 246, 228, .96);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 2rem;
  text-align: center;
  opacity: 0;
  transition: opacity .4s, transform .4s;
  pointer-events: none;
  max-width: min(92vw, 30rem);
}
#intro.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#intro h3 { font-size: 1.6rem; }
#intro p { font-weight: 700; opacity: .75; }
#intro .intro-goal { color: var(--blue-dark); opacity: 1; margin-top: .3rem; }

#toast {
  position: absolute; bottom: 22%; left: 50%;
  transform: translate(-50%, 20px);
  background: rgba(37, 48, 90, .92);
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  padding: .55em 1.4em;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- touch */
#touch { position: absolute; inset: 0; display: none; }
body.is-touch #touch.show, #touch.show { display: block; }
#touch-joy {
  position: absolute;
  left: max(4vw, 16px); bottom: max(4vh, 16px);
  width: clamp(96px, 24vmin, 132px);
  height: clamp(96px, 24vmin, 132px);
  border-radius: 50%;
  background: rgba(253, 246, 228, .35);
  border: 3px solid rgba(253, 246, 228, .7);
  pointer-events: auto;
  touch-action: none;
}
#touch-joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 44%; height: 44%;
  border-radius: 50%;
  background: var(--cream);
  border: 3px solid var(--ink);
  transform: translate(-50%, -50%);
  box-shadow: 0 3px 0 rgba(37, 48, 90, .35);
}
.touch-right {
  position: absolute;
  right: max(4vw, 16px); bottom: max(4vh, 16px);
  display: flex; align-items: flex-end; gap: 12px;
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  font: inherit; font-weight: 900;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
}
.tbtn.rot { width: clamp(48px, 11vmin, 60px); height: clamp(48px, 11vmin, 60px); font-size: 1.2rem; }
.tbtn.jump {
  width: clamp(76px, 18vmin, 96px); height: clamp(76px, 18vmin, 96px);
  background: var(--orange); color: #fff;
  font-size: 1rem;
  box-shadow: 0 5px 0 #a34f0e;
}
.tbtn.jump:active { transform: translateY(3px); box-shadow: 0 1px 0 #a34f0e; }
.tbtn.pause {
  position: absolute;
  top: max(10px, env(safe-area-inset-top)); right: 14px;
  width: 44px; height: 44px;
  font-size: .95rem;
  display: none;
}
body.is-touch #touch.show ~ * .tbtn.pause, #touch.show .tbtn.pause { display: block; }
#touch .tbtn.pause { display: block; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 640px), (max-height: 480px) {
  .char-card { width: 9.5rem; padding: .8rem; }
  .char-card .face { width: 5.2rem; height: 5.2rem; }
  .controls-hint { display: none; }
  #screen-title { padding-top: 12vh; }
  .map-node { min-width: 6.5rem; padding: .4rem .6rem; }
  .map-node .node-name { font-size: .7rem; }
  .map-node .node-ic { font-size: 1.3rem; }
}

@media (orientation: portrait) {
  .hud-pill { font-size: .85rem; padding: 4px 10px; }
  #hud { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .logo, .logo-studs i, .screen.show, .star.pop { animation: none !important; }
}
