/* The Beach Way: Handbook Layout */

/* Overlay controls: fixed, outside grid flow */
.handbook-nav-toggle,
.handbook-sidebar-backdrop {
  position: fixed;
  z-index: 100;
}

.handbook-nav-toggle {
  display: none;
  top: 16px;
  left: 16px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--color-black);
  color: var(--color-white);
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.handbook-sidebar-backdrop {
  display: none;
  inset: 0;
  z-index: 90;
  background: rgba(26, 23, 20, 0.4);
}

.handbook-sidebar-backdrop.is-visible {
  display: block;
}

.handbook-layout {
  display: grid;
  grid-template-columns: minmax(240px, var(--sidebar-width)) minmax(0, 1fr);
  grid-template-areas: "sidebar main";
  min-height: 100vh;
}

.handbook-sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 32px 20px;
  border-right: 1px solid var(--color-sand);
  background: var(--color-white);
}

.handbook-sidebar__brand {
  display: block;
  margin-bottom: 8px;
  color: inherit;
}

.handbook-sidebar__logo {
  width: 96px;
  height: auto;
  margin-bottom: 10px;
}

.handbook-sidebar__title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-black);
}

.handbook-sidebar__brand:hover .handbook-sidebar__title {
  color: var(--color-ember);
}

.handbook-sidebar__tagline {
  display: block;
  margin-bottom: 32px;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--color-muted);
}

.handbook-main {
  grid-area: main;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.handbook-content {
  flex: 1;
  width: 100%;
  max-width: var(--container-handbook);
  margin: 0;
  padding: 48px clamp(24px, 4vw, 64px) 80px;
  box-sizing: border-box;
}

@media (min-width: 1200px) {
  .handbook-content {
    max-width: min(var(--container-handbook-wide), calc(100% - 48px));
  }
}

@media (min-width: 1500px) {
  .handbook-content {
    max-width: min(1040px, calc(100% - 64px));
  }
}

/* Chapter nav */
.chapter-nav__heading {
  display: block;
  margin-bottom: 16px;
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-muted-light);
}

.chapter-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-nav__item {
  margin-bottom: 2px;
}

.chapter-nav__link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.35;
  color: var(--color-muted);
  transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}

.chapter-nav__link:hover {
  background: var(--color-sand);
  color: var(--color-black);
}

.chapter-nav__num {
  flex-shrink: 0;
  min-width: 1.5em;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-muted-light);
}

.chapter-nav__item--section {
  margin-top: 12px;
  margin-bottom: 4px;
}

.chapter-nav__item--section + .chapter-nav__item--section {
  margin-top: 0;
}

.chapter-nav__section-link {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}

.chapter-nav__section-link:hover {
  background: var(--color-sand);
  color: var(--color-black);
}

.handbook-page--home .nav-active-home,
.handbook-page--philosophy .nav-active-philosophy,
.handbook-page--quest .nav-active-quest,
.handbook-page--expedition .nav-active-expedition,
.handbook-page--campfire .nav-active-campfire,
.handbook-page--activity .nav-active-activity,
.handbook-page--trail .nav-active-trail,
.handbook-page--landmark .nav-active-landmark,
.handbook-page--guide .nav-active-guide,
.handbook-page--smith .nav-active-smith,
.handbook-page--apprentice .nav-active-apprentice,
.handbook-page--gleo .nav-active-gleo {
  background: var(--color-sand);
  color: var(--color-black);
  font-weight: 500;
}

.handbook-page--concepts .nav-active-concepts,
.handbook-page--tools .nav-active-tools,
.handbook-page--forge .nav-active-forge,
.handbook-page--hammer .nav-active-hammer,
.handbook-page--anvil .nav-active-anvil,
.handbook-page--chisel .nav-active-chisel,
.handbook-page--canvas .nav-active-canvas,
.handbook-page--canvas-history .nav-active-canvas-history,
.handbook-page--loop .nav-active-loop,
.handbook-page--glossary .nav-active-glossary {
  background: var(--color-sand);
  color: var(--color-ember);
}

.handbook-page--forge .nav-active-forge,
.handbook-page--hammer .nav-active-hammer,
.handbook-page--anvil .nav-active-anvil,
.handbook-page--chisel .nav-active-chisel,
.handbook-page--canvas .nav-active-canvas,
.handbook-page--canvas-history .nav-active-canvas-history {
  background: var(--color-sand);
  color: var(--color-black);
  font-weight: 500;
}

.handbook-page--home .nav-active-home .chapter-nav__num,
.handbook-page--philosophy .nav-active-philosophy .chapter-nav__num,
.handbook-page--quest .nav-active-quest .chapter-nav__num,
.handbook-page--expedition .nav-active-expedition .chapter-nav__num,
.handbook-page--campfire .nav-active-campfire .chapter-nav__num,
.handbook-page--activity .nav-active-activity .chapter-nav__num,
.handbook-page--trail .nav-active-trail .chapter-nav__num,
.handbook-page--landmark .nav-active-landmark .chapter-nav__num,
.handbook-page--guide .nav-active-guide .chapter-nav__num,
.handbook-page--smith .nav-active-smith .chapter-nav__num,
.handbook-page--apprentice .nav-active-apprentice .chapter-nav__num,
.handbook-page--gleo .nav-active-gleo .chapter-nav__num {
  color: var(--color-ember);
}

/* Tool pages */
.tool-badge {
  display: inline-block;
  margin-left: 0.5em;
  padding: 0.15em 0.5em;
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
  border-radius: 3px;
}

.tool-badge--deprecated {
  background: var(--color-sand);
  color: var(--color-muted);
}

.tool-badge--history {
  background: var(--color-sand);
  color: var(--color-muted);
}

.tool-badge--new {
  background: var(--color-ember);
  color: var(--color-white);
}

.chapter-nav__link .tool-badge {
  margin-left: 0.35em;
  font-size: 0.5625rem;
}

.chapter-header .tool-badge {
  position: relative;
  top: -0.15em;
}

.chapter-header--deprecated .h1 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em;
}

.handbook-page--tool-deprecated .chapter-header {
  opacity: 0.92;
}

/* Chapter header */
.chapter-header {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--color-sand);
}

.chapter-header__num {
  display: block;
  margin-bottom: 12px;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted-light);
}

.chapter-header .label {
  display: block;
  margin-bottom: 12px;
}

.chapter-header .h1 {
  margin-bottom: 16px;
}

.chapter-header__lead {
  font-size: 1.1875rem;
  line-height: 1.55;
  color: var(--color-muted);
  max-width: 36em;
}

/* Section header (overview pages without chapter number) */
.section-header {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--color-sand);
}

.section-header .label {
  display: block;
  margin-bottom: 16px;
}

.section-header__title {
  margin-bottom: 24px;
}

.section-header__lead {
  font-size: 1.25rem;
  line-height: 1.55;
  color: var(--color-muted);
  max-width: 36em;
}

/* Home hero */
.home-hero {
  margin-bottom: 48px;
}

.home-hero .label {
  display: block;
  margin-bottom: 16px;
}

.home-hero .display {
  margin-bottom: 24px;
}

.home-hero__lead {
  font-size: 1.25rem;
  line-height: 1.55;
  color: var(--color-muted);
  max-width: 36em;
}

.home-hero-visual {
  display: grid;
  margin: 0 0 48px;
  max-width: var(--container-handbook-wide);
}

.home-illustration {
  grid-area: 1 / 1;
  margin: 0;
  width: 100%;
  padding-top: clamp(140px, 22%, 220px);
}

.home-illustration picture {
  display: block;
  width: 100%;
  max-width: var(--container-handbook-wide);
}

.home-illustration__image {
  width: 100%;
  max-width: var(--container-handbook-wide);
  height: auto;
  display: block;
}

@media (max-width: 720px) {
  .home-illustration {
    padding-top: clamp(120px, 32%, 180px);
  }
}

.chapter-illustration {
  margin: 32px 0 40px;
}

.chapter-illustration picture,
.loop-diagram picture {
  display: block;
  width: 100%;
  max-width: var(--container-handbook-wide);
}

.chapter-illustration__image {
  width: 100%;
  max-width: var(--container-handbook-wide);
  height: auto;
  display: block;
}

/* Prose */
.handbook-chapter .prose {
  font-size: 1.0625rem;
  line-height: 1.7;
}

.handbook-chapter .prose + .prose,
.handbook-chapter .prose-block + .prose-block {
  margin-top: 1.25em;
}

.prose-block {
  margin-bottom: 1.5em;
}

.prose-list {
  margin: 1em 0;
  padding-left: 1.25em;
}

.prose-list li {
  margin-bottom: 0.4em;
}

.section-heading {
  margin: 2.5em 0 1em;
}

.section-heading:first-child {
  margin-top: 0;
}

/* Chapter index (Atlas-style) */
.chapter-index {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--color-sand);
}

.chapter-index li {
  margin: 0;
  border-bottom: 1px solid var(--color-sand);
}

.chapter-index a {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 18px 4px;
  transition: padding-left 0.2s var(--ease-out);
}

.chapter-index a:hover {
  padding-left: 8px;
  color: var(--color-ember);
}

.chapter-index span {
  flex-shrink: 0;
  min-width: 2em;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted-light);
}

.chapter-index__title {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 500;
}

/* Gleo bridge */
.gleo-bridge {
  margin-top: 2.5em;
  padding-top: 1.5em;
  border-top: 1px solid var(--color-sand);
  font-size: 0.875rem;
  color: var(--color-muted);
}

.gleo-bridge strong {
  color: var(--color-ink);
  font-weight: 500;
}

/* Gleo concept mapping */
.gleo-mapping {
  margin: 24px 0 40px;
  border: 1px solid var(--color-sand);
  border-radius: var(--radius);
  overflow: hidden;
}

.gleo-mapping__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-sand);
}

.gleo-mapping__row:last-child {
  border-bottom: none;
}

.gleo-mapping__row:nth-child(even) {
  background: rgba(245, 241, 235, 0.45);
}

.gleo-mapping__beach {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-black);
}

.gleo-mapping__beach a {
  color: inherit;
  text-decoration: none;
}

.gleo-mapping__beach a:hover {
  color: var(--color-ember);
}

.gleo-mapping__gleo {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--color-muted);
}

@media (max-width: 640px) {
  .gleo-mapping__row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* Beach Loop */
.loop-diagram {
  position: relative;
  margin: 40px 0;
}

.loop-diagram__image {
  width: 100%;
  max-width: var(--container-handbook-wide);
  height: auto;
  display: block;
}

.loop-callouts {
  display: grid;
  gap: 16px;
  margin-top: 32px;
}

.loop-callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.loop-callout__link {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--color-brand);
}

.loop-callout__link:hover {
  color: var(--color-ember);
}

/* Glossary */
.glossary-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.glossary-item {
  padding: 24px 0;
  border-bottom: 1px solid var(--color-sand);
}

.glossary-item:first-child {
  padding-top: 0;
}

.glossary-item__term {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.glossary-item__def {
  color: var(--color-ink);
  margin-bottom: 8px;
}

.glossary-item__gleo {
  font-size: 0.875rem;
  color: var(--color-muted);
}

/* Footer */
.handbook-footer {
  width: 100%;
  margin-top: auto;
  padding: 32px clamp(24px, 4vw, 64px);
  border-top: 1px solid var(--color-sand);
  background: color-mix(in srgb, var(--color-sand) 40%, var(--color-white));
  box-sizing: border-box;
}

.handbook-footer__inner {
  max-width: var(--container-handbook);
  margin: 0;
}

.handbook-footer__brand {
  display: inline-block;
  margin-bottom: 20px;
}

.handbook-footer__logo {
  width: 88px;
  height: auto;
  opacity: 0.72;
  transition: opacity 0.15s var(--ease-out);
}

.handbook-footer__brand:hover .handbook-footer__logo {
  opacity: 1;
}

@media (min-width: 1200px) {
  .handbook-footer__inner {
    max-width: min(var(--container-handbook-wide), calc(100% - 48px));
  }
}

@media (min-width: 1500px) {
  .handbook-footer__inner {
    max-width: min(1040px, calc(100% - 64px));
  }
}

.handbook-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  margin-bottom: 16px;
}

.handbook-footer__link {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-muted);
}

.handbook-footer__link:hover {
  color: var(--color-ember);
}

.handbook-footer__copy {
  font-size: 0.8125rem;
  color: var(--color-muted-light);
}

/* Responsive */
@media (max-width: 900px) {
  .handbook-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }

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

  .handbook-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 95;
    width: min(320px, 85vw);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease-out);
    box-shadow: none;
  }

  .handbook-sidebar.is-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(26, 23, 20, 0.12);
  }

  .handbook-content {
    padding-top: 72px;
  }
}
