/* ===========================================================
   Lumi's Cake Kick — UI layer
   Everything here floats above the WebGL canvas.
   =========================================================== */

:root {
  --yellow: #ffd23f;
  --yellow-deep: #f0a500;
  --teal: #12b5a5;
  --teal-deep: #0a7d75;
  --pink: #ff6f9c;
  --pink-deep: #e03e75;
  --cream: #fff8e7;
  --ink: #3b2a1e;
  --ink-soft: #6b5445;
  --shadow: 0 6px 0 rgba(59, 42, 30, 0.22), 0 14px 30px rgba(59, 42, 30, 0.28);
  --round: 22px;
  font-family: "Nunito", "Baloo 2", "Trebuchet MS", "Avenir Next Rounded",
    system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

html, body {
  height: 100%;
  height: 100dvh;              /* tracks mobile browser chrome sliding away */
  overflow: hidden;
  background: #8fd8ef;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;          /* no pinch zoom, no double-tap zoom */
  overscroll-behavior: none;   /* no pull-to-refresh mid-shot */
  -webkit-touch-callout: none; /* no long-press callout on the sprites */
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;             /* stops iOS rubber-banding the whole page */
  inset: 0;
  width: 100%;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ---------------- Full screens ---------------- */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 90px 20px 24px;
  z-index: 30;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 245, 210, 0.55), transparent 60%),
    linear-gradient(180deg, #7ecdf0 0%, #a8e6c9 100%);
}

#title {
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(255, 255, 255, 0.55), transparent 55%),
    linear-gradient(180deg, rgba(126, 205, 240, 0.85) 0%, rgba(168, 230, 201, 0.8) 100%);
  backdrop-filter: blur(3px);
}

/* ---------------- Loading ---------------- */

.loader-card { text-align: center; }

.loader-ball {
  width: 76px; height: 76px;
  margin: 0 auto 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, #fff 0 42%, #eee 43% 100%);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.15), var(--shadow);
  position: relative;
  animation: roll 1.1s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
.loader-ball::before {
  content: "";
  position: absolute; inset: 26%;
  background: #2f2a26;
  clip-path: polygon(50% 0%, 95% 35%, 78% 90%, 22% 90%, 5% 35%);
}
@keyframes roll {
  0%   { transform: translateY(0) rotate(0deg); }
  50%  { transform: translateY(-26px) rotate(180deg); }
  100% { transform: translateY(0) rotate(360deg); }
}

.loader-card h2 { font-size: 26px; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.18); }

.bar {
  width: min(320px, 70vw);
  height: 16px;
  margin: 16px auto 10px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 99px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15);
}
.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--yellow), var(--pink));
  transition: width 0.25s ease;
}
#load-label { color: #ffffffd0; font-size: 14px; font-weight: 700; letter-spacing: .3px; }

/* ---------------- Title card ---------------- */

.title-card {
  width: min(560px, 92vw);
  padding: 22px 26px 26px;
  text-align: center;
  background: var(--cream);
  border-radius: 34px;
  box-shadow: var(--shadow);
  border: 5px solid #fff;
  animation: pop 0.5s cubic-bezier(0.22, 1.4, 0.4, 1) both;
}
@keyframes pop {
  from { transform: scale(0.85) translateY(18px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

#lumi-portrait {
  width: 132px; height: 132px;
  object-fit: contain;
  margin-top: -78px;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.22));
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-8px) } }

.title-card h1 {
  display: flex; flex-direction: column; line-height: 0.94;
  font-weight: 900; letter-spacing: -1px; margin: 2px 0 8px;
}
h1 .lumi {
  font-size: clamp(34px, 8vw, 52px);
  color: var(--teal);
  text-shadow: 0 3px 0 var(--teal-deep);
  transform: rotate(-3deg);
}
h1 .cake {
  font-size: clamp(42px, 10vw, 66px);
  color: var(--pink);
  text-shadow: 0 4px 0 var(--pink-deep);
  transform: rotate(1.5deg);
}

.tagline { color: var(--ink-soft); font-weight: 700; font-size: 15px; margin-bottom: 18px; }

.big-btn {
  font: inherit;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #fff;
  padding: 14px 54px;
  border: none;
  border-radius: 99px;
  cursor: pointer;
  background: linear-gradient(180deg, #ffd85e, var(--yellow-deep));
  box-shadow: 0 7px 0 #c07d00, 0 12px 22px rgba(0, 0, 0, 0.25);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  animation: pulse 2s ease-in-out infinite;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 #c07d00, 0 6px 12px rgba(0,0,0,.25); }
@keyframes pulse { 0%,100% { filter: brightness(1) } 50% { filter: brightness(1.08) } }

.how {
  margin-top: 20px;
  display: grid;
  gap: 8px;
  text-align: left;
  background: #fff;
  border-radius: var(--round);
  padding: 14px 16px;
  box-shadow: inset 0 0 0 2px #f0e6d2;
}
.how-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.how-row b { color: var(--ink); }
.how-ico { font-size: 20px; width: 26px; text-align: center; }

/* ---------------- HUD ---------------- */

#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  padding: env(safe-area-inset-top, 12px) 14px 14px;
}

.hud-left, .hud-right {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  display: flex;
  gap: 10px;
  align-items: center;
}
.hud-left { left: 14px; }
.hud-right { right: 14px; }

.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 9px;
  background: rgba(255, 248, 231, 0.92);
  border-radius: 99px;
  box-shadow: 0 4px 0 rgba(59, 42, 30, 0.18), 0 8px 18px rgba(0, 0, 0, 0.14);
  border: 3px solid #fff;
}
.stat img, .stat .ico { width: 30px; height: 30px; font-size: 24px; line-height: 30px; text-align: center; object-fit: contain; }
.stat div { display: flex; flex-direction: column; line-height: 1; }
.stat b { font-size: 21px; font-weight: 900; color: var(--ink); }
.stat small { font-size: 10px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.6px; }

.stat.bump { animation: bump 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes bump { 0% { transform: scale(1) } 40% { transform: scale(1.22) rotate(-3deg) } 100% { transform: scale(1) } }

#streak-stat.hot { background: linear-gradient(180deg, #fff0c2, #ffd7a0); }

#level-pill {
  padding: 8px 16px;
  background: rgba(18, 181, 165, 0.94);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  border-radius: 99px;
  border: 3px solid #fff;
  box-shadow: 0 4px 0 rgba(10, 125, 117, 0.6), 0 8px 18px rgba(0, 0, 0, 0.14);
}
#level-pill b { font-size: 17px; }

.icon-btn {
  pointer-events: auto;
  width: 46px; height: 46px;
  font-size: 21px;
  border: 3px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255, 248, 231, 0.92);
  box-shadow: 0 4px 0 rgba(59, 42, 30, 0.18);
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }

/* ---------------- Shot meter ---------------- */

#shot-meter {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(340px, 78vw);
  display: grid;
  gap: 7px;
  padding: 12px 16px;
  background: rgba(255, 248, 231, 0.9);
  border-radius: var(--round);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
}
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row span { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); width: 46px; }
.meter { flex: 1; height: 14px; background: #e8dcc6; border-radius: 99px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.12); }
#power-fill { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, #8ee06a, var(--yellow), #ff6b4a); transition: width 0.04s linear; }
.meter.curve { position: relative; background: #e8dcc6; }
.meter.curve::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(0,0,0,.18); }
#curve-fill { position: absolute; top: 0; bottom: 0; left: 50%; width: 0%; background: linear-gradient(90deg, var(--teal), #6ee7d8); border-radius: 99px; }

/* ---------------- Hint + toast ---------------- */

.hint {
  position: absolute;
  left: 50%;
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
  transform: translateX(-50%);
  padding: 9px 20px;
  background: rgba(59, 42, 30, 0.7);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  border-radius: 99px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.hint.show { opacity: 1; }

.toast {
  position: absolute;
  left: 50%;
  top: 26%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: clamp(40px, 11vw, 92px);
  font-weight: 900;
  letter-spacing: -1px;
  color: #fff;
  text-shadow: 0 5px 0 var(--pink-deep), 0 10px 26px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { animation: toast 1.7s cubic-bezier(0.2, 1.5, 0.4, 1) forwards; }
@keyframes toast {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5) rotate(-8deg); }
  18%  { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(2deg); }
  32%  { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  78%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(0.9); }
}
.toast.miss { text-shadow: 0 5px 0 #4a7fb5, 0 10px 26px rgba(0, 0, 0, 0.35); }

/* ---------------- Level up ---------------- */

.levelup {
  position: fixed;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  z-index: 25;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 18px 46px;
  background: linear-gradient(180deg, #fff2b8, var(--yellow));
  border: 5px solid #fff;
  border-radius: var(--round);
  box-shadow: var(--shadow);
  animation: levelup 2.2s ease forwards;
}
.levelup b { font-size: 34px; font-weight: 900; color: var(--pink-deep); }
.levelup span { font-size: 14px; font-weight: 800; color: var(--ink-soft); }
@keyframes levelup {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(0.95); }
}

@media (max-width: 480px) {
  .stat { padding: 5px 10px 5px 7px; }
  .stat b { font-size: 17px; }
  .stat img, .stat .ico { width: 24px; height: 24px; font-size: 19px; line-height: 24px; }
  #level-pill { padding: 6px 12px; font-size: 12px; }
}

/* ===========================================================
   Halloween theme.
   The 3D scene is repainted from js/themes.js; this repaints
   the DOM layer on top of it.
   =========================================================== */

:root[data-theme="halloween"] {
  --yellow: #ff8c1a;
  --yellow-deep: #c25500;
  --teal: #9b5de5;
  --teal-deep: #5b2f96;
  --pink: #ff7a1a;
  --pink-deep: #b23c00;
  --cream: #241a3d;
  --ink: #f3ecff;
  --ink-soft: #b9a8dd;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.45), 0 14px 30px rgba(0, 0, 0, 0.6);
}

:root[data-theme="halloween"] body { background: #150f26; }

:root[data-theme="halloween"] .screen {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(155, 93, 229, 0.35), transparent 60%),
    linear-gradient(180deg, #1d1436 0%, #2b1b3f 100%);
}
:root[data-theme="halloween"] #title {
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(255, 140, 26, 0.28), transparent 55%),
    linear-gradient(180deg, rgba(29, 20, 54, 0.9) 0%, rgba(43, 27, 63, 0.85) 100%);
}

:root[data-theme="halloween"] .title-card { border-color: #3d2a5c; }
:root[data-theme="halloween"] .how {
  background: #1b1330;
  box-shadow: inset 0 0 0 2px #3d2a5c;
}
:root[data-theme="halloween"] .stat,
:root[data-theme="halloween"] .icon-btn,
:root[data-theme="halloween"] #shot-meter {
  background: rgba(36, 26, 61, 0.92);
  border-color: #4a3570;
}
:root[data-theme="halloween"] .meter { background: #3a2a5c; }
:root[data-theme="halloween"] #streak-stat.hot {
  background: linear-gradient(180deg, #5b2f96, #8a3d1f);
}
:root[data-theme="halloween"] #level-pill {
  background: rgba(155, 93, 229, 0.95);
  border-color: #d7c4ff;
  box-shadow: 0 4px 0 rgba(60, 25, 110, 0.7), 0 8px 18px rgba(0, 0, 0, 0.4);
}
:root[data-theme="halloween"] .theme-card { background: #241a3d; border-color: #4a3570; }

/* ---------------- Theme switch overlay ---------------- */

.theme-loading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(12, 8, 22, 0.72);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease both;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.theme-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 26px 40px 24px;
  background: var(--cream);
  border: 4px solid #fff;
  border-radius: 26px;
  box-shadow: var(--shadow);
}
.theme-card p { font-weight: 800; font-size: 15px; color: var(--ink); }
.theme-card .bar { margin: 0; width: 220px; }

.theme-spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--yellow);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ===========================================================
   Phones and tablets.

   Two shapes matter: upright (narrow, plenty of height) and
   landscape on a phone (wide, almost no height). The HUD has to
   shrink out of the way in both, and stay clear of notches.
   =========================================================== */

/* Notch / rounded-corner clearance, in every orientation. */
.hud-left  { left:  max(14px, env(safe-area-inset-left)); }
.hud-right { right: max(14px, env(safe-area-inset-right)); }
.hud-left, .hud-right { top: max(12px, env(safe-area-inset-top)); }

#shot-meter {
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 14px));
}

/* Give touch controls a proper target size (Apple/Google both want ~44px). */
@media (pointer: coarse) {
  .icon-btn { width: 52px; height: 52px; font-size: 24px; }
  .big-btn { padding: 18px 60px; }
  .how-row { font-size: 15px; }
}

/* ---- upright phone ---- */
@media (max-width: 560px) and (orientation: portrait) {
  .title-card { padding: 20px 18px 22px; border-radius: 28px; }
  #lumi-portrait { width: 112px; height: 112px; margin-top: -66px; }
  .tagline { font-size: 14px; margin-bottom: 14px; }
  .how { padding: 12px; gap: 7px; }

  /* There isn't room for five pills across a phone, so the scoreboard drops
     its captions and the level pill wraps onto a second line. */
  .hud-left { gap: 5px; }
  .stat { padding: 5px 10px 5px 6px; gap: 5px; border-width: 2px; }
  .stat b { font-size: 17px; }
  .stat small { display: none; }
  .stat img, .stat .ico { width: 22px; height: 22px; font-size: 18px; line-height: 22px; }

  .hud-right {
    gap: 6px;
    max-width: 46vw;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  #level-pill { order: 3; padding: 5px 12px; font-size: 11px; border-width: 2px; }
  #level-pill b { font-size: 14px; }
  .icon-btn { width: 46px; height: 46px; font-size: 21px; border-width: 2px; }

  #shot-meter { width: min(340px, 88vw); padding: 10px 12px; }
  .hint { bottom: max(104px, calc(env(safe-area-inset-bottom) + 104px)); font-size: 13px; }
  .toast { top: 22%; }
}

/* ---- phone on its side: height is the scarce resource ---- */
@media (max-height: 460px) and (orientation: landscape) {
  .screen { padding: 12px 20px; }
  .title-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 0 22px;
    width: min(720px, 94vw);
    padding: 14px 20px 16px;
  }
  #lumi-portrait { display: none; }
  .title-card h1 { grid-column: 1; margin: 0; }
  .tagline { grid-column: 1; margin-bottom: 10px; }
  #play-btn { grid-column: 1; font-size: 24px; padding: 10px 36px; }
  .how { grid-column: 2; grid-row: 1 / span 3; margin: 0; font-size: 12px; }
  .how-row { font-size: 12px; }

  .stat { padding: 4px 8px 4px 5px; }
  .stat b { font-size: 15px; }
  .stat small { display: none; }
  .icon-btn { width: 42px; height: 42px; font-size: 19px; }
  #shot-meter { width: min(320px, 52vw); padding: 8px 12px; gap: 4px; }
  .meter-row span { width: 40px; font-size: 10px; }
  .hint { bottom: 74px; }
  .toast { top: 20%; font-size: clamp(32px, 8vw, 60px); }
  .levelup { padding: 12px 30px; }
  .levelup b { font-size: 26px; }
}

/* Landscape on a phone hides the loading card's breathing room too. */
@media (max-height: 460px) {
  .screen { padding-top: 20px; }
  .loader-ball { width: 54px; height: 54px; margin-bottom: 14px; }
  .loader-card h2 { font-size: 20px; }
}
