/**
 * @ursamu/site — layout framing only.
 *
 * Structure mirrors court-template (shell / nav / banner / 3-col / footer)
 * with generic class names. Skins supply color, type, and decoration.
 */

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--site-bg);
  color: var(--site-text);
  font-family: var(--site-font-ui);
  font-size: var(--site-font-size);
  line-height: var(--site-line-height);
  -webkit-font-smoothing: antialiased;
}

/* ── Shell ───────────────────────────────────────────────────────── */

.site-shell {
  width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--site-bg);
  background-image: var(--site-bg-image-top), var(--site-bg-image-bottom);
  background-position: center top, bottom center;
  background-repeat: no-repeat, no-repeat;
  background-size: auto, auto;
}

.site-shell.is-plain {
  background-image: none, var(--site-bg-image-bottom);
}

/* ── Top nav ─────────────────────────────────────────────────────── */

.site-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--site-nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--site-max-w);
  margin: 0 auto;
  padding: 0 var(--site-gutter);
  box-sizing: border-box;
  background: transparent;
}

.site-nav::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--site-nav-h);
  z-index: -1;
  background: transparent;
  transition: background-color 0.45s ease;
}

.site-nav.is-scrolled::before {
  background: var(--site-bg);
}

.site-nav__brand {
  display: inline-flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  /* Text brands need room; images use .has-logo rules */
  max-width: min(28rem, 55vw);
  max-height: calc(var(--site-nav-h, 3.75rem) - 0.5rem);
  font-family: var(--site-font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--site-text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* Optional logo image (plugins.site.logoImage / theme logoImage) */
.site-nav__brand-logo,
.site-nav__brand img {
  display: block;
  height: auto;
  width: auto;
  max-height: calc(var(--site-nav-h, 3.75rem) - 0.75rem);
  max-width: min(14rem, 40vw);
  object-fit: contain;
  object-position: left center;
}

.site-nav__brand.has-logo {
  font-size: 0; /* image-only when logo is set */
  line-height: 0;
  max-width: min(16rem, 45vw);
}

.site-nav__list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--site-font-display);
  font-size: 1.125rem;
}

.site-nav__list a {
  color: var(--site-text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding-bottom: 0.15rem;
}

.site-nav__list a:hover {
  color: var(--site-text);
}

.site-nav__list a.is-active {
  color: var(--site-text);
  border-bottom-color: var(--site-accent);
}

/* Play unread: red/accent dot with count (since last check) */
.site-nav__list a.site-nav__play-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.site-nav__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--site-error, #c44);
  color: #fff;
  font-family: var(--site-font-ui, system-ui, sans-serif);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  vertical-align: middle;
}

.site-nav__list a.has-unread {
  color: var(--site-text);
}

/* Hamburger — hidden on desktop; shown ≤1024px */
.site-nav__toggle {
  display: none;
  flex: 0 0 auto;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius-sm, 4px);
  background: transparent;
  color: var(--site-text);
  cursor: pointer;
  z-index: 102;
}

.site-nav__toggle:hover,
.site-nav__toggle:focus-visible {
  border-color: var(--site-accent);
  outline: none;
}

.site-nav__toggle-bar {
  display: block;
  width: 1.15rem;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.site-nav.is-open .site-nav__toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.site-nav.is-open .site-nav__toggle-bar:nth-child(2) {
  opacity: 0;
}

.site-nav.is-open .site-nav__toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Banner ──────────────────────────────────────────────────────── */

.site-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-top: var(--site-banner-offset);
  padding: 0 var(--site-gutter);
  box-sizing: border-box;
}

.site-banner__title {
  margin: 0;
  width: 100%;
  text-align: center;
  font-family: var(--site-font-display);
  font-size: clamp(2.5rem, 8vw, 5.5rem);
  font-weight: 500;
  color: var(--site-text);
  line-height: 1.05;
}

.site-banner__img {
  display: block;
  max-width: min(100%, 720px);
  width: auto;
  height: auto;
  margin: 0 auto;
  box-sizing: border-box;
}

/* When JS wraps the banner img in .site-media, center the frame */
.site-banner > .site-media,
.site-banner .site-media--banner {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.site-banner .site-media > .site-banner__img,
.site-banner .site-media > img {
  margin: 0;
}

.site-banner__img:not([src]),
.site-banner__img[src=""] {
  display: none;
}

.site-banner__title:empty,
.site-banner__title[hidden] {
  display: none;
}

/* Telnet / connect host under hero title (not a right-rail menu) */
.site-banner__connect {
  display: block;
  margin: 0.85rem 0 0;
  padding: 0;
  text-align: center;
  font-family: var(--site-font-ui);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--site-text-muted);
  text-decoration: none;
  line-height: 1.3;
}

.site-banner__connect:hover {
  color: var(--site-accent-hover);
  text-decoration: underline;
}

.site-banner__connect:empty,
.site-banner__connect[hidden] {
  display: none;
}

/*
 * Compact hero (Figma no-banner): no banner image and no hero title.
 * Also used on login/profile (banner hidden by page mode).
 * Collapse the banner block; content starts just under fixed nav.
 */
.site-shell.is-compact,
.site-shell.is-mode-no-hero {
  --site-banner-offset: 0px;
  --site-sticky-top: calc(var(--site-nav-h) + 0.75rem);
  --site-body-pad-top: calc(var(--site-nav-h) + 1.5rem);
}

/* Login / profile — no side rails */
.site-shell.is-mode-login .site-aside,
.site-shell.is-mode-profile .site-aside {
  display: none !important;
}

/*
 * Login: leave the 3-col grid entirely. Otherwise .site-main stays
 * on grid-column: 2 and the gate looks off-center / too narrow.
 */
.site-shell.is-mode-login .site-body {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: none !important;
  margin: 0 auto 0;
  min-height: calc(100vh - var(--site-nav-h, 3.5rem));
  padding: calc(var(--site-nav-h, 3.5rem) + 1.25rem)
    var(--site-gutter, 1.25rem) 2.5rem;
  box-sizing: border-box;
  grid-template-columns: none !important;
  column-gap: 0;
  row-gap: 0;
}

.site-shell.is-mode-login .site-main {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  grid-column: auto !important;
  order: 0 !important;
  width: 100%;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  min-height: 0;
  flex: 1 1 auto;
}

.site-shell.is-mode-login .site-main > .site-gate,
.site-shell.is-mode-login .site-gate {
  width: 100%;
  max-width: 24rem;
  margin: 0 auto;
  min-height: 0;
  flex: 0 0 auto;
  display: block;
  padding: 0;
}

.site-shell.is-mode-profile .site-main {
  margin: 0 auto;
  max-width: 600px;
}

.site-shell.is-compact .site-banner,
.site-shell.is-mode-no-hero .site-banner {
  display: none;
  margin: 0;
  padding: 0;
  min-height: 0;
}

.site-shell.is-compact .site-body,
.site-shell.is-mode-no-hero .site-body {
  padding-top: var(
    --site-body-pad-top,
    calc(var(--site-nav-h) + 1.5rem)
  );
}

/* ── 3-column body (Figma Home wireframe 2054:137) ────────────────
 * docs/figma-wireframe-home.md — default shell, not Court brand.
 * @ 1728: gutter 42 | 314 | gap 21 | main 977 | gap ~17 | 312 | 42
 * Rails shrink on medium widths; stack ≤1024 (main → left → right).
 */

.site-body {
  width: 100%;
  max-width: var(--site-max-w);
  margin: 0 auto 3rem;
  padding: 4rem var(--site-gutter) 0;
  box-sizing: border-box;
  display: grid;
  grid-template-columns:
    minmax(var(--site-aside-min), var(--site-aside-width))
    minmax(0, var(--site-main-max))
    minmax(var(--site-aside-min), var(--site-aside-width));
  column-gap: var(--site-col-gap, 1.5rem);
  row-gap: 1.5rem;
  justify-content: center;
  align-items: start;
}

.site-aside {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--site-sticky-top);
  align-self: start;
  width: 100%;
  max-width: var(--site-aside-max);
  min-width: 0;
  min-height: 1px;
  box-sizing: border-box;
}

.site-aside--start {
  grid-column: 1;
}

.site-aside--end {
  grid-column: 3;
}

.site-main {
  display: flex;
  flex-direction: column;
  grid-column: 2;
  width: 100%;
  min-width: 0;
  max-width: var(--site-main-max);
  /* Center column owns its width; skin sets pad if needed */
  padding-inline: 0;
  box-sizing: border-box;
}

/* ── Footer ──────────────────────────────────────────────────────── */

.site-footer {
  margin-top: 3rem;
  padding: 1rem 0 2rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--site-text-muted);
}

.site-footer a {
  color: var(--site-accent);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--site-accent-hover);
  text-decoration: underline;
}

/* ── Responsive (prefer 3-col; shrink before stack) ──────────────── */

/* Large tablet / small desktop — still 3 columns */
@media (max-width: 1280px) {
  :root {
    --site-aside-width: 15.5rem;
    --site-aside-min: 12.5rem;
    --site-aside-max: 16.5rem;
    --site-main-pad-inline: 0.75rem;
    --site-col-gap: 1.25rem;
    --site-gutter: 1.5rem;
  }
}

/* Narrow desktop / wide tablet — still 3 columns, tighter rails */
@media (max-width: 1100px) {
  :root {
    --site-aside-width: 13rem;
    --site-aside-min: 10.5rem;
    --site-aside-max: 14rem;
    --site-col-gap: 0.85rem;
    --site-gutter: 1.15rem;
    --site-main-max: min(885px, 100%);
  }

  .site-body {
    /* keep left | main | right */
    grid-template-columns:
      minmax(var(--site-aside-min), var(--site-aside-width))
      minmax(0, 1fr)
      minmax(var(--site-aside-min), var(--site-aside-width));
    justify-content: stretch;
  }

  .site-aside {
    max-width: none;
  }

  .site-main {
    max-width: none;
  }
}

/* Tablet and below — stack main → left → right */
@media (max-width: 1024px) {
  :root {
    --site-gutter: 1.15rem;
    --site-banner-offset: 5.5rem;
    --site-nav-h: 3.25rem;
  }

  .site-body {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .site-aside,
  .site-main {
    grid-column: 1;
    max-width: none;
    position: static;
    padding-inline: 0;
  }

  /* Featured / search before main so wiki menu is not buried */
  .site-aside--start {
    order: 1;
  }

  .site-main {
    order: 2;
  }

  .site-aside--end {
    order: 3;
  }

  .site-nav {
    height: var(--site-nav-h);
    min-height: var(--site-nav-h);
    max-height: var(--site-nav-h);
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding-block: 0;
    align-items: center;
  }

  .site-nav::before {
    height: var(--site-nav-h);
    min-height: var(--site-nav-h);
  }

  .site-nav.is-open::before {
    background: var(--site-bg);
  }

  .site-nav__brand {
    flex: 1 1 auto;
    min-width: 0;
    /* Leave room for hamburger (~2.75rem) + gap */
    max-width: calc(100vw - 5.5rem);
    max-height: calc(var(--site-nav-h, 3.25rem) - 0.5rem);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(0.95rem, 3.6vw, 1.15rem);
  }

  /* Logo image shrinks on tablet/phone so hamburger fits */
  .site-nav__brand.has-logo,
  .site-nav__brand:has(img) {
    max-width: min(10rem, 55vw);
    flex: 0 1 auto;
  }

  .site-nav__brand-logo,
  .site-nav__brand img {
    max-height: 1.75rem; /* ~28px in 52px bar */
    max-width: min(10rem, 55vw);
  }

  .site-banner {
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
  }

  .site-banner__img {
    max-width: 100%;
    width: 100%;
    height: auto;
  }

  .site-nav__toggle {
    display: inline-flex;
    flex: 0 0 auto;
  }

  /* Slide-down panel under the fixed bar.
   * Use nearly full remaining viewport — old min(70vh, 28rem) forced
   * a short panel and pointless scroll for a handful of links. */
  .site-nav__list {
    position: fixed;
    top: var(--site-nav-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 101;
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    height: auto;
    max-height: calc(100vh - var(--site-nav-h, 3.25rem));
    max-height: calc(100dvh - var(--site-nav-h, 3.25rem));
    overflow-x: hidden;
    overflow-y: auto;
    margin: 0;
    padding: 0.75rem var(--site-gutter)
      max(1.5rem, env(safe-area-inset-bottom, 0px));
    gap: 0;
    font-size: 1.05rem;
    background: var(--site-bg);
    border-bottom: 1px solid var(--site-border-subtle, var(--site-border));
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
  }

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

  .site-nav__list > li {
    margin: 0;
    border-bottom: 1px solid var(--site-border-subtle, var(--site-border));
  }

  .site-nav__list > li:last-child {
    border-bottom: none;
  }

  .site-nav__list a,
  .site-nav__list .site-nav-login-link,
  .site-nav__list .site-nav-user-link {
    display: block;
    width: 100%;
    padding: 0.85rem 0.15rem;
    border-bottom: none;
  }

  .site-nav__list a.is-active {
    border-bottom: none;
    color: var(--site-accent);
  }

  /*
   * Account block in hamburger drawer — no nested dropdown.
   * Identity is a label row; Staff / Sign out are full-width taps.
   */
  .site-nav-account {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.35rem;
    padding: 0.25rem 0 0.5rem;
  }

  .site-nav-account-toggle {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-height: 3rem;
    padding: 0.65rem 0.25rem;
    border-bottom: none;
    pointer-events: none;
    cursor: default;
  }

  .site-nav-account.is-open .site-nav-account-toggle {
    border-bottom-color: transparent;
  }

  .site-nav-account-menu,
  .site-nav-account-menu[hidden] {
    display: flex !important;
    flex-direction: column;
    position: static;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    gap: 0.4rem;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  .site-nav-account-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-height: 3rem;
    margin: 0;
    padding: 0.85rem 0.9rem;
    font-size: 1.05rem;
    border: 1px solid var(--site-border-subtle, var(--site-border));
    border-radius: var(--site-radius-md, 6px);
    background: var(--site-bg-surface, rgba(255, 255, 255, 0.04));
    box-sizing: border-box;
  }

  .site-nav-account-item:hover,
  .site-nav-account-item:focus-visible {
    background: var(--site-accent-muted, rgba(196, 148, 74, 0.18));
  }

  .site-nav-account .site-nav-avatar,
  .site-nav-account .site-nav-avatar-initial {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.9rem;
    margin-right: 0;
  }

  .site-nav-account .site-nav-username {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.05rem;
  }

  .site-main {
    padding-inline: 0;
  }

  /* Dim page when menu open */
  body.site-nav-open {
    overflow: hidden;
  }

  body.site-nav-open .site-shell::after {
    content: "";
    position: fixed;
    inset: var(--site-nav-h) 0 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.55);
  }
}
