:root {
  --ink: #233746;
  --muted: #5f7180;
  --cream: #fff7de;
  --paper: #fffdf4;
  --water: #22a3aa;
  --deep: #155a68;
  --green: #77b84a;
  --gold: #ffd46d;
  --orange: #ef6c3e;
  --bad: #b34234;
  --line: rgba(35, 55, 70, .16);
  --shadow: 0 18px 42px rgba(35, 55, 70, .18);
  --radius: 8px;
  --display: "Arial Black", "Trebuchet MS", sans-serif;
  --body: "Trebuchet MS", Arial, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--body);
  background: var(--cream) url("../assets/images/bg.svg") center top / cover fixed;
}

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

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(14px, 4vw, 42px);
  background: rgba(255, 247, 222, .93);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
}

.brand img {
  width: 45px;
  height: 45px;
  border-radius: 10px;
}

.brand strong {
  display: block;
  font-family: var(--display);
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.brand span span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.nav a {
  padding: 8px 10px;
  color: var(--muted);
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 900;
  text-decoration: none;
}

.nav a:hover,
.nav a.active {
  color: var(--cream);
  background: var(--ink);
}

.wrap {
  width: min(1160px, calc(100% - 28px));
  max-width: 100%;
  margin: 0 auto;
  padding: 18px 0 42px;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  align-items: start;
}

.game-panel,
.rail,
.info-card,
.page-card,
.contact-card {
  min-width: 0;
  background: rgba(255, 253, 244, .95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.game-panel {
  padding: 16px;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 14px;
}

.hero-row h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 3.3rem);
  line-height: .95;
}

.hero-row p {
  margin: 7px 0 0;
  color: var(--muted);
  font-weight: 820;
}

.start-btn,
.mode-btn {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 950;
}

.start-btn {
  padding: 12px 18px;
  color: #fff;
  background: linear-gradient(180deg, var(--orange), #c84a2f);
  box-shadow: 0 7px 0 #823121;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--water);
  border-radius: var(--radius);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-family: var(--display);
  font-size: 1.35rem;
  line-height: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  aspect-ratio: 8 / 11;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
  padding: 0;
}

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

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

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 18px rgba(35, 55, 70, .2);
}

.face img {
  width: 100%;
  height: 100%;
  display: block;
}

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

.card.matched {
  cursor: default;
  filter: drop-shadow(0 0 10px rgba(119, 184, 74, .5));
}

.card.bad-pulse .face {
  animation: shake .25s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

.rail {
  padding: 14px;
}

.rail h2 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 1.3rem;
}

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

.mode-btn {
  padding: 10px;
  text-align: left;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
}

.mode-btn.active {
  color: var(--ink);
  background: #fff1bd;
  box-shadow: inset 5px 0 0 var(--orange);
}

.log {
  margin-top: 14px;
  min-height: 150px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.log-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  border-bottom: 1px dashed var(--line);
}

.log-row:last-child { border-bottom: 0; }
.log-row b { color: var(--ink); }

.rules {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-weight: 790;
  line-height: 1.55;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 16px;
}

.info-card,
.page-card,
.contact-card {
  padding: clamp(18px, 3vw, 28px);
}

.info-card h2,
.page-card h1,
.page-card h2 {
  margin: 0 0 9px;
  font-family: var(--display);
}

.info-card p,
.page-card p,
.page-card li {
  color: var(--muted);
  font-weight: 780;
  line-height: 1.65;
}

.page-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 18px;
  align-items: center;
}

.page-hero h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: .95;
}

.page-hero img {
  width: 100%;
}

.page-grid,
.contact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.contact-card span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.contact-card p,
.contact-card a {
  display: block;
  margin: 8px 0 0;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 18px clamp(14px, 4vw, 42px);
  color: var(--cream);
  background: var(--ink);
}

.footer a {
  color: var(--cream);
  font-weight: 900;
  text-decoration: none;
}

@media (max-width: 960px) {
  .game-layout,
  .info-grid,
  .page-grid,
  .contact-grid {
    grid-template-columns: 1fr;
  }

  .board {
    grid-template-columns: repeat(4, minmax(68px, 1fr));
  }
}

@media (max-width: 680px) {
  .header,
  .hero-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav {
    justify-content: flex-start;
  }

  .nav a {
    padding: 7px 6px;
    font-size: .68rem;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .board {
    grid-template-columns: repeat(3, minmax(70px, 1fr));
  }

  .page-hero {
    grid-template-columns: 1fr;
  }

  .page-hero img {
    max-width: 140px;
  }
}
