:root {
  --blue-deep: #063b59;
  --blue-main: #1b5e8b;
  --brown: #8a4f2d;
  --brown-dark: #5a321f;
  --text-dark: #172533;
  --text-light: #ffffff;
  --overlay: rgba(255, 255, 255, 0.18);
  --overlay-strong: rgba(255, 255, 255, 0.3);
  --shadow: 0 24px 70px rgba(3, 26, 43, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100svh;
  margin: 0;
  padding: clamp(8px, 1.6vw, 24px);
  display: grid;
  place-items: center;
  color: var(--text-dark);
  font-family: "Trebuchet MS", Calibri, Arial, sans-serif;
  background: var(--blue-deep);
}

button,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px 8px 999px 8px;
  padding: 7px 14px;
  color: var(--text-light);
  background: var(--blue-main);
  box-shadow: 0 3px 0 rgba(8, 48, 76, 0.36);
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

button:hover {
  background: var(--blue-main);
  border-color: rgba(255, 255, 255, 0.34);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(8, 48, 76, 0.36);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(138, 79, 45, 0.8);
  outline-offset: 2px;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.app-shell {
  width: min(1600px, calc(100vw - clamp(16px, 3.2vw, 48px)));
  height: min(600px, calc(100svh - clamp(16px, 3.2vw, 48px)));
  min-width: 320px;
  min-height: 420px;
}

.screen {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: clamp(14px, 2vw, 30px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 2.2vw, 30px);
  text-align: center;
  border: 3px solid rgba(138, 79, 45, 0.5);
  border-radius: 8px;
  background: var(--blue-main);
  box-shadow: var(--shadow);
}

.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03), rgba(6, 59, 89, 0.08)),
    url("../img/ocean.png");
  background-repeat: no-repeat, repeat-x;
  background-position: center, 0 center;
  background-size: 100% 100%, auto 100%;
  animation: ocean-drift 10s linear infinite;
}

.screen > * {
  z-index: 1;
}

.screen[hidden] {
  display: none;
}

@keyframes ocean-drift {
  from {
    background-position: center, 0 center;
  }

  to {
    background-position: center, 960px center;
  }
}

.screen__topbar {
  position: absolute;
  top: clamp(10px, 1.4vw, 18px);
  right: clamp(10px, 1.4vw, 18px);
  z-index: 4;
}

.audio-controls {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.audio-controls button {
  width: 122px;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.82rem;
  border-radius: 999px 0 0 999px;
}

.volume-control {
  width: 122px;
  display: grid;
  gap: 3px;
  padding: 7px;
  color: var(--text-light);
  font-size: 0.72rem;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px 0 0 12px;
  background: rgba(27, 94, 139, 0.32);
}

.volume-control input {
  width: 100%;
  accent-color: var(--blue-main);
}

.menu-copy {
  width: 100%;
  display: grid;
  gap: 12px;
  justify-items: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  width: 100%;
  max-width: none;
  color: var(--text-light);
  font-family: "Lucida Handwriting", "Trebuchet MS", cursive;
  font-size: clamp(2.2rem, 5.6vw, 5.4rem);
  line-height: 1.05;
  text-align: center;
  text-shadow: 0 4px 0 rgba(90, 50, 31, 0.54);
}

#main-title,
#credits-title {
  white-space: nowrap;
}

.lede {
  max-width: 820px;
  color: var(--text-light);
  font-size: clamp(1rem, 1.8vw, 1.45rem);
  line-height: 1.45;
  text-shadow: 0 2px 10px rgba(4, 36, 58, 0.58);
}

.text-panel {
  width: min(820px, 100%);
  display: grid;
  gap: 12px;
  padding: clamp(14px, 2vw, 22px);
  color: var(--text-dark);
  background: rgba(255, 255, 255, 0.54);
  border: 1px solid rgba(138, 79, 45, 0.3);
  border-radius: 8px;
  text-align: left;
  line-height: 1.45;
  box-shadow: 0 10px 24px rgba(4, 36, 58, 0.1);
}

.text-panel--compact {
  width: min(460px, 100%);
  text-align: center;
}

.button-stack {
  display: grid;
  gap: 10px;
  justify-items: center;
  width: min(230px, 100%);
}

.button-stack button {
  width: 100%;
}

.signature {
  position: absolute;
  right: 12px;
  bottom: 8px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.82rem;
  font-style: italic;
}

.screen--game {
  display: block;
  padding: 0;
}

.playfield {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.game-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  width: 100%;
  padding: clamp(10px, 1.2vw, 16px);
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(320px, 440px) minmax(130px, 1fr);
  align-items: start;
  gap: clamp(12px, 1.4vw, 22px);
  pointer-events: none;
}

.game-topbar button,
.game-topbar input {
  pointer-events: auto;
}

.game-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.game-stats > div,
.command-panel {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--overlay);
  backdrop-filter: blur(1px);
}

.game-stats > div {
  min-width: 0;
  padding: 6px 8px;
  text-align: left;
}

.hud-label {
  margin-bottom: 8px;
  color: rgba(90, 50, 31, 0.9);
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.hp-meter,
.hud-value {
  color: rgba(23, 37, 51, 0.9);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.1;
}

#hp,
.problem-row__damage {
  color: var(--brown-dark);
}

.command-panel {
  justify-self: center;
  width: 100%;
  display: grid;
  grid-template-rows: 35px 64px;
  gap: 10px;
  padding: 8px;
  text-align: left;
}

.answer-form {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.answer-form label {
  align-self: center;
  color: rgba(90, 50, 31, 0.92);
  font-size: 0.58rem;
  font-weight: 800;
  text-transform: uppercase;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  gap: 8px;
}

#user-answer {
  width: 100%;
  height: 30px;
  padding: 5px 8px;
  color: var(--text-dark);
  border: 1px solid rgba(27, 94, 139, 0.28);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.42);
}

.answer-row button {
  width: 56px;
  min-height: 30px;
  padding: 4px 8px;
  font-size: 0.76rem;
}

.problem-board {
  min-width: 0;
}

.problem-list {
  display: grid;
  grid-template-rows: repeat(2, 20px);
  gap: 6px;
  overflow: hidden;
}

.problem-row {
  height: 20px;
  display: grid;
  grid-template-columns: 58px minmax(78px, 1fr) 46px;
  gap: 6px;
  align-items: center;
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 0.72rem;
}

.problem-row__label {
  color: rgba(90, 50, 31, 0.92);
  font-weight: 800;
}

.problem-row__problem {
  font-weight: 800;
}

.problem-row__damage {
  font-size: 0.66rem;
  font-weight: 800;
  text-align: right;
}

.problem-empty {
  color: rgba(23, 37, 51, 0.62);
  font-size: 0.72rem;
}

#main-screen-button-from-game {
  justify-self: end;
  width: 112px;
  min-height: 34px;
  padding: 6px 9px;
  font-size: 0.78rem;
  border-radius: 999px 0 0 999px;
  pointer-events: auto;
}

.game-entity {
  position: absolute;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 8px 8px rgba(4, 36, 58, 0.3));
}

.player-ship {
  z-index: 2;
}

.enemy {
  z-index: 3;
}

.damage-splash {
  position: absolute;
  z-index: 4;
  width: clamp(46px, 5vw, 72px);
  height: clamp(34px, 3.8vw, 54px);
  display: grid;
  place-items: center;
  color: #c91f1f;
  font-size: clamp(1rem, 1.8vw, 1.8rem);
  font-weight: 900;
  line-height: 1;
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.72),
    0 4px 8px rgba(71, 6, 6, 0.38);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: damage-splash-pop 3s ease-out forwards;
}

.damage-splash::before,
.damage-splash::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
   background:
    radial-gradient(circle at 28% 34%, rgba(201, 31, 31, 0.8) 0 9%, transparent 10%),
    radial-gradient(circle at 70% 26%, rgba(201, 31, 31, 0.7) 0 7%, transparent 8%),
    radial-gradient(circle at 58% 74%, rgba(201, 31, 31, 0.6) 0 8%, transparent 9%),
    radial-gradient(circle at 44% 48%, rgba(255, 255, 255, 0.5) 0 12%, transparent 13%),
    radial-gradient(circle at center, rgba(201, 31, 31, 0.4) 0 44%, transparent 46%);
  clip-path: polygon(
    50% 0,
    60% 26%,
    88% 12%,
    70% 42%,
    100% 52%,
    70% 62%,
    86% 92%,
    56% 76%,
    44% 100%,
    38% 72%,
    8% 88%,
    26% 58%,
    0 48%,
    28% 38%,
    12% 8%,
    42% 24%
  );
}

.damage-splash::after {
  inset: 18%;
  opacity: 0.58;
  transform: rotate(18deg);
}

@keyframes damage-splash-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -38%) scale(0.62) rotate(-8deg);
  }

  24% {
    opacity: 1;
    transform: translate(-50%, -56%) scale(1.08) rotate(4deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -92%) scale(0.92) rotate(0deg);
  }
}

.result-screen h1 {
  font-size: clamp(2.2rem, 4.5vw, 4.4rem);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#marvel-char {
  width: 100px;
  height: 70px;
  position: absolute;
  top: 70%;
  right: -10%;
  z-index: 1;
  visibility: hidden;
  opacity: 0;
  animation: move-image 10s linear 15s forwards;
}

@keyframes move-image {
  0% {
    right: 0%;
    visibility: hidden;
    opacity: 0;
  }

  10% {
    right: 10%;
    visibility: visible;
    opacity: 1;
  }

  90% {
    right: 85%;
    visibility: visible;
    opacity: 1;
  }

  100% {
    right: 92%;
    visibility: hidden;
    opacity: 0;
  }
}

@media (max-width: 760px) {
  body {
    padding: 8px;
  }

  .app-shell {
    width: calc(100vw - 16px);
    height: calc(100svh - 16px);
    min-width: 0;
    min-height: 420px;
  }

  .screen {
    padding: 10px;
  }

  .screen__topbar {
    position: static;
    justify-self: stretch;
    width: 100%;
  }

  .audio-controls {
    grid-template-columns: 1fr;
    justify-items: stretch;
    width: 100%;
  }

  .audio-controls button,
  .volume-control {
    width: 100%;
    border-radius: 999px 8px 999px 8px;
  }

  .game-topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .game-stats {
    width: min(260px, 100%);
  }

  .command-panel {
    width: min(360px, 100%);
    justify-self: start;
    grid-template-rows: 35px 64px;
  }

  #main-screen-button-from-game {
    position: absolute;
    top: 0;
    right: 0;
    width: 92px;
    min-height: 30px;
    font-size: 0.68rem;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 2.35rem;
  }

  .command-panel {
    grid-template-rows: 35px 64px;
  }

  .answer-form {
    grid-template-columns: 42px minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
