@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
  --bg: #050915;
  --bg-accent: #0f162b;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #e7edf7;
  --muted: #9fb2cd;
  --accent: #22d3ee;
  --accent-strong: #5ef1ce;
  --danger: #f97316;
  --shadow: 0 28px 120px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg), var(--bg-accent) 70%, #050915 100%);
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  overflow: hidden;
}

.page {
  position: relative;
  width: min(920px, 100%);
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: clamp(20px, 6vw, 36px);
  padding-top: clamp(48px, 8vw, 68px);
  backdrop-filter: blur(16px) saturate(140%);
  position: relative;
  overflow: hidden;
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.badge-quality {
  position: absolute;
  top: 16px;
  right: 16px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(94, 241, 206, 0.12);
  border: 1px solid rgba(94, 241, 206, 0.4);
  color: #5ef1ce;
  font-weight: 600;
  font-size: 14px;
}

.badge-negative {
  position: absolute;
  top: 16px;
  left: 16px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #e7edf7;
  font-weight: 600;
  font-size: 14px;
}

.badge-icon {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: rgba(94, 241, 206, 0.2);
  display: grid;
  place-items: center;
}

.panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.04), rgba(255, 255, 255, 0));
  pointer-events: none;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 38px);
  letter-spacing: -0.02em;
}

.equation-card {
  margin: 0;
  padding: 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.counter-window {
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.counter-header {
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.equation {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 600;
}

.equation.loading {
  visibility: hidden;
}

.number {
  color: var(--accent-strong);
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.number.muted {
  color: #c8d6f2;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
}

.symbol {
  color: #cdd7ef;
}

.result {
  color: #fff;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.14), rgba(94, 241, 206, 0.22));
  border-radius: 12px;
  padding: 8px 14px;
  border: 1px solid rgba(94, 241, 206, 0.4);
}

.unit {
  font-size: 18px;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stamp {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
}

.stamp-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid rgba(94, 241, 206, 0.6);
  color: #5ef1ce;
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: inset 0 0 0 6px rgba(94, 241, 206, 0.08);
}

.stamp-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.3s ease, border-color 0.2s ease;
  letter-spacing: 0.01em;
}

.btn:active {
  transform: translateY(1px) scale(0.995);
}

.btn.pulse {
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 16px 40px rgba(94, 241, 206, 0.26);
}

.btn.primary {
  background: linear-gradient(120deg, #ff6b6b, #feca57, #48dbfb, #5ef1ce, #a29bfe, #ff6b6b);
  background-size: 300% 300%;
  animation: rainbow 6s linear infinite;
  color: #04101f;
  box-shadow: 0 18px 40px rgba(34, 211, 238, 0.25);
}

.btn.primary:hover {
  box-shadow: 0 22px 48px rgba(34, 211, 238, 0.32);
  animation-duration: 4s;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.12);
}

.btn.ghost:hover {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
}

.btn.danger {
  background: linear-gradient(135deg, #f97316, #fbbf24);
  color: #1b0d02;
  box-shadow: 0 18px 40px rgba(249, 115, 22, 0.3);
}

.btn.danger:hover {
  box-shadow: 0 22px 48px rgba(249, 115, 22, 0.4);
}

.input {
  width: 100%;
  min-height: 110px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 12px;
  font-size: 15px;
  resize: vertical;
}

.input:focus {
  outline: 2px solid rgba(34, 211, 238, 0.4);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 9, 21, 0.65);
  backdrop-filter: blur(12px) saturate(140%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2;
  padding: 18px;
}

.modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(480px, 100%);
  background: rgba(15, 22, 43, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 22px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px 16px;
  box-shadow: var(--shadow);
}

.modal-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(249, 115, 22, 0.14);
  color: #fbbf24;
  font-weight: 800;
  letter-spacing: 0.05em;
  align-self: center;
}

.modal-content h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.modal-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.modal-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 18px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(15, 22, 43, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow);
  transform: translateY(16px);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 3;
  max-width: min(360px, 90vw);
  color: #fbbf24;
  font-weight: 600;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.emoji {
  position: fixed;
  font-size: 24px;
  pointer-events: none;
  animation: pop var(--dur, 1.6s) ease-out forwards;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
  z-index: 5;
}

.game-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 8;
}

.game-layer.active {
  opacity: 1;
  visibility: visible;
}

.game-click-block {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 12;
}

.game-click-block.active {
  pointer-events: auto;
}

.game-field {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.game-hud {
  position: fixed;
  top: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  pointer-events: auto;
  z-index: 9;
}

.game-stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(5, 9, 21, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.game-label {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.game-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-strong);
}

.game-add {
  position: fixed;
  left: 18px;
  top: 18px;
  padding: 10px 14px;
  font-size: 13px;
  transition: left 0.35s ease, top 0.35s ease, transform 0.2s ease;
  z-index: 9;
}

.game-trap {
  pointer-events: auto;
  transform-origin: center;
}

.monster {
  position: absolute;
  left: 0;
  top: 0;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
  padding: 0;
  background: transparent;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  pointer-events: auto;
  border-radius: 12px;
  filter: saturate(120%);
  z-index: 10;
  touch-action: none;
  --monster-x: 0px;
  --monster-y: 0px;
  transform: translate(var(--monster-x), var(--monster-y));
  will-change: transform, opacity;
}

/* Monster removal animations */
.monster-hit {
  animation: monster-hit 0.5s ease-out forwards;
}

.monster-miss {
  animation: monster-miss 0.5s ease-out forwards;
}

@keyframes monster-hit {
  0% {
    transform: translate(var(--monster-x), var(--monster-y)) scale(1);
    opacity: 1;
  }
  25% {
    transform: translate(var(--monster-x), var(--monster-y)) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--monster-x), var(--monster-y)) scale(0);
    opacity: 0;
  }
}

@keyframes monster-miss {
  0% {
    transform: translate(var(--monster-x), var(--monster-y)) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--monster-x), var(--monster-y)) scale(0);
    opacity: 0;
  }
}

@media (max-width: 640px) {
  body {
    padding: 16px;
  }

  .panel {
    padding: 18px;
    padding-top: 18px;
  }

  .equation {
    justify-content: center;
  }

  .actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
    text-align: center;
  }

  .badge-quality,
  .badge-negative {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 8px;
  }

  .badge-quality {
    margin-top: 4px;
  }

  .panel-body {
    gap: 16px;
  }

  .game-hud {
    top: 12px;
    right: 12px;
    left: 12px;
    align-items: flex-start;
  }

  .game-stat {
    width: fit-content;
  }
}

@keyframes rainbow {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.6) rotate(0deg);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 0px), var(--dy, -140px)) scale(1.3) rotate(var(--rot, 8deg));
  }
}
