:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #22c55e;
  --error: #ef4444;
  --background: #0f172a;
  --surface: #1e293b;
  --card: #f8fafc;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --gold: #fbbf24;
  --border: rgba(255,255,255,.12);
  --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: var(--font-family);
  background:
    radial-gradient(circle at top, rgba(99,102,241,.24), transparent 36%),
    var(--background);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}

button {
  border: 0;
  outline: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 900;
  transition: transform .1s, opacity .2s, filter .2s;
}

button:active {
  transform: scale(.97);
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(.25);
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.app-container {
  width: 100%;
  min-height: 100vh;
  max-width: 520px;
  background: var(--surface);
  position: relative;
  box-shadow: 0 0 50px rgba(0,0,0,.55);
  overflow: hidden;
}

@media (min-width: 540px) {
  body {
    padding: 24px 12px;
    align-items: center;
  }

  .app-container {
    min-height: min(92vh, 900px);
    border-radius: 26px;
    border: 1px solid var(--border);
  }
}

.screen {
  width: 100%;
  min-height: 100vh;
  background: var(--surface);
  display: none;
  flex-direction: column;
  opacity: 0;
  transition: opacity .25s ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

.menu-screen {
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: max(16px, env(safe-area-inset-top)) 20px max(18px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.back-link {
  align-self: flex-start;
  font-size: .82rem;
  color: var(--text-muted);
  background: rgba(255,255,255,.06);
  padding: 8px 11px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.logo {
  font-size: clamp(2.6rem, 10vw, 4rem);
  margin: 4px 0 8px;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 0 18px rgba(99,102,241,.55));
}

h1 {
  font-size: clamp(1.8rem, 7vw, 2.45rem);
  letter-spacing: -1px;
}

.subtitle {
  color: var(--text-muted);
  font-size: .95rem;
  line-height: 1.45;
  max-width: 360px;
  margin: 8px auto 18px;
}

.section-label {
  width: 100%;
  text-align: left;
  font-size: .78rem;
  color: var(--text-muted);
  font-weight: 900;
  letter-spacing: .6px;
  margin: 4px 0 10px;
}

.cat-grid,
.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  width: 100%;
  margin-bottom: 18px;
}

.cat-btn,
.level-btn {
  background: rgba(255,255,255,.055);
  border: 2px solid transparent;
  border-radius: 16px;
  color: var(--text-muted);
  min-height: 78px;
  padding: 10px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.cat-btn span,
.level-btn span {
  font-size: 1.45rem;
}

.cat-btn strong,
.level-btn strong {
  font-size: .76rem;
}

.level-btn small {
  font-size: .63rem;
  line-height: 1.15;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0 4px;
}

.cat-btn.selected,
.level-btn.selected {
  border-color: var(--primary);
  background: rgba(99,102,241,.17);
  color: white;
}

.level-wide {
  grid-column: span 2;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 17px;
  border-radius: 17px;
  width: 100%;
  font-size: 1.05rem;
  letter-spacing: .7px;
  text-transform: uppercase;
  box-shadow: 0 10px 24px rgba(99,102,241,.33);
}

.btn-secondary {
  background: rgba(255,255,255,.1);
  color: white;
  padding: 14px;
  border-radius: 15px;
  width: 100%;
  margin-top: 13px;
  border: 1px solid var(--border);
}

.load-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.35);
  color: #fecaca;
  border-radius: 14px;
  padding: 12px;
  line-height: 1.35;
  font-size: .88rem;
  margin-bottom: 12px;
  width: 100%;
}

.game-screen {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

header {
  padding: max(14px, env(safe-area-inset-top)) 20px 12px;
  background: rgba(0,0,0,.22);
  width: 100%;
  flex-shrink: 0;
}

.hud-row,
.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.progress-row {
  font-size: .76rem;
  color: var(--text-muted);
}

.hud-row:last-child {
  margin-bottom: 0;
}

.badge {
  background: var(--primary);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score {
  color: var(--gold);
  font-weight: 900;
}

.hud-small {
  font-size: .82rem;
  color: var(--text-muted);
}

.phase-track {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,.12);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.phase-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(135deg, var(--success), var(--gold));
  transition: width .25s ease;
}

.game-area {
  flex: 1;
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 100%;
  gap: 12px;
}

.hangman-card {
  background: rgba(255,255,255,.055);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.hangman {
  width: 100%;
  max-width: 260px;
  height: 170px;
}

.base,
.part {
  fill: none;
  stroke: #f8fafc;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.base {
  opacity: .42;
}

.part {
  opacity: 0;
  transition: opacity .2s;
  stroke: var(--error);
}

.part.visible {
  opacity: 1;
}

.word-card {
  background: white;
  color: var(--background);
  border-radius: 22px;
  padding: 18px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.34);
  text-align: center;
}

.hint-label {
  color: #64748b;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.hint-text {
  color: #334155;
  font-size: .92rem;
  line-height: 1.35;
  margin-bottom: 14px;
}

.word-display {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
}

.letter-slot {
  width: 28px;
  height: 36px;
  border-bottom: 4px solid #0f172a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  font-weight: 900;
  text-transform: uppercase;
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
  width: 100%;
}

.key {
  min-height: 42px;
  border-radius: 11px;
  background: rgba(255,255,255,.1);
  color: white;
  border: 1px solid rgba(255,255,255,.08);
}

.key.correct {
  background: rgba(34,197,94,.9);
}

.key.wrong {
  background: rgba(239,68,68,.9);
}

.key:disabled {
  opacity: .8;
}

.result-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 20px;
  min-height: 100vh;
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 12px;
}

.result-screen h2 {
  font-size: clamp(1.8rem, 7vw, 2.25rem);
  margin-bottom: 8px;
  color: var(--gold);
}

.result-message {
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 18px;
}

.result-box {
  width: 100%;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  margin: 16px 0 22px;
}

.result-box p {
  font-size: .78rem;
  color: var(--text-muted);
  font-weight: 900;
  letter-spacing: .7px;
}

.result-box strong {
  display: block;
  font-size: clamp(3rem, 15vw, 4rem);
  line-height: 1;
  color: white;
  margin-top: 8px;
}

@media (max-height: 740px) {
  .menu-screen {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .back-link {
    margin-bottom: 6px;
  }

  .logo {
    font-size: 2.35rem;
    margin: 0 0 4px;
  }

  h1 {
    font-size: 1.65rem;
  }

  .subtitle {
    font-size: .82rem;
    margin-bottom: 11px;
  }

  .cat-grid,
  .level-grid {
    gap: 7px;
    margin-bottom: 12px;
  }

  .cat-btn,
  .level-btn {
    min-height: 63px;
    padding: 7px 4px;
    border-radius: 13px;
  }

  .cat-btn span,
  .level-btn span {
    font-size: 1.18rem;
  }

  .cat-btn strong,
  .level-btn strong {
    font-size: .68rem;
  }

  .level-btn small {
    font-size: .56rem;
  }

  .btn-primary {
    padding: 14px;
    font-size: .95rem;
  }

  header {
    padding-top: max(9px, env(safe-area-inset-top));
    padding-bottom: 8px;
  }

  .game-area {
    padding: 10px 14px 14px;
    gap: 9px;
  }

  .hangman {
    height: 128px;
  }

  .word-card {
    padding: 14px;
  }

  .hint-text {
    font-size: .84rem;
    margin-bottom: 10px;
  }

  .letter-slot {
    width: 24px;
    height: 31px;
    font-size: 1.2rem;
  }

  .key {
    min-height: 35px;
    border-radius: 9px;
    font-size: .82rem;
  }
}

@media (max-width: 380px) {
  .cat-grid,
  .level-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .level-wide {
    grid-column: span 2;
  }

  .keyboard {
    grid-template-columns: repeat(6, 1fr);
  }

  .letter-slot {
    width: 24px;
    height: 32px;
    font-size: 1.22rem;
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}
