:root {
  --board-bg: #c49b65;
  --board-fleck: rgba(95, 63, 32, 0.28);
  --board-fleck-light: rgba(255, 245, 227, 0.35);
  --board-shadow: rgba(46, 30, 10, 0.25);
  --frame: #b1824d;
  --text: #22150d;
  --accent: #1f6f6a;
  --paper: #f7f1e8;
  --pin: #7a1d1a;
  --card-shadow: rgba(26, 20, 15, 0.25);
  --font-display: "Luckiest Guy", "Cooper Black", "Impact", "Arial Black", sans-serif;
  --font-body: "Noto Sans", "Nunito", "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

@font-face {
  font-family: "Luckiest Guy";
  src:
    url("fonts/luckiest-guy-latin-400-normal.woff2") format("woff2"),
    url("fonts/luckiest-guy-latin-400-normal.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src:
    url("fonts/nunito-latin-400-normal.woff2") format("woff2"),
    url("fonts/nunito-latin-400-normal.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src:
    url("fonts/nunito-latin-700-normal.woff2") format("woff2"),
    url("fonts/nunito-latin-700-normal.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Sans";
  src:
    url("fonts/noto-sans-latin-400-normal.woff2") format("woff2"),
    url("fonts/noto-sans-latin-400-normal.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Sans";
  src:
    url("fonts/noto-sans-latin-700-normal.woff2") format("woff2"),
    url("fonts/noto-sans-latin-700-normal.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-body);
  background: radial-gradient(circle at top, #efe7dc 0%, #e0d1be 55%, #cfb49a 100%);
}

.page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 24px 12px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.title-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.controls {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.control-btn {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: default;
  color: rgba(34, 21, 13, 0.8);
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(26, 20, 15, 0.12);
  font-family: var(--font-body);
}

.title {
  position: relative;
  top: 0;
  left: 0;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  width: 100%;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6.5vw, 4.2rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #111;
  text-shadow: none;
  flex-wrap: wrap;
  z-index: 3;
  pointer-events: none;
}

.board-title {
  align-self: center;
}

.title-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.02em 0.08em;
  color: #111;
  line-height: 1;
  text-shadow:
    0 3px 4px rgba(0, 0, 0, 0.2),
    0 1px 0 rgba(0, 0, 0, 0.2);
  -webkit-text-stroke: 6px #ffffff;
  paint-order: stroke fill;
}

.title-space {
  width: clamp(16px, 4vw, 36px);
  height: 1px;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 1.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: var(--font-display);
  color: #111;
  -webkit-text-stroke: 4px rgba(245, 240, 230, 0.9);
  paint-order: stroke fill;
}

.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.legend span {
  background: rgba(255, 255, 255, 0.7);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: clamp(24px, 4vw, 36px);
  padding-top: clamp(24px, 4vw, 36px);
  background-color: var(--board-bg);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.22), transparent 45%),
    radial-gradient(circle at 80% 30%, rgba(0, 0, 0, 0.1), transparent 55%),
    radial-gradient(circle at 30% 70%, rgba(255, 255, 255, 0.12), transparent 45%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 40%),
    linear-gradient(25deg, rgba(0, 0, 0, 0.08), transparent 50%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Ccircle cx='8' cy='12' r='1.1' fill='%23000' fill-opacity='0.18'/%3E%3Ccircle cx='22' cy='30' r='0.9' fill='%23000' fill-opacity='0.14'/%3E%3Ccircle cx='40' cy='10' r='1.2' fill='%23000' fill-opacity='0.15'/%3E%3Ccircle cx='55' cy='26' r='0.8' fill='%23000' fill-opacity='0.12'/%3E%3Ccircle cx='70' cy='18' r='1' fill='%23000' fill-opacity='0.16'/%3E%3Ccircle cx='14' cy='54' r='1' fill='%23fff' fill-opacity='0.2'/%3E%3Ccircle cx='33' cy='62' r='0.9' fill='%23fff' fill-opacity='0.18'/%3E%3Ccircle cx='52' cy='48' r='1.1' fill='%23fff' fill-opacity='0.18'/%3E%3Ccircle cx='70' cy='60' r='0.9' fill='%23fff' fill-opacity='0.15'/%3E%3Ccircle cx='60' cy='70' r='0.8' fill='%23fff' fill-opacity='0.12'/%3E%3C/svg%3E");
  background-size: auto, auto, auto, auto, auto, 120px 120px;
  background-blend-mode: normal, normal, normal, normal, normal, multiply;
  border: 12px solid var(--frame);
  border-radius: 10px;
  box-shadow:
    0 20px 40px var(--board-shadow),
    inset 0 0 0 2px rgba(255, 255, 255, 0.25),
    inset 0 0 18px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2.6vw, 28px);
  overflow: hidden;
}

.board-cards {
  display: grid;
  --grid-gap: clamp(26px, 4vw, 44px);
  gap: var(--grid-gap);
  grid-template-columns: repeat(var(--grid-cols, auto-fit), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows, 1), minmax(0, 1fr));
  align-content: stretch;
  justify-content: stretch;
  place-items: center;
  place-content: start;
  flex: 1;
  min-height: 0;
  padding: clamp(6px, 1vw, 12px);
  --card-inset: 0px;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--grid-gap);
  width: 100%;
  height: 100%;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(var(--board-fleck) 1px, transparent 1px),
    radial-gradient(var(--board-fleck-light) 1px, transparent 1px),
    radial-gradient(rgba(0, 0, 0, 0.18) 1px, transparent 1px);
  background-size: 14px 14px, 22px 22px, 36px 36px;
  opacity: 0.7;
  pointer-events: none;
  z-index: 0;
}

.board::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(25deg, rgba(0, 0, 0, 0.06) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(-18deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 7px);
  opacity: 0.35;
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 0;
}

.board > * {
  position: relative;
  z-index: 1;
}

.card {
  position: relative;
  padding: clamp(6px, 1.2vw, 16px);
  min-height: 0;
  aspect-ratio: 8 / 5;
  width: var(--card-w, 100%);
  height: var(--card-h, auto);
  max-width: 100%;
  max-height: 100%;
  container-type: size;
  border-radius: 10px;
  --inner-inset: 8px;
  --safe-padding: clamp(8px, 1.6vw, 14px);
  --inner-safe: calc(var(--safe-padding) + var(--inner-inset));
  box-shadow:
    0 10px 18px rgba(26, 20, 15, 0.18),
    0 2px 0 rgba(255, 255, 255, 0.5) inset;
  border: 1px solid rgba(0, 0, 0, 0.2);
  cursor: pointer;
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.45), transparent 40%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.25), transparent 45%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.04), transparent 35%),
    var(--card-bg, var(--paper));
  --tilt: 0deg;
  --tilt-hover: 0deg;
  --nudge-x: 0px;
  --nudge-y: 0px;
  --lift: 0px;
  --delay: 0ms;
  transform:
    translate(0, var(--lift))
    rotate(calc((var(--tilt) * var(--tilt-scale, 0)) + var(--tilt-hover)))
    scale(1);
  animation: none;
}

.board.board-ready .card {
  animation: card-in 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: var(--delay);
}

.card:hover,
.card:focus-visible {
  --lift: -4px;
  --tilt-hover: -0.5deg;
  box-shadow:
    0 16px 26px rgba(26, 20, 15, 0.28),
    0 2px 0 rgba(255, 255, 255, 0.55) inset;
  outline: 2px solid rgba(0, 0, 0, 0.25);
  outline-offset: 2px;
}

@keyframes card-in {
  0% {
    opacity: 0;
    transform: translate(var(--nudge-x), calc(var(--nudge-y) + 12px))
      rotate(calc(var(--tilt) + var(--tilt-hover)))
      scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translate(var(--nudge-x), calc(var(--nudge-y) + var(--lift)))
      rotate(calc(var(--tilt) + var(--tilt-hover)))
      scale(1);
  }
}

.card::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 50%;
  width: 13px;
  height: 13px;
  transform: translateX(-50%);
  background:
    radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.9), transparent 40%),
    radial-gradient(circle at 50% 55%, #ff5a54 0%, #d63b36 45%, #8c1c1c 75%, #5a0b0b 100%);
  border-radius: 50%;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(0, 0, 0, 0.25),
    inset 0 -1px 2px rgba(0, 0, 0, 0.35),
    inset 0 1px 1px rgba(255, 255, 255, 0.6);
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.25));
  z-index: 2;
}

.card::after {
  content: "";
  position: absolute;
  inset: var(--inner-inset);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  pointer-events: none;
  z-index: 1;
}

.card .term {
  font-size: var(--card-term-size, clamp(9px, 16cqh, 22px));
  color: rgba(24, 20, 16, 0.85);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55),
    0 2px 4px rgba(0, 0, 0, 0.12);
  max-width: calc(100% - (var(--inner-safe) * 2));
  display: block;
  text-align: center;
  line-height: 1.12;
  white-space: normal;
  overflow: visible;
  word-break: normal;
  overflow-wrap: normal;
}

.footer {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  text-align: center;
  color: rgba(34, 21, 13, 0.75);
  background: rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  padding: 8px 16px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 6px 14px rgba(26, 20, 15, 0.1);
  align-self: center;
  margin: 0;
}

.wall-list {
  background: rgba(255, 255, 255, 0.65);
  border-radius: 12px;
  padding: 18px 20px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 10px 18px rgba(26, 20, 15, 0.15);
}

.wall-list h2 {
  margin: 0 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.wall-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.wall-links a {
  text-decoration: none;
  color: #111;
  background: #fff7ea;
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wall-links a:hover,
.wall-links a:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(26, 20, 15, 0.18);
  outline: 2px solid rgba(0, 0, 0, 0.2);
  outline-offset: 2px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(15, 10, 8, 0.55);
  backdrop-filter: blur(4px);
}

.modal-shell {
  position: relative;
  display: inline-block;
}

.modal-card {
  position: relative;
  --modal-bg: #f3eadc;
  --img-x: 0%;
  --img-y: 0%;
  --img-zoom: 1;
  background: var(--modal-bg);
  border-radius: 16px;
  padding: 24px;
  max-width: 540px;
  width: min(92vw, 540px);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.35),
    inset 0 0 0 2px rgba(255, 255, 255, 0.5);
  border: 2px solid rgba(0, 0, 0, 0.18);
  z-index: 1;
  font-family: var(--font-body);
}

.modal-close {
  position: absolute;
  top: -44px;
  right: -44px;
  border: none;
  background: #111;
  color: white;
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  z-index: 5;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.flip {
  perspective: 800px;
  position: relative;
  min-height: 280px;
}

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border-radius: 12px;
  background: var(--modal-bg);
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.55),
    inset 0 0 24px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.flip-front h2 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4.2vw, 2.8rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.flip-back h3 {
  margin: 0 0 12px;
  font-size: clamp(1.6rem, 3.4vw, 2.2rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.flip-back p {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.6rem);
  line-height: 1.45;
  color: rgba(24, 20, 16, 0.85);
}

.flip-front p {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.6rem);
  line-height: 1.45;
  color: rgba(24, 20, 16, 0.85);
}

.flip-back {
  padding: 0;
  overflow: hidden;
  justify-content: center;
  gap: 16px;
}

.flip-back-content {
  position: relative;
  z-index: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(2px);
}

.flip-back.has-image .flip-back-content {
  display: none;
}

.modal-media {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(0, 0, 0, 0.2);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.45),
    0 8px 16px rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.2);
}

.modal-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: calc(50% + var(--img-x)) calc(50% + var(--img-y));
  transform: scale(var(--img-zoom));
  transform-origin: center;
}

.modal.no-flip .hint {
  display: none;
}

.flip-back {
  transform: rotateY(180deg);
}

.flip.flipped .flip-front {
  transform: rotateY(180deg);
}

.flip.flipped .flip-back {
  transform: rotateY(360deg);
}

.flip-front .hint {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.55rem;
  color: rgba(0, 0, 0, 0.6);
}

@media (max-width: 640px) {
  .card .term {
    font-size: clamp(12px, 22cqh, 30px);
  }

  .controls {
    position: static;
    width: 100%;
    justify-content: center;
    order: 3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .flip,
  .flip-face {
    transition: none;
  }

  .card {
    animation: none;
  }
}
