:root {
  --bg-top: #101b3a;
  --bg-bottom: #07111f;
  --card-bg: rgba(11, 20, 44, 0.8);
  --card-border: rgba(255, 255, 255, 0.18);
  --text-main: #f7f7fb;
  --text-muted: #d2d7f2;
  --accent: #ffcc4d;
  --accent-strong: #ff8f3f;
  --mint: #6cf0c2;
  --pink: #ff5d9e;
  --danger: #ff6674;
  --shadow: 0 24px 80px rgba(2, 8, 20, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow: hidden;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(255, 203, 87, 0.2), transparent 30%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 38vmax;
  height: 38vmax;
  border-radius: 50%;
  filter: blur(20px);
  opacity: 0.4;
  animation: drift 12s ease-in-out infinite alternate;
  pointer-events: none;
}

body::before {
  top: -10vmax;
  right: -8vmax;
  background: radial-gradient(circle, rgba(108, 240, 194, 0.4), transparent 70%);
}

body::after {
  bottom: -14vmax;
  left: -10vmax;
  background: radial-gradient(circle, rgba(255, 93, 158, 0.35), transparent 70%);
  animation-duration: 15s;
}

.background-glow {
  position: fixed;
  width: 26rem;
  height: 26rem;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  pointer-events: none;
}

.background-glow-left {
  top: 18%;
  left: -8rem;
  background: rgba(255, 143, 63, 0.42);
}

.background-glow-right {
  bottom: 8%;
  right: -8rem;
  background: rgba(86, 161, 255, 0.35);
}

.game-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(0.65rem, 2vh, 1.25rem);
}

.game-card {
  position: relative;
  width: min(100%, 58rem);
  max-height: calc(100dvh - clamp(1.3rem, 4vh, 2.5rem));
  padding: clamp(1rem, 2.4vh, 1.8rem);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border: 1px solid var(--card-border);
  border-radius: 2rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    var(--card-bg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.game-card.finished {
  justify-content: center;
}

.play-layout {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 0.85rem;
  min-height: 0;
}

.display-side,
.keypad-side {
  min-height: 0;
}

.display-side {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.keypad-side {
  display: flex;
  flex: 1 1 auto;
}

.summary-label,
.status-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

h1,
h2 {
  margin: 0;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  line-height: 0.95;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.status-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.8rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.95rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.status-label {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.status-pill strong {
  font-size: 1.1rem;
  line-height: 1;
}

.question-panel {
  position: relative;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.1rem, 2.6vh, 1.6rem);
  border-radius: 1.8rem;
  background:
    linear-gradient(135deg, rgba(255, 204, 77, 0.16), rgba(255, 93, 158, 0.16)),
    rgba(8, 15, 33, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.question-panel.intro {
  text-align: center;
}

.question-panel::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.28), transparent 45%);
  opacity: 0;
  transform: scale(0.2);
  pointer-events: none;
}

.question-text {
  margin: 0 0 1rem;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: clamp(2.5rem, min(9vw, 10vh), 6.2rem);
  text-align: center;
  text-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.answer-display {
  position: relative;
  width: min(100%, 20rem);
  min-height: clamp(4.6rem, 10vh, 6.8rem);
  margin: 0 auto;
  padding: 0.85rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border-radius: 1.6rem;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.answer-display.filled {
  border-color: rgba(255, 204, 77, 0.65);
  background: rgba(255, 204, 77, 0.18);
}

.answer-display.typing {
  animation: typeBounce 220ms ease-out;
}

.answer-display.submitting {
  animation: submitFlash 320ms ease-out;
}

.answer-display.correct-hit {
  animation: correctPulse 500ms ease-out;
}

.answer-display.wrong-hit {
  animation: wrongPulse 500ms ease-out;
}

.answer-value {
  min-width: 3ch;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: clamp(2rem, min(7vw, 6vh), 4rem);
  letter-spacing: 0.08em;
  text-align: center;
}

.start-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 9rem;
  margin: 1rem auto 0;
  padding: 0.8rem 1.2rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #1f1731;
  font: 800 1rem/1 "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  box-shadow: 0 14px 36px rgba(255, 143, 63, 0.28);
  cursor: pointer;
  touch-action: manipulation;
}

.start-action.hidden {
  display: none;
}

.keypad {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 0.7rem;
  min-height: 20rem;
  height: 100%;
}

.keypad.locked {
  opacity: 0.58;
}

.pad-key {
  min-height: clamp(3.5rem, 8vh, 4.7rem);
  height: 100%;
  border: 0;
  border-radius: 1.2rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05)),
    rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font: 800 clamp(1.2rem, 3.4vh, 1.8rem)/1 "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 10px 24px rgba(2, 8, 20, 0.18);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, opacity 140ms ease;
  touch-action: manipulation;
}

.pad-key:disabled {
  cursor: default;
}

.pad-key.active-press {
  transform: translateY(0.12rem) scale(0.98);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 10px rgba(2, 8, 20, 0.2);
}

.pad-key.pad-muted {
  color: var(--text-muted);
  font-size: clamp(1rem, 2.6vh, 1.2rem);
}

.pad-key.pad-primary {
  background: linear-gradient(135deg, rgba(255, 204, 77, 0.95), rgba(255, 143, 63, 0.92));
  color: #24192d;
}

.pad-key.pad-submit {
  grid-column: 1 / -1;
}

.game-card.finished .play-layout,
.game-card.finished .status-row,
.game-card.finished .question-panel,
.game-card.finished .feedback,
.game-card.finished .keypad {
  display: none;
}

.game-card.correct {
  box-shadow:
    0 24px 80px rgba(2, 8, 20, 0.45),
    0 0 0 2px rgba(108, 240, 194, 0.32);
}

.game-card.wrong {
  box-shadow:
    0 24px 80px rgba(2, 8, 20, 0.45),
    0 0 0 2px rgba(255, 102, 116, 0.28);
}

.feedback {
  display: none;
}

.feedback.correct {
  color: var(--mint);
}

.feedback.wrong {
  color: #ffb1ba;
}

.question-panel.submit-flash::after {
  animation: panelFlash 360ms ease-out;
}

.question-panel.correct-hit {
  animation: panelCelebrate 520ms ease-out;
}

.question-panel.wrong-hit {
  animation: panelShake 420ms ease-out;
}

.summary-panel {
  margin-top: 1rem;
  padding: 1rem 1.2rem;
  border-radius: 1.5rem;
  background: rgba(108, 240, 194, 0.12);
  border: 1px solid rgba(108, 240, 194, 0.28);
}

.summary-media {
  position: relative;
  overflow: hidden;
  margin: 0.2rem 0 0.8rem;
  border-radius: 1.2rem;
  background: rgba(255, 255, 255, 0.06);
}

.summary-image {
  width: 100%;
  height: clamp(11rem, 28vh, 18rem);
  object-fit: cover;
  display: block;
  background: rgba(255, 255, 255, 0.08);
}

.summary-credit {
  position: absolute;
  left: 0.8rem;
  bottom: 0.8rem;
  margin: 0;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(4, 12, 25, 0.55);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
  backdrop-filter: blur(12px);
}

.summary-credit:empty {
  display: none;
}

.summary-panel h2 {
  font-size: clamp(2.2rem, 7vw, 3.8rem);
  margin-top: 0.25rem;
}

.summary-copy {
  margin: 0.6rem 0 0;
  color: var(--text-muted);
}

.summary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 10rem;
  margin-top: 1rem;
  padding: 0.9rem 1.3rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 204, 77, 0.95), rgba(255, 143, 63, 0.92));
  color: #20162e;
  font: 800 1rem/1 "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  box-shadow: 0 14px 36px rgba(255, 143, 63, 0.24);
  cursor: pointer;
  touch-action: manipulation;
}

.start-action.active-press,
.summary-button.active-press {
  transform: translateY(0.12rem) scale(0.98);
  box-shadow: 0 6px 18px rgba(255, 143, 63, 0.2);
}

.hidden {
  display: none;
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(-2rem, 1rem, 0) scale(1.1);
  }
}

@keyframes typeBounce {
  0% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-0.3rem) scale(1.03);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes submitFlash {
  0% {
    transform: scale(1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
  45% {
    transform: scale(1.04);
    box-shadow:
      0 0 0 4px rgba(255, 204, 77, 0.15),
      0 0 32px rgba(255, 204, 77, 0.3),
      inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
  100% {
    transform: scale(1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
}

@keyframes correctPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
    background: rgba(108, 240, 194, 0.24);
    border-color: rgba(108, 240, 194, 0.6);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes wrongPulse {
  0% {
    transform: scale(1);
  }
  25% {
    transform: translateX(-0.35rem);
  }
  50% {
    transform: translateX(0.35rem);
    background: rgba(255, 102, 116, 0.22);
    border-color: rgba(255, 102, 116, 0.6);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes panelFlash {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  35% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes panelCelebrate {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.015);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes panelShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-0.45rem);
  }
  50% {
    transform: translateX(0.45rem);
  }
  75% {
    transform: translateX(-0.2rem);
  }
}

@media (max-width: 640px) {
  .game-shell {
    padding: 0;
  }

  .game-card {
    width: 100%;
    max-height: 100dvh;
    min-height: 100dvh;
    height: 100dvh;
    padding: 0.8rem;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    justify-content: flex-start;
  }

  .play-layout {
    flex: 1;
    gap: 0.7rem;
    height: 100%;
  }

  .display-side,
  .keypad-side {
    flex: 1 1 50%;
  }

  .display-side {
    gap: 0.55rem;
  }

  .keypad-side {
    min-height: 0;
  }

  .status-pill {
    min-height: 2.45rem;
    padding: 0.45rem 0.5rem;
  }

  .status-label {
    font-size: 0.62rem;
  }

  .status-pill strong {
    font-size: 0.98rem;
  }

  .question-panel {
    padding: 0.95rem 0.85rem;
  }

  .answer-display {
    min-height: 4.9rem;
  }

  .keypad {
    gap: 0.5rem;
    min-height: 0;
    height: 100%;
  }

  .pad-key {
    min-height: 0;
  }

  .summary-image {
    height: clamp(9rem, 22vh, 12rem);
  }
}

@media (max-height: 780px) {
  .play-layout {
    gap: 0.65rem;
  }

  .display-side {
    gap: 0.55rem;
  }

  .status-pill strong {
    font-size: 1rem;
  }

  .question-text {
    font-size: clamp(2.2rem, 7.8vh, 4.8rem);
  }

  .pad-key {
    min-height: 0;
  }

  .summary-image {
    height: clamp(9rem, 24vh, 13rem);
  }
}
