/* ============================================================
   Maya — A Systems Reader
   Brand: void-black surfaces, Maya red, Inter / IBM Plex Mono /
   Source Serif 4. One window scroller; sticky rail on desktop,
   off-canvas drawer on handhelds.
   ============================================================ */

:root {
  --void:    #0c0b0a;
  --surface: #121110;
  --matter:  #181715;
  --matter-2:#21201e;
  --accent:  #c4716a;
  --accent-bright: #d4837c;
  --accent-glow: rgba(196, 113, 106, 0.16);
  --accent-fill: #a85f58;
  --accent-fill-hover: #9a564f;
  --accent-ring: rgba(196, 113, 106, 0.14);
  --ink:   #e4e2de;
  --ink-2: #9c9892;
  --ink-3: #73706b;
  --read:  #cac6c1;
  --line:   #2a2826;
  --line-2: #3d3a37;
  --ui:   'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --serif:'Source Serif 4', Georgia, serif;
  --rail: 340px;
  --ease: cubic-bezier(.22, .68, 0, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  background: var(--void);
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 56px);
  scroll-padding-bottom: env(safe-area-inset-bottom, 0px);
}
body {
  background: var(--void);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
body.drawer-open,
body.intro-open { overflow: hidden; }
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
::selection { background: var(--accent); color: #fff; }

/* ============================================================
   Reading progress
   ============================================================ */
.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 60;
  background: transparent;
  pointer-events: none;
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}

/* ============================================================
   Shell
   ============================================================ */
.app { display: flex; align-items: flex-start; }

/* ---- vertical rail / navigation ---------------------------- */
.nav {
  flex: 0 0 var(--rail);
  width: var(--rail);
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 40;
}

.nav-head {
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; gap: 9px; }
.brand img {
  height: 26px;
  width: auto;
  max-width: 100%;
  aspect-ratio: 188 / 43;
  object-fit: contain;
}
.brand .brand-tag {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding-left: 2px;
}

/* ---- controls ---------------------------------------------- */
.nav-controls {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.seg {
  display: flex;
  gap: 3px;
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
}
.seg-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 4px;
  cursor: pointer;
  transition: color 0.18s, background 0.2s;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active {
  background: var(--accent-fill);
  color: #fff;
}
.search { position: relative; }
.search input {
  width: 100%;
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  font-family: var(--ui);
  font-size: 1rem;
  padding: 10px 12px 10px 34px;
  outline: none;
  transition: border-color 0.2s;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { border-color: var(--accent); }
.search::before {
  content: "";
  position: absolute;
  left: 13px; top: 50%;
  width: 11px; height: 11px;
  margin-top: -7px;
  border: 1.6px solid var(--ink-3);
  border-radius: 50%;
  box-shadow: 7px 7px 0 -5px var(--ink-3);
  pointer-events: none;
}

/* ---- the list ---------------------------------------------- */
.nav-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.nav-list::-webkit-scrollbar { width: 8px; }
.nav-list::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 8px;
  border: 2px solid var(--surface);
}

.nav-part {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  padding: 18px 20px 8px;
  transition: color 0.18s;
}
.nav-part .np-num {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  flex: none;
}
.nav-part .np-title {
  font-family: var(--ui);
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  line-height: 1.4;
  transition: color 0.18s;
}
.nav-part:hover .np-title { color: var(--ink); }
.nav-part.is-current .np-title { color: var(--accent-bright); }

.nav-sec {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  text-align: left;
  cursor: pointer;
  padding: 9px 18px 9px 22px;
  color: var(--ink-2);
  font-family: var(--ui);
  font-size: 0.875rem;
  line-height: 1.42;
  transition: color 0.16s, background 0.16s, border-color 0.16s;
}
.nav-sec:hover { color: var(--ink); background: rgba(255, 255, 255, 0.03); }
.nav-sec.is-current {
  color: var(--accent-bright);
  background: rgba(196, 113, 106, 0.08);
  border-left-color: var(--accent);
}
.nav-sec .ns-tag {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 4px;
}
.nav-sec.is-current .ns-tag { color: var(--accent); }
.nav-empty {
  padding: 26px 22px;
  color: var(--ink-3);
  font-size: 1rem;
  line-height: 1.5;
}

.nav-foot {
  border-top: 1px solid var(--line);
  padding: 13px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}
.logout {
  color: var(--ink-3);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  transition: color 0.18s;
}
.logout:hover { color: var(--accent); }

/* ============================================================
   Reading surface
   ============================================================ */
.reader { flex: 1 1 0; min-width: 0; }
.reader-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(44px, 6vw, 104px) clamp(24px, 6vw, 104px) 24px;
}

.loader {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.loader span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
}

.view { max-width: 39rem; margin: 0 auto; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 0.8125rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 20px;
}
.eyebrow::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line-2), transparent);
}

.section-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2rem, 1.4rem + 2.6vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -0.012em;
  color: var(--ink);
}
.section-title .tail {
  color: var(--ink-2);
  font-weight: 400;
  font-style: italic;
}

.part-subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.15rem, 1rem + 0.7vw, 1.5rem);
  line-height: 1.36;
  color: var(--accent-bright);
  margin-top: 10px;
}

/* ---- epigraph ---------------------------------------------- */
.epigraph {
  margin: 26px 0 28px;
  padding: 2px 0 2px 20px;
  border-left: 2px solid var(--accent);
}
.epigraph p {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.1rem, 1rem + 0.4vw, 1.28rem);
  line-height: 1.55;
  color: var(--ink);
}
.epigraph p + p { margin-top: 0.5em; }
.epigraph cite {
  display: block;
  margin-top: 10px;
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---- prose ------------------------------------------------- */
.body { margin-top: 8px; }
.body p {
  font-family: var(--serif);
  font-size: clamp(1.06rem, 1rem + 0.34vw, 1.2rem);
  line-height: 1.74;
  color: var(--read);
  margin-bottom: 1.25em;
}
.body p:last-child { margin-bottom: 0; }
.body em { color: var(--ink); font-style: italic; }
.body strong { color: var(--ink); font-weight: 600; }

.body.has-drop > p:first-of-type::first-letter {
  font-family: var(--serif);
  font-weight: 600;
  float: left;
  font-size: 3.7em;
  line-height: 0.82;
  margin: 0.02em 0.12em 0 0;
  color: var(--accent);
}

.body h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.3rem, 1.15rem + 0.7vw, 1.62rem);
  color: var(--ink);
  line-height: 1.25;
  margin: 1.8em 0 0.5em;
}
.body h2 strong { color: var(--ink); }
.body blockquote {
  margin: 1.4em 0;
  padding-left: 18px;
  border-left: 2px solid var(--line-2);
  font-style: italic;
  color: var(--ink-2);
}
.body hr { border: none; height: 1px; background: var(--line); margin: 2em 0; }

/* ---- part overview ----------------------------------------- */
.part-lead {
  font-family: var(--serif);
  font-size: clamp(1.12rem, 1rem + 0.5vw, 1.32rem);
  line-height: 1.62;
  color: var(--read);
  margin-top: 4px;
}
.part-lead p { margin-bottom: 0.7em; }
.part-lead p:last-child { margin-bottom: 0; }
.part-lead em { color: var(--ink); }

.sec-grid { margin-top: 34px; display: flex; flex-direction: column; gap: 10px; }
.sec-grid-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.sec-card {
  display: flex;
  align-items: baseline;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: var(--matter);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.sec-card:hover {
  border-color: var(--accent);
  background: var(--matter-2);
}
.sec-card .sc-num {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
  flex: none;
  min-width: 1.6em;
}
.sec-card .sc-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.1rem;
  line-height: 1.3;
  color: var(--ink);
}

/* ---- footer step nav --------------------------------------- */
.reader-foot {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px clamp(24px, 6vw, 104px) calc(40px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
}
.step {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--matter);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 16px;
  cursor: pointer;
  color: var(--ink-2);
  font-family: var(--ui);
  text-align: left;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}
.step-next { justify-content: flex-end; text-align: right; }
.step-body { flex: 1 1 auto; min-width: 0; }
.step:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--matter-2);
}
.step:disabled { opacity: 0.32; cursor: default; }
.step .arrow {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--accent);
  flex: none;
}
.step .step-k {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 3px;
}
.step .step-txt {
  font-size: 1rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.to-top {
  flex: none;
  width: 50px;
  background: var(--matter);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}
.to-top:hover { border-color: var(--accent); background: var(--matter-2); }

/* ============================================================
   Mobile drawer
   ============================================================ */
.menu-toggle {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 70;
  width: 44px; height: 44px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
}
.menu-toggle span {
  width: 18px; height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.58);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ============================================================
   Cinematic entry
   ============================================================ */
.intro {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--void);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.intro-skip {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: 18px;
  z-index: 2;
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 8px 14px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.intro-skip:hover { color: var(--accent); border-color: var(--accent); }

.intro-stage {
  position: relative;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 84px 26px 64px;
  gap: 26px;
}
.intro-root {
  width: 2px;
  height: 0;
  background: var(--accent);
  flex: none;
}

.intro-lines {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 620px;
}
.intro-line {
  font-family: var(--serif);
  font-size: clamp(1.15rem, 0.95rem + 1.4vw, 1.85rem);
  line-height: 1.4;
  color: var(--ink);
  opacity: 0;
}

.intro-title { opacity: 0; }
.intro-title img {
  width: min(440px, 78vw);
  height: auto;
  margin: 0 auto;
  aspect-ratio: 2048 / 511;
  object-fit: contain;
}
.intro-title .intro-tag {
  font-family: var(--mono);
  font-size: clamp(0.75rem, 0.72rem + 0.2vw, 0.875rem);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 22px;
}
.intro-sub {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1rem, 0.9rem + 0.4vw, 1.2rem);
  color: var(--accent-bright);
  margin-top: 14px;
  opacity: 0;
}

.intro-begin {
  background: var(--accent-fill);
  border: 1px solid var(--accent-fill);
  border-radius: 10px;
  color: #fff;
  font-family: var(--ui);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.04em;
  padding: 14px 34px;
  cursor: pointer;
  opacity: 0;
  flex: none;
  transition: background 0.2s;
}
.intro-begin:hover { background: var(--accent-fill-hover); }
.intro-begin:active { transform: scale(0.98); }

body.loading .reader-foot { display: none; }

/* ============================================================
   Responsive
   ============================================================ */

/* tablet & below — rail becomes a drawer, document scrolls */
@media (max-width: 1024px) {
  .menu-toggle { display: flex; }
  .nav {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    height: 100dvh;
    width: min(330px, 88vw);
    flex-basis: auto;
    box-shadow: 1px 0 0 var(--line);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }
  .reader { width: 100%; }
  .reader-inner {
    padding-top: max(3.5rem, calc(12px + 44px + env(safe-area-inset-top)));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* phones */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .reader-inner { padding-left: 20px; padding-right: 20px; }
  .body.has-drop > p:first-of-type::first-letter {
    font-size: 3.1em;
    margin-top: 0.04em;
  }
  .epigraph { padding-left: 15px; margin: 22px 0 24px; }
  .reader-foot {
    flex-wrap: wrap;
    padding-left: 20px; padding-right: 20px;
  }
  .to-top { order: 3; width: 100%; height: 44px; }
  .sec-card { padding: 14px 15px; gap: 13px; }
  .intro-stage { padding: 76px 20px 52px; gap: 22px; }
}

@media (max-width: 360px) {
  .brand img { height: 22px; }
}

/* large / studio displays */
@media (min-width: 1680px) {
  :root { --rail: 384px; }
  .view { max-width: 41rem; }
}
@media (min-width: 2200px) {
  body { font-size: 19px; }
  .view { max-width: 44rem; }
  .reader-inner { padding-top: 120px; }
}

/* portrait monitors — wider gutters keep the column literary */
@media (orientation: portrait) and (min-width: 1025px) {
  .reader-inner {
    padding-left: clamp(48px, 9vw, 160px);
    padding-right: clamp(48px, 9vw, 160px);
  }
}

/* short landscape (handhelds turned sideways) */
@media (max-height: 460px) and (orientation: landscape) {
  .intro-stage { min-height: auto; padding-top: 70px; gap: 16px; }
}

@media (hover: none) {
  .sec-card:hover { border-color: var(--line); background: var(--matter); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ============================================================
   Gate page (passcode)
   ============================================================ */
body.gate-page {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}

.gate {
  position: relative;
  width: min(420px, 100%);
  text-align: center;
}
.gate .wordmark {
  width: min(280px, 76vw);
  height: auto;
  margin: 0 auto 18px;
  aspect-ratio: 188 / 43;
  object-fit: contain;
}
.gate .tagline {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.gate .rule {
  width: 100%; height: 1px;
  margin: 30px 0 26px;
  background: linear-gradient(90deg, transparent, var(--line-2), transparent);
}
.gate .prompt {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin-bottom: 14px;
}
.gate input {
  width: 100%;
  background: var(--matter);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.25rem;
  text-align: center;
  padding: 15px 14px;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.gate input::placeholder { color: var(--ink-3); }
.gate input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.gate button[type="submit"] {
  width: 100%;
  margin-top: 14px;
  background: var(--accent-fill);
  border: 1px solid var(--accent-fill);
  color: #fff;
  font-family: var(--ui);
  font-weight: 600;
  font-size: 1rem;
  padding: 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.22s, box-shadow 0.22s, transform 0.12s;
}
.gate button[type="submit"]:hover { background: var(--accent-fill-hover); }
.gate button[type="submit"]:active { transform: scale(0.985); }
.gate button[type="submit"]:disabled { opacity: 0.6; cursor: default; }
.gate .msg {
  min-height: 1.3em;
  margin-top: 16px;
  font-family: var(--ui);
  font-size: 0.9375rem;
  color: var(--ink-2);
  opacity: 0;
  transition: opacity 0.3s;
}
.gate .msg.show { opacity: 1; }
.gate.is-invalid input { border-color: var(--accent); }
body.gate-page.dissolving { opacity: 0; transition: opacity 0.4s ease; }
