@import url("./tokens.css");

/* home_ui_v2 shell — editorial chapter layout with sticky index rail */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--paper);
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

img { max-width: 100%; height: auto; display: block; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 85% 0%, rgba(34, 163, 90, 0.08), transparent 60%),
    linear-gradient(180deg, #fbfdfc 0%, var(--paper) 100%);
}

/* App shell */
.shell {
  display: grid;
  grid-template-columns: 15rem 1fr;
  gap: 0;
  max-width: 1440px;
  margin: 0 auto;
  min-height: 100vh;
}

/* Sticky index rail */
.rail-nav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 2rem 1.5rem 2rem 2rem;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2rem;
  background: rgba(251, 253, 252, 0.6);
  backdrop-filter: blur(8px);
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.rail-brand .mark {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: 0.45rem;
  display: grid;
  place-items: center;
  background: var(--leaf-deep);
  color: #a7f3c8;
}

.rail-index {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: chapter;
}

.rail-index a {
  display: grid;
  grid-template-columns: 2rem 1fr;
  align-items: baseline;
  gap: 0.25rem;
  padding: 0.4rem 0;
  font-size: 0.86rem;
  color: var(--ink-soft);
  border-top: 1px solid transparent;
  transition: color 0.2s var(--ease);
}

.rail-index a::before {
  counter-increment: chapter;
  content: counter(chapter, decimal-leading-zero);
  font-family: var(--font-lcd);
  font-size: 0.68rem;
  color: var(--line-strong);
  letter-spacing: 0.05em;
}

.rail-index a:hover,
.rail-index a.is-active {
  color: var(--leaf-deep);
}

.rail-index a.is-active::before { color: var(--leaf); }

.rail-index a.is-active span {
  font-weight: 600;
  border-bottom: 1.5px solid var(--leaf);
  padding-bottom: 1px;
}

.rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.rail-foot a:hover { color: var(--leaf-deep); }

/* Mobile top bar */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(251, 253, 252, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar .rail-brand { font-size: 0.92rem; }

.topbar-toggle {
  width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 0.45rem;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.topbar-toggle span {
  display: block;
  width: 1.05rem;
  height: 1.5px;
  background: currentColor;
  position: relative;
}

.topbar-toggle span::before,
.topbar-toggle span::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  background: currentColor;
}

.topbar-toggle span::before { top: -5px; }
.topbar-toggle span::after { top: 5px; }

/* Content column */
.content {
  min-width: 0;
  padding: 0 0 4rem;
}

.measure {
  width: min(62rem, calc(100% - 4rem));
  margin: 0 auto;
}

/* Type */
.display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.02;
  margin: 0;
}

.lede {
  color: var(--ink-soft);
  font-size: 1.06rem;
  margin: 0;
}

.overline {
  display: block;
  font-family: var(--font-lcd);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--leaf);
  margin-bottom: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.72rem 1.3rem;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.btn-solid {
  background: var(--ink);
  color: #fff;
}

.btn-solid:hover { background: var(--leaf-deep); }

.btn-ghost {
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-ghost:hover {
  border-color: var(--ink);
}

.btn-text {
  padding: 0;
  border-radius: 0;
  border-bottom: 1.5px solid var(--leaf);
  color: var(--leaf-deep);
}

.btn-text:hover { border-color: var(--ink); color: var(--ink); }

/* Live dock */
.dock {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  background: rgba(18, 32, 24, 0.94);
  color: #eaf5ef;
  box-shadow: 0 14px 34px rgba(18, 32, 24, 0.22);
  font-family: var(--font-lcd);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.dock-live {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #7ef0ad;
}

.dock-live i {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: #7ef0ad;
  animation: dockPulse 1.8s ease-in-out infinite;
}

@keyframes dockPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.dock em {
  font-style: normal;
  color: rgba(234, 245, 239, 0.55);
  margin-right: 0.3rem;
}

.dock-item + .dock-item::before {
  content: "";
  display: inline-block;
  width: 1px;
  height: 0.8rem;
  margin-right: 1rem;
  background: rgba(234, 245, 239, 0.2);
  vertical-align: middle;
}

/* Reveal */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}

.reveal.in { opacity: 1; transform: none; }

/* Footer */
.site-foot {
  border-top: 1px solid var(--line);
  margin-top: 3rem;
  padding-top: 2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.site-foot strong { color: var(--ink); }

.site-foot nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
}

.site-foot a:hover { color: var(--leaf-deep); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }

  .topbar { display: flex; }

  .rail-nav {
    position: fixed;
    inset: 0 0 auto 0;
    height: auto;
    max-height: 100vh;
    overflow-y: auto;
    z-index: 45;
    padding: 4.5rem 1.5rem 1.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(251, 253, 252, 0.98);
    transform: translateY(-104%);
    transition: transform 0.35s var(--ease);
  }

  .rail-nav .rail-brand { display: none; }

  body.rail-open .rail-nav { transform: none; }
  body.rail-open { overflow: hidden; }

  .measure { width: calc(100% - 2.5rem); }

  .dock {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.7rem;
  }

  .dock-item + .dock-item::before { margin-right: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .dock-live i { animation: none; }
}
