﻿:root {
  --bg-a: #eaf7ff;
  --bg-b: #eaf2ff;
  --bg-c: #fef6ea;
  --panel: rgba(255, 255, 255, 0.9);
  --text: #122033;
  --muted: #4d6078;
  --line: #d4def0;
  --brand: #1467c7;
  --brand-strong: #0b4c97;
  --accent: #ff8f3f;
  --accent-2: #46c2a9;
  --shadow: 0 14px 36px rgba(16, 42, 90, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  min-height: 100vh;
  background: radial-gradient(circle at 15% 15%, var(--bg-a), transparent 36%),
              radial-gradient(circle at 85% 25%, #e5fffb, transparent 35%),
              linear-gradient(140deg, var(--bg-b), var(--bg-c));
  background-size: 140% 140%;
  animation: bg-shift 18s ease-in-out infinite;
}

.site-header {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 8px;
  animation: fade-in 320ms ease-out, header-float 5.5s ease-in-out infinite;
}

.site-header h1 {
  margin: 0;
  font-size: 38px;
  letter-spacing: -0.6px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.site-header p { margin: 8px 0 0; color: var(--muted); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

.game-card,
.game-shell {
  background: var(--panel);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  animation: lift-in 350ms ease-out;
}

.game-card {
  position: relative;
  overflow: hidden;
  transition: transform 220ms ease, box-shadow 220ms ease;
  animation: lift-in 350ms ease-out, card-bob 6s ease-in-out infinite;
}

.game-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.35), transparent 45%);
  pointer-events: none;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 38px rgba(16, 42, 90, 0.24);
}

.game-icon {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
  transition: transform 240ms ease, filter 260ms ease;
  animation: icon-glow 3.4s ease-in-out infinite alternate;
}

.icon-fallback {
  display: grid;
  place-items: center;
  font-size: 50px;
  background: linear-gradient(145deg, #f7fbff, #ebf3ff);
}

.game-card h2 { margin: 0 0 8px; font-size: 22px; }
.game-card p { margin: 0 0 14px; color: var(--muted); }

.game-card:hover .game-icon {
  transform: scale(1.04) rotate(-0.6deg);
  filter: saturate(1.18);
}

.btn,
button,
select {
  border: 1px solid var(--brand);
  background: linear-gradient(135deg, var(--brand), #2b8ef5);
  color: #fff;
  text-decoration: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 180ms ease;
}

button.secondary,
.btn.secondary,
select {
  background: #fff;
  color: var(--brand);
  border-color: var(--line);
}

.btn:hover,
button:hover,
select:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 10px 22px rgba(20, 103, 199, 0.24);
  filter: saturate(1.08);
}

button:active,
.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; flex-wrap: wrap; }
.hud { display: flex; gap: 14px; color: var(--muted); flex-wrap: wrap; }

canvas {
  width: 100%;
  max-width: 480px;
  border: 1px solid var(--line);
  background: #fff;
  display: block;
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: canvas-in 280ms ease-out;
}

.game-shell:fullscreen {
  padding: 18px;
  max-width: 100%;
}

.game-shell:fullscreen canvas {
  max-width: 100%;
  height: calc(100vh - 180px);
}

.game-shell:fullscreen .top-row,
.game-shell:fullscreen .note {
  max-width: 760px;
}

.game-layout { display: grid; gap: 14px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.pad { display: grid; gap: 8px; margin-top: 12px; }
.pad-row { display: flex; gap: 8px; }

.board-3 { display: grid; grid-template-columns: repeat(3, minmax(86px, 120px)); gap: 10px; }
.cell {
  height: 96px;
  font-size: 32px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: pop 220ms ease-out;
}

.cell.filled { background: linear-gradient(160deg, #f8fbff, #eef4ff); }
.cell.win {
  background: linear-gradient(160deg, #eafdf2, #dcf8ea);
  border-color: #4dc37f;
}

.select-wrap { display: inline-flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
select { min-width: 120px; padding: 8px 10px; }

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(70px, 100px));
  gap: 12px;
}

.memory-shell {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.95), rgba(247, 252, 255, 0.9));
  border-color: #cddcf3;
  box-shadow: 0 20px 44px rgba(36, 78, 140, 0.22);
}

.memory-card {
  position: relative;
  height: 88px;
  border: none;
  background: transparent;
  padding: 0;
  perspective: 900px;
  box-shadow: none;
}

.memory-inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  transform-style: preserve-3d;
  transition: transform 420ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.memory-card.revealed .memory-inner,
.memory-card.matched .memory-inner {
  transform: rotateY(180deg);
}

.memory-card.flipping .memory-inner {
  animation: card-flip-180 420ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.memory-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  backface-visibility: hidden;
  box-shadow: var(--shadow);
  font-size: 34px;
}

.memory-front {
  background: linear-gradient(155deg, #ffffff, #eef6ff);
  color: var(--accent);
}

.memory-back {
  background: linear-gradient(155deg, #fff4ea, #ffe8d7);
  transform: rotateY(180deg);
}

.memory-card.matched .memory-back {
  background: linear-gradient(155deg, #e8fff4, #d7f8ea);
}

.memory-card:hover .memory-inner {
  transform: translateY(-2px);
}

.memory-card.revealed:hover .memory-inner,
.memory-card.matched:hover .memory-inner {
  transform: rotateY(180deg) translateY(-2px);
}

.mole-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 120px));
  gap: 12px;
}

.mole-cell {
  height: 92px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, #fbfdff, #edf4ff);
}

.mole-cell.active {
  background: radial-gradient(circle at 40% 35%, #fff9d8, #ffd259);
  box-shadow: 0 0 0 2px #ffd259 inset, 0 0 22px rgba(255, 168, 0, 0.55);
  animation: pulse 420ms ease-in-out infinite alternate;
}

.mole-cell.hit {
  transform: scale(0.92);
}

.note { color: var(--muted); margin: 10px 0 0; }
.fade-in { animation: fade-in 360ms ease-out; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes header-float {
  0% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

@keyframes lift-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes card-bob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-1px); }
  100% { transform: translateY(0); }
}

@keyframes icon-glow {
  from { box-shadow: 0 0 0 rgba(20, 103, 199, 0); }
  to { box-shadow: 0 10px 22px rgba(20, 103, 199, 0.18); }
}

@keyframes canvas-in {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pop {
  from { transform: scale(0.94); }
  to { transform: scale(1); }
}

@keyframes card-flip-180 {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(180deg); }
}

@keyframes bg-shift {
  0% { background-position: 0% 10%; }
  50% { background-position: 100% 90%; }
  100% { background-position: 0% 10%; }
}

@keyframes pulse {
  from { transform: scale(0.98); }
  to { transform: scale(1.02); }
}

@media (max-width: 700px) {
  .container {
    padding: 10px 12px 24px;
  }

  .site-header h1 { font-size: 31px; }
  .site-header {
    padding: 16px 12px 8px;
  }

  .site-header p {
    font-size: 14px;
  }

  .game-shell {
    max-width: 520px;
    margin: 0 auto;
    padding: 12px;
  }

  canvas {
    max-width: 100%;
    width: 100%;
    height: auto;
  }

  .hud {
    gap: 10px;
    font-size: 14px;
  }

  .controls {
    width: 100%;
  }

  .controls button,
  .controls select {
    flex: 1 1 auto;
    min-height: 40px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .board-3 { grid-template-columns: repeat(3, minmax(70px, 1fr)); }
}

@media (max-width: 900px) and (orientation: landscape) {
  .site-header::after {
    content: "For best gameplay, rotate to portrait.";
    display: inline-block;
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(20, 103, 199, 0.12);
    color: #0b4c97;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
