:root {
  --bg: #fff7d6;
  --panel: rgba(255, 255, 255, 0.92);
  --text: #293241;
  --muted: #62748a;
  --accent: #2ec4b6;
  --accent-strong: #ffca3a;
  --danger: #ff5c8a;
  --success: #44af69;
  --sky: #8ed8ff;
  --pink: #ffafcc;
  --shadow: 0 18px 40px rgba(66, 93, 119, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(ellipse at 18% 18%, #ffffff 0 7%, transparent 8%),
    radial-gradient(ellipse at 25% 16%, #ffffff 0 10%, transparent 11%),
    radial-gradient(ellipse at 78% 22%, #ffffff 0 8%, transparent 9%),
    radial-gradient(ellipse at 86% 20%, #ffffff 0 11%, transparent 12%),
    linear-gradient(180deg, #8ed8ff 0%, #dff6ff 62%, #8fd16a 63%, #5fbf4a 100%);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow-x: hidden;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100%);
  position: relative;
  background: var(--panel);
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.title-bar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
}

.title-bar h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
  color: #2f80ed;
}

.title-bar p {
  margin: 0;
  color: var(--muted);
}

.home-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  margin-top: 0;
  padding: 14px 18px;
  background: #eaf7ff;
  border: none;
  border-radius: 14px;
  color: #2f80ed;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.15s ease;
}

.home-link:hover {
  transform: translateY(-1px);
  background: #d9f1ff;
}

.home-link:focus-visible {
  outline: 3px solid #8ed8ff;
  outline-offset: 2px;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stats span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  background: #ffffff;
  border: 2px solid #d9f1ff;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 700;
}

.stats strong {
  color: #ff7a59;
}

.game-area {
  margin-top: 20px;
}

.word-panel {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(260px, 2fr) minmax(120px, 0.7fr);
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}

.word-panel > div {
  min-height: 84px;
  padding: 14px;
  border-radius: 16px;
  background: #ffffff;
  border: 2px solid #d9f1ff;
  box-shadow: 0 10px 22px rgba(66, 93, 119, 0.08);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.target-display {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.target-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: #fff3b0;
  border: 2px solid #ffd166;
  font-size: 2rem;
}

#targetWord {
  display: block;
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}

.progress {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.progress span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 38px;
  border-radius: 9px;
  background: #f1fbff;
  border: 2px solid #cdeeff;
  color: var(--text);
  font-weight: 900;
}

.progress .filled {
  background: #e2ffd9;
  border-color: #8bd46e;
  color: var(--success);
}

.next-letter {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #293241;
  font-size: 1.7rem;
  box-shadow: 0 0 28px rgba(255, 209, 102, 0.45);
}

.arena {
  position: relative;
  height: min(58vh, 540px);
  min-height: 380px;
  border: 3px solid #9ee3ff;
  border-radius: 20px;
  background:
    radial-gradient(ellipse at 18% 18%, rgba(255, 255, 255, 0.92) 0 8%, transparent 9%),
    radial-gradient(ellipse at 26% 16%, rgba(255, 255, 255, 0.92) 0 11%, transparent 12%),
    radial-gradient(ellipse at 74% 20%, rgba(255, 255, 255, 0.92) 0 9%, transparent 10%),
    radial-gradient(ellipse at 84% 18%, rgba(255, 255, 255, 0.92) 0 12%, transparent 13%),
    linear-gradient(180deg, #bfefff 0%, #eefcff 66%, #9ad66f 67%, #6bc957 100%);
  background-size: auto;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.arena.flash-good {
  animation: flashGood 180ms ease-out;
}

.arena.flash-bad {
  animation: flashBad 240ms ease-out;
}

.hero {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, #fff3b0 13% 48%, #ffca3a 78%);
  color: #293241;
  cursor: grab;
  box-shadow:
    0 0 0 6px rgba(255, 209, 102, 0.12),
    0 0 26px rgba(255, 209, 102, 0.46),
    0 16px 34px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%);
  z-index: 5;
}

.hero span {
  font-size: 2.25rem;
  line-height: 1;
  transform: translateY(-1px);
}

.hero.dragging {
  cursor: grabbing;
  box-shadow:
    0 0 0 9px rgba(255, 209, 102, 0.15),
    0 0 34px rgba(255, 209, 102, 0.58),
    0 16px 34px rgba(0, 0, 0, 0.28);
}

.hero.hit {
  animation: heroHit 240ms ease-out;
}

.letter {
  position: absolute;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffffff, #bde0fe);
  color: #293241;
  font-size: 1.35rem;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
  will-change: transform;
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.letter.needed {
  background: linear-gradient(135deg, #ffe08a, #ffb703);
  box-shadow:
    0 0 0 4px rgba(255, 209, 102, 0.16),
    0 0 24px rgba(255, 209, 102, 0.5),
    0 12px 24px rgba(0, 0, 0, 0.2);
}

.letter.pop {
  animation: pop 180ms ease-out forwards;
}

.letter.bad-pop {
  animation: badPop 220ms ease-out forwards;
}

.options-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(255, 247, 214, 0.84);
  z-index: 12;
}

.options-modal.hidden {
  display: none;
}

.options-card {
  width: min(540px, 100%);
  max-height: min(720px, 92vh);
  overflow: auto;
  display: grid;
  gap: 18px;
  padding: 22px;
  border-radius: 22px;
  background: #ffffff;
  border: 3px solid #d9f1ff;
  box-shadow: var(--shadow);
}

.options-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.options-header h2 {
  margin: 0;
  color: #2f80ed;
}

.options-header button {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: #ffca3a;
  color: #293241;
  cursor: pointer;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

.option-group {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: #f8fdff;
  border: 2px solid #d9f1ff;
}

.option-title {
  color: var(--muted);
  font-weight: 900;
}

.option-group label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.option-group input[type="radio"],
.option-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.custom-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 800;
}

.custom-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.option-group textarea {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  border: 2px solid #d9f1ff;
  border-radius: 12px;
  padding: 12px 14px;
  background: #f8fdff;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.option-group textarea:focus {
  outline: 2px solid rgba(68, 215, 182, 0.75);
}

.option-group p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.controls {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.controls button,
.overlay-card button {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #ffca3a, #2ec4b6);
  color: #293241;
  cursor: pointer;
  font-weight: 900;
}

.controls button:hover,
.overlay-card button:hover {
  transform: translateY(-1px);
}

.hint {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(255, 247, 214, 0.82);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(430px, 100%);
  padding: 26px;
  border-radius: 22px;
  background: #ffffff;
  border: 3px solid #d9f1ff;
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card h2 {
  margin: 0 0 12px;
  font-size: 2rem;
}

.overlay-card p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.6;
}

.particle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success);
  pointer-events: none;
  animation: particle 420ms ease-out forwards;
  z-index: 6;
}

@keyframes flashGood {
  from { border-color: rgba(126, 231, 135, 0.9); }
  to { border-color: rgba(255, 255, 255, 0.12); }
}

@keyframes flashBad {
  0%, 100% { transform: translateX(0); border-color: rgba(255, 255, 255, 0.12); }
  25% { transform: translateX(-5px); border-color: rgba(255, 107, 107, 0.88); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@keyframes heroHit {
  0% { transform: translate(-50%, -50%) scale(1); }
  45% { transform: translate(-50%, -50%) scale(1.18); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes pop {
  to {
    opacity: 0;
    transform: scale(1.65) rotate(12deg);
  }
}

@keyframes badPop {
  to {
    opacity: 0;
    transform: scale(0.4) rotate(-18deg);
  }
}

@keyframes particle {
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.2);
  }
}

@media (max-width: 760px) {
  body {
    align-items: stretch;
    padding: 12px;
  }

  .app-shell {
    padding: 16px;
    border-radius: 18px;
  }

  .title-bar {
    align-items: stretch;
  }

  .word-panel {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr) auto;
    gap: 8px;
    align-items: stretch;
  }

  .word-panel > div {
    min-height: 68px;
    padding: 10px;
  }

  .label {
    font-size: 0.72rem;
    margin-bottom: 5px;
  }

  .target-display {
    gap: 7px;
  }

  .target-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    font-size: 1.45rem;
  }

  #targetWord {
    font-size: 1.18rem;
    letter-spacing: 0.04em;
  }

  .progress {
    gap: 4px;
  }

  .progress span {
    width: 24px;
    height: 30px;
    border-radius: 7px;
    font-size: 0.88rem;
  }

  .next-letter {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }

  .arena {
    height: 56vh;
    min-height: 360px;
  }

  .hero {
    width: 62px;
    height: 62px;
  }

  .letter {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 430px) {
  .word-panel {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) auto;
  }

  .word-panel > div {
    padding: 8px;
  }

  .target-icon {
    width: 34px;
    height: 34px;
    font-size: 1.25rem;
  }

  #targetWord {
    font-size: 1rem;
  }

  .progress span {
    width: 21px;
    height: 28px;
    font-size: 0.78rem;
  }

  .next-letter {
    width: 36px;
    height: 36px;
  }
}
