@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap");

/* =========================
  Theme + base
   ========================= */
:root {
  --color-text: #f8f3ff;
  --color-muted: #cbc4de;
  --color-panel: rgba(20, 15, 34, 0.88);
  --color-panel-2: rgba(255, 255, 255, 0.06);
  --color-border: rgba(255, 255, 255, 0.14);
  --color-accent: #5cf2ff;
  --color-accent-2: #ff9e59;
  --color-warn: #ffd970;
  --text: var(--color-text);
  --muted: var(--color-muted);
  --panel: var(--color-panel);
  --panel-2: var(--color-panel-2);
  --border: var(--color-border);
  --accent: var(--color-accent);
  --accent-2: var(--color-accent-2);
  --warn: var(--color-warn);
  --shadow-lg: 0 14px 28px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 18px rgba(0, 0, 0, 0.22);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 16px;
  --body-font: "Poppins", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body.game-body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.45;
  font-family: var(--body-font);
  background: linear-gradient(170deg, #231a38 0%, #120f22 60%, #08070f 100%);
}

/* =========================
   Layout
   ========================= */
.arcade-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 16px;
}

.arcade-top {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  padding: 2px 4px;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.arcade-top h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

.arcade-layout {
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
  gap: 14px;
}

.arcade-sidebar {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 32%), var(--panel);
  box-shadow: var(--shadow-md);
  overflow: auto;
}

.arcade-stage {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: stretch;
  padding: 8px 10px;
}

.stage-card {
  width: 100%;
  max-width: 940px;
  height: 100%;
  margin: 0 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 30%), var(--panel);
  box-shadow: var(--shadow-lg), 0 1px 0 rgba(255, 255, 255, 0.07) inset;
  overflow: hidden;
}

/* =========================
   Components
   ========================= */
.player-field {
  display: grid;
  gap: 8px;
}

.player-field label {
  font-size: 0.9rem;
  font-weight: 600;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.24);
  color: var(--text);
  font: inherit;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

input:focus,
input:focus-visible {
  outline: none;
  border-color: rgba(92, 242, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(92, 242, 255, 0.16);
}

.helper-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.hud {
  display: grid;
  gap: 8px;
}

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

.status {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--panel-2);
  color: var(--muted);
}

.status strong {
  color: var(--text);
}

.status-panel {
  text-align: center;
}

.game-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

button,
.back-link {
  min-height: 42px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(135deg, #ffe67b, var(--accent-2));
  color: #241631;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
}

button:hover:not(:disabled),
.back-link:hover {
  transform: translateY(-1px) scale(1.005);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
  filter: brightness(1.02);
}

button:active,
.back-link:active {
  transform: translateY(0) scale(0.99);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:focus-visible,
.back-link:focus-visible {
  outline: 2px solid rgba(92, 242, 255, 0.8);
  outline-offset: 2px;
}

.back-link {
  text-align: center;
  margin-top: auto;
}

.hide {
  display: none !important;
}

/* =========================
   RPS
   ========================= */
.game-rps .stage-card {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.rps-choice {
  width: 118px;
  height: 108px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.24);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}

.rps-choice:hover:not(:disabled),
.rps-choice:focus-visible:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(92, 242, 255, 0.55);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.2);
}

.rps-choice:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}

.rps-choice img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.choice-box img {
  width: 100px;
  height: 100px;
  object-fit: contain;
}

#computer-preview {
  --rps-image-flip: -1;
  transform: scaleX(-1);
  transform-origin: center;
}

.rps-choice.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(92, 242, 255, 0.2);
}

.versus-preview {
  width: 100%;
  max-width: 980px;
  margin: 0 auto 22px;
  padding: 30px;
  border-radius: 22px;
  background: linear-gradient(
    135deg,
    rgba(90, 132, 198, 0.52),
    rgba(123, 84, 192, 0.46)
  );
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 22px;
}

.versus-preview .choice-box {
  min-height: 148px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 1.06rem;
  font-weight: 600;
  padding: 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.preview-versus {
  font-size: 2.2rem;
  font-weight: 800;
  color: #ffd166;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.26);
}

.game-rps .stage-card > .rps-actions {
  width: 100%;
  max-width: 760px;
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 6px 0 14px;
  flex-wrap: nowrap;
  align-items: center;
}

.game-rps .stage-card > .status-panel {
  width: 100%;
  max-width: 920px;
  margin: 6px auto;
  text-align: center;
}

#rps-status[data-outcome="win"] {
  color: #c7ffd4;
  border-color: rgba(130, 255, 168, 0.22);
}

#rps-status[data-outcome="loss"] {
  color: #ffc7c7;
  border-color: rgba(255, 129, 129, 0.24);
}

#rps-status[data-outcome="draw"] {
  color: #ffe8aa;
  border-color: rgba(255, 217, 112, 0.24);
}

/* =========================
   Whack
   ========================= */
.whack-stage {
  position: relative;
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(180deg, #77d83a 0%, #4ea824 58%, #2f6f15 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.whack-stage,
.whack-stage * {
  cursor: none !important;
}

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

.whack-grid.is-live {
  animation: pulse 1.1s ease-in-out infinite;
}

.whack-hole {
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #814715 0%, #5f320f 58%, #3f2009 100%);
  box-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.32), 0 0 0 1px rgba(255, 232, 170, 0.22);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.2s ease;
}

.whack-grid.is-live .whack-hole:hover,
.whack-grid.is-live .whack-hole:focus-visible {
  box-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.32), 0 0 0 2px rgba(255, 232, 170, 0.45);
}

.whack-grid.is-live .whack-hole:active {
  transform: scale(0.96);
}

.whack-hole img {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 76%;
  transform: translateX(-50%) translateY(100%);
  opacity: 0;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.52)) saturate(1.08) contrast(1.08);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.whack-hole.is-active img {
  transform: translateX(-50%) translateY(0) scale(1);
  opacity: 1;
  animation: molePop 0.26s ease-out;
}

.whack-hole.is-hiding img {
  transform: translateX(-50%) translateY(92%);
  opacity: 0;
}

.whack-hole.is-hit {
  box-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.32), 0 0 0 2px rgba(92, 242, 255, 0.54);
}

.whack-hole.is-hit img {
  transform: translateX(-50%) translateY(100%) scale(0.8);
  opacity: 0;
}

#whack-time.is-urgent {
  color: #ffd0ab;
  animation: blink 0.8s linear infinite;
}

.hammer-cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 102px;
  height: 112px;
  pointer-events: none;
  background: url("../assets/hammer.png") center / contain no-repeat;
  transform: translate(-22%, -26%) rotate(20deg);
  transition: transform 0.12s ease;
}

.hammer-cursor.hide {
  opacity: 0;
}

.hammer-cursor.is-active {
  transform: translate(-22%, -26%) rotate(-24deg) scale(0.95);
}

/* =========================
   Memory
   ========================= */
.memory-grid,
.tutorial-grid {
  width: min(100%, 520px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  perspective: 1000px;
  align-content: center;
}

.card-container {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  appearance: none;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
  cursor: pointer;
}

.card-container:hover:not(.flipped):not(.matched) {
  transform: translateY(-1px);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.14));
}

.card-container:focus-visible {
  outline: 2px solid rgba(92, 242, 255, 0.8);
  outline-offset: 2px;
}

.card-before,
.card-after {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 0.35s ease;
}

.card-before {
  background: linear-gradient(145deg, #ffe566 0%, #e4b52a 100%);
  color: #261734;
  font-size: 1.65rem;
  font-weight: 700;
  transform: rotateY(0deg);
  z-index: 2;
}

.card-after {
  background: #fff;
  transform: rotateY(180deg);
  padding: 6px;
  z-index: 1;
}

.card-after img.image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-container.flipped .card-before,
.card-container.matched .card-before {
  transform: rotateY(-180deg);
}

.card-container.flipped .card-after,
.card-container.matched .card-after {
  transform: rotateY(0deg);
}

.card-container.matched {
  box-shadow: 0 0 0 2px rgba(255, 217, 112, 0.45);
}

.stats-container > div {
  min-width: 0;
  padding: 8px;
  border-radius: 10px;
  background: #fff;
  color: #2b2037;
  font-size: 0.84rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.stats-container,
.level-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stats-container span {
  margin-right: 4px;
  color: #8a6210;
}

.memory-controls {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: linear-gradient(160deg, #ffe566 0%, #e8b420 100%);
  color: #2a1d34;
}

.memory-action {
  background: #111;
  color: #fff;
}

.level-option {
  background: rgba(39, 28, 51, 0.16);
  color: #2a1e35;
  font-size: 0.9rem;
  line-height: 1.1;
}

.level-option.is-active {
  background: #23182f;
  color: #fff;
}

/* =========================
   Animations + utilities
   ========================= */
.is-pulsing {
  animation: pulse 0.42s ease-in-out;
}

.animate-pop {
  animation: pulse 0.42s ease-in-out;
}

.versus-preview.is-dueling .preview-versus {
  animation: blink 0.7s ease-in-out infinite;
}

.versus-preview.is-resolving .preview-token {
  animation: pulse 0.45s ease-in-out;
}

.versus-preview.is-dueling.is-duel-shake .preview-token:first-child img {
  animation: shakeA 0.95s ease-in-out both;
}

.versus-preview.is-dueling.is-duel-shake .preview-token:last-child img {
  animation: shakeB 0.95s ease-in-out both;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes shakeA {
  0% { transform: scaleX(var(--rps-image-flip, 1)) rotate(30deg); }
  25% { transform: scaleX(var(--rps-image-flip, 1)) rotate(-30deg); }
  50% { transform: scaleX(var(--rps-image-flip, 1)) rotate(30deg); }
  75% { transform: scaleX(var(--rps-image-flip, 1)) rotate(-30deg); }
  100% { transform: scaleX(var(--rps-image-flip, 1)) rotate(0); }
}

@keyframes shakeB {
  0% { transform: scaleX(var(--rps-image-flip, 1)) rotate(-30deg); }
  25% { transform: scaleX(var(--rps-image-flip, 1)) rotate(30deg); }
  50% { transform: scaleX(var(--rps-image-flip, 1)) rotate(-30deg); }
  75% { transform: scaleX(var(--rps-image-flip, 1)) rotate(30deg); }
  100% { transform: scaleX(var(--rps-image-flip, 1)) rotate(0); }
}

@keyframes molePop {
  0% { transform: translateX(-50%) translateY(100%) scale(0.82); opacity: 0; }
  65% { transform: translateX(-50%) translateY(-4%) scale(1.05); opacity: 1; }
  100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

/* =========================
   Responsive
   ========================= */
@media (max-width: 1024px) {
  body.game-body {
    height: auto;
    overflow: auto;
  }

  .arcade-shell {
    height: auto;
    min-height: 100vh;
  }

  .arcade-layout {
    grid-template-columns: 1fr;
  }

  .arcade-sidebar {
    order: 2;
  }

  .arcade-stage {
    order: 1;
    min-height: 420px;
    padding: 0;
  }

  .stage-card {
    min-height: 420px;
  }

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

@media (max-width: 760px) {
  .arcade-shell {
    padding: 10px;
  }

  .arcade-top {
    flex-direction: column;
    gap: 4px;
  }

  .rps-hud,
  .stats-container,
  .level-picker {
    grid-template-columns: 1fr;
  }

  .game-rps .stage-card > .game-actions {
    flex-wrap: wrap;
  }

  .rps-choice {
    width: 100%;
    max-width: 200px;
  }

  .versus-preview {
    grid-template-columns: 1fr;
  }

  .hammer-cursor {
    display: none;
  }
}
