:root {
  --ink: #1d1430;
  --paper: #fffaf0;
  --panel: rgba(255, 250, 240, 0.92);
  --line: rgba(29, 20, 48, 0.16);
  --shadow: 0 18px 44px rgba(20, 10, 35, 0.28);
  --red: #f04f5f;
  --blue: #1e9ee8;
  --green: #36c96f;
  --yellow: #ffd54a;
  --violet: #7d5cf2;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(rgba(13, 8, 28, 0.12), rgba(13, 8, 28, 0.28)),
    url("assets/grammar-arena-bg.png") center / cover fixed no-repeat;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
  caret-color: transparent;
  user-select: none;
}

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

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.screen {
  width: min(1320px, 100%);
}

.hidden {
  display: none !important;
}

.start-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  gap: 24px;
  align-items: center;
}

.start-copy {
  min-height: 560px;
  display: grid;
  align-content: end;
  padding: clamp(18px, 4vw, 44px);
  color: #fff;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.48);
}

.kicker {
  width: fit-content;
  margin: 0 0 12px;
  padding: 8px 11px;
  border: 3px solid #12091f;
  border-radius: 8px;
  background: var(--yellow);
  color: #241600;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow: 4px 4px 0 #12091f;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 9ch;
  margin-bottom: 18px;
  font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
  font-size: clamp(3.4rem, 8vw, 7.6rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 5px 5px 0 #12091f, 0 10px 30px rgba(0, 0, 0, 0.42);
}

.intro {
  max-width: 38rem;
  margin-bottom: 0;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 850;
}

.setup-panel,
.result-panel,
.leaderboard-panel,
.task-panel,
.hud {
  border: 3px solid #12091f;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow), 7px 7px 0 #12091f;
}

.setup-panel {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 3vw, 28px);
}

label {
  display: grid;
  gap: 8px;
  font-weight: 900;
}

input,
select {
  min-height: 48px;
  width: 100%;
  border: 2px solid rgba(18, 9, 31, 0.28);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 750;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(255, 213, 74, 0.75);
  outline-offset: 2px;
}

.rules {
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
}

.rules p {
  margin: 6px 0 0;
  line-height: 1.45;
}

.start-actions,
.game-over-actions,
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #12091f;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 950;
  cursor: pointer;
  caret-color: transparent;
  user-select: none;
  box-shadow: 4px 4px 0 #12091f;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.primary-button {
  background: var(--green);
  color: #07140b;
}

.secondary-button {
  background: #fff;
  color: var(--ink);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #12091f;
}

.game-screen {
  display: grid;
  gap: 14px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
}

.hud div,
.result-grid div {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}

.hud span,
.result-grid span {
  display: block;
  color: rgba(29, 20, 48, 0.72);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

.hud strong,
.result-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.1rem, 2vw, 1.55rem);
}

.battlefield {
  min-height: clamp(520px, 58vh, 680px);
  overflow: hidden;
  position: relative;
  border: 3px solid #12091f;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(18, 9, 31, 0.34)),
    url("assets/grammar-arena-bg.png") center 58% / cover no-repeat;
  box-shadow: var(--shadow), 7px 7px 0 #12091f;
}

.battlefield::after {
  content: "";
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 7%;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(47, 20, 67, 0.28), transparent 68%);
  pointer-events: none;
}

.battle-status {
  position: absolute;
  z-index: 3;
  inset: 12px 12px auto;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #fff;
  font-weight: 950;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.battle-status span {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(18, 9, 31, 0.68);
}

.lane {
  position: absolute;
  inset: 0;
}

.lane::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 36%;
  bottom: 22%;
  width: clamp(170px, 17vw, 235px);
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(42, 16, 43, 0.46), rgba(42, 16, 43, 0.16) 48%, transparent 72%);
  transform: rotate(-4deg);
  pointer-events: none;
}

.player {
  position: absolute;
  z-index: 2;
  left: 35%;
  bottom: 19%;
  width: clamp(160px, 13.6vw, 195px);
  max-height: 86%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 12px 10px rgba(0, 0, 0, 0.36));
  animation: hero-breathe 1.8s ease-in-out infinite;
  transform-origin: 50% 86%;
}

.monster {
  position: absolute;
  z-index: 2;
  left: var(--monster-left, 58%);
  bottom: 17%;
  width: clamp(165px, 14vw, 205px);
  aspect-ratio: 2 / 3;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center bottom;
  filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.38));
  transition: right 420ms ease;
  animation: monster-wobble 1.35s ease-in-out infinite;
  transform-origin: 50% 84%;
}

.monster::after {
  content: "";
  position: absolute;
  left: 17%;
  right: 10%;
  bottom: 10%;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(42, 16, 43, 0.45), rgba(42, 16, 43, 0.15) 48%, transparent 72%);
  pointer-events: none;
}

.monster-one {
  background-image: url("assets/grammar-monster-one.png?v=20260510-separated");
}

.monster-two {
  background-image: url("assets/grammar-monster-two.png?v=20260510-separated");
}

.monster-three {
  background-image: url("assets/grammar-monster-three.png?v=20260510-separated");
}

.impact {
  position: absolute;
  z-index: 4;
  left: 42%;
  bottom: 43%;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle, #fff 0 18%, #ffd54a 19% 44%, rgba(240, 79, 95, 0.5) 45% 62%, transparent 63%);
}

.impact.active {
  animation: pop 420ms ease-out;
}

.task-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 16px;
  padding: 14px;
}

.game-actions {
  justify-content: center;
}

.task-card {
  min-width: 0;
  padding: 16px;
  border-radius: 8px;
  background: #fff;
}

.task-label {
  margin-bottom: 8px;
  color: var(--violet);
  font-weight: 950;
  text-transform: uppercase;
}

.task-card h2 {
  margin-bottom: 10px;
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  letter-spacing: 0;
}

.feedback {
  min-height: 1.5em;
  margin-bottom: 0;
  font-weight: 850;
}

.feedback.good {
  color: #117739;
}

.feedback.bad {
  color: #b51f34;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.answers.typed-answer {
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
}

.typed-answer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.typed-answer-input {
  min-height: 58px;
  border: 3px solid #12091f;
  box-shadow: 3px 3px 0 #12091f;
  font-size: clamp(1rem, 2vw, 1.24rem);
  font-weight: 950;
}

.typed-answer-input.correct {
  background: #d9f8e5;
  border-color: #117739;
}

.typed-answer-input.wrong {
  background: #ffe0e5;
  border-color: #b51f34;
}

.typed-answer-button {
  min-width: 96px;
  min-height: 58px;
}

.answer-button {
  min-height: 58px;
  border: 3px solid #12091f;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  font-size: clamp(1rem, 2vw, 1.24rem);
  font-weight: 950;
  line-height: 1.1;
  text-decoration: none;
  user-select: none;
  caret-color: transparent;
  appearance: none;
  cursor: pointer;
  box-shadow: 3px 3px 0 #12091f;
}

.answer-button:focus {
  outline: 0;
}

.answer-button:focus-visible {
  outline: 4px solid rgba(255, 213, 74, 0.82);
  outline-offset: 2px;
}

.answer-button:hover {
  background: #e7f6ff;
}

.answer-button.correct {
  background: var(--green);
}

.answer-button.wrong {
  background: var(--red);
  color: #fff;
}

.lives-display {
  color: #e71935;
  letter-spacing: 2px;
  text-shadow: 0 2px 0 #7b0616, 0 0 10px rgba(231, 25, 53, 0.38);
}

.player.react-correct {
  animation: hero-correct 620ms ease-out;
}

.player.react-wrong {
  animation: hero-wrong 560ms ease-out;
}

.monster.react-hit {
  animation: monster-hit 620ms ease-out;
}

.monster.react-attack {
  animation: monster-attack 560ms ease-out;
}

.game-over-screen {
  display: grid;
  grid-template-columns: minmax(300px, 0.86fr) minmax(0, 1.14fr);
  gap: 18px;
  align-items: start;
}

.result-panel,
.leaderboard-panel {
  padding: clamp(16px, 3vw, 24px);
}

.result-panel h2 {
  margin-bottom: 16px;
  font-size: clamp(2rem, 4vw, 3.2rem);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.leaderboard-panel h3,
.dialog-top h2 {
  margin-bottom: 14px;
  font-size: clamp(1.5rem, 3vw, 2rem);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(29, 20, 48, 0.12);
  text-align: left;
  vertical-align: top;
}

.leaderboard-table th {
  background: #20143f;
  color: #fff;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.empty-board {
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  background: #fff;
  font-weight: 850;
}

.leaderboard-dialog {
  width: min(860px, calc(100% - 24px));
  border: 3px solid #12091f;
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow), 7px 7px 0 #12091f;
}

.leaderboard-dialog::backdrop {
  background: rgba(11, 7, 24, 0.64);
}

.dialog-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 3px solid #12091f;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

@keyframes hero-breathe {
  0%,
  100% {
    transform: translateY(0);
  }

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

@keyframes monster-wobble {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }

  50% {
    transform: translateY(-7px) rotate(2deg);
  }
}

@keyframes hero-correct {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
  }

  38% {
    transform: translateY(-24px) rotate(-5deg) scale(1.08);
  }

  100% {
    transform: translateY(0) rotate(0deg) scale(1);
  }
}

@keyframes hero-wrong {
  0%,
  100% {
    transform: translateX(0) rotate(0deg);
    filter: drop-shadow(0 12px 10px rgba(0, 0, 0, 0.36));
  }

  24% {
    transform: translateX(-16px) rotate(-5deg);
    filter: drop-shadow(0 12px 10px rgba(0, 0, 0, 0.36)) saturate(1.5) hue-rotate(-18deg);
  }

  52% {
    transform: translateX(10px) rotate(3deg);
  }
}

@keyframes monster-hit {
  0% {
    transform: translateX(0) rotate(0deg) scale(1);
    filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.38));
  }

  45% {
    transform: translateX(34px) rotate(10deg) scale(0.94);
    filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.38)) brightness(1.35) saturate(1.4);
  }

  100% {
    transform: translateX(0) rotate(0deg) scale(1);
    filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.38));
  }
}

@keyframes monster-attack {
  0%,
  100% {
    transform: translateX(0) rotate(0deg) scale(1);
  }

  44% {
    transform: translateX(-42px) rotate(-5deg) scale(1.08);
  }
}

@keyframes pop {
  0% {
    opacity: 1;
    transform: scale(0.3);
  }

  100% {
    opacity: 0;
    transform: scale(1.65);
  }
}

@media (max-width: 880px) {
  .start-screen,
  .game-over-screen,
  .task-panel {
    grid-template-columns: 1fr;
  }

  .start-copy {
    min-height: 360px;
  }

  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .battlefield {
    min-height: clamp(430px, 54vh, 560px);
  }

  .player {
    width: clamp(190px, 34vw, 250px);
  }

  .monster {
    width: clamp(170px, 29vw, 230px);
  }
}

@media (max-width: 560px) {
  .app {
    padding: 12px;
  }

  .start-copy {
    padding: 10px 4px;
    min-height: 300px;
  }

  h1 {
    font-size: clamp(3rem, 18vw, 5rem);
  }

  .hud,
  .answers,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .typed-answer-form {
    grid-template-columns: 1fr;
  }

  .battle-status {
    flex-direction: column;
    align-items: start;
  }

  .battlefield {
    min-height: 390px;
  }

  .leaderboard-panel {
    overflow-x: auto;
  }

  .leaderboard-table {
    min-width: 650px;
  }
}
