/* ==========================================================================
   Chess Anywhere — shared chrome
   Loaded by every page, on top of the Industry design system
   (css/industry.css). Theme tokens, page furniture, the header and its
   mobile nav, the footer, and the touch rules that apply site-wide.

   Page-specific styles live next to their page: css/home.css for the
   homepage, css/page.css for the prose pages.
   ========================================================================== */

/* ---------------------------------------------------------------------- */
/* Theme                                                                   */
/* ---------------------------------------------------------------------- */
/* The design ships a light default and a JS toggle that remembers the choice.
   Only the core surface tokens live here; page-specific ones (the board's
   square and piece colours) are redefined alongside the thing they colour. */

[data-theme='dark'] {
  --color-bg: #1d1f20;
  --color-text: #f2f2f3;
  --color-surface: #2b2b2d;
  --color-divider: color-mix(in srgb, #f2f2f3 18%, transparent);

}

html { background: var(--color-bg); }
body { min-height: 100vh; }

/* ---------------------------------------------------------------------- */
/* Layout primitives                                                       */
/* ---------------------------------------------------------------------- */

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.section {
  padding: clamp(48px, 7vw, 88px) 0;
  border-top: 1px solid var(--color-divider);
}

/* Numbered section label — "01 · Three ways to play" */
.section-num {
  display: block;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent-700);
  margin-bottom: 10px;
}

.rule {
  height: 1px;
  border: 0;
  margin: 0 0 32px;
  background: var(--color-divider);
}

.h-section {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  text-transform: uppercase;
  font-size: clamp(26px, 4vw, 36px);
  margin: 0 0 16px;
}

.lede {
  font-size: 16px;
  line-height: 1.65;
  margin: 0 0 32px;
  color: color-mix(in srgb, var(--color-text) 85%, transparent);
}

.muted-copy {
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
  color: color-mix(in srgb, var(--color-text) 80%, transparent);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  z-index: 30;
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--color-accent);
  color: var(--color-bg);
}

/* ---------------------------------------------------------------------- */
/* Header                                                                  */
/* ---------------------------------------------------------------------- */

.site-header { border-bottom: 1px solid var(--color-divider); }

.site-header .nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
}

.nav-links { display: contents; }

/* The toggle's mark is a square that flips on its vertical axis. */
.theme-mark {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 1px solid var(--color-text);
  transition: transform 220ms linear;
  overflow: hidden;
}
.theme-mark::after {
  content: '';
  display: block;
  width: 100%;
  height: 50%;
  background: var(--color-text);
}
[data-theme='dark'] .theme-mark { transform: rotateY(180deg); }

/* ---------------------------------------------------------------------- */
/* Footer                                                                  */
/* ---------------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--color-divider);
  padding: 40px 0;
}

.site-footer__row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
}

.site-footer nav {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 14px;
}

.site-footer__colophon {
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 0 24px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}

/* ---------------------------------------------------------------------- */
/* Mobile nav                                                              */
/* ---------------------------------------------------------------------- */
/* Hidden above the breakpoint. Below it the inline links come out of the
   bar and this takes over — the bar is too narrow to hold four section
   links, a theme toggle and a call to action at a size a thumb can hit. */

.nav-toggle { display: none; }

.nav-toggle__bars,
.nav-toggle__bars::before,
.nav-toggle__bars::after {
  display: block;
  width: 18px;
  height: 1px;
  background: var(--color-text);
}
.nav-toggle__bars {
  position: relative;
  transition: background-color 160ms linear;
}
.nav-toggle__bars::before,
.nav-toggle__bars::after {
  content: '';
  position: absolute;
  left: 0;
  transition: transform 160ms linear;
}
.nav-toggle__bars::before { top: -6px; }
.nav-toggle__bars::after { top: 6px; }

/* Open state folds the three bars into a cross. */
[aria-expanded='true'] .nav-toggle__bars { background: transparent; }
[aria-expanded='true'] .nav-toggle__bars::before { transform: translateY(6px) rotate(45deg); }
[aria-expanded='true'] .nav-toggle__bars::after { transform: translateY(-6px) rotate(-45deg); }

.mobile-nav {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--color-divider);
  background: var(--color-bg);
  padding: 8px 24px calc(20px + env(safe-area-inset-bottom));
  max-height: calc(100dvh - 100%);
  overflow-y: auto;
}
.mobile-nav[hidden] { display: none; }

.mobile-nav a:not(.btn) {
  display: flex;
  align-items: center;
  min-height: 52px;
  color: inherit;
  text-decoration: none;
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: 19px;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--color-divider);
}
.mobile-nav a:last-of-type { border-bottom: 0; }

.mobile-nav__cta {
  margin-top: 16px;
  min-height: 52px;
  font-size: 16px;
}

/* ---------------------------------------------------------------------- */
/* Touch                                                                   */
/* ---------------------------------------------------------------------- */
/* A pointer that cannot hover needs bigger targets and no hover styling —
   on iOS a :hover rule sticks to the last thing tapped until you tap
   something else, which reads as a stuck selection. */

@media (hover: none) {
  .btn-secondary:hover { background: transparent; }
  .btn-primary:hover { background: var(--color-accent); }
  .opt:hover { background: transparent; }
  .opt[aria-pressed='true']:hover { background: var(--color-accent); }
  .table tbody tr:hover { background: transparent; }
  .nav a:hover { color: inherit; }
}

@media (pointer: coarse) {
  /* 44px is the smallest target most people can hit reliably. */
  .btn,
  .opt,
  .clock-face,
  .mobile-nav a { min-height: 44px; }

  .btn-icon { width: 44px; height: 44px; }

  /* Links in the header and footer bars are the only navigation on the prose
     pages, so they get the same floor as the buttons beside them. Excluding
     .btn matters: buttons already get their height from the rule above, and
     a bare `.nav a` here outranks `.nav-download { display: none }` further
     down, which would put the header CTA back on phones. */
  .nav a:not(.btn),
  .site-footer--page nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
  }

  .movelist summary {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Stops the browser waiting to see whether a tap is a double-tap-to-zoom,
     which otherwise puts ~300ms between touching a square and it selecting. */
  .sq,
  .btn,
  .opt,
  .clock-face,
  .nav-toggle,
  .mobile-nav a,
  .movelist summary { touch-action: manipulation; }

  .sq { -webkit-tap-highlight-color: transparent; }
}

/* ---------------------------------------------------------------------- */
/* Responsive — shared chrome                                             */
/* ---------------------------------------------------------------------- */

@media (max-width: 700px) {
  .nav-links,
  .nav-download { display: none; }

  .nav-toggle { display: inline-flex; }

  /* Keep the brand and the menu reachable however long the page runs. */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--color-bg);
  }

  .site-header .nav {
    padding: 10px 24px;
    flex-wrap: wrap;
    row-gap: 0;
  }

  .site-footer__row { gap: 16px; }
  .site-footer nav { gap: 4px 20px; }
  .site-footer nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    min-width: 44px;
  }
}

/* Notched phones in landscape put content under the rounded corners. */
@supports (padding: env(safe-area-inset-left)) {
  @media (max-width: 700px) {
    .wrap,
    .site-header .nav,
    .mobile-nav,
    .site-footer__colophon {
      padding-left: max(24px, env(safe-area-inset-left));
      padding-right: max(24px, env(safe-area-inset-right));
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-mark,
  .nav-toggle__bars,
  .nav-toggle__bars::before,
  .nav-toggle__bars::after {
    animation: none !important;
    transition: none !important;
  }
}
