/* styles.css — little LETTERS client shell.
 *
 * One token scale drives every size/color/radius/font in this file (see
 * :root below) — screens should never hardcode a raw px/color. Screens are
 * shown/hidden purely via the `.screen.active` class (router.js toggles
 * it); each screen module builds its own inner markup at mount time, so
 * this file only needs one generic `.screen` layout plus per-screen
 * decoration classes.
 */

:root {
  /* Palette */
  --plum: #5C2648;
  --teal: #42bdb8;
  --gold: #fbd868;
  --pink: #ff009e;
  --ink: var(--plum);
  --bg: #fff;

  /* Spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 16px;
  --s4: 24px;
  --s5: 32px;
  --s6: 48px;

  /* Radius scale */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  /* Type scale */
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 28px;
  --fs-2xl: 40px;
  --fs-hero: 64px;
  --font: ui-rounded, "SF Pro Rounded", "Baloo 2", system-ui, sans-serif;

  /* Layout */
  --max-width: 480px;
  --tap-min: 56px;

  /* Shadow */
  --shadow-card: 0 20px 60px rgba(0, 0, 0, .35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

h1,
h2,
p {
  margin: 0;
}

img {
  max-width: 100%;
}

button {
  font-family: inherit;
}

/* Honor prefers-reduced-motion everywhere, not just the splash screen --
   every future animation (including the play-loop cluster's) gets this for
   free without having to remember to opt in per-rule. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ── Screens ─────────────────────────────────────────────────────────── */

#screens {
  position: relative;
  max-width: var(--max-width);
  margin-inline: auto;
}

.screen {
  display: none;
  position: relative;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  text-align: center;
  padding: calc(var(--nb-topbar-h, 0px) + var(--s5)) var(--s4) var(--s5);
  min-height: calc(100vh - var(--nb-topbar-h, 0px));
  min-height: calc(100dvh - var(--nb-topbar-h, 0px));
}

.screen.active {
  display: flex;
}

/* A soft "phone in a room" frame once there's room for it, so the app
   still looks intentional (not just narrow content adrift) on desktop. */
@media (min-width: 560px) {
  body {
    background: linear-gradient(180deg, var(--teal) 0%, var(--plum) 100%);
  }

  #screens {
    background: var(--bg);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-block: var(--s5);
  }
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--s3) var(--s5);
  border: none;
  border-radius: var(--radius-pill);
  background: var(--teal);
  color: var(--bg);
  font-weight: 800;
  font-size: var(--fs-md);
  cursor: pointer;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--teal) 60%, black);
  transition: transform .08s ease, box-shadow .08s ease;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--teal) 60%, black);
}

.btn-lg {
  font-size: var(--fs-lg);
}

.btn-primary {
  background: var(--pink);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--pink) 60%, black);
}

.btn-primary:active {
  box-shadow: 0 2px 0 color-mix(in srgb, var(--pink) 60%, black);
}

.btn-secondary {
  background: var(--gold);
  color: var(--plum);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--gold) 60%, black);
}

.btn-secondary:active {
  box-shadow: 0 2px 0 color-mix(in srgb, var(--gold) 60%, black);
}

.btn:disabled,
.btn-dimmed {
  opacity: .55;
  filter: grayscale(.4);
  cursor: not-allowed;
  transform: none;
}

.btn-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-min);
  height: var(--tap-min);
  flex: none;
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--teal) 15%, white);
  cursor: pointer;
}

.icon-btn img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.pill-soon {
  display: inline-block;
  margin-left: var(--s2);
  padding: 2px var(--s2);
  border-radius: var(--radius-pill);
  background: var(--plum);
  color: var(--bg);
  font-size: var(--fs-sm);
  font-weight: 700;
  vertical-align: middle;
}

/* ── Modal (nickname entry) ─────────────────────────────────────────── */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  background: rgba(44, 16, 34, .6);
}

.modal.active {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 320px;
  padding: var(--s5) var(--s4);
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: var(--shadow-card);
  text-align: center;
}

.modal-card h2 {
  margin-bottom: var(--s4);
  font-size: var(--fs-lg);
}

.modal-card input {
  width: 100%;
  min-height: var(--tap-min);
  margin-bottom: var(--s4);
  padding: 0 var(--s3);
  border: 2px solid color-mix(in srgb, var(--teal) 50%, white);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--fs-md);
  text-align: center;
}

.modal-card input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ── Splash ──────────────────────────────────────────────────────────── */

.splash-bg {
  background-image: url("img/bg-splash.png");
  background-size: cover;
  background-position: center;
  gap: var(--s5);
}

.splash-wordmark {
  width: min(70vw, 320px);
  height: auto;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .25));
}

.splash-blocks {
  display: flex;
  gap: var(--s2);
}

.splash-block {
  width: 40px;
  height: 40px;
  object-fit: contain;
  animation: ll-tumble .6s cubic-bezier(.34, 1.56, .64, 1) both;
}

@keyframes ll-tumble {
  0% {
    transform: translateY(-160px) rotate(-30deg);
    opacity: 0;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
}

.splash-giftbox {
  width: min(50vw, 220px);
  height: auto;
}

/* ── Home ────────────────────────────────────────────────────────────── */

.settings-btn {
  position: absolute;
  top: calc(var(--nb-topbar-h, 0px) + var(--s3));
  right: var(--s3);
}

.home-greeting {
  font-size: var(--fs-2xl);
}

.home-highscore {
  color: color-mix(in srgb, var(--ink) 70%, transparent);
  font-size: var(--fs-md);
  margin-bottom: var(--s3);
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  width: 100%;
}

/* ── Play (placeholder) ─────────────────────────────────────────────── */

.play-placeholder {
  font-size: var(--fs-lg);
  font-weight: 700;
}

/* ── Results ─────────────────────────────────────────────────────────── */

.results-score-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.results-burst {
  position: absolute;
  z-index: 0;
  width: min(80vw, 320px);
}

.results-score {
  position: relative;
  z-index: 1;
  font-size: var(--fs-hero);
  font-weight: 900;
  color: var(--pink);
}

.results-new-high {
  color: var(--plum);
  background: var(--gold);
  border-radius: var(--radius-pill);
  padding: var(--s1) var(--s4);
  font-weight: 800;
  font-size: var(--fs-lg);
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  width: 100%;
  margin-top: var(--s3);
}

/* ── Leaderboard ─────────────────────────────────────────────────────── */

.lb-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
}

.lb-header h1 {
  flex: 1;
  font-size: var(--fs-xl);
}

.lb-tabs {
  display: flex;
  gap: var(--s2);
  width: 100%;
}

.lb-tab {
  flex: 1;
  min-height: var(--tap-min);
  padding: var(--s2) var(--s3);
  border: 2px solid var(--plum);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--plum);
  font-weight: 800;
  font-size: var(--fs-md);
  cursor: pointer;
}

.lb-tab.active {
  background: var(--plum);
  color: var(--bg);
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--teal) 10%, white);
}

.lb-row-you {
  border: 2px solid var(--gold);
  background: color-mix(in srgb, var(--gold) 25%, white);
  font-weight: 800;
}

.lb-rank {
  width: 2.5em;
  flex: none;
  color: var(--plum);
  font-weight: 800;
}

.lb-nickname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.lb-score {
  flex: none;
  color: var(--teal);
  font-weight: 800;
}

.lb-status {
  padding: var(--s5);
  color: color-mix(in srgb, var(--ink) 60%, transparent);
  text-align: center;
}

/* ── Play (camera loop) ─────────────────────────────────────────────── */
#screen-play {
  padding: var(--nb-topbar-h, 0px) 0 0;
  gap: 0;
}
.play-root {
  position: relative;
  width: 100%;
  height: calc(100dvh - var(--nb-topbar-h, 0px));
  overflow: hidden;
  background: #160c12;
  border-radius: inherit;
  touch-action: manipulation;
  user-select: none;
}
.play-video,
.play-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.play-video.mirrored {
  transform: scaleX(-1);
}
.play-scene {
  background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--teal)
    40%, #160c12), #160c12 70%);
}
.play-scene::after {
  content: "debug scene — tap anywhere";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: color-mix(in srgb, var(--gold) 80%, white);
  font-weight: 700;
  opacity: .7;
}
.play-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding: var(--s3);
  pointer-events: none;
  background: linear-gradient(180deg, rgba(22,12,18,.55), transparent);
}
.hud-timer {
  position: relative;
  width: 56px;
  height: 56px;
  flex: none;
}
.hud-timer-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.hud-timer-track {
  fill: none;
  stroke: rgba(255,255,255,.25);
  stroke-width: 6;
}
.hud-timer-fill {
  fill: none;
  stroke: var(--teal);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset .12s linear;
}
.hud-timer-low .hud-timer-fill {
  stroke: var(--pink);
}
.hud-timer-low .hud-timer-num {
  color: var(--pink);
}
.hud-timer-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: #fff;
  font-size: var(--fs-md);
}
.hud-letter-img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.4));
}
.hud-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s1);
  flex: none;
}
.hud-score-num {
  color: #fff;
  font-weight: 900;
  font-size: var(--fs-xl);
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.hud-stars {
  display: flex;
  align-items: center;
  gap: 2px;
}
.hud-star-img {
  width: 22px;
  height: 22px;
}
.hud-star-num {
  color: var(--gold);
  font-weight: 800;
}
.play-prompt {
  position: absolute;
  left: 50%;
  bottom: var(--s6);
  transform: translateX(-50%);
  max-width: 90%;
  padding: var(--s2) var(--s4);
  border-radius: var(--radius-pill);
  background: rgba(22,12,18,.7);
  color: #fff;
  font-size: var(--fs-lg);
  font-weight: 700;
  pointer-events: none;
}
.play-prompt b {
  color: var(--gold);
}
.play-word {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%,-50%);
  display: flex;
  gap: var(--s1);
  pointer-events: none;
}
.play-word-block {
  width: 48px;
  height: 48px;
  object-fit: contain;
  animation: ll-drop .5s cubic-bezier(.34,1.56,.64,1) both;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.4));
}
@keyframes ll-drop {
  0% {
    transform: translateY(-120px) rotate(-20deg);
    opacity: 0;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translateY(0) rotate(0);
    opacity: 1;
  }
}
.play-feedback {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  padding: var(--s2) var(--s4);
  border-radius: var(--radius-pill);
  background: var(--plum);
  color: #fff;
  font-weight: 800;
  pointer-events: none;
  max-width: 90%;
}
.play-feedback.shake {
  animation: ll-shake .4s both;
}
@keyframes ll-shake {
  0%,
  100% {
    transform: translate(-50%,-50%);
  }
  25% {
    transform: translate(calc(-50% - 8px),-50%);
  }
  50% {
    transform: translate(calc(-50% + 8px),-50%);
  }
  75% {
    transform: translate(calc(-50% - 6px),-50%);
  }
}
.play-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--s6) + 64px);
  transform: translateX(-50%);
  pointer-events: none;
}
.play-hint-bubble {
  background: var(--gold);
  color: var(--plum);
  font-weight: 800;
  padding: var(--s2) var(--s4);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--gold) 60%, black);
}
.play-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}
.play-flash.on {
  animation: ll-flash .25s ease-out;
}
@keyframes ll-flash {
  0% {
    opacity: .9;
  }
  100% {
    opacity: 0;
  }
}
.play-flip {
  position: absolute;
  right: var(--s3);
  bottom: var(--s3);
  z-index: 4;
  background: rgba(255,255,255,.85);
}
.play-back {
  position: absolute;
  left: var(--s3);
  bottom: var(--s3);
  z-index: 4;
  background: rgba(255,255,255,.85);
}
.play-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(22,12,18,.72);
  padding: var(--s4);
}
.play-overlay[hidden] {
  display: none;
}
.play-overlay-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s5) var(--s4);
  border-radius: var(--radius-lg);
  background: var(--bg);
  text-align: center;
}
.play-overlay-card h2 {
  color: var(--plum);
  font-size: var(--fs-2xl);
}
.play-gameover {
  flex-direction: column;
  gap: var(--s3);
  color: #fff;
}
.play-gameover-img {
  width: min(60vw, 240px);
}
.play-star-pop {
  position: absolute;
  left: 50%;
  top: 30%;
  width: 56px;
  height: 56px;
  transform: translate(-50%,-50%);
  pointer-events: none;
  z-index: 3;
  animation: ll-star-pop .9s ease-out both;
}
@keyframes ll-star-pop {
  0% {
    transform: translate(-50%,-50%) scale(.3);
    opacity: 0;
  }
  30% {
    transform: translate(-50%,-70%) scale(1.2);
    opacity: 1;
  }
  100% {
    transform: translate(-50%,-140%) scale(1);
    opacity: 0;
  }
}

/* ── Play: growing letter tower + recognized-name toast ─────────────── */
.play-tower {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  z-index: 2;
  width: min(92%, 420px);
  max-height: 46%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  overflow-y: auto;
  pointer-events: none;
  padding: var(--s2);
}
.play-tower::-webkit-scrollbar {
  display: none;
}
.tower-word {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  background: rgba(22, 12, 18, .35);
}
.tower-block {
  width: 30px;
  height: 30px;
  object-fit: contain;
}
.tower-block.drop {
  animation: ll-drop .45s cubic-bezier(.34, 1.56, .64, 1) both;
}
.play-name {
  position: absolute;
  left: 50%;
  top: 66%;
  transform: translate(-50%, -50%);
  z-index: 3;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
  padding: var(--s2) var(--s4);
  border-radius: var(--radius-pill);
  background: var(--teal);
  color: #fff;
  font-weight: 900;
  font-size: var(--fs-xl);
  word-break: break-word;
}
.play-name[hidden] {
  display: none;
}
