:root {
  --bg: #050607;
  --glass: rgba(16, 18, 21, 0.72);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-border-strong: rgba(255, 255, 255, 0.24);
  --text: #f5f5f7;
  --muted: #9a9ca4;
  --accent: #e84a27;
  --emerald: #10b981;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background-color: var(--bg);
  color: var(--text);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  line-height: 1.5;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: var(--font-mono);
}

/* Fixed Fullscreen WebGL Canvas */
#webgl-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
}

/* Quiet Top Hairline Header */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(5, 6, 7, 0.56);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.header-inner {
  max-width: 1220px;
  height: 58px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -0.02em;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 13.5px;
  font-weight: 500;
}

.header-nav a {
  color: var(--muted);
  text-decoration: none;
  transition: color 160ms ease;
}

.header-nav a:hover {
  color: var(--text);
}

.scrolly-main {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

/* Hero Chapter: Spacious Open Center for the 3D Hardware Monolith */
.chapter {
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 28px;
  scroll-margin-top: 72px;
}

.chapter-hero {
  min-height: 100svh;
  padding-top: 58px;
  padding-bottom: 36px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
}

.hero-interaction-zone {
  position: absolute;
  inset: 58px 0 180px 0;
  cursor: grab;
  pointer-events: auto;
  touch-action: pan-y;
}

.hero-interaction-zone:active {
  cursor: grabbing;
}

.hero-bottom {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
  padding-top: 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: auto;
}

.hero-copy-block h1 {
  margin: 0 0 8px;
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 700;
  line-height: 1.03;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.hero-sub {
  margin: 0 0 10px;
  font-size: 15.5px;
  color: var(--muted);
  max-width: 54ch;
}

.hero-sub code {
  color: var(--text);
  font-size: 0.9em;
}

.hero-hint {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: rgba(245, 245, 247, 0.48);
}

.hero-pills {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.glass-pill {
  appearance: none;
  cursor: pointer;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  transition: border-color 160ms ease, transform 90ms ease, background-color 160ms ease;
}

.glass-pill:hover {
  border-color: var(--glass-border-strong);
  background: rgba(26, 30, 35, 0.84);
}

.glass-pill:active,
.pulse-btn:active,
.cmd-btn:active {
  transform: scale(0.97);
}

.pill-state {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

/* Split Chapters leaving opposite half open for 3D WebGL Sculpture */
.chapter-split {
  min-height: 100svh;
  padding-top: 96px;
  padding-bottom: 96px;
  display: flex;
  align-items: center;
}

.chapter-inner {
  width: 100%;
  display: flex;
}

.align-left {
  justify-content: flex-start;
}

.align-right {
  justify-content: flex-end;
}

.glass-panel {
  pointer-events: auto;
  width: 100%;
  max-width: 510px;
  padding: 28px;
  border-radius: 20px;
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.panel-links {
  display: flex;
  gap: 8px;
}

.panel-links a {
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  color: var(--text);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
  transition: border-color 160ms ease;
}

.panel-links a:hover {
  border-color: var(--glass-border-strong);
}

.panel-copy {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.panel-copy code {
  color: var(--text);
  font-size: 0.9em;
}

/* Live 3D Spring Controls inside tactile-ui panel */
.spring-controls {
  padding: 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.controls-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}

.reduce-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.reduce-toggle input {
  accent-color: var(--accent);
}

.slider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.slider-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.slider-field span {
  display: flex;
  justify-content: space-between;
}

.slider-field strong {
  font-family: var(--font-mono);
  color: var(--text);
}

.slider-field input {
  width: 100%;
  accent-color: var(--accent);
}

.pulse-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  transition: transform 90ms ease, filter 160ms ease;
}

.pulse-btn:hover {
  filter: brightness(1.08);
}

/* Embedded GIF Frame (inner = outer - pad) */
.media-box {
  border-radius: 12px;
  overflow: clip;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #040605;
}

.media-box img {
  display: block;
  width: 100%;
  height: auto;
}

.panel-copy-btn {
  width: 100%;
}

/* Live Diff Block inside skill-sync panel */
.diff-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diff-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.diff-label {
  font-size: 13px;
  font-weight: 600;
}

.diff-tabs {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.diff-tab {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 5px 9px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.diff-tab.is-active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.diff-surface {
  border-radius: 12px;
  background: rgba(5, 7, 8, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: clip;
}

.diff-meta {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
}

.diff-count { font-family: var(--font-mono); font-size: 11px; }
.diff-count.is-blocked { color: #f87171; }
.diff-count.is-safe { color: #34d399; }
.diff-count.is-compressed { color: #38bdf8; }

.diff-pre {
  margin: 0;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: hidden;
  scrollbar-width: none;
}

.diff-pre::-webkit-scrollbar {
  display: none;
}

.d-ctx { color: var(--muted); }
.d-add-risk { display: block; color: #fca5a5; }
.d-add-safe { display: block; color: #6ee7b7; }
.d-add-cyan { display: block; color: #7dd3fc; }

.diff-verdict {
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
}

.diff-verdict.is-blocked { color: #fca5a5; }
.diff-verdict.is-safe { color: #6ee7b7; }
.diff-verdict.is-compressed { color: #7dd3fc; }

.cmd-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.cmd-btn {
  appearance: none;
  cursor: pointer;
  padding: 8px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 11px;
  transition: border-color 160ms ease, transform 90ms ease;
}

.cmd-btn:hover {
  border-color: var(--glass-border-strong);
}

/* Finale Chapter */
.chapter-finale {
  min-height: 92svh;
  padding-top: 120px;
  padding-bottom: 36px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 44px;
}

.finale-content {
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.finale-content h2 {
  margin: 0;
  font-size: clamp(32px, 4.5vw, 52px);
  font-weight: 700;
  letter-spacing: -0.035em;
}

.site-footer {
  pointer-events: auto;
  padding-top: 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

.footer-links {
  display: flex;
  gap: 20px;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--text);
}

@media (max-width: 900px) {
  .align-left,
  .align-right {
    justify-content: center;
  }
  .chapter-split {
    padding-top: 220px;
  }
  .cmd-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
    gap: 12px;
  }
  .brand {
    flex-shrink: 0;
  }
  .header-nav {
    overflow-x: auto;
    white-space: nowrap;
    gap: 14px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-right: 12px;
    -webkit-mask-image: linear-gradient(to right, black 88%, transparent);
    mask-image: linear-gradient(to right, black 88%, transparent);
  }
  .header-nav::-webkit-scrollbar {
    display: none;
  }
  .header-nav a {
    padding: 8px 2px;
    flex-shrink: 0;
  }
}

@media (max-width: 640px) {
  .chapter {
    padding: 0 16px;
  }
  .chapter-hero {
    padding-top: 72px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .hero-interaction-zone {
    inset: 58px 0 320px 0;
  }
  .hero-bottom {
    gap: 16px;
    padding-top: 16px;
  }
  .hero-copy-block h1 {
    font-size: clamp(28px, 8.5vw, 38px);
  }
  .hero-pills {
    width: 100%;
    gap: 8px;
  }
  .glass-pill {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 12px;
    gap: 10px;
  }
  .glass-pill code {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chapter-split {
    min-height: auto;
    padding-top: 190px;
    padding-bottom: 56px;
  }
  .glass-panel {
    padding: 18px;
    border-radius: 16px;
    gap: 16px;
    max-width: 100%;
  }
  .panel-head {
    flex-wrap: wrap;
    gap: 10px;
  }
  .panel-head h2 {
    font-size: 26px;
  }
  .panel-links a {
    padding: 8px 12px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  .panel-copy {
    font-size: 14px;
  }
  .pulse-btn,
  .cmd-btn {
    min-height: 40px;
  }
  .diff-tab {
    padding: 7px 10px;
  }
  .diff-pre {
    font-size: 11px;
    padding: 10px 12px;
  }
  .chapter-finale {
    min-height: auto;
    padding-top: 84px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    gap: 28px;
  }
  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  .footer-links {
    flex-wrap: wrap;
    gap: 12px 18px;
  }
}

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

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