:root {
  --ink: #1d241f;
  --cream: #f5edda;
  --paper: #fffaf0;
  --forest: #173a2b;
  --forest-soft: #285b43;
  --gold: #c79b42;
  --wine: #8b2436;
  --shadow: 0 22px 65px rgba(22, 34, 26, .24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at 15% 12%, rgba(199,155,66,.26), transparent 24rem),
    radial-gradient(circle at 85% 28%, rgba(139,36,54,.18), transparent 22rem),
    linear-gradient(145deg, #193629, #0e251b 58%, #142c22);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .11;
  background-image: url("assets/backgrounds/bg-2.jpg?v=20261101-7");
  background-size: 420px;
  mix-blend-mode: screen;
}

button, a { font: inherit; }
button { cursor: pointer; }

.page-shell {
  width: min(100% - 28px, 900px);
  margin: 0 auto;
  padding: 42px 0 54px;
}

.game-header {
  color: #fff8e7;
  text-align: center;
  text-shadow: 0 2px 18px rgba(0,0,0,.35);
}

.eyebrow {
  margin: 0 0 10px;
  color: #e8c877;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.game-title {
  display: grid;
  justify-items: center;
  gap: 2px;
  margin: 0;
  color: #fff4d1;
  font-family: Baskerville, "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  font-size: clamp(2.15rem, 7vw, 4.6rem);
  font-weight: 500;
  letter-spacing: -.035em;
  line-height: .95;
  text-wrap: balance;
}

.game-title span::before,
.game-title span::after {
  content: "❦";
  display: inline-block;
  margin: 0 .28em;
  color: #d9b868;
  font-size: .35em;
  vertical-align: middle;
}

.game-title small {
  color: #e8c877;
  font-size: .31em;
  font-style: italic;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
}

.instructions {
  margin: 12px auto 28px;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
}

.game-frame {
  padding: clamp(14px, 3vw, 26px);
  border: 1px solid rgba(226,194,115,.65);
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255,250,240,.98), rgba(240,228,200,.97));
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr)) repeat(2, auto);
  gap: 10px;
  margin-bottom: 18px;
}

.score-card, .control-button {
  min-height: 54px;
  border: 1px solid rgba(23,58,43,.19);
  border-radius: 12px;
  background: rgba(255,255,255,.62);
}

.score-card {
  display: grid;
  place-content: center;
  text-align: center;
}

.score-card span {
  color: #536158;
  font-size: .69rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.score-card strong { font-size: 1.2rem; }

.control-button {
  padding: 0 15px;
  color: var(--forest);
  font-weight: 700;
  transition: background .2s ease, transform .2s ease;
}

.control-button:hover, .control-button:focus-visible {
  background: #fff;
  transform: translateY(-1px);
}

.game-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 640px);
  width: min(100%, 640px, max(220px, calc(100dvh - 330px)));
  margin-inline: auto;
  gap: 0;
  padding: 0;
  border: 8px solid #204a37;
  border-radius: 18px;
  background-color: #102d21;
  background-image: url("assets/backgrounds/bg-1.jpg?v=20261101-7");
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 2px rgba(226,194,115,.72), inset 0 0 32px rgba(0,0,0,.55);
  perspective: 1000px;
}

.memory-card {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  transform-style: preserve-3d;
  transition: transform .48s cubic-bezier(.2,.72,.25,1);
}

.memory-card.is-flipped { transform: rotateY(180deg); }

.memory-card.is-matched {
  opacity: 0;
  pointer-events: none;
  transform: rotateY(180deg);
  transition: none;
}

.memory-card.is-clearing {
  pointer-events: none;
  transform: none;
  transition: none !important;
}

.memory-card.is-clearing .card-back,
.memory-card.is-matched .card-back {
  opacity: 0;
  visibility: hidden;
}

.memory-card.is-clearing .card-front,
.memory-card.is-matched .card-front {
  opacity: 1;
  visibility: visible;
}

.memory-card.is-clearing .card-front {
  transform: none;
  backface-visibility: visible;
  transition: none !important;
}

.memory-card:focus-visible {
  outline: 4px solid #ffe08a;
  outline-offset: 3px;
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  overflow: hidden;
  border: 2px solid #d9b868;
  border-radius: 0;
  background: #123f2b;
  box-shadow: 0 5px 12px rgba(0,0,0,.25);
  backface-visibility: hidden;
}

.card-face picture, .card-face img { display: block; width: 100%; height: 100%; }
.card-face img { object-fit: cover; }
.card-front { transform: rotateY(180deg); background: #fff; }
.card-back img { filter: saturate(.95) contrast(1.04); }
.memory-card:not(.is-flipped):not(.is-matched):hover { transform: translateY(-1.5px) rotate(.175deg); }

.gentle-note {
  margin: 17px 0 0;
  color: #536158;
  text-align: center;
  font-style: italic;
}

.site-footer {
  display: grid;
  grid-template-columns: minmax(190px, 280px) 1fr;
  align-items: center;
  gap: clamp(24px, 5vw, 52px);
  margin-top: 24px;
  padding: clamp(22px, 4vw, 38px);
  border: 1px solid rgba(226,194,115,.72);
  border-radius: 24px;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 14%, rgba(199,155,66,.2), transparent 15rem),
    linear-gradient(135deg, rgba(255,250,240,.98), rgba(238,224,191,.98));
  box-shadow: 0 18px 48px rgba(0,0,0,.2);
}

.invitation-art {
  display: block;
  border: 5px solid #fff8e7;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 32px rgba(38,31,21,.24), 0 0 0 1px rgba(139,36,54,.35);
  transform: rotate(-1.25deg);
  transition: transform .25s ease, box-shadow .25s ease;
}
.invitation-art:hover { transform: rotate(0) translateY(-2px); box-shadow: 0 20px 38px rgba(38,31,21,.28), 0 0 0 1px rgba(139,36,54,.45); }
.invitation-art:focus-visible { outline: 4px solid var(--wine); outline-offset: 5px; }
.invitation-art img { display: block; width: 100%; height: auto; }
.invitation-copy .eyebrow { margin-bottom: 9px; color: var(--wine); }
.invitation-copy h2 { margin: 0; color: var(--forest); font-size: clamp(1.9rem, 4.4vw, 3rem); line-height: 1.04; }
.invitation-copy > p:not(.eyebrow) { max-width: 33rem; margin: 18px 0 24px; color: #465047; font-size: 1.05rem; line-height: 1.65; }
.invitation-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 999px;
  color: #fffaf0;
  background: var(--wine);
  box-shadow: 0 8px 18px rgba(139,36,54,.22);
  font-weight: 700;
  text-decoration: none;
  transition: transform .2s ease, background .2s ease;
}
.invitation-button:hover { background: #a02b40; transform: translateY(-1px); }
.invitation-button:focus-visible { outline: 4px solid #e8c877; outline-offset: 3px; }

.leaderboard {
  margin-top: 24px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid rgba(226,194,115,.42);
  border-radius: 20px;
  color: #f8edd2;
  background: rgba(9,29,20,.72);
  box-shadow: 0 14px 40px rgba(0,0,0,.18);
}

.leaderboard-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.leaderboard h2 { margin: 0; font-size: 1.7rem; }
.leaderboard-tabs { display: flex; gap: 5px; padding: 4px; border-radius: 999px; background: rgba(255,255,255,.09); }
.leaderboard-tab { padding: 7px 14px; border: 0; border-radius: 999px; color: #f8edd2; background: transparent; }
.leaderboard-tab.is-active { color: var(--forest); background: #f4d98e; font-weight: 700; }
.leaderboard-table-wrap { max-height: 340px; margin-top: 16px; overflow: auto; }
.leaderboard table { width: 100%; border-collapse: collapse; }
.leaderboard th, .leaderboard td { padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,.12); text-align: left; }
.leaderboard th { color: #e8c877; font-size: .73rem; letter-spacing: .09em; text-transform: uppercase; }
.leaderboard th:first-child, .leaderboard td:first-child { width: 42px; text-align: center; }
.leaderboard th:nth-child(3), .leaderboard td:nth-child(3),
.leaderboard th:nth-child(4), .leaderboard td:nth-child(4) { width: 80px; text-align: right; }
.leaderboard-message { min-height: 1.2em; margin: 12px 0 0; color: #e8c877; font-size: .9rem; }
.leaderboard tr.is-player-score td { color: #152f23; background: #f4d98e; font-weight: 700; }
.leaderboard tr.is-player-score td:first-child { border-radius: 8px 0 0 8px; }
.leaderboard tr.is-player-score td:last-child { border-radius: 0 8px 8px 0; }
.leaderboard tr.score-separator td { border-top: 2px dashed rgba(232,200,119,.5); }

.ranking-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(232,200,119,.42);
  border-radius: 14px;
  background: rgba(255,255,255,.08);
}
.ranking-actions[hidden] { display: none; }
.ranking-actions p { margin: 0; font-weight: 700; }
.ranking-actions > div { display: flex; flex-wrap: wrap; gap: 9px; }
.prospero-button { display: inline-flex; align-items: center; padding: 11px 20px; border-radius: 999px; color: var(--forest); background: #f4d98e; font-weight: 700; text-decoration: none; }

.score-form { margin-top: 20px; padding-top: 18px; border-top: 1px solid rgba(23,58,43,.18); }
.score-form label { display: block; margin-bottom: 8px; color: var(--forest); font-weight: 700; }
.score-entry { display: flex; gap: 8px; }
.score-entry input { min-width: 0; flex: 1; padding: 10px 12px; border: 1px solid rgba(23,58,43,.3); border-radius: 10px; background: #fff; }
.score-message { min-height: 1.2em; margin: 8px 0 0; color: var(--wine); font-size: .9rem; }

.prospero-logo { max-width: 120px; border-radius: 8px; }
.dialog-actions a { color: #f1cf78; font-weight: 700; }

.win-dialog {
  width: min(92vw, 520px);
  padding: 34px;
  border: 2px solid var(--gold);
  border-radius: 20px;
  color: var(--ink);
  text-align: center;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.win-dialog::backdrop { background: rgba(7,24,16,.78); backdrop-filter: blur(4px); }
.win-dialog h2 { margin: 8px 0 10px; color: var(--forest); font-size: clamp(1.8rem, 6vw, 2.7rem); }
.dialog-ornament { color: var(--wine); letter-spacing: .38em; }
.dialog-actions { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 18px; margin-top: 24px; }
.dialog-actions a { color: var(--forest); }
.primary-button { padding: 11px 20px; border: 0; border-radius: 999px; color: #fff; background: var(--wine); font-weight: 700; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 680px) {
  .page-shell { width: min(100% - 16px, 900px); padding-top: 24px; }
  .toolbar { grid-template-columns: repeat(3, 1fr); }
  .control-button { grid-column: span 1; min-height: 46px; padding: 0 8px; }
  #musicButton { grid-column: 1 / span 1; }
  #restartButton { grid-column: 2 / span 2; }
  .game-board { border-width: 5px; }
  .leaderboard-heading { align-items: stretch; flex-direction: column; }
  .leaderboard-tabs { align-self: flex-start; }
  .score-entry { flex-direction: column; }
  .ranking-actions { align-items: stretch; flex-direction: column; }
  .site-footer { grid-template-columns: 1fr; text-align: center; }
  .invitation-art { width: min(76%, 290px); margin-inline: auto; transform: none; }
  .invitation-copy > p:not(.eyebrow) { margin-inline: auto; }
}

@media (max-height: 760px) {
  .page-shell { padding-top: 10px; padding-bottom: 12px; }
  .eyebrow { display: none; }
  .game-title { font-size: clamp(1.75rem, 6vw, 3rem); }
  .instructions { margin: 4px auto 10px; font-size: .96rem; }
  .game-frame { padding: 10px; }
  .toolbar { margin-bottom: 8px; }
  .score-card, .control-button { min-height: 42px; }
  .game-board { width: min(100%, 560px); width: min(100%, 560px, max(190px, calc(100dvh - 225px))); }
  .gentle-note { margin-top: 6px; font-size: .88rem; }
}

@media (max-height: 560px) and (min-width: 681px) {
  .game-header { display: none; }
  .game-frame {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto;
    grid-template-areas:
      "board toolbar"
      "board note";
    align-items: start;
    gap: 10px;
  }
  .toolbar {
    grid-area: toolbar;
    width: 245px;
    grid-template-columns: repeat(3, 1fr);
  }
  .control-button { grid-column: span 3; }
  .game-board {
    grid-area: board;
    width: min(calc(100vh - 32px), calc(100vw - 300px));
    width: min(calc(100dvh - 32px), calc(100vw - 300px));
  }
  .gentle-note { grid-area: note; max-width: 245px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
