/* ===========================================================================
   TYPING INVADERS — a night sky, a shield, a city and a turret
   =========================================================================== */

.ty-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* --- Sky + falling words --- */
.ty-sky {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.ty-stars {
  position: absolute;
  inset: -50% 0 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255, 255, 255, 0.7), transparent 60%),
    radial-gradient(1px 1px at 30% 70%, rgba(255, 255, 255, 0.5), transparent 60%),
    radial-gradient(1.5px 1.5px at 55% 35%, rgba(255, 255, 255, 0.8), transparent 60%),
    radial-gradient(1px 1px at 75% 15%, rgba(255, 255, 255, 0.5), transparent 60%),
    radial-gradient(1px 1px at 90% 60%, rgba(255, 255, 255, 0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 20% 45%, rgba(255, 220, 180, 0.6), transparent 60%),
    radial-gradient(1px 1px at 65% 85%, rgba(255, 255, 255, 0.4), transparent 60%);
  background-size: 260px 260px;
  animation: ty-stars 40s linear infinite;
  opacity: 0.8;
}

@keyframes ty-stars {
  to { transform: translateY(260px); }
}

.ty-field {
  position: absolute;
  inset: 0;
}

.ty-shield {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--game-accent) 15%, #fff 50%, var(--game-accent) 85%, transparent);
  box-shadow: 0 0 18px var(--game-accent), 0 -8px 40px var(--game-glow);
  animation: ty-shield 2.4s ease-in-out infinite;
}

@keyframes ty-shield {
  50% { opacity: 0.7; }
}

.ty-stage[data-damage="1"] .ty-shield { filter: hue-rotate(-20deg) saturate(1.4); }
.ty-stage[data-damage="2"] .ty-shield {
  background: linear-gradient(90deg, transparent, #FF5468 15%, #FFB3BC 50%, #FF5468 85%, transparent);
  box-shadow: 0 0 18px #FF5468, 0 -8px 40px rgba(255, 84, 104, 0.4);
  animation: ty-flicker 0.6s steps(2) infinite;
}

@keyframes ty-flicker {
  50% { opacity: 0.45; }
}

/* --- Words --- */
.ty-word {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: clamp(0.92rem, 1.8vw, 1.05rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--arena-ink);
  white-space: nowrap;
  background: rgba(12, 15, 32, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.8);
  will-change: transform;
  pointer-events: none;
}

.ty-word__text span {
  transition: color 0.08s linear, text-shadow 0.08s linear;
}

.ty-word__text span.hit {
  color: var(--game-accent);
  text-shadow: 0 0 10px var(--game-glow);
}

.ty-word__icon {
  font-size: 0.86em;
}

.ty-word.locked {
  border-color: var(--game-accent);
  background: rgba(30, 18, 8, 0.85);
  box-shadow: 0 0 0 1px var(--game-accent), 0 0 24px var(--game-glow);
  z-index: 2;
}

/* Target brackets on the locked word */
.ty-word.locked::before,
.ty-word.locked::after {
  content: '';
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 8px;
  border: 2px solid var(--game-accent);
  animation: ty-bracket 0.8s ease-in-out infinite alternate;
}

.ty-word.locked::before { left: -8px; border-right: none; border-radius: 4px 0 0 4px; }
.ty-word.locked::after { right: -8px; border-left: none; border-radius: 0 4px 4px 0; }

@keyframes ty-bracket {
  to { opacity: 0.4; transform: scaleY(0.85); }
}

.ty-word--bomb {
  border-color: rgba(255, 212, 71, 0.7);
  box-shadow: 0 0 20px rgba(255, 212, 71, 0.35);
}

.ty-word--bomb .ty-word__icon { color: #FFD447; }

.ty-word--freeze {
  border-color: rgba(127, 232, 255, 0.7);
  box-shadow: 0 0 20px rgba(127, 232, 255, 0.35);
}

.ty-word--freeze .ty-word__icon { color: #7FE8FF; }

.ty-word--heal {
  border-color: rgba(59, 240, 160, 0.7);
  box-shadow: 0 0 20px rgba(59, 240, 160, 0.35);
}

.ty-word--heal .ty-word__icon { color: #3BF0A0; }

.ty-word--boss {
  flex-direction: column;
  gap: 5px;
  padding: 9px 16px 8px;
  font-size: clamp(1.1rem, 2.6vw, 1.4rem);
  border-color: rgba(255, 84, 104, 0.8);
  background: rgba(40, 6, 14, 0.85);
  box-shadow: 0 0 30px rgba(255, 84, 104, 0.45), inset 0 0 20px rgba(255, 84, 104, 0.15);
  animation: ty-boss 1.6s ease-in-out infinite;
}

@keyframes ty-boss {
  50% { box-shadow: 0 0 46px rgba(255, 84, 104, 0.7), inset 0 0 20px rgba(255, 84, 104, 0.2); }
}

.ty-word__hp {
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.ty-word__hp i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #FF5468, #FFB547);
  transform-origin: left;
  transition: transform 0.15s var(--ease);
}

.ty-word.boom {
  animation: ty-boom 0.26s var(--ease) forwards;
}

@keyframes ty-boom {
  to { opacity: 0; filter: blur(4px) brightness(2); scale: 1.4; }
}

.ty-stage.frozen .ty-sky {
  background: linear-gradient(180deg, rgba(127, 232, 255, 0.12), transparent 70%);
}

.ty-stage.frozen .ty-word {
  border-color: rgba(127, 232, 255, 0.6);
  box-shadow: 0 0 16px rgba(127, 232, 255, 0.35);
}

/* --- Wave banner --- */
.ty-banner {
  position: absolute;
  left: 50%;
  top: 38%;
  translate: -50% -50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  opacity: 0;
}

.ty-banner small {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--game-accent);
}

.ty-banner b {
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 12vw, 6rem);
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 40px var(--game-accent);
}

.ty-banner.show {
  animation: ty-banner 1.6s var(--ease) forwards;
}

@keyframes ty-banner {
  0% { opacity: 0; transform: scale(0.6); }
  20% { opacity: 1; transform: scale(1.05); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); }
}

/* --- Ground: city + turret --- */
.ty-ground {
  position: relative;
  height: clamp(54px, 12%, 86px);
  flex-shrink: 0;
}

.ty-city {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 1%;
  opacity: 0.9;
}

.ty-city i {
  width: var(--w);
  height: var(--h);
  background:
    repeating-linear-gradient(180deg, transparent 0 5px, rgba(255, 200, 120, 0.22) 5px 7px),
    linear-gradient(180deg, #1A1E33, #0E1120);
  background-size: 100% 100%, 100% 100%;
  border-radius: 2px 2px 0 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: filter 0.4s var(--ease);
}

.ty-stage[data-damage="1"] .ty-city i:nth-child(3n) { filter: brightness(0.4); }
.ty-stage[data-damage="2"] .ty-city i:nth-child(2n) { filter: brightness(0.35) sepia(1) hue-rotate(-30deg); }

.ty-turret {
  --aim: 0rad;
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 52px;
  height: 46px;
  translate: -50% 0;
}

.ty-turret__base {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22px;
  border-radius: 26px 26px 4px 4px;
  background: linear-gradient(180deg, #2B3050, #151829);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 0 20px var(--game-glow);
}

.ty-turret__base::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 6px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--game-accent);
  box-shadow: 0 0 12px var(--game-accent);
}

.ty-turret__barrel {
  position: absolute;
  left: 50%;
  bottom: 12px;
  width: 8px;
  height: 34px;
  margin-left: -4px;
  border-radius: 4px;
  background: linear-gradient(90deg, #3A4068, #8A93C8, #3A4068);
  transform-origin: 50% 100%;
  transform: rotate(var(--aim));
}

.ty-turret.recoil .ty-turret__barrel {
  animation: ty-recoil 0.09s linear;
}

@keyframes ty-recoil {
  50% { height: 28px; }
}

/* --- Console --- */
.ty-console {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.45));
  border-top: 1px solid var(--arena-line);
  flex-shrink: 0;
}

.ty-lock {
  width: 20px;
  text-align: center;
  color: var(--game-accent);
  font-size: 1rem;
  text-shadow: 0 0 10px var(--game-glow);
}

.ty-input {
  width: min(440px, 100%);
  height: 46px;
  padding: 0 16px;
  font-family: var(--font-mono);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--arena-ink);
  caret-color: var(--game-accent);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--arena-line-strong);
  border-radius: var(--r-full);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.ty-input::placeholder {
  color: var(--arena-ink-3);
}

.ty-input:focus {
  border-color: var(--game-accent);
  box-shadow: 0 0 0 3px var(--game-soft), 0 0 30px -6px var(--game-glow);
}

.ty-input.typo {
  animation: ty-typo 0.3s var(--ease);
}

@keyframes ty-typo {
  0%, 60% { border-color: var(--arena-bad); box-shadow: 0 0 0 3px rgba(255, 84, 104, 0.3); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
}

@media (max-width: 760px) {
  .ty-word { padding: 4px 9px; font-size: 0.95rem; }
  .ty-word--boss { font-size: 1.15rem; }
  .ty-console { padding: 8px 10px calc(8px + var(--safe-bottom)); }
  .ty-input { height: 42px; }
}
