/* ============================================================
   THE TRANSFORMATION OPERATOR'S MANUAL — v2.0
   Aesthetic: editorial / technical field-manual / Swiss-modern
   ============================================================ */

/* ---------- 1. DESIGN TOKENS ---------- */
:root {
  /* Color — warm paper, deep ink, single sharp accent */
  --paper:       #f2ede1;
  --paper-warm:  #ede6d5;
  --paper-deep:  #e4dcc6;
  --paper-card:  #fbf8f0;
  --ink:         #0f1a2b;
  --ink-soft:    #2a3548;
  --ink-mute:    #5a647a;
  --ink-faint:   #8a93a3;
  --rule:        #c9bfa5;
  --rule-soft:   #ddd4bc;
  --rule-faint:  #e8e1cb;
  --accent:      #b84720;
  --accent-deep: #8c3518;
  --accent-soft: #e7aa8f;
  --accent-tint: rgba(184, 71, 32, 0.08);
  --sage:        #5a6b51;
  --sage-tint:   rgba(90, 107, 81, 0.10);
  --amber:       #b88515;
  --amber-tint:  rgba(184, 133, 21, 0.10);
  --success:     #3f6b4a;

  /* Type */
  --font-display: "Instrument Serif", "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --font-body:    "Literata", "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-mono:    "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;

  /* Layout */
  --wrap-max:   1280px;
  --side-w:     260px;
  --measure:    70ch;

  /* Shadows */
  --shadow-card:    0 1px 0 rgba(15,26,43,0.04), 0 1px 3px rgba(15,26,43,0.06);
  --shadow-hover:   0 2px 0 rgba(15,26,43,0.05), 0 6px 18px rgba(15,26,43,0.10);

  /* Transitions */
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---------- 2. RESET + BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 24px; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern", "liga", "onum";
}

@media (min-width: 1100px) { body { font-size: 18px; } }

img, svg { max-width: 100%; display: block; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-soft);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.18s var(--ease), text-decoration-color 0.18s var(--ease);
}
a:hover { color: var(--accent-deep); text-decoration-color: var(--accent); }

::selection { background: var(--accent); color: var(--paper); }

.wrap { max-width: var(--wrap-max); margin: 0 auto; padding: 0 clamp(16px, 3vw, 40px); }

.skip-link {
  position: absolute; top: -48px; left: 16px;
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; font-family: var(--font-mono);
  font-size: 12px; text-decoration: none;
  z-index: 1000; transition: top 0.2s;
}
.skip-link:focus { top: 12px; color: var(--paper); }

/* ---------- 3. SITE HEADER ---------- */
.site-header {
  background: var(--paper-warm);
  border-bottom: 1px solid var(--rule);
  padding: 28px 0 26px;
  position: relative;
}
.site-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 1px; background: linear-gradient(90deg, transparent, var(--accent-soft) 20%, var(--accent-soft) 80%, transparent);
  opacity: 0.6;
}

.header-wrap {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: clamp(24px, 4vw, 56px); flex-wrap: wrap;
}

.brand { display: flex; align-items: flex-start; gap: 20px; }

.brand-mark {
  font-family: var(--font-display); font-style: italic;
  font-size: 64px; line-height: 0.8; color: var(--accent);
  padding-top: 4px; flex-shrink: 0;
}

.brand-sup {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-mute); margin: 0 0 6px;
}

.brand-title {
  font-family: var(--font-display); font-weight: 400; font-size: clamp(30px, 4.5vw, 46px);
  line-height: 1.05; margin: 0 0 10px; color: var(--ink); letter-spacing: -0.01em;
}
.brand-title em { font-style: italic; color: var(--accent); }

.brand-sub {
  font-size: 14.5px; color: var(--ink-soft); max-width: 44ch; margin: 0;
  font-family: var(--font-body);
}

.header-aside {
  display: flex; flex-direction: column; align-items: flex-end; gap: 14px;
  min-width: 260px;
}

/* progress chip */
.progress-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--paper); border: 1px solid var(--rule);
  padding: 8px 14px; border-radius: 2px;
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.progress-label { color: var(--ink-mute); }
.progress-bar {
  width: 120px; height: 6px; background: var(--paper-deep);
  border: 1px solid var(--rule-soft); border-radius: 1px; overflow: hidden;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.4s var(--ease); }
.progress-val { color: var(--ink); font-weight: 500; min-width: 3ch; text-align: right; }

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn-ghost {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.1em;
  text-transform: uppercase; background: transparent; color: var(--ink-soft);
  border: 1px solid var(--rule); padding: 7px 12px; cursor: pointer;
  border-radius: 2px; transition: all 0.15s var(--ease);
}
.btn-ghost:hover { background: var(--paper); border-color: var(--ink-mute); color: var(--ink); }
.btn-danger { border-color: var(--accent-soft); color: var(--accent); }
.btn-danger:hover { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-deep); }

/* ---------- 4. LAYOUT GRID ---------- */
.main-grid {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  gap: clamp(24px, 4vw, 56px);
  padding: 36px 0 80px;
  align-items: start;
}
@media (max-width: 900px) { .main-grid { grid-template-columns: 1fr; } }

/* ---------- 5. SIDEBAR ---------- */
.sidebar {
  position: sticky; top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding-right: 10px;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 2px; }
@media (max-width: 900px) {
  .sidebar { position: static; max-height: none; overflow-y: visible; padding-right: 0; }
}

.side-nav { display: flex; flex-direction: column; gap: 2px; padding-bottom: 18px; }

.nav-heading {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-mute);
  padding: 0 0 10px; border-bottom: 1px solid var(--rule-soft); margin-bottom: 8px;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 2px;
  font-family: var(--font-body); font-size: 14.5px; color: var(--ink-soft);
  text-decoration: none; border-left: 2px solid transparent;
  transition: all 0.15s var(--ease);
}
.nav-link:hover { background: var(--paper-warm); color: var(--ink); }
.nav-link.active {
  background: var(--accent-tint); color: var(--accent-deep);
  border-left-color: var(--accent);
}
.nav-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--rule); flex-shrink: 0; transition: background 0.15s;
}
.nav-link:hover .nav-dot { background: var(--ink-mute); }
.nav-link.active .nav-dot { background: var(--accent); }

.side-note {
  margin-top: 24px; padding: 14px 16px;
  background: var(--sage-tint); border-left: 2px solid var(--sage);
  border-radius: 2px;
}
.side-note-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--sage); margin-bottom: 6px; font-weight: 600;
}
.side-note p { margin: 0; font-size: 13px; color: var(--ink-soft); line-height: 1.55; }

/* ---------- 6. MAIN CONTENT ---------- */
.main-content { min-width: 0; }

.preface {
  background: var(--paper-card); border: 1px solid var(--rule-soft);
  padding: clamp(24px, 3.5vw, 40px); margin-bottom: 48px;
  border-radius: 2px; position: relative;
}
.preface::before {
  content: ""; position: absolute; top: 0; left: 0; width: 3px; height: 100%;
  background: var(--accent);
}
.preface-eyebrow {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 12px; font-weight: 500;
}
.preface-title {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(26px, 3.5vw, 36px); line-height: 1.15; margin: 0 0 18px;
  color: var(--ink); letter-spacing: -0.005em;
}
.preface p { max-width: 72ch; margin: 0 0 14px; color: var(--ink-soft); }
.preface p:last-child { margin-bottom: 0; }
.preface-tip {
  margin-top: 20px !important; padding: 14px 16px;
  background: var(--paper-warm); border-left: 2px solid var(--ink-mute);
  font-size: 15px; color: var(--ink-soft);
}

/* ---------- 7. LEVEL SECTIONS ---------- */
.level-section {
  margin: 0 0 72px;
  scroll-margin-top: 20px;
}

.section-head { margin-bottom: 32px; }

.section-meta {
  display: flex; align-items: center; gap: 14px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-mute); margin-bottom: 14px;
}
.section-num { color: var(--accent); font-weight: 600; }
.section-label { color: var(--ink-soft); }

.section-title {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(28px, 4vw, 44px); line-height: 1.1; letter-spacing: -0.01em;
  margin: 0 0 20px; color: var(--ink); padding-bottom: 20px;
  border-bottom: 1px solid var(--rule);
  position: relative;
}
.section-title::after {
  content: ""; position: absolute; left: 0; bottom: -1px;
  width: 60px; height: 2px; background: var(--accent);
}

.section-intro { margin-top: 18px; max-width: var(--measure); }
.section-intro blockquote {
  margin: 0; padding: 16px 20px;
  background: var(--amber-tint); border-left: 3px solid var(--amber);
  border-radius: 2px;
}
.section-intro blockquote p {
  margin: 0; font-size: 15.5px; color: var(--ink-soft); line-height: 1.6;
}
.section-intro hr { display: none; }

/* ---------- 8. MODULES ---------- */
.modules { display: flex; flex-direction: column; gap: 12px; }

.module {
  background: var(--paper-card); border: 1px solid var(--rule-soft);
  border-radius: 2px; overflow: hidden;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
  scroll-margin-top: 20px;
}
.module:hover { border-color: var(--rule); }
.module.open { border-color: var(--rule); box-shadow: var(--shadow-card); }

.module-head {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 22px; cursor: pointer;
  user-select: none; background: transparent;
  transition: background 0.15s var(--ease);
}
.module-head:hover { background: var(--paper-warm); }
.module-head:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}
.module.open > .module-head {
  background: var(--paper-warm);
  border-bottom: 1px solid var(--rule-soft);
}

.module-title {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(18px, 2vw, 22px); line-height: 1.25;
  color: var(--ink); margin: 0; flex: 1;
  letter-spacing: -0.005em;
}

.module-chev {
  font-family: var(--font-body); font-size: 22px; color: var(--ink-mute);
  transition: transform 0.25s var(--ease), color 0.15s;
  flex-shrink: 0;
}
.module.open .module-chev { transform: rotate(90deg); color: var(--accent); }

.module-body {
  display: none;
  padding: 24px clamp(20px, 3vw, 36px) 28px;
  max-width: var(--measure);
}
.module.open .module-body { display: block; animation: slideDown 0.25s var(--ease); }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 9. MODULE-BODY TYPOGRAPHY ---------- */
.module-body h3 {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--accent);
  margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px dotted var(--rule-soft);
  font-weight: 600;
}
.module-body h3:first-child { margin-top: 0; }

.module-body h4 {
  font-family: var(--font-display); font-weight: 400; font-style: italic;
  font-size: 19px; margin: 20px 0 8px; color: var(--ink);
}

.module-body p { margin: 0 0 12px; color: var(--ink-soft); }
.module-body p strong { color: var(--ink); font-weight: 600; }
.module-body p em { color: var(--ink); }

.module-body ul, .module-body ol {
  margin: 0 0 16px; padding-left: 22px; color: var(--ink-soft);
}
.module-body li { margin-bottom: 6px; }
.module-body li > strong { color: var(--ink); }

.module-body ul { list-style: none; padding-left: 0; }
.module-body ul > li {
  position: relative; padding-left: 20px;
}
.module-body ul > li::before {
  content: "—"; position: absolute; left: 0; top: 0;
  color: var(--accent); font-weight: 600;
}

.module-body ol { padding-left: 26px; }
.module-body ol > li::marker {
  font-family: var(--font-mono); color: var(--accent); font-weight: 600;
}

.module-body blockquote {
  margin: 16px 0; padding: 12px 18px;
  background: var(--paper-warm); border-left: 3px solid var(--ink-mute);
  border-radius: 2px; color: var(--ink-soft);
}
.module-body blockquote p { margin-bottom: 8px; }
.module-body blockquote p:last-child { margin-bottom: 0; }

.module-body code {
  font-family: var(--font-mono); font-size: 0.88em;
  background: var(--paper-warm); padding: 2px 6px;
  border: 1px solid var(--rule-soft); border-radius: 2px;
  color: var(--ink);
}

.module-body pre {
  background: var(--ink); color: #e8e3d5;
  padding: 16px 18px; overflow-x: auto; border-radius: 2px;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.55;
  margin: 16px 0;
}
.module-body pre code {
  background: transparent; border: none; color: inherit; padding: 0;
}

.module-body table {
  width: 100%; border-collapse: collapse; margin: 16px 0;
  font-size: 14.5px; border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.module-body th, .module-body td {
  padding: 10px 14px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--rule-soft);
}
.module-body th {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-mute); font-weight: 600;
  background: var(--paper-warm);
}
.module-body tr:last-child td { border-bottom: none; }

.module-body hr {
  border: none; height: 1px; background: var(--rule-soft);
  margin: 24px 0;
}

.module-body details {
  margin: 12px 0; padding: 10px 14px;
  background: var(--paper-warm); border: 1px solid var(--rule-soft);
  border-radius: 2px;
}
.module-body details summary {
  cursor: pointer; font-family: var(--font-mono);
  font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}
.module-body details[open] summary { margin-bottom: 10px; }
.module-body details > *:not(summary) { color: var(--ink-soft); }

/* Form elements inside modules */
.module-body input[type="checkbox"] {
  appearance: none; width: 16px; height: 16px;
  border: 1.5px solid var(--rule); background: var(--paper);
  border-radius: 2px; cursor: pointer; position: relative;
  vertical-align: -3px; margin-right: 10px; flex-shrink: 0;
  transition: all 0.15s var(--ease);
}
.module-body input[type="checkbox"]:hover { border-color: var(--ink-mute); }
.module-body input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
}
.module-body input[type="checkbox"]:checked::after {
  content: "✓"; position: absolute; top: -2px; left: 2px;
  color: var(--paper); font-size: 13px; font-weight: 700;
}

/* Self-assessment checklists */
.module-body ul.check-list {
  list-style: none; padding-left: 0; margin: 8px 0 16px;
}
.module-body ul.check-list > li.check-item {
  padding-left: 0; margin-bottom: 6px;
}
.module-body ul.check-list > li.check-item::before { content: none; }
.module-body label.checkable {
  display: flex; align-items: flex-start; gap: 4px;
  padding: 8px 12px; border: 1px solid var(--rule-soft);
  background: var(--paper); border-radius: 2px;
  cursor: pointer; transition: all 0.15s var(--ease);
}
.module-body label.checkable:hover {
  border-color: var(--ink-mute); background: var(--paper-warm);
}
.module-body label.checkable input[type="checkbox"] {
  margin-top: 3px;
}
.module-body label.checkable .check-text {
  flex: 1; color: var(--ink-soft); line-height: 1.5;
}
.module-body label.checkable:has(input:checked) {
  background: var(--accent-tint); border-color: var(--accent-soft);
}
.module-body label.checkable:has(input:checked) .check-text {
  color: var(--ink);
}

.module-body textarea {
  width: 100%; min-height: 90px; padding: 10px 12px;
  font-family: var(--font-body); font-size: 14.5px; line-height: 1.55;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: 2px;
  resize: vertical; transition: border-color 0.15s;
}
.module-body textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

/* ---------- 10. TOP BUTTON ---------- */
.top-btn {
  position: fixed; bottom: 24px; right: 24px;
  width: 44px; height: 44px; border-radius: 2px;
  background: var(--ink); color: var(--paper);
  border: none; font-size: 18px; cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.15s var(--ease);
  z-index: 100; box-shadow: var(--shadow-card);
}
.top-btn.visible { opacity: 1; pointer-events: auto; }
.top-btn:hover { background: var(--accent); transform: translateY(-2px); }

/* ---------- 11. FOOTER ---------- */
.site-footer {
  background: var(--paper-warm); border-top: 1px solid var(--rule);
  padding: 36px 0; margin-top: 60px;
}
.footer-grid {
  display: grid; grid-template-columns: 2fr 1fr;
  gap: clamp(24px, 4vw, 48px); align-items: start;
}
@media (max-width: 700px) { .footer-grid { grid-template-columns: 1fr; } }

.footer-brand {
  font-family: var(--font-display); font-style: italic;
  font-size: 20px; color: var(--ink); margin-bottom: 10px;
}
.footer-note {
  font-size: 14px; color: var(--ink-soft); max-width: 60ch; margin: 0;
  line-height: 1.55;
}
.footer-label {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-mute); margin-bottom: 8px;
}
.footer-meta p {
  margin: 0; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5;
  font-family: var(--font-mono);
}

/* ---------- 12. RESPONSIVE ADJUSTMENTS ---------- */
@media (max-width: 900px) {
  .site-header { padding: 22px 0; }
  .header-wrap { flex-direction: column; }
  .header-aside { width: 100%; align-items: flex-start; min-width: 0; }
  .brand-mark { font-size: 52px; }
}

@media (max-width: 600px) {
  body { font-size: 16px; }
  .brand { gap: 14px; }
  .brand-mark { font-size: 44px; }
  .module-head { padding: 14px 16px; gap: 12px; }
  .module-body { padding: 18px 18px 22px; }
  .progress-bar { width: 90px; }
  .btn-ghost { padding: 6px 10px; font-size: 10px; }
}

/* ---------- 13. PRINT ---------- */
@media print {
  .sidebar, .top-btn, .header-aside, .site-footer { display: none !important; }
  .main-grid { grid-template-columns: 1fr; }
  .module { page-break-inside: avoid; border: 1px solid #ccc; }
  .module .module-body { display: block !important; }
  .module-chev { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
}

/* ---------- 14. SUBTLE ENHANCEMENTS ---------- */
.preface-title::first-letter {
  font-style: italic; color: var(--accent);
}

.section-title, .module-title { font-variant-emoji: text; }

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
.nav-link:focus-visible, .btn-ghost:focus-visible { outline-offset: 1px; }
