:root {
  --bg-1: #fff7fb;
  --bg-2: #e8fff7;
  --bg-3: #fff4d8;
  --ink: #2f2637;
  --muted: #7d7187;
  --pink: #ff6ea8;
  --pink-dark: #e64b8a;
  --mint: #53dfb9;
  --yellow: #ffd76b;
  --glass: rgba(255, 255, 255, 0.68);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --shadow: 0 10px 28px rgba(85, 49, 92, 0.08);
  --soft-border: rgba(255, 255, 255, 0.72);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: var(--app-height, 100svh);
  min-height: var(--app-height, 100svh);
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 170, 205, 0.55), transparent 26%),
    radial-gradient(circle at 88% 14%, rgba(108, 231, 197, 0.5), transparent 23%),
    radial-gradient(circle at 50% 100%, rgba(255, 216, 113, 0.48), transparent 32%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2) 52%, var(--bg-3));
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: var(--app-height, 100svh);
  min-height: var(--app-height, 100svh);
  max-height: var(--app-height, 100svh);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(max(8px, env(safe-area-inset-top)) + 12px) 12px calc(max(10px, env(safe-area-inset-bottom)) + var(--browser-bottom-pad, 0px));
  isolation: isolate;
}

.app-shell::before,
.app-shell::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(4px);
  opacity: 0.82;
  pointer-events: none;
}

.app-shell::before {
  width: 180px;
  height: 180px;
  left: -74px;
  bottom: 11%;
  background: rgba(255, 110, 168, 0.2);
}

.app-shell::after {
  width: 210px;
  height: 210px;
  right: -82px;
  top: 22%;
  background: rgba(83, 223, 185, 0.2);
}

.hud {
  width: min(100%, 480px);
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  z-index: 3;
}

.back-button,
.brand-pill,
.score-card,
.next-card {
  min-height: 60px;
  display: flex;
  align-items: center;
  border: 1px solid var(--soft-border);
  background: var(--glass);
  box-shadow: 0 8px 22px rgba(68, 41, 80, 0.07);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.back-button {
  min-width: 64px;
  justify-content: center;
  gap: 0;
  padding: 7px;
  border-radius: 24px;
  color: var(--ink);
  position: relative;
  overflow: hidden;
}

.back-button::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 30% 27%, rgba(255, 255, 255, 0.95), transparent 24%),
    linear-gradient(145deg, rgba(255, 105, 158, 0.34), rgba(255, 216, 113, 0.18) 48%, rgba(83, 223, 185, 0.26));
}

.back-button::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 13px;
  width: 13px;
  height: 8px;
  border-radius: 80% 20% 80% 20%;
  background: #59c96d;
  transform: rotate(24deg);
  opacity: .92;
}

.back-arrow {
  position: relative;
  z-index: 1;
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #ffffff;
  background: linear-gradient(135deg, #ff6ea8, #ff9d35);
  font-size: 25px;
  line-height: 1;
  font-weight: 1000;
  transform: translateX(-1px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 6px 14px rgba(230,75,138,.22);
}

.back-button:active {
  transform: scale(0.985);
}

.brand-pill {
  gap: 8px;
  padding: 8px 10px;
  border-radius: 22px;
}

.brand-icon-only {
  justify-content: center;
  padding: 8px;
}

.brand-pill img {
  flex: 0 0 auto;

}

.brand-pill strong,
.score-card strong {
  display: block;
  line-height: 1;
}

.brand-pill strong {
  font-size: 15px;
  letter-spacing: -0.02em;
}

.brand-pill span,
.score-card span,
.next-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.score-card {
  justify-content: center;
  flex-direction: column;
  padding: 8px 10px;
  border-radius: 20px;
}

.score-card strong {
  margin-top: 2px;
  font-size: clamp(30px, 11vw, 44px);
  letter-spacing: -0.06em;
}

.next-card {
  justify-content: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 20px;
}

.next-card img {
  width: 34px;
  height: 34px;
  object-fit: contain;

}

.game-stage {
  position: relative;
  width: min(100%, 480px);
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 10px;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0.2)),
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.92), transparent 34%);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.danger-label {
  position: absolute;
  left: 50%;
  top: 18.9%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  color: rgba(218, 55, 96, 0.76);
  background: rgba(255, 255, 255, 0.54);
  border: 1px solid rgba(255, 99, 139, 0.22);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.16em;
  pointer-events: none;
  opacity: 0.86;
}

.screen-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(255, 245, 250, 0.3);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.screen-overlay.is-visible {
  display: flex;
}

.panel {
  width: min(100%, 430px);
  max-height: min(calc(var(--app-height, 100svh) - 28px), 780px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 34px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.72)),
    radial-gradient(circle at top left, rgba(255, 126, 178, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(83, 223, 185, 0.18), transparent 28%);
  box-shadow: 0 28px 90px rgba(73, 40, 87, 0.22);
}

.loading-panel,
.hero-panel {
  padding: 34px 24px 26px;
  text-align: center;
}

.hero-panel .primary-btn {
  margin-top: 12px;
}

.leave-panel {
  padding: 28px 22px 22px;
  text-align: center;
}

.leave-badge {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255, 110, 168, 0.18), rgba(83, 223, 185, 0.18));
  border: 1px solid rgba(255,255,255,.82);
  font-size: 28px;
}

.leave-panel .secondary-btn {
  margin-top: 10px;
}

.hero-wordmark,
.loading-wordmark {
  display: block;
  width: min(82vw, 330px);
  height: auto;
  margin: 0 auto 6px;
}

.panel h1,
.panel h2 {
  margin: 10px 0 4px;
  line-height: 0.96;
  letter-spacing: -0.08em;
}

.panel h1 {
  font-size: clamp(44px, 13vw, 68px);
}

.panel h2 {
  font-size: clamp(34px, 10vw, 48px);
}

.panel p {
  margin: 8px auto 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.35;
}

.primary-btn,
.secondary-btn {
  width: 100%;
  min-height: 54px;
  margin-top: 18px;
  border-radius: 19px;
  font-weight: 1000;
  letter-spacing: -0.02em;
  transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease;
}

.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  box-shadow: 0 16px 34px rgba(230, 75, 138, 0.28);
}

.secondary-btn {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 26px rgba(71, 46, 85, 0.12);
}

.primary-btn:active,
.secondary-btn:active {
  transform: scale(0.985);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.loader-bar {
  width: 100%;
  height: 10px;
  margin-top: 22px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
}

.loader-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--pink), var(--yellow), var(--mint));
  animation: loaderMove 1.1s ease-in-out infinite alternate;
}

@keyframes loaderMove {
  from { transform: translateX(-18%); }
  to { transform: translateX(160%); }
}

.mini-leaderboard {
  margin-top: 18px;
  display: grid;
  gap: 7px;
}

.mini-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.76);
  color: var(--ink);
  font-weight: 900;
}

.mini-row span:nth-child(2) {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}


.mini-row em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mini-king {
  min-height: 62px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .76), rgba(255,255,255,.52)),
    radial-gradient(circle at 15% 20%, rgba(255, 216, 113, .32), transparent 36%);
}

.king-crown {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 216, 113, .44);
  font-size: 18px;
}

.game-over-panel {
  padding: 18px;
}

.game-over-head {
  text-align: center;
  padding: 10px 4px 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 12px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #ff8abd, #ffb85f);
  font-size: 12px;
  font-weight: 1000;
  box-shadow: 0 10px 22px rgba(255, 105, 158, 0.24);
}

.leaderboard-box,
.submit-form {
  padding: 12px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.84);
  background: rgba(255, 255, 255, 0.56);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title strong {
  font-size: 15px;
  letter-spacing: -0.02em;
}

.section-title span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-height: 42px;
  padding: 7px 10px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.leaderboard-row.is-empty {
  color: var(--muted);
}

.rank {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 216, 113, 0.36);
  font-weight: 1000;
  font-size: 13px;
}

.player-name {
  min-width: 0;
}

.player-name strong,
.player-name span {
  display: block;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.player-name strong {
  font-size: 14px;
  letter-spacing: -0.02em;
}

.player-name span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.player-score {
  font-weight: 1000;
  letter-spacing: -0.04em;
}


.leaderboard-toggle {
  width: 100%;
  min-height: 38px;
  margin-top: 9px;
  border-radius: 14px;
  color: var(--pink-dark);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.88);
  font-size: 13px;
  font-weight: 1000;
}

.play-again-cta {
  margin-top: 14px;
  box-shadow: 0 18px 40px rgba(230, 75, 138, 0.34);
}

.submit-form {
  display: none;
  margin-top: 12px;
}

.submit-form.is-visible {
  display: block;
}

.submit-form label {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 1000;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.submit-form input {
  width: 100%;
  height: 48px;
  margin-top: 5px;
  padding: 0 14px;
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.9);
  outline: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.submit-form input:focus {
  border-color: rgba(255, 110, 168, 0.58);
  box-shadow: 0 0 0 4px rgba(255, 110, 168, 0.12);
}

.form-message {
  min-height: 20px;
  font-size: 12px;
  font-weight: 900;
}

@media (min-width: 760px) {
  html,
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .app-shell {
    width: min(440px, calc(100vw - 36px));
    height: min(840px, calc(var(--app-height, 100svh) - 36px));
    min-height: min(840px, calc(var(--app-height, 100svh) - 36px));
    max-height: min(840px, calc(var(--app-height, 100svh) - 36px));
    padding: 18px 14px;
    border-radius: 34px;
    overflow: hidden;
    box-shadow: 0 22px 80px rgba(67, 42, 82, .16);
    background:
      radial-gradient(circle at 12% 18%, rgba(255, 170, 205, 0.38), transparent 28%),
      radial-gradient(circle at 88% 14%, rgba(108, 231, 197, 0.36), transparent 26%),
      linear-gradient(160deg, rgba(255,247,251,.88), rgba(232,255,247,.86) 52%, rgba(255,244,216,.88));
  }

  .hud,
  .game-stage {
    width: 100%;
    max-width: 412px;
  }

  .game-stage {
    max-height: none;
    border-radius: 30px;
  }

  .screen-overlay {
    position: absolute;
    inset: 0;
    border-radius: 34px;
  }
}

@media (max-width: 370px) {
  .hud {
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 10px;
  }

  .back-button,
  .brand-pill,
  .score-card {
    min-height: 56px;
    border-radius: 20px;
  }

  .score-card strong {
    font-size: clamp(28px, 10vw, 40px);
  }

  .panel {
    border-radius: 28px;
  }
}


/* V12: mobile keyboard + desktop frame polish */
input {
  user-select: text;
  -webkit-user-select: text;
  font-size: 16px;
}

body.keyboard-open {
  touch-action: pan-y;
}

body.keyboard-open .screen-overlay.is-visible {
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(8px, env(safe-area-inset-top)) 14px 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

body.keyboard-open .game-over-panel {
  width: min(100%, 430px);
  max-height: none;
  overflow: visible;
  border-radius: 28px;
  padding: 14px;
  margin: 0 auto 12px;
}

body.keyboard-open .game-over-head {
  padding: 6px 4px 10px;
}

body.keyboard-open .leaderboard-box {
  max-height: 178px;
  overflow: auto;
}

body.keyboard-open .submit-form input {
  height: 46px;
}

body.keyboard-open .play-again-cta {
  margin-top: 10px;
}

@media (min-width: 760px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    height: 100%;
    overflow: auto;
    padding: 0;
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    background:
      radial-gradient(circle at 20% 16%, rgba(255, 170, 205, 0.32), transparent 28%),
      radial-gradient(circle at 80% 18%, rgba(108, 231, 197, 0.28), transparent 26%),
      linear-gradient(160deg, #fff9fc, #f1fffb 54%, #fff7df);
  }

  .app-shell {
    width: min(390px, calc(100vw - 88px));
    height: min(760px, calc(100vh - 88px));
    height: min(760px, calc(100dvh - 88px));
    min-height: 620px;
    max-height: 760px;
    margin: auto;
    padding: 16px 13px;
    border-radius: 38px;
    flex: 0 0 auto;
    box-shadow: 0 30px 110px rgba(67, 42, 82, .18), inset 0 1px 0 rgba(255,255,255,.72);
    border: 1px solid rgba(255,255,255,.82);
  }

  .hud,
  .game-stage {
    width: 100%;
    max-width: none;
  }

  .hud {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 10px;
  }

  .back-button,
  .score-card {
    min-height: 56px;
  }

  .score-card strong {
    font-size: 40px;
  }

  .game-stage {
    margin-top: 10px;
    border-radius: 32px;
  }

  .panel {
    width: min(100%, 360px);
    max-height: calc(100% - 26px);
  }

  .hero-wordmark,
  .loading-wordmark {
    width: min(280px, 78vw);
  }
}

@media (min-width: 1120px) and (min-height: 780px) {
  .app-shell {
    width: 400px;
    height: 780px;
  }
}
