/* ===== CSS Variables ===== */
:root {
  --bg-dark: #0a0e17;
  --bg-panel: rgba(15, 22, 38, 0.92);
  --accent-green: #39ff14;
  --accent-red: #ff2d55;
  --accent-orange: #ff9500;
  --accent-cyan: #00d4ff;
  --accent-purple: #a855f7;
  --text-primary: #e8edf5;
  --text-muted: #8892a4;
  --border-glow: rgba(57, 255, 20, 0.3);
  --font-display: "Orbitron", sans-serif;
  --font-body: "Roboto", sans-serif;
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  --safe-top: max(12px, env(safe-area-inset-top));
  --typing-area-bottom: max(104px, calc(env(safe-area-inset-bottom) + 80px));
  --scrollbar-track: rgba(255, 255, 255, 0.05);
  --scrollbar-thumb: rgba(0, 212, 255, 0.35);
  --scrollbar-thumb-hover: rgba(57, 255, 20, 0.5);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    rgba(0, 212, 255, 0.5),
    rgba(57, 255, 20, 0.35)
  );
  border-radius: 999px;
  border: 2px solid rgba(10, 14, 23, 0.8);
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(
    180deg,
    rgba(0, 212, 255, 0.7),
    rgba(57, 255, 20, 0.55)
  );
}

*::-webkit-scrollbar-button {
  display: none;
  height: 0;
  width: 0;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ===== Screens ===== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen:not(.active) {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.screen.active {
  display: flex;
  visibility: visible;
  pointer-events: auto;
  padding-left: 16px;
  padding-right: 16px;
  box-sizing: border-box;
}

/* Shared centered panel for menu sub-screens */
.screen-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 0
    max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  box-sizing: border-box;
}

.screen-heading {
  width: 100%;
  text-align: center;
  margin-bottom: 16px;
}

.screen-actions {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-top: 12px;
  flex-shrink: 0;
}

.btn-screen-back {
  width: 100%;
  max-width: 320px;
  align-self: center;
}

.screen-heading .shop-sub,
.screen-heading .settings-sub,
.screen-heading .bestiary-sub {
  margin-bottom: 0;
}

#shop-screen.active,
#bestiary-screen.active,
#settings-screen.active {
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Stars Background ===== */
.stars {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(1px 1px at 10% 20%, #fff8, transparent),
    radial-gradient(1px 1px at 30% 60%, #fff6, transparent),
    radial-gradient(1px 1px at 50% 10%, #fff8, transparent),
    radial-gradient(1px 1px at 70% 80%, #fff6, transparent),
    radial-gradient(1px 1px at 90% 40%, #fff8, transparent),
    radial-gradient(1px 1px at 15% 85%, #fff5, transparent),
    radial-gradient(1px 1px at 85% 15%, #fff5, transparent),
    linear-gradient(180deg, #0a0e17 0%, #121a2e 50%, #1a0a0a 100%);
  animation: twinkle 4s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes twinkle {
  from { opacity: 0.85; }
  to { opacity: 1; }
}

/* ===== Start Screen — Home ===== */
#start-screen {
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;
  height: 100%;
  max-height: 100dvh;
  flex-direction: column;
  position: relative;
  isolation: isolate;
  box-sizing: border-box;
}

#start-screen .home-topbar,
#start-screen .home-main {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

.io-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #0c1222 0%, #141028 45%, #1a0e18 100%);
  overflow: hidden;
  pointer-events: none;
}

.io-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black, transparent);
}

.io-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: io-drift 8s ease-in-out infinite alternate;
}

.io-glow-a {
  width: 320px;
  height: 320px;
  background: #39ff14;
  top: -80px;
  left: -60px;
}

.io-glow-b {
  width: 280px;
  height: 280px;
  background: #a855f7;
  bottom: 10%;
  right: -40px;
  animation-delay: -3s;
}

@keyframes io-drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(24px, 16px) scale(1.08); }
}

.io-float {
  position: absolute;
  font-size: 2rem;
  opacity: 0.12;
  animation: io-bob 6s ease-in-out infinite;
}

.io-float-1 { top: 18%; left: 8%; animation-delay: 0s; }
.io-float-2 { top: 62%; right: 10%; font-size: 2.4rem; animation-delay: -2s; }
.io-float-3 { bottom: 22%; left: 14%; animation-delay: -4s; }

@keyframes io-bob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-18px) rotate(5deg); }
}

.home-topbar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  max-width: none;
  margin: 0;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    4px
    max(16px, env(safe-area-inset-left));
  flex-shrink: 0;
  box-sizing: border-box;
  pointer-events: none;
}

.home-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.home-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 12px var(--accent-green);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(0.75rem, 3vw, 0.95rem);
  letter-spacing: 0.06em;
  color: var(--text-primary);
  line-height: 1.2;
}

.coin-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 193, 7, 0.35);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.btn-icon:hover {
  border-color: var(--accent-cyan);
  transform: scale(1.06);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.25);
}

.home-main {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding:
    max(52px, calc(env(safe-area-inset-top) + 44px))
    16px
    8px;
  overflow: hidden;
  min-height: 0;
  pointer-events: auto;
}

.home-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 12px;
}

.home-footer {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 16px max(8px, env(safe-area-inset-bottom));
  text-align: center;
  pointer-events: none;
  background: linear-gradient(
    0deg,
    rgba(10, 14, 23, 0.95) 0%,
    rgba(10, 14, 23, 0.5) 70%,
    transparent 100%
  );
}

.home-footer a {
  pointer-events: auto;
}

.footer-contact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35em 0.65em;
  font-size: 0.58rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.footer-contact a {
  color: var(--accent-cyan);
  text-decoration: none;
}

.footer-contact a:hover {
  text-decoration: underline;
}

.home-hero {
  text-align: center;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.hero-badge {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 999px;
  padding: 5px 14px;
  margin-bottom: 14px;
}

.hero-title {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 0.95;
  margin-bottom: 0;
}

.hero-line {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 7vh, 2.6rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  -webkit-text-stroke: 2px rgba(0, 0, 0, 0.5);
  paint-order: stroke fill;
}

.hero-green {
  color: var(--accent-green);
  text-shadow: 0 4px 0 #166534, 0 0 30px rgba(57, 255, 20, 0.4);
}

.hero-cyan {
  color: var(--accent-cyan);
  text-shadow: 0 4px 0 #0e7490, 0 0 30px rgba(0, 212, 255, 0.35);
}

.hero-red {
  color: var(--accent-red);
  text-shadow: 0 4px 0 #9f1239, 0 0 30px rgba(255, 45, 85, 0.35);
}

.hero-tagline {
  font-size: 0.9rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.io-panel {
  width: 100%;
  background: rgba(8, 12, 22, 0.75);
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 12px 12px;
  backdrop-filter: blur(12px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  flex-shrink: 1;
  min-height: 0;
}

.panel-label {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: left;
}

.io-mode-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 0;
}

.io-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  height: 58px;
  min-height: 58px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  color: var(--text-primary);
  font-family: var(--font-body);
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.io-tile:hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.07);
}

.io-tile.selected {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.io-subpanel-slot {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  min-height: 168px;
  box-sizing: border-box;
}

.io-subpanel-slot .io-subpanel {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.io-subpanel-slot .io-subpanel.is-hidden {
  display: none !important;
}

.io-subpanel {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.io-diff-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 0;
}

.io-pill {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: 44px;
  text-align: center;
  border-radius: 12px;
}

.io-pill .diff-icon {
  font-size: 1.2rem;
}

.io-pill .diff-name {
  min-width: unset;
  font-size: 0.72rem;
}

.io-pill:hover {
  transform: translateY(-2px);
}

.btn-play-io {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 14px 24px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #0a0e17;
  background: linear-gradient(180deg, #5dff2e 0%, #22c55e 50%, #16a34a 100%);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 52px;
  box-shadow:
    0 5px 0 #15803d,
    0 10px 24px rgba(57, 255, 20, 0.3);
  transition: all 0.15s ease;
  animation: play-pulse 2.5s ease-in-out infinite;
}

.btn-play-io:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 0 #15803d,
    0 16px 40px rgba(57, 255, 20, 0.45);
}

.btn-play-io:active {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #15803d,
    0 4px 16px rgba(57, 255, 20, 0.3);
}

.play-icon {
  font-size: 1.2rem;
}

@keyframes play-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}

/* Legacy title classes (other screens) */
.game-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 6vw, 3.2rem);
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-zombie {
  color: var(--accent-green);
  text-shadow: 0 0 20px rgba(57, 255, 20, 0.6);
}

.title-typing {
  color: var(--accent-cyan);
  text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
}

.title-defense {
  color: var(--accent-red);
  text-shadow: 0 0 20px rgba(255, 45, 85, 0.5);
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 32px;
}

.difficulty-panel h2,
.mode-panel h2,
.campaign-panel h2 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.difficulty-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 28px;
}

.difficulty-cards.io-diff-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex-direction: unset;
  margin-bottom: 0;
}

.diff-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg-panel);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  color: var(--text-primary);
  font-family: var(--font-body);
  min-height: 56px;
}

.diff-card.io-pill {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: 44px;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 0;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.diff-card.io-pill:hover {
  border-color: rgba(255, 255, 255, 0.28);
  transform: translateY(-2px);
}

.diff-card.io-pill.selected {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.diff-card:not(.io-pill):hover {
  border-color: rgba(57, 255, 20, 0.4);
  transform: translateX(4px);
}

.diff-card.selected {
  border-color: var(--accent-green);
  box-shadow: 0 0 20px rgba(57, 255, 20, 0.2);
  background: rgba(57, 255, 20, 0.08);
}

.diff-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.diff-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  min-width: 72px;
}

.diff-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-primary {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 16px 48px;
  background: linear-gradient(135deg, var(--accent-green), #22c55e);
  color: #0a0e17;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 52px;
  min-width: 180px;
}

.btn-primary:hover {
  transform: scale(1.04);
  box-shadow: 0 0 30px rgba(57, 255, 20, 0.5);
}

.btn-primary:active {
  transform: scale(0.98);
}

.hint {
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Coin Bar ===== */
.coin-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 10px 16px;
  background: rgba(255, 193, 7, 0.08);
  border: 1px solid rgba(255, 193, 7, 0.25);
  border-radius: 24px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

.coin-bar.inline {
  margin-bottom: 0;
}

.coin-icon {
  font-size: 1.2rem;
}

.coin-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: #ffc107;
}

/* ===== Mode tile shared ===== */
.mode-icon {
  font-size: 1.3rem;
}

.mode-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.72rem;
}

.difficulty-panel .io-diff-row {
  min-height: 132px;
  align-content: center;
}
.campaign-panel {
  margin-bottom: 0;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 0;
  max-height: 132px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.level-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  min-height: 34px;
  background: var(--bg-panel);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
  font-family: var(--font-body);
}

.level-btn:hover:not(:disabled) {
  border-color: rgba(255, 193, 7, 0.5);
  transform: translateY(-2px);
}

.level-btn.selected {
  border-color: #ffc107;
  box-shadow: 0 0 16px rgba(255, 193, 7, 0.25);
  background: rgba(255, 193, 7, 0.1);
}

.level-btn.completed {
  border-color: rgba(57, 255, 20, 0.55);
  background: rgba(57, 255, 20, 0.08);
}

.level-btn.completed:hover:not(:disabled) {
  border-color: rgba(57, 255, 20, 0.75);
}

.level-btn.completed.selected {
  border-color: var(--accent-green);
  box-shadow: 0 0 16px rgba(57, 255, 20, 0.25);
  background: rgba(57, 255, 20, 0.12);
}

.level-btn.completed .level-num {
  color: var(--accent-green);
}

.level-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.level-num {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 0.9rem;
  color: #ffc107;
  line-height: 1;
}

.level-btn.locked .level-num {
  color: var(--text-muted);
}

.level-check {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 0.45rem;
  color: var(--accent-green);
  line-height: 1;
}

/* ===== Victory Screen ===== */
.victory-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  box-sizing: border-box;
}

.victory-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 900;
  color: var(--accent-green);
  text-shadow: 0 0 30px rgba(57, 255, 20, 0.6);
  margin-bottom: 8px;
  animation: pulse-green 1.5s ease-in-out infinite;
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

.victory-sub {
  color: var(--accent-cyan);
  font-family: var(--font-display);
  font-size: 1rem;
  margin-bottom: 28px;
}

.wave-badge.campaign {
  background: rgba(255, 193, 7, 0.15);
  border-color: #ffc107;
  color: #ffc107;
  font-size: 0.75rem;
  max-width: min(280px, 90vw);
  text-align: center;
  line-height: 1.3;
  padding: 6px 12px;
}

/* ===== Buttons ===== */
.btn-secondary {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 12px 28px;
  background: transparent;
  color: var(--accent-cyan);
  border: 2px solid var(--accent-cyan);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-secondary:hover {
  background: rgba(0, 212, 255, 0.12);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.25);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.75rem;
  min-height: 32px;
}

/* ===== Shop Screen ===== */
.shop-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 0
    max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  box-sizing: border-box;
}

.shop-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 4px;
  text-align: center;
}

.shop-title {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 5vw, 1.6rem);
  color: var(--accent-cyan);
  width: 100%;
}

.shop-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
  text-align: center;
  width: 100%;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.upgrade-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
}

.upgrade-card.maxed {
  border-color: rgba(57, 255, 20, 0.3);
  opacity: 0.85;
}

.upgrade-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.upgrade-info {
  flex: 1;
  min-width: 0;
}

.upgrade-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
}

.upgrade-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.upgrade-level {
  font-size: 0.7rem;
  color: var(--accent-purple);
  margin-top: 4px;
  font-family: var(--font-display);
}

.btn-buy {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 10px 14px;
  background: rgba(255, 193, 7, 0.15);
  color: #ffc107;
  border: 1px solid rgba(255, 193, 7, 0.4);
  border-radius: 8px;
  cursor: pointer;
  min-width: 72px;
  min-height: 40px;
  transition: all 0.2s;
}

.btn-buy:hover:not(:disabled) {
  background: rgba(255, 193, 7, 0.25);
  transform: scale(1.04);
}

.btn-buy:disabled {
  opacity: 0.6;
  cursor: default;
  color: var(--accent-green);
  border-color: rgba(57, 255, 20, 0.4);
}

.btn-buy.shake {
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ===== Bestiary ===== */
.bestiary-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 0
    max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  box-sizing: border-box;
}

.bestiary-title {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 900;
  color: var(--accent-green);
  text-align: center;
  margin-bottom: 4px;
}

.bestiary-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.bestiary-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  min-height: 0;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

.bestiary-card {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  text-align: left;
}

.bestiary-card.boss-card {
  border-color: rgba(255, 193, 7, 0.45);
  background: rgba(255, 193, 7, 0.08);
}

.bestiary-icon {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  background: color-mix(in srgb, var(--z-color) 20%, transparent);
  border: 2px solid color-mix(in srgb, var(--z-color) 50%, transparent);
  border-radius: 12px;
}

.bestiary-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bestiary-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  line-height: 1.2;
}

.bestiary-desc {
  font-size: 0.875rem;
  color: #c5cede;
  line-height: 1.45;
}

.bestiary-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trait-pill {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 212, 255, 0.14);
  border: 1px solid rgba(0, 212, 255, 0.35);
  color: #7ee8ff;
  font-family: var(--font-body);
  line-height: 1.3;
}

.bestiary-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 2px;
}

.bestiary-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  text-align: center;
}

.bestiary-stat-label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-display);
}

.bestiary-stat-value {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-display);
  line-height: 1.2;
}

/* ===== Settings ===== */
.settings-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 0
    max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-sizing: border-box;
}

.settings-title {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 900;
  color: var(--accent-cyan);
  margin-bottom: 4px;
}

.settings-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  text-align: left;
  width: 100%;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.setting-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.setting-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.toggle-switch {
  flex-shrink: 0;
  width: 52px;
  height: 30px;
  min-width: 52px;
  min-height: 30px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-switch.on {
  background: rgba(57, 255, 20, 0.2);
  border-color: rgba(57, 255, 20, 0.5);
}

.toggle-switch.on::after {
  transform: translateX(22px);
  background: var(--accent-green);
}

.settings-contact {
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: 10px;
  width: 100%;
  box-sizing: border-box;
}

.settings-contact-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.settings-contact-email {
  font-size: 0.8rem;
  color: var(--accent-cyan);
  text-decoration: none;
}

.settings-contact-email:hover {
  text-decoration: underline;
}

.btn-website-link {
  display: block;
  width: 100%;
  max-width: 320px;
  margin-bottom: 10px;
  text-decoration: none;
  text-align: center;
  box-sizing: border-box;
  align-self: center;
}

/* ===== Game Over Actions ===== */
.gameover-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.final-stat.coin-stat .final-value.coin {
  color: #ffc107;
}

/* ===== Game Screen ===== */
#game-screen {
  background: #0d1520;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.game-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

.game-overlay * {
  pointer-events: auto;
}

/* ===== HUD ===== */
.hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--safe-top) 16px 8px;
  background: linear-gradient(
    180deg,
    rgba(10, 14, 23, 0.9) 0%,
    transparent 100%
  );
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 120px;
}

.hud-right {
  align-items: flex-end;
  gap: 8px;
}

.hud-audio {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-audio {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  backdrop-filter: blur(8px);
}

.btn-audio:hover {
  border-color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.12);
}

.btn-audio.muted {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
  opacity: 0.75;
}

.btn-audio .audio-off {
  display: none;
}

.btn-audio.muted .audio-on {
  display: none;
}

.btn-audio.muted .audio-off {
  display: inline;
}

.btn-quit {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 14px;
  min-height: 36px;
  min-width: 44px;
  background: rgba(255, 45, 85, 0.12);
  border: 1px solid rgba(255, 45, 85, 0.4);
  border-radius: 8px;
  color: var(--accent-red);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.btn-quit:hover {
  background: rgba(255, 45, 85, 0.22);
  border-color: rgba(255, 45, 85, 0.6);
}

.stat {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-label {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  font-family: var(--font-display);
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
}

.stat-value.score {
  color: var(--accent-cyan);
}

.health-bar {
  width: 100px;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.health-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-green), #86efac);
  border-radius: 5px;
  transition: width 0.3s ease, background 0.3s ease;
}

.health-fill.low {
  background: linear-gradient(90deg, var(--accent-orange), var(--accent-red));
}

.wave-badge {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 6px 16px;
  background: rgba(168, 85, 247, 0.2);
  border: 1px solid var(--accent-purple);
  border-radius: 20px;
  color: var(--accent-purple);
}

/* ===== Typing Area ===== */
.typing-area {
  position: absolute;
  bottom: var(--typing-area-bottom);
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
}

.target-word {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-weight: 700;
  letter-spacing: 0.15em;
  min-height: 2.2em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 16px;
  background: rgba(10, 14, 23, 0.85);
  border: 1px solid rgba(57, 255, 20, 0.3);
  border-radius: 8px;
  width: 100%;
  gap: 4px;
}

.target-tag {
  font-size: 0.55rem;
  letter-spacing: 0.12em;
  color: var(--accent-cyan);
  font-family: var(--font-display);
  text-transform: uppercase;
}

.target-tag.boss-tag {
  color: #ffc107;
  font-weight: 700;
}

.target-chars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  letter-spacing: 0.15em;
}

.target-word .placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

.target-word .char {
  display: inline-block;
  transition: color 0.1s;
}

.target-word .char.matched {
  color: var(--accent-green);
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.6);
}

.target-word .char.current {
  color: var(--accent-cyan);
  border-bottom: 2px solid var(--accent-cyan);
  animation: blink 0.8s step-end infinite;
}

.target-word .char.pending {
  color: var(--text-muted);
}

.target-word .char.wrong {
  color: var(--accent-red);
  text-shadow: 0 0 8px rgba(255, 45, 85, 0.6);
}

@keyframes blink {
  50% { opacity: 0.3; }
}

#typing-input {
  width: 100%;
  padding: 14px 18px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  background: rgba(15, 22, 38, 0.95);
  border: 2px solid rgba(0, 212, 255, 0.4);
  border-radius: 8px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}

#typing-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.25);
}

#typing-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.typing-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ===== Damage Flash ===== */
.damage-flash {
  position: absolute;
  inset: 0;
  background: rgba(255, 45, 85, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.damage-flash.active {
  opacity: 1;
}

/* ===== Game Over ===== */
.gameover-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  box-sizing: border-box;
}

.gameover-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  color: var(--accent-red);
  text-shadow: 0 0 30px rgba(255, 45, 85, 0.6);
  margin-bottom: 8px;
  animation: pulse-red 1.5s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.gameover-sub {
  color: var(--text-muted);
  margin-bottom: 32px;
}

.final-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.final-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 24px;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  min-width: 100px;
}

.final-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.final-value {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

/* ===== Responsive ===== */
@media (max-height: 640px) {
  .hero-line {
    font-size: clamp(1.4rem, 6vh, 2rem);
  }

  .io-tile {
    min-height: 58px;
    padding: 6px 3px;
  }

  .btn-play-io {
    min-height: 46px;
    padding: 10px 20px;
    font-size: 1.1rem;
  }
}

@media (min-width: 600px) {
  .home-main {
    max-width: 600px;
  }
}

@media (max-width: 480px) {
  .level-grid {
    grid-template-columns: repeat(6, 1fr);
    max-height: 120px;
  }
}

@media (max-height: 500px) {
  .typing-area {
    bottom: max(64px, calc(env(safe-area-inset-bottom) + 48px));
  }
}
