/* Word Invaders — English Room Games */
:root {
  --night: #120f33;
  --night-2: #1d1850;
  --ink: #f4f1ff;
  --muted: #b3aee6;
  --muted-2: #8580c4;
  --line: rgba(255, 255, 255, .14);
  --green: #57e3a3;
  --gold: #ffc93c;
  --gold-dark: #c99a1c;
  --red: #ff5f6d;
  --violet: #7b6cf0;
  --display: 'Fredoka', 'Nunito', sans-serif;
  --body: 'Nunito', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--body); color: var(--ink);
  background: var(--night);
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: #0d0a28; border-bottom: 1px solid var(--line); flex-shrink: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font: 700 24px var(--display); white-space: nowrap; }
.brand .site { font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); text-decoration: none; white-space: nowrap; }
.brand .site:hover { color: var(--gold); }
.spacer { flex: 1; }
.iconbtn {
  width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.05);
  color: var(--muted); cursor: pointer; text-decoration: none;
}
.iconbtn:hover { color: var(--ink); border-color: var(--gold); }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn[aria-pressed="false"] .wave { display: none; }
.pill-stat { padding: 5px 14px; border-radius: 999px; background: rgba(0,0,0,.35); border: 1px solid var(--line); font: 700 1.2rem var(--display); color: var(--gold); min-width: 70px; text-align: center; }
.lives { display: flex; gap: 3px; }
.lives svg { width: 22px; height: 22px; }
.lives .lost { opacity: .22; }
.lives .pop { animation: heartpop .5s; }
@keyframes heartpop { 30% { transform: scale(1.6); } }

/* ---------- play area ---------- */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.space {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  background: radial-gradient(ellipse at 50% 120%, #3a2a8a 0%, #1d1850 35%, #120f33 70%, #0a0822 100%);
}
#fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.words { position: absolute; inset: 0; pointer-events: none; }
.word {
  position: absolute; left: 0; top: 0; will-change: transform;
  padding: 6px 14px 7px; border-radius: 14px;
  background: rgba(30, 24, 80, .88); border: 2px solid rgba(160, 150, 255, .55);
  box-shadow: 0 0 18px rgba(123, 108, 240, .35);
  font: 700 clamp(1.15rem, 2.4vw, 1.6rem) var(--display); letter-spacing: .04em; white-space: nowrap;
  color: var(--ink);
}
.word::before { /* little alien antenna */
  content: ''; position: absolute; left: 50%; top: -9px; width: 2px; height: 8px; background: rgba(160, 150, 255, .7); transform: translateX(-50%);
}
.word::after { content: ''; position: absolute; left: 50%; top: -13px; width: 7px; height: 7px; border-radius: 50%; background: var(--green); transform: translateX(-50%); }
.word .done { color: var(--green); }
.word.target { border-color: var(--green); box-shadow: 0 0 0 3px rgba(87, 227, 163, .3), 0 0 24px rgba(87, 227, 163, .45); z-index: 2; }
.word.slow { background: rgba(80, 60, 10, .92); border-color: var(--gold); box-shadow: 0 0 22px rgba(255, 201, 60, .55); }
.word.slow::after { background: var(--gold); }
.word.bomb { background: rgba(90, 15, 30, .92); border-color: var(--red); box-shadow: 0 0 22px rgba(255, 95, 109, .6); }
.word.bomb::after { background: var(--red); }
.word.wrong { animation: wobble .3s; }
@keyframes wobble { 25% { margin-left: -6px; } 75% { margin-left: 6px; } }
.space.slowmo { filter: saturate(.7) hue-rotate(-20deg); }
.space.hurt { animation: hurt .45s; }
@keyframes hurt { 0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 95, 109, 0); } 30% { box-shadow: inset 0 0 0 12px rgba(255, 95, 109, .7); } }

.hud { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.wave-label { font: 600 1rem var(--display); color: var(--muted); background: rgba(0,0,0,.3); padding: 3px 12px; border-radius: 999px; }
.combo { font: 700 1.3rem var(--display); color: var(--night); background: var(--gold); padding: 2px 12px; border-radius: 999px; animation: combo .3s; }
@keyframes combo { from { transform: scale(1.6); } }
.banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  text-align: center; font: 700 clamp(2rem, 6vw, 3.4rem)/1.1 var(--display); color: var(--gold);
  text-shadow: 0 4px 0 rgba(0,0,0,.4); pointer-events: none; animation: bannerIn .5s ease-out;
}
.banner small { display: block; font-size: .45em; color: var(--ink); margin-top: 6px; }
@keyframes bannerIn { from { transform: translate(-50%, -50%) scale(.4); opacity: 0; } }
.planet {
  position: absolute; left: 50%; bottom: -260px; width: 160%; height: 320px; transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 20%, #57e3a3 0%, #2fae7a 25%, #1b6d55 55%, #0f3d33 80%);
  box-shadow: 0 -6px 30px rgba(87, 227, 163, .35);
}
.cannon { position: absolute; left: 50%; bottom: 18px; width: 54px; height: 64px; margin-left: -27px; transform-origin: 50% 75%; transition: transform .08s; }
.cannon svg { width: 100%; height: 100%; display: block; }
.typed {
  position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%);
  font: 700 1.2rem var(--display); letter-spacing: .1em; color: var(--green);
  text-shadow: 0 2px 0 rgba(0,0,0,.5); pointer-events: none; min-height: 1.4em;
}

/* ---------- on-screen keyboard (tablets and phones) ---------- */
.keyboard { flex-shrink: 0; padding: 6px 4px 8px; background: #0d0a28; display: flex; flex-direction: column; gap: 6px; user-select: none; }
.krow { display: flex; justify-content: center; gap: 4px; }
.key {
  flex: 1; max-width: 44px; height: 46px; border: 0; border-radius: 7px;
  background: #2c2670; color: var(--ink); font: 700 1.1rem var(--display); text-transform: uppercase;
  touch-action: manipulation; box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.key:active { background: var(--violet); transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.key.wide { max-width: 80px; flex: 1.6; font-size: .78rem; letter-spacing: .03em; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(8, 6, 26, .78); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 14px; }
.card { width: min(520px, 100%); max-height: calc(100dvh - 28px); overflow: auto; background: var(--night-2); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: 0 30px 70px rgba(0,0,0,.6); }
.card.small { width: min(380px, 100%); }
.card.center { text-align: center; }
.card h2 { margin: 0 0 6px; font: 700 2rem var(--display); }
.card h3 { margin: 18px 0 6px; font: 600 1.15rem var(--display); color: var(--gold); }
.card p { line-height: 1.5; margin: 0 0 10px; }
.card .big { font-size: 1.1rem; }
.kicker { font: 600 .8rem var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.kicker a { color: inherit; text-decoration: none; }
.label { display: block; font: 600 .8rem var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 10px 0 6px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.levels button { text-align: left; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--line); background: rgba(0,0,0,.25); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.levels button b { font: 700 1.15rem var(--display); }
.levels button span { font-size: .85rem; color: var(--muted); line-height: 1.3; }
.levels button em { font-style: normal; font-size: .8rem; color: var(--gold); font-weight: 800; min-height: 1em; }
.levels button[aria-pressed="true"] { border-color: var(--green); background: rgba(87, 227, 163, .12); }
.howto { padding-left: 20px; margin: 14px 0 6px; line-height: 1.55; }
.howto li { margin-bottom: 4px; }
.g { color: var(--green); } .gold { color: var(--gold); } .red { color: var(--red); }
.note { color: var(--muted-2); font-size: .85rem; margin-top: 12px !important; text-align: center; }
.hint { color: var(--muted); font-size: .92rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.07); border-radius: 12px; padding: 11px 16px; font-weight: 800; font-size: 1rem; cursor: pointer; min-height: 44px; }
.btn:hover { background: rgba(255,255,255,.13); }
.btn.primary { background: var(--gold); color: var(--night); border-color: transparent; box-shadow: 0 4px 0 var(--gold-dark); font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.btn.primary:hover { background: #ffd35e; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn.wide { width: 100%; margin-top: 10px; }
.linkbtn { background: none; border: 0; color: var(--gold); font-weight: 800; cursor: pointer; margin-top: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.stats div { background: rgba(0,0,0,.25); border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font: 700 1.5rem var(--display); color: var(--gold); }
.stats span { color: var(--muted); font-size: .8rem; font-weight: 700; }
.stats .newbest { grid-column: 1 / -1; background: rgba(87, 227, 163, .2); font-weight: 800; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chips li { padding: 5px 12px; border-radius: 999px; background: rgba(0,0,0,.3); border: 1px solid var(--line); font: 600 1.05rem var(--display); cursor: pointer; }
.chips li:hover { border-color: var(--gold); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }

@media (max-width: 560px) {
  .brand .site { display: none; }
  .brand h1 { font-size: 19px; }
  .topbar { gap: 6px; padding-inline: 8px; }
  .iconbtn { width: 33px; height: 33px; }
  .pill-stat { min-width: 54px; padding: 4px 10px; font-size: 1rem; }
  .lives svg { width: 18px; height: 18px; }
  .levels { grid-template-columns: 1fr; }
  .levels button { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
  .card { padding: 18px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
