:root {
  --wine: #3b1714;
  --wine-soft: #55221d;
  --red: #8f2d25;
  --red-dark: #6f211b;
  --cream: #f5efe2;
  --paper: #fffdf7;
  --gold: #bd8c3b;
  --muted: #746f68;
  --line: #ded7ca;
  --shadow: 0 28px 70px rgba(59, 23, 20, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--wine);
  background:
    radial-gradient(circle at 14% 8%, rgba(189, 140, 59, 0.12), transparent 24rem),
    linear-gradient(180deg, #fbf8f1 0%, #eee7da 100%);
  font-family: "DM Sans", sans-serif;
}

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

.page-shell {
  width: min(1180px, calc(100% - 44px));
  margin: 0 auto;
}

.arcade-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color 160ms ease;
}

.arcade-link:hover,
.arcade-link:focus-visible {
  color: var(--red);
}

.site-header {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(59, 23, 20, 0.14);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--wine);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.19em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--paper);
  background: var(--wine);
  border: 2px solid var(--gold);
  border-radius: 50%;
  font-family: "Cinzel", Georgia, serif;
  font-size: 19px;
  font-weight: 600;
}

.best-badge {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.15em;
}

.best-badge strong {
  min-width: 64px;
  padding: 7px 11px;
  color: var(--wine);
  background: rgba(59, 23, 20, 0.06);
  border: 1px solid rgba(59, 23, 20, 0.12);
  border-radius: 4px;
  font-size: 14px;
  letter-spacing: 0.05em;
  text-align: center;
}

main { padding: 20px 0 42px; }

.game-panel {
  overflow: hidden;
  max-width: 760px;
  margin: 0 auto;
  background: rgba(255, 253, 247, 0.88);
  border: 1px solid rgba(59, 23, 20, 0.14);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.game-toolbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.round-label { display: flex; align-items: center; gap: 11px; }
.status-dot {
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(189, 140, 59, 0.15);
}
.round-label div, .timer-wrap, .progress-text { display: flex; flex-direction: column; }
.round-label span:not(.status-dot), .timer-wrap span, .progress-text span {
  color: #96908a;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}
.round-label strong { margin-top: 3px; font-size: 13px; letter-spacing: 0.07em; }

.timer-wrap { align-items: center; }
.timer-wrap strong {
  margin-top: 1px;
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}
.timer-wrap.danger strong { color: #b32d27; }

.icon-button {
  justify-self: end;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  color: var(--paper);
  background: var(--wine);
  border: 2px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 5px 14px rgba(59, 23, 20, .24);
  cursor: pointer;
  transition: background 160ms, box-shadow 160ms, transform 160ms;
}
.icon-button:hover { background: var(--red); box-shadow: 0 7px 18px rgba(59, 23, 20, .3); transform: translateY(-1px); }
.icon-button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.icon-button:disabled { opacity: .55; cursor: wait; }
.icon-button span { font-size: 11px; font-weight: 700; letter-spacing: .1em; white-space: nowrap; }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; transition: transform 160ms; }
.icon-button:hover svg { transform: rotate(-18deg); }

.board-wrap { position: relative; padding: 28px; }
.play-area { display: block; }
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 570px;
  margin: 0 auto;
  transition: filter 220ms;
}
.matches-panel {
  max-width: 570px;
  margin: 20px auto 0;
  padding: 18px;
  background: rgba(59, 23, 20, 0.035);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.matches-heading {
  display: flex;
  flex-direction: column;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}
.matches-heading span {
  color: #96908a;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .16em;
}
.matches-heading strong { margin-top: 3px; font-size: 12px; letter-spacing: .07em; }
.matches-empty { margin: 18px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.matches-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}
.matches-list li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 50px;
  padding: 6px 9px;
  background: var(--paper);
  border: 1px solid rgba(143, 45, 37, .18);
  border-radius: 4px;
  box-shadow: 0 3px 10px rgba(59, 23, 20, .05);
}
.matches-list li strong { overflow: hidden; color: var(--red); font-family: "Cinzel", Georgia, serif; font-size: 14px; text-overflow: ellipsis; }
.matches-list li span { overflow: hidden; color: var(--wine); font-size: 10px; text-overflow: ellipsis; }
.matches-empty[hidden] { display: none; }

.card {
  position: relative;
  min-width: 0;
  aspect-ratio: 2.25;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 700px;
  cursor: pointer;
  user-select: none;
  transition: opacity 220ms, transform 220ms, visibility 0s 220ms;
}
.card:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 5px; }
.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 440ms cubic-bezier(.2, .72, .25, 1);
}
.card.is-flipped .card-inner, .card.is-matched .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 8px;
  border-radius: 5px;
  backface-visibility: hidden;
}
.card-front {
  color: #f8e7bc;
  background:
    linear-gradient(135deg, transparent 46%, rgba(255,255,255,.05) 46%, rgba(255,255,255,.05) 48%, transparent 48%),
    var(--red);
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.045), 0 3px 7px rgba(111, 33, 27, .18);
}
.card-front::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(248, 231, 188, .3);
  border-radius: 2px;
}
.card-number { font-family: "Cinzel", Georgia, serif; font-size: clamp(24px, 4vw, 36px); }
.card-back {
  transform: rotateY(180deg);
  color: var(--wine);
  background: #fffefa;
  border: 1px solid rgba(59, 23, 20, .22);
  box-shadow: inset 0 0 0 4px #f1eadc;
  font-size: clamp(15px, 2.7vw, 22px);
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: center;
}
.card-back.is-latin { color: var(--red); font-family: "Cinzel", Georgia, serif; font-size: clamp(16px, 3vw, 25px); }
.card-back.is-english { font-size: clamp(14px, 2.5vw, 21px); }
.card-back.is-decoy {
  padding: 4px 8px 12px;
  color: var(--gold);
  font-family: "Segoe UI Symbol", "Arial Unicode MS", sans-serif;
  font-size: clamp(36px, 6vw, 52px);
  line-height: 1;
}
.card.is-matched { cursor: default; }
.card.is-cleared { visibility: hidden; opacity: 0; transform: scale(.88); }
.card.is-matched .card-back {
  color: var(--red);
  background: #f3fff8;
  border: 3px solid #2f9c67;
  animation: match-flash 500ms ease-in-out 2;
}
@keyframes match-flash {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(47, 156, 103, .12), 0 0 0 0 rgba(47, 156, 103, .38); }
  50% { box-shadow: inset 0 0 0 3px rgba(47, 156, 103, .2), 0 0 0 6px rgba(47, 156, 103, .26); }
}
.card.is-matched .card-back::after {
  content: "✓";
  position: absolute;
  right: 8px;
  top: 6px;
  font-family: "DM Sans", sans-serif;
  font-size: 11px;
  font-weight: 700;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: safe center;
  flex-direction: column;
  padding: 24px;
  background: rgba(255, 253, 247, .93);
  text-align: center;
  opacity: 1;
  overflow-y: auto;
  transition: opacity 220ms, visibility 220ms;
  backdrop-filter: blur(7px);
}
.start-overlay.is-hidden { visibility: hidden; opacity: 0; }
.start-overlay.is-opening, .start-overlay.is-result { justify-content: flex-start; padding-top: 18px; }
.start-overlay h2 { margin: 0 0 8px; font-family: "Cinzel", Georgia, serif; font-size: 25px; font-weight: 600; }
.start-overlay p { margin: 0 0 20px; color: var(--muted); font-size: 15px; }
.vocabulary-reference {
  width: min(650px, 100%);
  margin: -2px 0 20px;
  padding: 14px;
  background: rgba(59, 23, 20, .035);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.vocabulary-reference[hidden] { display: none; }
.vocabulary-reference > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.vocabulary-reference ol {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-height: 250px;
  margin: 10px 0 0;
  padding: 2px 8px 2px 2px;
  overflow-y: auto;
  scrollbar-color: var(--gold) rgba(59, 23, 20, .08);
  scrollbar-width: thin;
  list-style: none;
}
.vocabulary-reference ol::-webkit-scrollbar { width: 8px; }
.vocabulary-reference ol::-webkit-scrollbar-track { background: rgba(59, 23, 20, .08); border-radius: 4px; }
.vocabulary-reference ol::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 4px; }
.vocabulary-reference li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid rgba(59, 23, 20, .1);
  border-radius: 3px;
  text-align: left;
}
.vocabulary-reference li strong { overflow: hidden; color: var(--red); font-family: "Cinzel", Georgia, serif; font-size: 16px; text-overflow: ellipsis; }
.vocabulary-reference li span { overflow: hidden; color: var(--muted); font-size: 14px; text-overflow: ellipsis; }
.round-matches {
  width: min(540px, 100%);
  margin: -2px 0 20px;
  padding: 14px;
  background: rgba(143, 45, 37, .05);
  border: 1px solid rgba(143, 45, 37, .16);
  border-radius: 5px;
}
.round-matches[hidden] { display: none; }
.round-matches > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.round-matches ol {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.round-matches li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 9px 14px;
  background: var(--paper);
  border: 1px solid rgba(143, 45, 37, .14);
  border-radius: 3px;
  text-align: left;
}
.round-matches li strong { color: var(--red); font-family: "Cinzel", Georgia, serif; font-size: 17px; }
.round-matches li span { color: var(--muted); font-size: 14px; }
.game-footer {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
}
.game-footer p { display: flex; align-items: center; gap: 7px; margin: 0; }
.legend-card, .legend-decoy {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  color: var(--red);
  background: #f5e7e3;
  border-radius: 2px;
  font-family: "Cinzel", Georgia, serif;
  font-size: 11px;
}
.legend-decoy { color: var(--gold); background: #f8f0df; }
.progress-text { align-items: flex-end; margin-left: auto; }
.progress-text strong { color: var(--wine); font-size: 13px; }

footer {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 24px 0 36px;
  color: #96908a;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: .17em;
}
.footer-line { flex: 1; height: 1px; background: rgba(59, 23, 20, .12); }

@media (max-width: 700px) {
  .page-shell { width: min(100% - 24px, 560px); }
  .site-header { height: 66px; }
  .arcade-link { font-size: 10px; letter-spacing: 0.08em; }
  .best-badge > span { display: none; }
  main { padding-top: 14px; }
  .game-toolbar { min-height: 65px; padding: 0 16px; }
  .round-label span:not(.status-dot) { display: none; }
  .board-wrap { padding: 14px; }
  .board { gap: 7px; grid-template-columns: repeat(3, 1fr); }
  .card { aspect-ratio: 2.05; }
  .matches-panel { padding: 14px; }
  .matches-list { grid-template-columns: repeat(2, 1fr); }
  .vocabulary-reference ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-footer { padding: 12px 16px; }
  .game-footer p { display: none; }
  .progress-text { margin: auto; align-items: center; }
  footer { gap: 10px; }
  footer span:not(.footer-line) { white-space: nowrap; font-size: 7px; }
}

@media (max-width: 480px) {
  .vocabulary-reference ol, .round-matches ol { grid-template-columns: 1fr; }
  .start-overlay h2 { font-size: 22px; }
}

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