/* Memori — Estética limpia y accesible, similar a puzzle-fotos. */

:root {
  --bg: #e8e0d6;
  --surface: #fff;
  --border: #c4b8a8;
  --text: #2c2c2c;
  --primary: #5a7a6a;
  --primary-hover: #4a6a5a;
  --accent: #da8c1f;
  --accent-hover: #c47a14;
  --accent-soft: rgba(201, 118, 46, 0.15);
  --shadow: rgba(0,0,0,0.08);
  --shadow-soft: rgba(0,0,0,0.05);
  --card-size: min(24vw, 180px);
  --card-gap: 1rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 20px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(circle, rgba(140, 115, 95, 0.28) 1.2px, transparent 1.2px),
    radial-gradient(ellipse 100% 70% at 20% 20%, rgba(200, 120, 50, 0.18) 0%, transparent 50%),
    radial-gradient(ellipse 90% 60% at 85% 85%, rgba(70, 95, 80, 0.14) 0%, transparent 50%),
    linear-gradient(180deg, #f2ebe2 0%, #e4dcd0 45%, #d8cec0 100%);
  background-size: 28px 28px, 100% 100%, 100% 100%, 100% 100%;
  background-attachment: fixed;
  min-height: 100vh;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: linear-gradient(145deg, rgba(252, 248, 243, 0.85) 0%, rgba(242, 236, 228, 0.75) 100%);
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(140, 118, 95, 0.25),
    0 4px 24px rgba(0, 0, 0, 0.08);
}

.app::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(160, 140, 115, 0.45);
  border-radius: 10px;
  pointer-events: none;
}

.app .btn-back {
  position: absolute;
  top: 40px;
  left: 60px;
  z-index: 10;
}

.main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
}

.game-box {
  /* sin position para que .btn-back se posicione respecto a .app */
}

/* Tablero del memori: grid de cartas */
.memori-board-wrap {
  padding: 5rem 1rem 1rem;
}

.memori-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--card-size));
  gap: var(--card-gap);
  justify-content: center;
  max-width: 100%;
}

.memori-card {
  width: var(--card-size);
  height: var(--card-size);
  border-radius: 10px;
  border: 3px solid var(--border);
  padding: 0;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-soft);
  transition: transform 0.2s ease, border-color 0.2s;
  perspective: 640px;
  overflow: hidden;
  background: transparent;
}

.memori-card:hover:not(.matched):not(.flipped) {
  border-color: var(--accent);
  transform: scale(1.02);
}

.memori-card.matched {
  border-color: var(--primary);
  cursor: default;
  opacity: 0.9;
}

.memori-card.flipped {
  cursor: default;
}

.memori-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
}

.memori-card.flipped .memori-card-inner {
  transform: rotateY(180deg);
}

.memori-card .card-back,
.memori-card .card-front {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.memori-card .card-back {
  background:
    linear-gradient(90deg,
      rgba(255,255,255,0.85) 0%,
      rgba(255,255,255,0.85) 6%,
      transparent 6%,
      transparent 94%,
      rgba(255,255,255,0.85) 94%,
      rgba(255,255,255,0.85) 100%),
    linear-gradient(145deg, #f0ddd4 0%, #e9d0c8 100%);
  background-size: 100% 100%;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35);
}

.memori-card .card-front {
  transform: rotateY(180deg);
  background: var(--surface) center / cover no-repeat;
}

/* Modal de dibujo */
.modal-draw .draw-area {
  margin: 1rem 0;
  display: flex;
  justify-content: center;
}

.modal-draw #drawCanvas {
  display: block;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.modal-actions-draw {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  margin-top: 1rem;
}

/* Modal genérico */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  border: none;
  border-top: 4px solid var(--accent);
}

.modal-title {
  margin: 0 0 0.9rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.modal-text {
  margin: 0 0 1.15rem;
  font-size: 1.1rem;
  line-height: 1.5;
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.modal-actions.modal-actions-draw {
  justify-content: space-between;
}

.modal-actions .btn {
  min-width: 120px;
  padding: 0.65rem 1.2rem;
  font-size: 1.1rem;
}

/* Botones */
.btn {
  padding: 0.65rem 1.2rem;
  font-size: 1.1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.modal-actions .btn-primary {
  background: var(--accent);
  color: #fff;
}

.modal-actions .btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-back {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-back:hover {
  border-color: var(--accent);
  color: var(--accent);
}
