.wrap {
  width: min(var(--wrap), calc(100% - 2rem));
  margin-inline: auto;
}

.site-main {
  padding-top: 0.25rem;
  padding-bottom: var(--space-section);
}

.site-header {
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--header-bg);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: 0.65rem 0;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.04em;
  font-size: clamp(1.2rem, 3vw, 1.4rem);
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s var(--ease);
}

.brand:hover { color: var(--accent); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.theme-toggle,
.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.theme-toggle:hover,
.nav-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.theme-toggle-icon::before {
  content: "◐";
  font-size: 1.05rem;
  line-height: 1;
}

.nav-toggle {
  flex-direction: column;
  gap: 5px;
}

.nav-toggle span {
  display: block;
  width: 1.05rem;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.35rem;
}

.nav a {
  color: var(--text);
  text-decoration: none;
  opacity: 0.78;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius);
  transition: opacity 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}

.nav a:hover {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.nav a.is-active {
  opacity: 1;
  color: var(--accent-2);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* —— Multigame switcher —— */
.game-switch {
  position: relative;
  margin-right: 0.1rem;
}

.game-switch > summary,
.lang-switch > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: min(14rem, 42vw);
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.game-switch > summary:hover,
.lang-switch > summary:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.game-switch > summary::-webkit-details-marker,
.lang-switch > summary::-webkit-details-marker { display: none; }

.game-switch-label {
  display: none;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.game-switch-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.game-switch > summary::after,
.lang-switch > summary::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-1px);
  flex-shrink: 0;
  opacity: 0.8;
}

.game-menu,
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 50;
  margin: 0;
  padding: 0.4rem;
  list-style: none;
  min-width: 14rem;
  max-height: min(70vh, 22rem);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.game-menu a,
.lang-menu a {
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}

.game-menu a:hover,
.game-menu a.is-active,
.lang-menu a:hover,
.lang-menu a.is-active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-2);
}

.game-menu-id {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 4.2rem;
}

.lang-switch {
  position: relative;
  margin-left: 0.35rem;
  padding-left: 0.65rem;
  border-left: 1px solid var(--line);
}

.lang-code {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.72rem;
  opacity: 0.75;
  min-width: 2.4rem;
}

.lang-switch > summary {
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* —— Footer —— */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 2rem 0 2.75rem;
  color: var(--footer-muted);
  font-size: 0.9rem;
  background: color-mix(in srgb, var(--bg-elev) 55%, transparent);
}

.footer-inner {
  display: grid;
  gap: 1rem;
}

.footer-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.site-footer p { margin: 0 0 0.5rem; }
.site-footer a {
  color: var(--accent-2);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 0.25rem;
}

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

body.nav-open .nav-backdrop {
  display: block;
}

.nav-backdrop[hidden] {
  display: none !important;
}

@media (min-width: 768px) {
  .game-switch-label { display: inline; }

  .game-switch > summary {
    max-width: 16rem;
    padding: 0.45rem 0.75rem;
  }

  .nav-toggle { display: none; }

  .nav-backdrop { display: none !important; }
}

/* Mobile: collapse nav into panel */
@media (max-width: 767px) {
  .header-inner { gap: 0.5rem; }

  .nav {
    display: none;
    position: fixed;
    inset: var(--header-h) 0 auto 0;
    z-index: 45;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.85rem 1rem 1.5rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    max-height: calc(100vh - var(--header-h));
    overflow: auto;
  }

  .nav.is-open { display: flex; }

  .nav a {
    padding: 0.85rem 0.5rem;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    opacity: 1;
    font-size: 1rem;
  }

  .lang-switch {
    margin: 0.75rem 0 0;
    padding: 0.75rem 0 0;
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .lang-switch > summary {
    width: 100%;
    justify-content: space-between;
    max-width: none;
    min-height: 2.75rem;
  }

  .lang-menu {
    position: static;
    max-height: none;
    box-shadow: none;
    margin-top: 0.5rem;
    border: 1px solid var(--line);
  }

  .game-switch > summary {
    min-height: 2.5rem;
  }
}
