/* ===== Memory Flip =====
   Brand: #01311F / #BF9E69 / #F4F2EE
   Style: Claymorphism (soft 3D, playful)
   Fonts: Baloo 2 (headings) + Comic Neue (body)
   ========================= */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;500;600;700;800&family=Comic+Neue:wght@300;400;700&display=swap');

:root {
  /* Brand */
  --primary: #01311F;
  --primary-mid: #0A5438;
  --primary-light: #3D8B6B;
  --primary-bg: #E2EDE7;
  --accent: #BF9E69;
  --accent-light: #D4BC8E;
  --accent-pale: #E8DCC8;
  --accent-bg: #F5F0E5;
  --cream: #F4F2EE;

  /* Derived */
  --terracotta: #C07650;
  --terracotta-bg: #F8EDE6;
  --sage: #5A8A6E;
  --sage-bg: #E8F2EC;
  --warm-brown: #8B6F4E;
  --success: #3D8B6B;
  --error: #C45B5B;

  /* Text */
  --text: #1A2A22;
  --text-muted: #5E6E64;
  --bg: var(--cream);
  --white: #FFFFFF;

  /* Tokens */
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow-clay: 6px 6px 12px rgba(1, 49, 31, 0.06), -2px -2px 8px rgba(255, 255, 255, 0.9);
  --shadow-clay-hover: 8px 8px 16px rgba(1, 49, 31, 0.10), -3px -3px 10px rgba(255, 255, 255, 0.95);
  --shadow-clay-inset: inset 2px 2px 4px rgba(1, 49, 31, 0.05), inset -1px -1px 3px rgba(255, 255, 255, 0.7);
  --shadow-soft: 0 8px 24px rgba(1, 49, 31, 0.08);
  --border: 3px solid rgba(1, 49, 31, 0.06);
  --font-display: 'Baloo 2', cursive, sans-serif;
  --font-body: 'Comic Neue', cursive, sans-serif;
  --transition: 250ms ease;
  --board-gap: 8px;
}

/* --- Back Link --- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 0;
  margin-bottom: 4px;
  cursor: pointer;
  transition: color 250ms ease;
}

.back-link:hover {
  color: var(--primary);
}

/* --- Reset --- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  margin: 0 0 12px;
  color: var(--text);
}

p {
  margin: 0 0 12px;
  color: var(--text-muted);
}

/* --- App container --- */
.app {
  min-height: 100vh;
}

.screen {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.screen--game {
  align-items: stretch;
}

.screen--game.is-focus {
  padding: 0;
}

.hidden {
  display: none;
}

/* ==================
   INTRO SCREEN
   ================== */
.screen--intro {
  background: var(--bg);
}

.intro-card {
  background: var(--white);
  padding: 48px 44px;
  border-radius: var(--radius);
  border: var(--border);
  box-shadow: var(--shadow-clay);
  max-width: 520px;
  text-align: center;
  animation: floatIn 500ms ease-out;
}

.eyebrow {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 8px;
}

.lead {
  font-size: 1.1rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.intro-card h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.15;
  font-weight: 800;
}

.intro-card .btn--primary {
  padding: 14px 36px;
  font-size: 1.1rem;
}

/* --- Buttons --- */
.btn {
  border: none;
  border-radius: 50px;
  padding: 10px 22px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--white);
  color: var(--text);
  border: var(--border);
  box-shadow: var(--shadow-clay);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-clay-hover);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-clay-inset);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

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

.btn--primary {
  background: var(--primary);
  color: var(--white);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: var(--shadow-clay), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

.btn--primary:hover {
  background: #024A2E;
}

.btn--ghost {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
  box-shadow: none;
}

.btn--ghost:hover {
  background: var(--primary-bg);
  box-shadow: none;
  transform: none;
}

.btn--small {
  padding: 7px 14px;
  font-size: 0.82rem;
}

.btn--icon {
  width: 48px;
  height: 48px;
  min-width: 48px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn--icon .icon {
  width: 100%;
  height: 100%;
  display: block;
}

.btn--icon.btn--ghost {
  border: none;
  background: var(--white);
  box-shadow: var(--shadow-clay-inset);
}

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

/* ==================
   GAME LAYOUT
   ================== */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  width: min(1200px, 100%);
  min-height: calc(100vh - 64px);
  min-height: calc(100dvh - 64px);
  align-items: start;
}

.game-layout.is-sidebar-hidden {
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
}

.game-layout.is-sidebar-hidden .main-column {
  height: 100vh;
  height: 100dvh;
}

.main-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  min-width: 0;
  position: sticky;
  top: 32px;
}

/* --- Info Bar --- */
.info-bar {
  background: var(--white);
  border-radius: var(--radius);
  border: var(--border);
  padding: 16px 20px;
  box-shadow: var(--shadow-clay);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.info-bar h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

#boardSubtitle {
  font-size: 0.9rem;
  margin: 0;
  color: var(--text-muted);
}

.toggle-sidebar {
  align-self: center;
  flex-shrink: 0;
}

.toggle-sidebar--floating {
  display: none;
  align-self: center;
}

.game-layout.is-sidebar-hidden .info-bar {
  display: none;
}

.game-layout.is-sidebar-hidden .toggle-sidebar--floating {
  display: inline-flex;
}

/* --- Play Area --- */
.play-area {
  background: var(--white);
  border-radius: var(--radius);
  border: var(--border);
  padding: 24px;
  box-shadow: var(--shadow-clay);
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  max-height: 100%;
  min-width: 0;
  overflow: hidden;
}

.play-area.is-focus {
  padding: 16px;
  gap: 8px;
}

.game-layout.is-sidebar-hidden .play-area {
  border-radius: 0;
  box-shadow: none;
  border: none;
}

/* --- Card Board --- */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--board-gap);
  padding: 0;
  align-content: center;
  justify-content: center;
  margin: auto;
  flex: 1;
  min-height: 0;
}

.board.is-locked {
  pointer-events: none;
}

/* --- Cards --- */
.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  perspective: 800px;
  cursor: pointer;
}

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  transition: transform 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-style: preserve-3d;
}

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

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(20px, 3vw, 36px);
  backface-visibility: hidden;
}

/* Card Front (face down) */
.card-front {
  background: linear-gradient(145deg, var(--primary-bg) 0%, #D1E4D9 100%);
  color: var(--primary);
  border: 3px solid rgba(1, 49, 31, 0.08);
  box-shadow:
    var(--shadow-clay),
    inset 0 -3px 0 rgba(1, 49, 31, 0.06);
  transition: box-shadow var(--transition);
}

.card:hover .card-front {
  box-shadow:
    var(--shadow-clay-hover),
    inset 0 -3px 0 rgba(1, 49, 31, 0.06);
}

/* Card Back (face up - shows image) */
.card-back {
  background: var(--white);
  transform: rotateY(180deg);
  border: 3px solid rgba(1, 49, 31, 0.06);
  color: var(--text);
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  box-shadow: var(--shadow-clay);
}

.card.is-matched .card-face {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(61, 139, 107, 0.15), var(--shadow-clay);
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-xs);
}

.card-text {
  font-size: clamp(18px, 3vw, 34px);
  font-family: var(--font-display);
  font-weight: 700;
}

.card-back.has-image .card-text {
  display: none;
}

.card-back.has-image {
  padding: 0;
  overflow: hidden;
}

/* --- Board Footer --- */
.board-footer {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ==================
   SIDEBAR
   ================== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.game-layout.is-sidebar-hidden .sidebar {
  display: none;
}

.panel {
  background: var(--white);
  border-radius: var(--radius);
  border: var(--border);
  padding: 18px;
  box-shadow: var(--shadow-clay);
}

.panel h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

/* Sponsor panel */
.sponsor-box {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  background: var(--cream);
  overflow: hidden;
  border: 2px solid rgba(1, 49, 31, 0.04);
}

.sponsor-box img {
  width: auto;
  height: auto;
  max-width: 85%;
  max-height: 85%;
  object-fit: contain;
}

/* Info rows */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(1, 49, 31, 0.08);
  font-size: 0.9rem;
}

.info-row:last-child {
  border-bottom: none;
}

.info-row span:first-child {
  color: var(--text-muted);
}

.info-row span:last-child {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
}

/* Controls */
.control-buttons {
  display: flex;
  flex-direction: row;
  gap: 10px;
  justify-content: space-between;
}

/* Select / Dropdowns */
select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(1, 49, 31, 0.1);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  background: var(--cream);
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: auto;
}

select:hover {
  border-color: var(--primary-light);
}

select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1, 49, 31, 0.08);
}

#roundSelect {
  margin-top: 10px;
}

/* ==================
   CELEBRATION
   ================== */
.celebration {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 50;
}

.celebration.is-active {
  opacity: 1;
  visibility: visible;
}

.celebration-message {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4.5vw, 2.6rem);
  font-weight: 800;
  padding: 16px 34px;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--primary-bg) 0%, var(--accent-bg) 50%, var(--terracotta-bg) 100%);
  color: var(--primary);
  box-shadow: 0 16px 34px rgba(1, 49, 31, 0.15);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  animation: popIn 400ms cubic-bezier(0.34, 1.56, 0.64, 1), shimmer 1.8s ease-in-out infinite;
}

.celebration-message::before,
.celebration-message::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-light);
  box-shadow: 0 0 0 5px rgba(191, 158, 105, 0.2);
  transform: translateY(-50%);
}

.celebration-message::before {
  left: -16px;
}

.celebration-message::after {
  right: -16px;
}

/* Fireworks */
.fireworks {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.burst {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow:
    0 0 0 0 rgba(191, 158, 105, 0.8),
    0 0 0 0 rgba(61, 139, 107, 0.8),
    0 0 0 0 rgba(90, 138, 110, 0.8);
  animation: burst 1200ms ease-out infinite;
}

.burst--one {
  top: 20%;
  left: 15%;
}

.burst--two {
  top: 35%;
  right: 20%;
  animation-delay: 150ms;
  background: var(--primary-light);
}

.burst--three {
  bottom: 25%;
  left: 45%;
  animation-delay: 300ms;
  background: var(--sage);
}

/* ==================
   ANIMATIONS
   ================== */
@keyframes floatIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes popIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes shimmer {
  0%   { filter: brightness(1); }
  50%  { filter: brightness(1.06); }
  100% { filter: brightness(1); }
}

@keyframes burst {
  0% {
    transform: scale(0.4);
    box-shadow:
      0 0 0 0 rgba(191, 158, 105, 0.8),
      0 0 0 0 rgba(61, 139, 107, 0.8),
      0 0 0 0 rgba(90, 138, 110, 0.8);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: scale(1.6);
    box-shadow:
      0 -70px 0 -8px rgba(191, 158, 105, 0),
      60px 20px 0 -8px rgba(61, 139, 107, 0),
      -50px 50px 0 -8px rgba(90, 138, 110, 0);
    opacity: 0;
  }
}

/* ==================
   RESPONSIVE
   ================== */
@media (max-width: 960px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .main-column {
    height: calc(100vh - 32px);
    height: calc(100dvh - 32px);
    position: static;
  }

  .sidebar {
    order: -1;
  }

  .board {
    min-height: 0;
  }
}

@media (max-width: 600px) {
  .screen {
    padding: 12px;
  }

  .screen--game {
    padding: 8px;
  }

  .game-layout {
    gap: 10px;
  }

  .main-column {
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
  }

  .intro-card {
    padding: 32px 24px;
  }

  .intro-card h1 {
    font-size: 1.6rem;
  }

  .board {
    --board-gap: 6px;
    gap: var(--board-gap);
  }

  .info-bar {
    padding: 10px 14px;
  }

  .info-bar h2 {
    font-size: 0.9rem;
    margin-bottom: 2px;
  }

  #boardSubtitle {
    font-size: 0.8rem;
  }

  .play-area {
    padding: 12px;
    gap: 10px;
  }

  .play-area.is-focus {
    padding: 8px;
    gap: 6px;
  }

  .panel {
    padding: 14px;
  }

}

/* ==================
   REDUCED MOTION
   ================== */
@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition: none;
  }

  .intro-card,
  .celebration-message {
    animation: none;
  }

  .burst {
    animation: none;
  }

  .btn {
    transition: none;
  }
}
