:root {
  --bg-top: #e9f8d9;
  --bg-bottom: #8dd277;
  --panel: rgba(255, 255, 246, 0.86);
  --panel-strong: rgba(255, 250, 224, 0.96);
  --wood: #a96725;
  --wood-dark: #6d421d;
  --leaf: #6da840;
  --text: #3d2b18;
  --muted: #786249;
  --line: rgba(108, 75, 36, 0.2);
  --shadow: 0 20px 52px rgba(50, 90, 45, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 12%, rgba(255, 255, 210, 0.85), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  font-family: Arial, "Noto Sans KR", sans-serif;
}

button,
a {
  color: inherit;
  font: inherit;
}

a { text-decoration: none; }

.page-shell {
  min-height: 100vh;
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(180px, 250px) minmax(0, 720px) minmax(180px, 250px);
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px 0;
}

.side-panel {
  display: grid;
  gap: 16px;
}

.home-link,
.panel-block,
.hud-chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.home-link {
  display: block;
  padding: 14px 18px;
  color: var(--wood-dark);
  font-size: 1.15rem;
  font-weight: 900;
  text-align: center;
}

.panel-block {
  padding: 18px;
}

.panel-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.panel-block strong {
  color: #d08326;
  font-size: 1.55rem;
}

.panel-block p {
  margin: 0;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.7;
}

.difficulty-list {
  display: grid;
  gap: 8px;
}

.difficulty-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(109, 66, 29, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.64);
  color: var(--wood-dark);
  font-weight: 900;
  cursor: pointer;
}

.difficulty-button.is-active {
  background: #f3c569;
  border-color: #c4832c;
}

.game-panel {
  position: relative;
  min-height: min(94vh, 900px);
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  border: 1px solid rgba(116, 75, 31, 0.18);
  border-radius: 24px;
  background: rgba(255, 248, 221, 0.6);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.hud-chip {
  min-height: 52px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-chip span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.hud-chip strong {
  color: #d08326;
  font-size: 1.2rem;
  font-weight: 900;
}

.board-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
}

.board {
  --cols: 4;
  --rows: 4;
  width: min(100%, calc((100vh - 238px) * var(--cols) / var(--rows)));
  max-width: 676px;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: clamp(5px, 1.3vw, 10px);
}

.memory-card {
  position: relative;
  aspect-ratio: 5 / 7;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
}

.memory-card:disabled {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.24s ease;
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  filter: drop-shadow(0 8px 12px rgba(59, 41, 24, 0.18));
}

.card-back {
  background-image: url("assets/card-back.png?v=20260707-3");
}

.card-front {
  transform: rotateY(180deg);
  background-image: url("assets/card-front-frame.png?v=20260707-3");
}

.card-front img {
  width: 68%;
  height: 68%;
  object-fit: contain;
  transform: translateY(2%);
}

.memory-card.is-matched .card-front {
  filter: drop-shadow(0 8px 12px rgba(59, 41, 24, 0.18)) saturate(1.1);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(238, 248, 218, 0.9);
  backdrop-filter: blur(8px);
}

.overlay[hidden] {
  display: none;
}

.overlay-icon {
  width: min(180px, 34vw);
  height: min(180px, 34vw);
  object-fit: contain;
  margin-bottom: 14px;
  border-radius: 28px;
}

.overlay h1 {
  margin: 0 0 10px;
  color: var(--wood-dark);
  font-size: clamp(2rem, 5vw, 3.25rem);
  letter-spacing: 0;
}

.overlay p {
  max-width: 460px;
  margin: 0 0 20px;
  color: var(--text);
  font-weight: 800;
  line-height: 1.65;
}

.overlay button {
  min-width: 132px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  background: #e5b958;
  color: var(--wood-dark);
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(120, 83, 32, 0.2);
  cursor: pointer;
}

@media (max-width: 980px) {
  .page-shell {
    min-height: 100vh;
    width: min(100% - 16px, 720px);
    grid-template-columns: 1fr;
    align-items: start;
    padding: 8px 0 14px;
  }

  .side-panel {
    display: none;
  }

  .game-panel {
    min-height: calc(100vh - 22px);
    grid-template-rows: auto minmax(0, 1fr);
    padding: 10px;
    border-radius: 18px;
  }

  .game-header {
    gap: 6px;
  }

  .hud-chip {
    min-height: 42px;
    padding: 6px 8px;
  }

  .hud-chip span {
    font-size: 0.72rem;
  }

  .hud-chip strong {
    font-size: 1rem;
  }

  .board {
    width: min(100%, calc((100vh - 170px) * var(--cols) / var(--rows)));
    gap: 5px;
  }
}
