@import url("https://fonts.googleapis.com/css2?family=Bungee&family=Fredoka:wght@500;600;700&display=swap");

:root {
  color-scheme: light;
  --ink: #2b174f;
  --ink-2: #4a236f;
  --cream: #fff6cf;
  --paper: #fff9df;
  --mint: #36e7bd;
  --cyan: #47d8f2;
  --sky: #55aaff;
  --blue: #2387ff;
  --sun: #ffe05b;
  --coral: #ff725f;
  --pink: #ff4fd8;
  --magenta: #ff2fa6;
  --grape: #5b35ff;
  --aqua: #24ffe2;
  --lime: #9be64b;
  --violet: #7958ff;
  --shadow: #1d113a;
  --soft-shadow: rgba(43, 23, 79, 0.2);
  --line: rgba(43, 23, 79, 0.22);
  --radius: 8px;
  --step-shadow: 7px 7px 0 var(--shadow);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "Fredoka", "Segoe UI", sans-serif;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.28) 0 2px, transparent 2px 72px),
    repeating-linear-gradient(0deg, rgba(43, 23, 79, 0.08) 0 2px, transparent 2px 64px),
    linear-gradient(135deg, rgba(255, 79, 216, 0.5), transparent 34%),
    linear-gradient(225deg, rgba(36, 255, 226, 0.45), transparent 38%),
    linear-gradient(180deg, #72e7f7 0%, #8cf0d1 34%, #ffe66f 68%, #ff8f74 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 0 48%, rgba(255, 255, 255, 0.34) 48% 52%, transparent 52% 100%) 0 0 / 160px 160px,
    linear-gradient(45deg, transparent 0 46%, rgba(43, 23, 79, 0.08) 46% 50%, transparent 50% 100%) 0 0 / 128px 128px;
  opacity: 0.6;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.6) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 18%, rgba(255, 224, 91, 0.72) 0 2px, transparent 3px),
    radial-gradient(circle at 84% 62%, rgba(255, 79, 216, 0.64) 0 2px, transparent 3px),
    radial-gradient(circle at 34% 78%, rgba(36, 255, 226, 0.6) 0 2px, transparent 3px);
  background-size: 170px 150px, 210px 180px, 190px 210px, 230px 170px;
  opacity: 0.58;
}

@keyframes background-party-shift {
  from {
    filter: saturate(1.05) hue-rotate(0deg);
  }
  to {
    filter: saturate(1.24) hue-rotate(8deg);
  }
}

@keyframes sparkle-field-drift {
  to {
    background-position: 170px 150px, -210px 180px, 190px -210px, -230px -170px;
  }
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(255, 224, 91, 0.95);
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
}

.game-backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
}

.app-copyright {
  position: fixed;
  left: max(4px, env(safe-area-inset-left, 0px));
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  z-index: 4;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: rgba(43, 23, 79, 0.82);
  font-size: 0.64rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  pointer-events: none;
  text-transform: none;
}

.game-backdrop::before,
.game-backdrop::after {
  content: "";
  position: absolute;
  left: -8%;
  right: -8%;
  height: 18%;
  border-top: 5px solid rgba(43, 23, 79, 0.22);
  background:
    repeating-linear-gradient(135deg, rgba(43, 23, 79, 0.12) 0 12px, transparent 12px 28px),
    linear-gradient(90deg, rgba(255, 246, 207, 0.64), rgba(255, 224, 91, 0.48));
}

.light-ribbon {
  position: absolute;
  left: -18%;
  width: 136%;
  height: 92px;
  border: 5px solid rgba(43, 23, 79, 0.24);
  border-left: 0;
  border-right: 0;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.78), transparent),
    repeating-linear-gradient(90deg, rgba(255, 79, 216, 0.78) 0 34px, rgba(255, 224, 91, 0.78) 34px 68px, rgba(36, 255, 226, 0.78) 68px 102px, rgba(121, 88, 255, 0.76) 102px 136px);
  box-shadow:
    0 0 28px rgba(255, 255, 255, 0.42),
    0 12px 0 rgba(43, 23, 79, 0.08);
  opacity: 0.62;
  mix-blend-mode: screen;
}

.ribbon-one {
  top: 22%;
  transform: rotate(-10deg);
}

.ribbon-two {
  top: 58%;
  transform: rotate(8deg);
}

.ribbon-three {
  bottom: 2%;
  height: 58px;
  opacity: 0.4;
  transform: rotate(-3deg);
}

@keyframes ribbon-glide {
  to {
    background-position: 420px 0, 420px 0;
  }
}

.game-backdrop::before {
  bottom: -7%;
  transform: rotate(-2deg);
}

.game-backdrop::after {
  bottom: -12%;
  transform: rotate(3deg);
  opacity: 0.7;
}

.sky-rail {
  position: absolute;
  left: -10%;
  width: 120%;
  height: 28px;
  border: 4px solid rgba(43, 23, 79, 0.26);
  background: repeating-linear-gradient(90deg, rgba(255, 246, 207, 0.72) 0 28px, rgba(255, 114, 95, 0.68) 28px 56px, rgba(54, 231, 189, 0.68) 56px 84px);
  box-shadow: 0 6px 0 rgba(43, 23, 79, 0.12);
}

.rail-one {
  top: 9%;
  transform: rotate(-7deg);
}

.rail-two {
  bottom: 21%;
  transform: rotate(6deg);
  opacity: 0.52;
}

.floating-token {
  position: absolute;
  display: grid;
  place-items: center;
  width: 78px;
  aspect-ratio: 1;
  color: white;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 2rem;
  line-height: 1;
  background: var(--token-bg, var(--coral));
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  clip-path: polygon(10% 0, 90% 0, 100% 10%, 100% 90%, 90% 100%, 10% 100%, 0 90%, 0 10%);
  box-shadow: var(--step-shadow);
  opacity: 0.9;
  animation: token-float 5s ease-in-out infinite;
}

.token-a {
  --token-bg: var(--coral);
  top: 16%;
  left: 3%;
  transform: rotate(-10deg);
}

.token-b {
  --token-bg: var(--sun);
  top: 9%;
  right: 11%;
  color: var(--ink);
  animation-delay: 0.5s;
}

.token-c {
  --token-bg: var(--mint);
  right: 3%;
  bottom: 25%;
  animation-delay: 1.1s;
}

.token-l {
  --token-bg: var(--violet);
  left: 44%;
  top: 16%;
  bottom: auto;
  animation: none;
  opacity: 0.86;
  z-index: 1;
}

.token-s {
  --token-bg: var(--pink);
  top: 16%;
  left: 53%;
  width: 58px;
  animation: none;
  opacity: 0.86;
  z-index: 1;
}

.floating-spark {
  position: absolute;
  width: 34px;
  aspect-ratio: 1;
  background: var(--sun);
  border: 4px solid var(--ink);
  clip-path: polygon(50% 0, 62% 35%, 100% 35%, 70% 56%, 82% 100%, 50% 74%, 18% 100%, 30% 56%, 0 35%, 38% 35%);
  box-shadow: 5px 5px 0 rgba(43, 23, 79, 0.24);
  animation: spark-twirl 3.4s ease-in-out infinite;
}

.spark-one {
  left: 23%;
  top: 13%;
}

.spark-two {
  right: 27%;
  bottom: 17%;
  animation-delay: 1s;
}

.spark-three {
  right: 6%;
  top: 46%;
  animation-delay: 1.8s;
}

@keyframes token-float {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -14px;
  }
}

@keyframes spark-twirl {
  0%,
  100% {
    rotate: -8deg;
    scale: 1;
  }
  50% {
    rotate: 10deg;
    scale: 1.08;
  }
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1540px, 100%);
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 4px 16px 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(270px, 1fr) minmax(360px, auto);
  gap: 14px;
  align-items: center;
}

.brand-text {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  width: 92px;
  height: 92px;
  flex: 0 0 auto;
  filter:
    drop-shadow(5px 6px 0 rgba(43, 23, 79, 0.28))
    drop-shadow(0 0 18px rgba(36, 255, 226, 0.42));
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.brand-text p,
.zone-label,
.topbar-stats span {
  margin: 0;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-text p {
  width: fit-content;
  padding: 6px 10px;
  color: var(--ink);
  background: var(--sun);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 rgba(43, 23, 79, 0.28);
}

.brand-text h1 {
  margin: 0;
  color: white;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 2.55rem;
  line-height: 1;
  letter-spacing: 0;
  text-shadow:
    3px 3px 0 var(--ink),
    6px 6px 0 var(--coral),
    9px 9px 0 rgba(43, 23, 79, 0.18),
    0 0 18px rgba(255, 255, 255, 0.42);
}

.hud-card {
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--step-shadow);
}

.topbar-stats {
  justify-self: end;
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: min(540px, 100%);
  padding: 8px;
  overflow: hidden;
}

.topbar-stats::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(135deg, rgba(255, 114, 95, 0.16) 0 10px, transparent 10px 22px),
    linear-gradient(90deg, rgba(54, 231, 189, 0.22), rgba(255, 224, 91, 0.18), rgba(35, 135, 255, 0.22));
}

.topbar-stats div {
  position: relative;
  z-index: 1;
  min-height: 78px;
  display: grid;
  place-items: center;
  gap: 3px;
  padding: 8px;
  text-align: center;
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 249, 223, 0.9);
  box-shadow:
    inset 0 -6px 0 rgba(43, 23, 79, 0.08),
    3px 3px 0 rgba(43, 23, 79, 0.16);
}

.topbar-stats div:nth-child(1) {
  background: linear-gradient(180deg, #fff9df, #b8f6dc);
}

.topbar-stats div:nth-child(2) {
  background: linear-gradient(180deg, #fff9df, #ffe78f);
}

.topbar-stats div:nth-child(3) {
  background: linear-gradient(180deg, #fff9df, #b9ddff);
}

.topbar-stats span {
  color: var(--ink-2);
  font-size: 0.8rem;
}

.topbar-stats strong {
  display: block;
  color: var(--ink);
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.74);
}

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 6px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow:
    var(--step-shadow),
    0 22px 36px rgba(43, 23, 79, 0.18);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.56) 0 10%, transparent 10% 78%, rgba(43, 23, 79, 0.08) 78% 100%),
    repeating-linear-gradient(90deg, rgba(43, 23, 79, 0.04) 0 2px, transparent 2px 34px);
  z-index: 0;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.camera-panel,
.mission-panel {
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
}

.camera-panel {
  background:
    linear-gradient(150deg, rgba(71, 216, 242, 0.9), rgba(54, 231, 189, 0.72) 48%, rgba(255, 246, 207, 0.96));
}

.mission-panel {
  background:
    linear-gradient(150deg, rgba(255, 224, 91, 0.86), rgba(71, 216, 242, 0.78) 48%, rgba(255, 249, 223, 0.96));
}

.camera-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  border: 8px solid var(--ink);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.82), transparent 18%),
    radial-gradient(circle at 84% 24%, rgba(255, 79, 216, 0.32), transparent 24%),
    radial-gradient(circle at 55% 82%, rgba(255, 224, 91, 0.36), transparent 28%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.7), transparent 18% 74%, rgba(255, 255, 255, 0.3) 74% 100%),
    repeating-linear-gradient(0deg, rgba(43, 23, 79, 0.08) 0 3px, transparent 3px 18px),
    linear-gradient(165deg, #dafcff 0%, #9cf2ff 44%, #7ee5d1 100%);
  box-shadow:
    inset 0 0 0 6px rgba(255, 255, 255, 0.52),
    inset 0 -22px 0 rgba(43, 23, 79, 0.1),
    5px 5px 0 rgba(43, 23, 79, 0.22),
    0 0 28px rgba(36, 255, 226, 0.34);
}

#webcam,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#webcam {
  z-index: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.camera-stage.is-live #webcam {
  opacity: 1;
}

#overlay {
  z-index: 2;
}

.camera-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
  color: #f4f8ff;
  background:
    linear-gradient(135deg, rgba(36, 33, 81, 0.9), rgba(23, 20, 61, 0.94)),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0 10px, transparent 10px 22px);
  transition: opacity 180ms ease;
}

.camera-empty::before {
  content: none;
}

.camera-empty::after {
  content: "";
  display: none;
  width: min(260px, 78%);
  height: 16px;
  margin-top: 8px;
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, var(--mint), var(--sun), var(--coral), var(--pink)) 0 0 / 44% 100% no-repeat,
    rgba(255, 249, 223, 0.96);
  box-shadow: 4px 4px 0 rgba(43, 23, 79, 0.18);
  animation: camera-loading-bar 880ms cubic-bezier(.22, 1, .36, 1) infinite;
}

.camera-empty strong {
  color: #f7fbff;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 2.4rem;
  line-height: 1;
  letter-spacing: 0;
  text-shadow:
    3px 3px 0 #140d37,
    6px 6px 0 rgba(10, 7, 28, 0.9),
    0 0 14px rgba(85, 170, 255, 0.35);
}

.camera-empty span {
  max-width: 360px;
  padding: 8px 12px;
  color: #eaf2ff;
  font-weight: 700;
  line-height: 1.2;
  background: rgba(15, 12, 44, 0.82);
  border: 4px solid rgba(231, 242, 255, 0.42);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    4px 4px 0 rgba(12, 8, 33, 0.5);
}

.camera-start-button {
  width: min(360px, 100%);
}

.camera-start-button.is-hidden,
.camera-empty-status.is-hidden {
  display: none;
}

.camera-stage.is-live .camera-empty {
  opacity: 0;
  pointer-events: none;
}

.camera-stage.is-starting .camera-empty::after {
  display: block;
}

.camera-stage.is-starting .camera-empty strong {
  animation: start-pop 820ms ease-in-out infinite;
}


@keyframes start-pop {
  0%,
  100% {
    scale: 1;
  }
  50% {
    scale: 1.04;
  }
}

@keyframes camera-loading-bar {
  0% {
    background-position: -48% 0, 0 0;
  }
  100% {
    background-position: 148% 0, 0 0;
  }
}


.button-row,
.mission-button-row {
  display: grid;
  gap: 10px;
  align-items: stretch;
}

.button-row {
  grid-template-columns: minmax(0, 1fr);
}

.button-row button,
.mission-skip-button {
  width: 100%;
  min-width: 0;
}

.primary-button,
.secondary-button,
.ghost-button,
.hud-button {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 52px;
  padding: 0 16px;
  color: white;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow:
    0 2px 0 var(--ink),
    2px 0 0 var(--ink),
    -2px 0 0 var(--ink),
    0 -2px 0 var(--ink),
    2px 2px 0 var(--ink),
    0 0 8px rgba(29, 17, 58, 0.45);
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow:
    0 7px 0 var(--shadow),
    0 14px 18px rgba(43, 23, 79, 0.18),
    inset 0 4px 0 rgba(255, 255, 255, 0.4);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.primary-button::before,
.secondary-button::before,
.ghost-button::before,
.hud-button::before {
  content: "";
  position: absolute;
  inset: -45% -22%;
  z-index: -1;
  background:
    linear-gradient(110deg, transparent 0 34%, rgba(255, 255, 255, 0.72) 44% 50%, transparent 60% 100%),
    radial-gradient(circle, rgba(255, 255, 255, 0.68) 0 3px, transparent 4px);
  background-size: 100% 100%, 42px 42px;
  opacity: 0.5;
  transform: translateX(-58%) rotate(3deg);
  transition: transform 360ms ease, opacity 160ms ease;
}

.primary-button::after,
.secondary-button::after,
.ghost-button::after,
.hud-button::after {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: -1;
  border: 2px dashed rgba(255, 255, 255, 0.42);
  border-radius: 5px;
  opacity: 0.72;
}

.primary-button {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), transparent 38%),
    linear-gradient(180deg, #4beed2, #19bfae);
}

.secondary-button {
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
  background: linear-gradient(180deg, #ffe965, #ffad3d);
}

.ghost-button,
.hud-button {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 38%),
    linear-gradient(180deg, #55aaff, #2372e8);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.hud-button:hover {
  transform: translateY(-4px) rotate(-0.6deg);
  filter: saturate(1.28) brightness(1.08);
  box-shadow:
    0 11px 0 var(--shadow),
    0 18px 22px rgba(43, 23, 79, 0.24),
    0 0 22px rgba(255, 224, 91, 0.55),
    inset 0 4px 0 rgba(255, 255, 255, 0.58);
}

.primary-button:hover::before,
.secondary-button:hover::before,
.ghost-button:hover::before,
.hud-button:hover::before {
  opacity: 0.95;
  transform: translateX(48%) rotate(3deg);
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.hud-button:active {
  transform: translateY(4px);
  box-shadow:
    0 3px 0 var(--shadow),
    0 8px 14px rgba(43, 23, 79, 0.18),
    inset 0 3px 0 rgba(255, 255, 255, 0.34);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.hud-button:disabled {
  filter: grayscale(0.16) saturate(0.74);
  opacity: 0.82;
  transform: translateY(4px);
  box-shadow:
    0 3px 0 var(--shadow),
    inset 0 3px 0 rgba(255, 255, 255, 0.24);
}

.word-zone {
  position: relative;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: 38px minmax(0, 1fr) auto;
  gap: 10px;
  overflow: hidden;
  padding: 14px;
  border: 8px solid var(--ink);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.9), transparent 18%),
    radial-gradient(circle at 82% 16%, rgba(255, 79, 216, 0.28), transparent 20%),
    radial-gradient(circle at 50% 90%, rgba(36, 255, 226, 0.34), transparent 30%),
    linear-gradient(180deg, rgba(255, 249, 223, 0.94) 0 54%, rgba(255, 222, 126, 0.92) 54% 100%),
    repeating-linear-gradient(90deg, rgba(43, 23, 79, 0.08) 0 2px, transparent 2px 44px);
  box-shadow:
    inset 0 0 0 6px rgba(255, 255, 255, 0.44),
    5px 5px 0 rgba(43, 23, 79, 0.22),
    0 0 26px rgba(255, 79, 216, 0.2);
  transition: transform 260ms ease, box-shadow 260ms ease;
}

.word-zone::before {
  content: "";
  position: absolute;
  inset: auto -18px 62px -18px;
  height: 60px;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(43, 23, 79, 0.16) 0 26px, rgba(43, 23, 79, 0.05) 26px 52px),
    linear-gradient(180deg, rgba(255, 246, 207, 0), rgba(43, 23, 79, 0.08));
  transform: skewY(-3deg);
}

.word-zone::after {
  content: "";
  position: absolute;
  inset: 10px;
  z-index: 1;
  pointer-events: none;
  border: 4px solid rgba(255, 255, 255, 0.32);
  border-radius: 5px;
  box-shadow:
    inset 0 0 28px rgba(36, 255, 226, 0.18),
    0 0 22px rgba(255, 224, 91, 0.22);
  opacity: 0.72;
}

.zone-label {
  position: relative;
  z-index: 2;
  width: fit-content;
  padding: 7px 12px;
  color: var(--ink);
  font-size: 0.85rem;
  background: var(--lime);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 rgba(43, 23, 79, 0.18);
}

.target-word {
  --word-size: 5.2rem;
  --word-len: 3;
  --word-gap: 14px;
  position: relative;
  z-index: 2;
  grid-row: 2;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: center;
  align-content: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--word-gap);
  padding: 10px;
  text-transform: uppercase;
  overflow: hidden;
}

.target-char {
  --fill: 0%;
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: clamp(68px, calc(var(--word-size) + 26px), 118px);
  min-height: clamp(88px, calc(var(--word-size) + 58px), 142px);
  overflow: hidden;
  color: white;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: var(--word-size);
  line-height: 1;
  letter-spacing: 0;
  border: 6px solid var(--ink);
  border-radius: var(--radius);
  background:
    linear-gradient(to top, rgba(54, 231, 189, 0.96) 0 var(--fill), transparent var(--fill) 100%),
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.92), transparent 28%),
    linear-gradient(180deg, #8bdcff, #2e91ff 52%, #5b35ff);
  box-shadow:
    0 9px 0 var(--shadow),
    0 18px 22px rgba(43, 23, 79, 0.18),
    0 0 20px rgba(85, 170, 255, 0.34),
    inset 0 5px 0 rgba(255, 255, 255, 0.44);
  text-shadow:
    3px 3px 0 var(--ink),
    5px 5px 0 rgba(43, 23, 79, 0.2);
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, color 180ms ease;
}

.target-char::before {
  content: "";
  position: absolute;
  inset: -38% -56%;
  z-index: -1;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.68) 48%, transparent 62%);
  transform: translateX(-62%) rotate(4deg);
  opacity: 0;
}

.target-char::after {
  content: "";
  position: absolute;
  inset: 8px;
  z-index: -1;
  border: 3px dashed rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  opacity: 0.7;
}

.target-char.is-current {
  color: var(--cream);
  background:
    linear-gradient(to top, rgba(54, 231, 189, 0.96) 0 var(--fill), transparent var(--fill) 100%),
    radial-gradient(circle at 28% 16%, rgba(255, 255, 255, 0.95), transparent 26%),
    linear-gradient(180deg, #fff06a, #ff4fd8 36%, #5b35ff 74%, #2387ff);
  transform: translateY(-4px) rotate(-1deg);
  box-shadow:
    0 13px 0 var(--shadow),
    0 22px 28px rgba(43, 23, 79, 0.22),
    0 0 28px rgba(255, 79, 216, 0.55),
    0 0 44px rgba(36, 255, 226, 0.28),
    inset 0 5px 0 rgba(255, 255, 255, 0.52);
  animation: current-letter-bounce 1.25s ease-in-out infinite, current-letter-glow 920ms ease-in-out infinite alternate;
}

.target-char.is-current::before {
  animation: char-shine 1500ms ease-in-out infinite;
  opacity: 1;
}

.target-char.is-done {
  color: var(--ink);
  background:
    radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.9), transparent 30%),
    linear-gradient(180deg, #fff7bf, #9be64b 42%, #36e7bd 70%, #24ffe2);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.72);
  box-shadow:
    0 9px 0 var(--shadow),
    0 18px 22px rgba(43, 23, 79, 0.16),
    0 0 22px rgba(54, 231, 189, 0.55),
    inset 0 5px 0 rgba(255, 255, 255, 0.5);
}

.target-char.is-done::after {
  border-color: rgba(43, 23, 79, 0.28);
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.28) 0 8px, transparent 8px 18px);
}

.target-char.is-hit {
  animation: char-hit 980ms cubic-bezier(.18, 1.12, .26, 1), char-hit-flash 980ms ease-out;
}

.target-word.is-advancing::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 16%;
  height: 12px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--mint), var(--sun), var(--coral), var(--pink));
  box-shadow: 4px 4px 0 rgba(43, 23, 79, 0.22);
  animation: letter-pass 220ms cubic-bezier(.22, 1, .36, 1) 1;
  pointer-events: none;
}

.target-word.is-advancing .target-char.is-done {
  transform: translateY(-3px) rotate(1deg);
}

.target-word.is-advancing .target-char.is-current {
  animation: current-handoff 220ms cubic-bezier(.22, 1, .36, 1) 1;
}

@keyframes char-hit {
  0% {
    transform: translateY(-4px) scale(1);
  }
  42% {
    transform: translateY(-12px) scale(1.16) rotate(2deg);
  }
  100% {
    transform: translateY(-4px) scale(1) rotate(-1deg);
  }
}

@keyframes char-hit-flash {
  0% {
    filter: saturate(1) brightness(1);
  }
  36% {
    filter: saturate(1.8) brightness(1.24) hue-rotate(18deg);
  }
  100% {
    filter: saturate(1) brightness(1);
  }
}

@keyframes char-shine {
  0%,
  36% {
    transform: translateX(-62%) rotate(4deg);
  }
  82%,
  100% {
    transform: translateX(62%) rotate(4deg);
  }
}

@keyframes current-letter-glow {
  from {
    filter: saturate(1.05);
  }
  to {
    filter: saturate(1.42) brightness(1.08);
  }
}

@keyframes letter-pass {
  0% {
    translate: -70% 0;
    opacity: 0;
  }
  25% {
    opacity: 1;
  }
  100% {
    translate: 70% 0;
    opacity: 0;
  }
}

@keyframes current-handoff {
  0% {
    transform: translateY(-4px) scale(1);
  }
  50% {
    transform: translateY(-8px) scale(1.08);
  }
  100% {
    transform: translateY(-4px) scale(1);
  }
}

@keyframes current-letter-bounce {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -7px;
  }
}

.word-reveal {
  position: absolute;
  inset: 62px 18px 82px;
  z-index: 7;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  color: #f3f8ff;
  border: 7px solid var(--ink);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.16), transparent 24%),
    radial-gradient(circle at 82% 24%, rgba(255, 79, 216, 0.2), transparent 30%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0 12px, transparent 12px 24px),
    linear-gradient(180deg, #2a1d53, #1f1746 62%, #151134);
  box-shadow:
    8px 8px 0 rgba(43, 23, 79, 0.28),
    inset 0 0 0 6px rgba(255, 255, 255, 0.48);
  animation: reveal-panel-in 220ms ease-out both, reveal-panel-glow 1200ms ease-in-out infinite alternate;
}

.word-reveal strong {
  color: #ffffff;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 1.35rem;
  line-height: 1;
  letter-spacing: 0;
  text-shadow:
    3px 3px 0 #0f0b2a,
    6px 6px 0 rgba(255, 79, 216, 0.65);
}

.word-reveal span {
  color: #d7e8ff;
  font-weight: 700;
}

.word-reveal.is-hidden {
  display: none;
}

.word-reveal::before {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  top: 18px;
  height: 10px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--mint), var(--sun), var(--pink));
  animation: reveal-scan 1400ms cubic-bezier(.16, .76, .27, 1) infinite;
}

.word-reveal-bar {
  width: min(300px, 88%);
  height: 18px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  background: rgba(14, 12, 36, 0.8);
  box-shadow: inset 0 -4px 0 rgba(43, 23, 79, 0.08);
}

.word-reveal-bar::after {
  content: "";
  display: block;
  width: 42%;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--sun), var(--coral), var(--pink));
  animation: reveal-progress 1400ms cubic-bezier(.22, 1, .36, 1) infinite;
}

.word-zone.is-revealing .target-word {
  opacity: 0.28;
  filter: saturate(0.65);
  transform: scale(0.98);
}

@keyframes reveal-scan {
  0% {
    translate: 0 0;
    opacity: 0.45;
  }
  44% {
    translate: 0 126px;
    opacity: 1;
  }
  100% {
    translate: 0 240px;
    opacity: 0.32;
  }
}

@keyframes reveal-progress {
  0% {
    translate: -70% 0;
  }
  100% {
    translate: 210% 0;
  }
}

@keyframes reveal-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes reveal-panel-glow {
  from {
    filter: saturate(1);
  }
  to {
    filter: saturate(1.25) brightness(1.03);
  }
}

.feedback {
  position: relative;
  z-index: 2;
  grid-row: 3;
  min-height: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 8px 12px;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 249, 223, 0.92);
  box-shadow:
    4px 4px 0 rgba(43, 23, 79, 0.18),
    inset 0 -6px 0 rgba(43, 23, 79, 0.06);
}

.feedback.is-good {
  background: linear-gradient(180deg, #fff9df, #b8f5a1);
}

.feedback.is-alert {
  color: white;
  background: linear-gradient(180deg, #5fb7ff, #2366d9);
  text-shadow: 2px 2px 0 var(--ink);
}

.fx-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
}

.fx-burst,
.fx-word,
.fx-word-spark,
.fx-glitter,
.fx-comet,
.fx-ribbon,
.fx-pop-text,
.fx-phase-pop {
  position: absolute;
  pointer-events: none;
}

.fx-burst {
  width: var(--size, 18px);
  height: var(--size, 18px);
  border: 3px solid var(--ink);
  border-radius: 2px;
  background: var(--burst-color, var(--sun));
  box-shadow: 3px 3px 0 rgba(43, 23, 79, 0.22);
  animation: burst-fly 980ms ease-out forwards;
}

.fx-burst:nth-child(3n) {
  background: var(--mint);
}

.fx-burst:nth-child(3n + 1) {
  background: var(--pink);
}

.fx-glitter {
  width: var(--size, 9px);
  height: var(--size, 9px);
  background: var(--burst-color, white);
  border: 2px solid rgba(43, 23, 79, 0.72);
  clip-path: polygon(50% 0, 62% 35%, 100% 50%, 62% 65%, 50% 100%, 38% 65%, 0 50%, 38% 35%);
  filter: drop-shadow(0 0 8px var(--burst-color, white));
  animation: glitter-fly 1300ms cubic-bezier(.18, .82, .22, 1) forwards;
}

.fx-word {
  inset: 50% auto auto 50%;
  width: 14px;
  height: 14px;
  border: 4px solid var(--ring-color, var(--lime));
  border-radius: 50%;
  box-shadow:
    0 0 0 4px rgba(255, 224, 91, 0.34),
    0 0 22px var(--ring-color, var(--lime));
  transform: translate(-50%, -50%) scale(0.4);
  animation: word-ring 2300ms cubic-bezier(.12, .75, .2, 1) forwards;
}

.fx-word-spark {
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  background: var(--burst-color, var(--coral));
  border: 3px solid var(--ink);
  clip-path: polygon(50% 0, 62% 35%, 100% 35%, 70% 56%, 82% 100%, 50% 74%, 18% 100%, 30% 56%, 0 35%, 38% 35%);
  animation: word-spark 1700ms cubic-bezier(.2, .9, .22, 1) forwards;
}

.fx-word-spark:nth-child(2n) {
  background: var(--cyan);
}

.fx-comet {
  left: 50%;
  top: 50%;
  width: var(--size, 16px);
  height: var(--size, 16px);
  border: 3px solid var(--ink);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, white, transparent 24%),
    var(--burst-color, var(--sun));
  box-shadow:
    0 0 18px var(--burst-color, var(--sun)),
    4px 4px 0 rgba(43, 23, 79, 0.18);
  animation: comet-orbit 2000ms cubic-bezier(.16, .76, .24, 1) forwards;
}

.fx-comet::after {
  content: "";
  position: absolute;
  right: 70%;
  top: 50%;
  width: 48px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--burst-color, var(--sun)));
  transform: translateY(-50%);
}

.fx-ribbon {
  left: 50%;
  top: 50%;
  width: var(--w, 96px);
  height: 18px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--burst-color, var(--pink)), var(--sun), var(--aqua));
  box-shadow:
    4px 4px 0 rgba(43, 23, 79, 0.2),
    0 0 18px rgba(255, 255, 255, 0.44);
  animation: ribbon-burst 1700ms cubic-bezier(.16, .76, .22, 1) forwards;
}

.fx-pop-text {
  left: 50%;
  top: 50%;
  min-width: 150px;
  padding: 10px 14px;
  color: white;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: clamp(1.15rem, 3.4vw, 2.2rem);
  line-height: 1;
  text-align: center;
  text-shadow:
    3px 3px 0 var(--ink),
    6px 6px 0 var(--magenta);
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.34), transparent 34%),
    linear-gradient(90deg, var(--grape), var(--pink), var(--coral), var(--sun));
  box-shadow:
    7px 7px 0 var(--shadow),
    0 0 32px rgba(255, 79, 216, 0.55);
  transform: translate(-50%, -50%) scale(0.62) rotate(-4deg);
  animation: pop-text-celebrate 2400ms cubic-bezier(.18, .9, .18, 1) forwards;
}

@keyframes burst-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.12) rotate(120deg);
  }
}

@keyframes glitter-fly {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.35) rotate(0deg);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.1) rotate(260deg);
  }
}

@keyframes word-ring {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(34);
  }
}

@keyframes word-spark {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
  }
  18% {
    opacity: 1;
    transform: translate(calc(-50% + var(--dx) * 0.2), calc(-50% + var(--dy) * 0.2)) scale(1) rotate(28deg);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2) rotate(150deg);
  }
}

@keyframes comet-orbit {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle, 0deg)) translateX(12px) scale(0.45);
  }
  14% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(calc(var(--angle, 0deg) + 190deg)) translateX(var(--distance, 160px)) scale(0.08);
  }
}

@keyframes ribbon-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle, 0deg)) scaleX(0.12) scaleY(0.72);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(calc(var(--angle, 0deg) + 18deg)) scaleX(0.95) scaleY(0.72);
  }
}

@keyframes pop-text-celebrate {
  0% {
    opacity: 0;
    transform: translate(-50%, -42%) scale(0.38) rotate(-8deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -62%) scale(1.06) rotate(2deg);
  }
  74% {
    opacity: 1;
    transform: translate(-50%, -74%) scale(1) rotate(-1deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -98%) scale(0.82) rotate(3deg);
  }
}

.word-zone.is-celebrating {
  transform: scale(1.018) rotate(-0.35deg);
  box-shadow:
    inset 0 0 0 6px rgba(255, 255, 255, 0.54),
    8px 8px 0 var(--shadow),
    0 0 0 8px rgba(255, 224, 91, 0.38),
    0 0 48px rgba(255, 79, 216, 0.42),
    0 0 68px rgba(36, 255, 226, 0.32);
  animation: word-zone-party 1000ms ease-in-out 3;
}

.word-zone.is-celebrating .target-char.is-done {
  animation: done-letter-party 980ms cubic-bezier(.18, .9, .18, 1) both;
}

@keyframes word-zone-party {
  0%,
  100% {
    filter: saturate(1);
  }
  50% {
    filter: saturate(1.45) brightness(1.08);
  }
}

@keyframes done-letter-party {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  42% {
    transform: translateY(-12px) rotate(3deg) scale(1.08);
  }
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 16px;
  color: var(--ink);
  font-weight: 700;
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow:
    6px 6px 0 var(--shadow),
    0 18px 24px rgba(43, 23, 79, 0.2);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.level-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    repeating-linear-gradient(135deg, rgba(25, 16, 54, 0.42) 0 14px, rgba(16, 10, 41, 0.56) 14px 28px),
    rgba(18, 10, 42, 0.78);
}

.level-modal.is-hidden {
  display: none;
}

.level-card {
  position: relative;
  width: min(520px, 100%);
  padding: 96px 26px 26px;
  color: var(--ink);
  text-align: center;
  border: 7px solid var(--ink);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(90deg, rgba(43, 23, 79, 0.06) 0 3px, transparent 3px 32px),
    linear-gradient(180deg, #4d4693, #302a72 58%, #221c58);
  box-shadow:
    10px 10px 0 var(--shadow),
    0 26px 40px rgba(0, 0, 0, 0.22);
  animation: phase-card-pop 340ms cubic-bezier(.2,.88,.24,1.05);
}

.modal-badge {
  position: absolute;
  left: 50%;
  top: -148px;
  transform: translateX(-50%);
  width: 248px;
  height: 248px;
  filter: drop-shadow(5px 6px 0 rgba(43, 23, 79, 0.28));
}

.level-card > span {
  display: inline-grid;
  place-items: center;
  min-height: 30px;
  padding: 5px 12px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--mint);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 rgba(43, 23, 79, 0.18);
}

.level-card h2 {
  margin: 12px 0 10px;
  color: #f7fbff;
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 2rem;
  line-height: 1.18;
  letter-spacing: 0.1em;
  text-shadow:
    2px 2px 0 var(--ink),
    4px 4px 0 var(--coral);
}

#welcomeTitle {
  line-height: 1.32;
}

.level-card p {
  margin: 0 0 14px;
  color: #e9f1ff;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.075em;
  text-shadow: 0 1px 0 rgba(7, 4, 20, 0.72);
}

.level-card strong {
  color: var(--ink);
}

.welcome-card strong {
  color: #ffe05b;
  text-shadow:
    0 1px 0 rgba(17, 11, 42, 0.85),
    0 0 8px rgba(255, 224, 91, 0.35);
}

.welcome-card .primary-button,
#nextPhase {
  width: 100%;
}

.welcome-tip {
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: inset 0 -5px 0 rgba(43, 23, 79, 0.06);
}

.phase-modal {
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 224, 91, 0.52), transparent 23%),
    radial-gradient(circle at 82% 20%, rgba(255, 79, 216, 0.5), transparent 24%),
    radial-gradient(circle at 50% 84%, rgba(36, 255, 226, 0.42), transparent 28%),
    repeating-linear-gradient(45deg, rgba(255, 224, 91, 0.38) 0 18px, rgba(35, 135, 255, 0.38) 18px 36px, rgba(54, 231, 189, 0.38) 36px 54px, rgba(255, 79, 216, 0.34) 54px 72px),
    rgba(43, 23, 79, 0.78);
  animation: phase-modal-colorwash 2400ms ease-in-out infinite alternate;
}

.phase-modal::before,
.phase-modal::after {
  content: "";
  position: absolute;
  inset: -18%;
  pointer-events: none;
}

.phase-modal::before {
  background:
    radial-gradient(circle at 18% 28%, rgba(255, 255, 255, 0.78) 0 3px, transparent 4px),
    radial-gradient(circle at 72% 32%, rgba(255, 224, 91, 0.78) 0 4px, transparent 5px),
    radial-gradient(circle at 84% 68%, rgba(36, 255, 226, 0.72) 0 3px, transparent 4px),
    radial-gradient(circle at 38% 78%, rgba(255, 79, 216, 0.75) 0 4px, transparent 5px);
  background-size: 150px 130px, 190px 170px, 180px 150px, 210px 190px;
  animation: modal-spark-rain 5s linear infinite;
}

.phase-modal::after {
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.15) 0 7deg, transparent 7deg 18deg);
  animation: modal-light-spin 12s linear infinite;
}

.phase-card {
  width: min(680px, 100%);
  min-height: 460px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  overflow: hidden;
  padding: 28px 42px 36px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 14%, rgba(255, 255, 255, 0.9), transparent 18%),
    radial-gradient(circle at 18% 32%, rgba(36, 255, 226, 0.32), transparent 22%),
    radial-gradient(circle at 86% 42%, rgba(255, 79, 216, 0.28), transparent 24%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0 12px, transparent 12px 26px),
    linear-gradient(180deg, #fff9df, #ffe05b 48%, #ff9c66 76%, #ff4fd8);
  isolation: isolate;
  box-shadow:
    12px 12px 0 var(--shadow),
    0 0 0 10px rgba(255, 224, 91, 0.28),
    0 30px 56px rgba(0, 0, 0, 0.3),
    0 0 70px rgba(255, 79, 216, 0.42);
}

.phase-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  z-index: -1;
  border: 6px dashed rgba(43, 23, 79, 0.28);
  border-radius: var(--radius);
  animation: phase-dashed-pulse 980ms ease-in-out infinite alternate;
}

.phase-card::after {
  content: "";
  position: absolute;
  inset: -55%;
  z-index: -2;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.52) 0 8deg, rgba(255, 255, 255, 0) 8deg 18deg);
  animation: phase-rays-spin 5.4s linear infinite;
}

.phase-rays {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(90deg, transparent 0 22%, rgba(255, 255, 255, 0.38) 22% 24%, transparent 24% 76%, rgba(255, 255, 255, 0.28) 76% 78%, transparent 78% 100%),
    repeating-linear-gradient(0deg, rgba(43, 23, 79, 0.08) 0 5px, transparent 5px 28px);
  opacity: 0.72;
  animation: phase-rays-pulse 1700ms ease-in-out infinite;
}

.phase-medal {
  position: relative;
  z-index: 2;
  width: 168px;
  height: 168px;
  display: grid;
  place-items: center;
  margin-bottom: 2px;
  color: var(--ink);
  font-family: "Bungee", "Fredoka", sans-serif;
  font-size: 3.55rem;
  line-height: 1;
  background:
    radial-gradient(circle at 30% 22%, white, transparent 20%),
    linear-gradient(180deg, #fff5a4, #ffc048 50%, #ff7f4e 72%, #ff4fd8);
  border: 8px solid var(--ink);
  clip-path: polygon(50% 0%, 62% 17%, 83% 8%, 79% 31%, 100% 50%, 79% 69%, 83% 92%, 62% 83%, 50% 100%, 38% 83%, 17% 92%, 21% 69%, 0% 50%, 21% 31%, 17% 8%, 38% 17%);
  box-shadow:
    0 10px 0 var(--shadow),
    0 20px 28px rgba(43, 23, 79, 0.22),
    0 0 26px rgba(255, 224, 91, 0.7),
    0 0 40px rgba(255, 79, 216, 0.35),
    inset 0 6px 0 rgba(255, 255, 255, 0.54);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.68);
  animation: phase-medal-bounce 1400ms ease-in-out infinite;
}

.phase-medal::before,
.phase-medal::after {
  content: "";
  position: absolute;
  top: 106px;
  z-index: -1;
  width: 40px;
  height: 84px;
  background: linear-gradient(180deg, var(--sky), #2458d6);
  border: 5px solid var(--ink);
  border-radius: 0 0 6px 6px;
}

.phase-medal::before {
  left: 30px;
  transform: rotate(16deg);
}

.phase-medal::after {
  right: 30px;
  transform: rotate(-16deg);
}

.phase-medal span {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  background: var(--paper);
  border: 6px solid var(--ink);
  border-radius: 50%;
}

.phase-card > span {
  background: linear-gradient(90deg, var(--mint), var(--sun), #ffadff);
  box-shadow:
    4px 4px 0 rgba(43, 23, 79, 0.18),
    0 0 20px rgba(255, 255, 255, 0.42);
}

#modalKicker {
  min-height: 56px;
  padding: 8px 18px;
  font-size: clamp(1.45rem, 3.1vw, 2.2rem);
  line-height: 1;
  font-family: "Bungee", "Fredoka", sans-serif;
  letter-spacing: 0;
  text-transform: uppercase;
}

.phase-card > span:empty {
  display: none;
}

.phase-card h2 {
  max-width: 560px;
  margin: 0;
  color: white;
  font-size: 3.2rem;
  line-height: 0.98;
  text-transform: uppercase;
  text-shadow:
    4px 4px 0 var(--ink),
    8px 8px 0 var(--pink),
    12px 12px 0 rgba(43, 23, 79, 0.2),
    0 0 24px rgba(255, 255, 255, 0.6);
  animation: phase-title-pop 900ms cubic-bezier(.18, .9, .18, 1) both;
}

.phase-card p {
  max-width: 520px;
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 1.25rem;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.48);
  border: 4px solid rgba(43, 23, 79, 0.72);
  border-radius: var(--radius);
  box-shadow:
    inset 0 -5px 0 rgba(43, 23, 79, 0.08),
    0 0 20px rgba(255, 255, 255, 0.32);
}

.phase-card #nextPhase {
  width: min(320px, 100%);
  min-height: 60px;
}

@keyframes phase-card-pop {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.92) rotate(-1deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

@keyframes phase-modal-colorwash {
  from {
    filter: saturate(1.04);
  }
  to {
    filter: saturate(1.32) hue-rotate(10deg);
  }
}

@keyframes modal-spark-rain {
  to {
    background-position: 150px 260px, -190px 300px, 180px -240px, -210px 280px;
  }
}

@keyframes modal-light-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes phase-dashed-pulse {
  from {
    opacity: 0.42;
  }
  to {
    opacity: 0.9;
    box-shadow: inset 0 0 32px rgba(255, 255, 255, 0.3);
  }
}

@keyframes phase-title-pop {
  0% {
    opacity: 0;
    transform: scale(0.72) rotate(-3deg);
  }
  58% {
    opacity: 1;
    transform: scale(1.08) rotate(1deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes phase-medal-bounce {
  0%,
  100% {
    translate: 0 0;
    rotate: -2deg;
  }
  50% {
    translate: 0 -8px;
    rotate: 2deg;
  }
}

@keyframes phase-rays-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes phase-rays-pulse {
  0%,
  100% {
    opacity: 0.52;
  }
  50% {
    opacity: 0.86;
  }
}

.fx-phase-pop {
  width: var(--size, 18px);
  height: var(--size, 18px);
  z-index: 34;
  border: 3px solid rgba(43, 23, 79, 0.86);
  background: var(--burst-color, var(--sun));
  box-shadow:
    4px 4px 0 rgba(43, 23, 79, 0.22),
    0 0 16px var(--burst-color, var(--sun));
  clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 100%, 50% 72%, 21% 100%, 32% 56%, 2% 35%, 39% 34%);
  animation: phase-pop-fly var(--duration, 1500ms) cubic-bezier(.16, .8, .2, 1) forwards;
}

@keyframes phase-pop-fly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25) rotate(0deg);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.08) rotate(360deg);
  }
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-rows: auto auto auto;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-stats {
    width: 100%;
    justify-self: stretch;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .camera-panel,
  .mission-panel {
    min-height: auto;
    height: auto;
  }

  .camera-stage,
  .target-word {
    min-height: 0;
  }
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100svh;
  }

  .game-backdrop {
    opacity: 0.7;
  }

  .floating-token,
  .floating-spark,
  .light-ribbon,
  .sky-rail {
    display: none;
  }

  .app-shell {
    width: 100%;
    height: 100svh;
    min-height: 100svh;
    max-height: 100svh;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px;
    padding: calc(env(safe-area-inset-top, 0px) + 2px) 6px calc(env(safe-area-inset-bottom, 0px) + 6px);
    overflow: hidden;
  }

  .topbar {
    gap: 6px;
  }

  .brand-text {
    gap: 7px;
  }

  .brand-badge {
    width: 48px;
    height: 48px;
  }

  .brand-text p {
    display: none;
  }

  .brand-text h1 {
    font-size: 1.18rem;
    text-shadow:
      2px 2px 0 var(--ink),
      4px 4px 0 var(--coral);
  }

  .hud-card,
  .panel {
    box-shadow:
      4px 4px 0 var(--shadow),
      0 12px 20px rgba(43, 23, 79, 0.14);
  }

  .topbar-stats {
    gap: 3px;
    padding: 4px;
    border-width: 4px;
  }

  .topbar-stats div {
    min-height: 42px;
    padding: 4px 2px;
    border-width: 3px;
  }

  .topbar-stats span {
    font-size: 0.52rem;
  }

  .topbar-stats strong {
    font-size: 0.92rem;
  }

  .game-layout {
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 51.5%) minmax(0, 48.5%);
    gap: 6px;
  }

  .camera-panel,
  .mission-panel {
    min-height: 0;
    height: 100%;
    gap: 5px;
    padding: 6px;
    border-width: 4px;
  }

  .camera-stage {
    min-height: 0;
    height: 100%;
    border-width: 5px;
  }


  .camera-empty {
    padding: 12px;
    gap: 6px;
  }

  .camera-empty::before {
    width: 76px;
    height: 76px;
  }

  .camera-empty strong {
    font-size: 1.2rem;
    text-shadow:
      2px 2px 0 var(--ink),
      4px 4px 0 var(--coral);
  }

  .camera-empty span {
    padding: 6px 8px;
    font-size: 0.76rem;
    border-width: 3px;
  }

  .button-row,
  .mission-button-row {
    gap: 5px;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .hud-button {
    min-height: 34px;
    padding: 0 8px;
    border-width: 4px;
    font-size: 0.78rem;
    box-shadow:
      0 4px 0 var(--shadow),
      inset 0 3px 0 rgba(255, 255, 255, 0.36);
  }

  .word-zone {
    isolation: isolate;
    min-height: 0;
    height: 100%;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 5px;
    padding: 6px;
    border-width: 5px;
    background:
      radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.9), transparent 18%),
      radial-gradient(circle at 82% 16%, rgba(255, 79, 216, 0.28), transparent 20%),
      radial-gradient(circle at 50% 90%, rgba(36, 255, 226, 0.34), transparent 30%),
      linear-gradient(180deg, rgba(255, 249, 223, 0.94) 0 calc(100% - 72px), rgba(255, 238, 162, 0.94) calc(100% - 72px) calc(100% - 58px), rgba(255, 222, 126, 0.92) calc(100% - 58px) 100%),
      repeating-linear-gradient(90deg, rgba(43, 23, 79, 0.08) 0 2px, transparent 2px 44px);
  }

  .word-zone::before {
    display: block;
    inset: auto 7px 7px 7px;
    z-index: 0;
    height: clamp(44px, 20%, 72px);
    border-radius: 6px;
    background:
      repeating-linear-gradient(90deg, rgba(43, 23, 79, 0.13) 0 20px, rgba(43, 23, 79, 0.04) 20px 40px),
      linear-gradient(180deg, rgba(255, 239, 151, 0.96), rgba(255, 217, 88, 0.95));
    transform: none;
    opacity: 0.82;
  }

  .zone-label {
    padding: 4px 7px;
    font-size: 0.6rem;
    border-width: 3px;
  }

  .target-word {
    grid-row: 1;
    min-height: 0;
    height: 100%;
    align-content: center;
    gap: 6px;
    padding: 2px;
  }

  .target-char {
    width: clamp(42px, calc(min(var(--word-size), 2.65rem) + 18px), 68px);
    min-height: clamp(50px, calc(min(var(--word-size), 2.65rem) + 30px), 78px);
    font-size: min(var(--word-size), 2.65rem);
    border-width: 4px;
    box-shadow:
      0 5px 0 var(--shadow),
      inset 0 4px 0 rgba(255, 255, 255, 0.4);
    text-shadow:
      2px 2px 0 var(--ink),
      4px 4px 0 rgba(43, 23, 79, 0.16);
  }

  .target-char::after {
    inset: 5px;
    border-width: 2px;
  }

  .feedback {
    min-height: 34px;
    height: 34px;
    padding: 5px 7px;
    border-width: 4px;
    font-size: 0.7rem;
  }

  .word-reveal {
    inset: 36px 8px 50px;
    gap: 7px;
    padding: 12px;
    border-width: 5px;
  }

  .word-reveal strong {
    font-size: 0.98rem;
    text-shadow:
      2px 2px 0 var(--ink),
      4px 4px 0 var(--coral);
  }

  .word-reveal span {
    font-size: 0.78rem;
  }

  .word-reveal::before {
    top: 10px;
    height: 7px;
    border-width: 3px;
  }

  .word-reveal-bar {
    height: 14px;
    border-width: 3px;
  }

  .toast {
    left: 8px;
    right: 8px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
    max-width: none;
    padding: 9px 10px;
    border-width: 4px;
    font-size: 0.78rem;
  }

  .level-modal {
    padding: 8px;
  }

  .level-card {
    max-height: calc(100svh - 16px);
    overflow: hidden;
    padding: 64px 14px 14px;
    border-width: 5px;
  }

  .welcome-card {
    overflow: visible;
  }

  .modal-badge {
    left: 50%;
    top: -78px;
    transform: translateX(-50%);
    width: 152px;
    height: 152px;
  }

  .level-card > span {
    min-height: 26px;
    border-width: 3px;
    font-size: 0.72rem;
  }

  .level-card h2 {
    font-size: 1.18rem;
    text-shadow:
      2px 2px 0 var(--ink),
      4px 4px 0 var(--coral);
  }

  .level-card p {
    margin-bottom: 10px;
    font-size: 0.84rem;
  }

  .phase-card {
    min-height: min(560px, calc(100svh - 20px));
    gap: 10px;
    padding: 18px 16px 22px;
  }

  .phase-card::before {
    inset: 9px;
    border-width: 4px;
  }

  .phase-medal {
    width: 132px;
    height: 132px;
    border-width: 6px;
    font-size: 2.75rem;
  }

  .phase-medal::before,
  .phase-medal::after {
    top: 86px;
    width: 32px;
    height: 66px;
    border-width: 4px;
  }

  .phase-medal::before {
    left: 22px;
  }

  .phase-medal::after {
    right: 22px;
  }

  .phase-medal span {
    width: 66px;
    height: 66px;
    border-width: 5px;
  }

  .phase-card h2 {
    max-width: 320px;
    font-size: 2rem;
    text-shadow:
      3px 3px 0 var(--ink),
      6px 6px 0 var(--pink);
  }

  .phase-card p {
    font-size: 0.95rem;
  }

  .phase-card #nextPhase {
    min-height: 50px;
  }
}

@media (max-width: 420px) {
  .brand-text h1 {
    font-size: 1.12rem;
  }

  .topbar-stats span {
    font-size: 0.52rem;
  }

  .topbar-stats strong {
    font-size: 0.9rem;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .hud-button {
    font-size: 0.7rem;
  }

  .target-char {
    width: clamp(38px, calc(min(var(--word-size), 2.35rem) + 16px), 60px);
    min-height: clamp(46px, calc(min(var(--word-size), 2.35rem) + 28px), 70px);
    font-size: min(var(--word-size), 2.35rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
