/* ==========================================================================
   mdbase.dev — Terminal Elegance
   A specification site with warmth, precision, and quiet confidence.
   ========================================================================== */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,500;0,8..60,600;1,8..60,400&display=swap');

/* --- Custom Properties --- */
:root {
  --bg:         #0e0e0e;
  --bg-raised:  #161616;
  --bg-code:    #1a1a1a;
  --bg-sidebar: #111111;
  --surface:    #1c1c1c;
  --border:     #2a2a2a;
  --border-dim: #1e1e1e;

  --text:       #c8c4b8;
  --text-dim:   #6b6760;
  --text-muted: #4a4843;
  --text-bright:#e8e4d8;

  --amber:      #d4a053;
  --amber-dim:  #a07830;
  --amber-glow: rgba(212, 160, 83, 0.08);
  --amber-bright:#e8b86a;

  --green:      #7a9e6a;
  --blue:       #6a8a9e;
  --red:        #9e6a6a;
  --purple:     #8a7a9e;

  --mono:       'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
  --serif:      'Source Serif 4', 'Georgia', serif;

  --measure:    68ch;
  --sidebar-w:  280px;
  --header-h:   56px;

  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out:cubic-bezier(0.65, 0, 0.35, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 2rem);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

/* Dot grid background — subtle structural motif */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, var(--border-dim) 0.8px, transparent 0.8px);
  background-size: 24px 24px;
  opacity: 0.5;
  pointer-events: none;
}

::selection {
  background: var(--amber);
  color: var(--bg);
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text-bright);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.75rem; margin: 2.5rem 0 1rem; }
h2 { font-size: 1.35rem; margin: 2.5rem 0 0.75rem; padding-top: 1.5rem; border-top: 1px solid var(--border-dim); }
h3 { font-size: 1.1rem; margin: 2rem 0 0.5rem; color: var(--text); }
h4 { font-size: 0.95rem; margin: 1.5rem 0 0.5rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
h5, h6 { font-size: 0.9rem; margin: 1rem 0 0.5rem; color: var(--text-dim); }

p { margin: 0 0 1rem; }
strong { color: var(--text-bright); font-weight: 600; }
em { font-style: italic; }

a {
  color: var(--amber);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease, color 0.2s ease;
}
a:hover {
  color: var(--amber-bright);
  border-bottom-color: var(--amber-dim);
}

hr {
  border: none;
  border-top: 1px solid var(--border-dim);
  margin: 2rem 0;
}

blockquote {
  border-left: 2px solid var(--amber-dim);
  padding: 0.25rem 0 0.25rem 1.25rem;
  margin: 1rem 0;
  color: var(--text-dim);
  font-style: italic;
}

ul, ol {
  margin: 0 0 1rem;
  padding-left: 1.5rem;
}
li { margin-bottom: 0.3rem; }
li > ul, li > ol { margin: 0.3rem 0 0; }

/* --- Code --- */
code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-code);
  color: var(--amber);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border-dim);
}

pre {
  margin: 1.25rem 0;
  padding: 1.25rem 1.5rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-x: auto;
  position: relative;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}

/* Syntax highlighting hints via classes */
pre code .comment { color: var(--text-muted); font-style: italic; }
pre code .keyword { color: var(--purple); }
pre code .string  { color: var(--green); }
pre code .number  { color: var(--blue); }
pre code .key     { color: var(--amber); }

/* Language label on code blocks */
pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0;
  right: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.92rem;
}

thead {
  border-bottom: 2px solid var(--border);
}

th {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-align: left;
  padding: 0.6rem 1rem;
}

td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-dim);
  vertical-align: top;
}

tr:hover td {
  background: var(--amber-glow);
}

/* ==========================================================================
   Landing Page
   ========================================================================== */

.landing-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: rgba(14, 14, 14, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-dim);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

.landing-logo {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-bright);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  border: none;
}

.landing-logo .dot {
  width: 8px;
  height: 8px;
  background: var(--amber);
  border-radius: 50%;
  display: inline-block;
}

.landing-nav {
  display: flex;
  gap: 2rem;
  align-items: center;
}

.landing-nav a {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

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

.landing-nav .nav-cta {
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  padding: 0.35rem 1rem;
  border-radius: 3px;
  transition: all 0.2s ease;
}

.landing-nav .nav-cta:hover {
  background: var(--amber);
  color: var(--bg);
  border-bottom-color: var(--amber);
}

/* --- Hero --- */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(var(--header-h) + 4rem) 2rem 4rem;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
}

.hero-version {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hero-version .tag {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 3px;
  color: var(--amber);
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 1.5rem;
  letter-spacing: -0.03em;
}

.hero h1 .accent {
  color: var(--amber);
}

.hero-sub {
  font-family: var(--serif);
  font-size: 1.2rem;
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 56ch;
  margin-bottom: 2.5rem;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.65rem 1.5rem;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--amber);
  color: var(--bg);
}
.btn-primary:hover {
  background: var(--amber-bright);
  color: var(--bg);
  border-bottom-color: transparent;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-dim);
  border-bottom-color: var(--text-dim);
}

/* --- Sections --- */
.landing-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 5rem 2rem;
}

.section-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--amber-dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  border-top: none;
  padding-top: 0;
}

/* --- Principles Grid --- */
.principles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1px;
  background: var(--border-dim);
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  overflow: hidden;
  margin: 2rem 0;
}

.principle {
  background: var(--bg-raised);
  padding: 1.5rem;
  transition: background 0.2s ease;
}

.principle:hover {
  background: var(--surface);
}

.principle-num {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--amber-dim);
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
}

.principle h3 {
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
  color: var(--text-bright);
}

.principle p {
  font-size: 0.88rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}

/* --- Code Examples Tabs --- */
.examples-container {
  margin: 2rem 0;
}

.example-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
  overflow-x: auto;
}

.example-tab {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.example-tab:hover {
  color: var(--text-dim);
}

.example-tab.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
}

.example-panel {
  display: none;
  animation: fadeIn 0.25s ease;
}

.example-panel.active {
  display: block;
}

.example-panel pre {
  border-radius: 0 0 4px 4px;
  border-top: none;
  margin-top: 0;
}

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

/* --- Conformance Levels --- */
.levels {
  display: flex;
  gap: 0;
  margin: 2rem 0;
  background: var(--border-dim);
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  overflow: hidden;
}

.level {
  flex: 1;
  background: var(--bg-raised);
  padding: 1.25rem 1rem;
  text-align: center;
  border-right: 1px solid var(--border-dim);
  transition: background 0.2s ease;
}

.level:last-child {
  border-right: none;
}

.level:hover {
  background: var(--surface);
}

.level-num {
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--amber);
  display: block;
  margin-bottom: 0.35rem;
}

.level-name {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* --- Spec TOC --- */
.spec-toc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 2rem 0;
}

.toc-item {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.65rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-dim);
  border-radius: 3px;
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  transition: all 0.2s ease;
  text-decoration: none;
  color: var(--text);
}

.toc-item:hover {
  border-color: var(--amber-dim);
  background: var(--surface);
  color: var(--text-bright);
  border-bottom-color: var(--amber-dim);
}

.toc-num {
  color: var(--text-muted);
  font-size: 0.75rem;
  min-width: 2.5ch;
}

/* --- Footer --- */
.landing-footer {
  border-top: 1px solid var(--border-dim);
  padding: 3rem 2rem;
  text-align: center;
}

.landing-footer p {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.landing-footer a {
  color: var(--text-dim);
}


/* ==========================================================================
   Spec Reader Page
   ========================================================================== */

.spec-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  padding-top: var(--header-h);
}

/* --- Spec Header --- */
.spec-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: rgba(14, 14, 14, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-dim);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

/* --- Sidebar --- */
.spec-sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-dim);
  overflow-y: auto;
  padding: 1.5rem 0;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.spec-sidebar::-webkit-scrollbar {
  width: 5px;
}
.spec-sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.spec-sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar-group {
  margin-bottom: 1rem;
}

.sidebar-group-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.5rem 1.25rem 0.35rem;
}

.sidebar-link {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 1.25rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  text-decoration: none;
  border: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  line-height: 1.35;
}

.sidebar-link:hover {
  color: var(--text);
  background: rgba(255,255,255,0.02);
  border-bottom: none;
}

.sidebar-link.active {
  color: var(--amber);
  border-left-color: var(--amber);
  background: var(--amber-glow);
}

.sidebar-link .num {
  color: var(--text-muted);
  font-size: 0.72rem;
  min-width: 2.2ch;
  flex-shrink: 0;
}

.sidebar-link.active .num {
  color: var(--amber-dim);
}

/* --- Spec Content --- */
.spec-content {
  grid-column: 2;
  padding: 3rem 4rem 6rem;
  max-width: calc(var(--measure) + 8rem);
  min-width: 0;
}

.spec-section {
  margin-bottom: 4rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-dim);
}

.spec-section:last-child {
  border-bottom: none;
}

/* First h1 in each section gets special treatment */
.spec-section > h1:first-child {
  font-size: 1.6rem;
  margin-top: 0;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--amber-dim);
  margin-bottom: 1.5rem;
}

/* Section anchors */
.spec-section h1[id],
.spec-section h2[id],
.spec-section h3[id] {
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

/* --- Mobile Sidebar Toggle --- */
.sidebar-toggle {
  display: none;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: 3px;
  cursor: pointer;
}

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

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

  .spec-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-out);
    width: 280px;
    background: var(--bg);
  }

  .spec-sidebar.open {
    transform: translateX(0);
    box-shadow: 20px 0 40px rgba(0,0,0,0.5);
  }

  .sidebar-toggle {
    display: block;
  }

  .spec-content {
    grid-column: 1;
    padding: 2rem 1.25rem 4rem;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .hero-sub {
    font-size: 1.05rem;
  }

  .levels {
    flex-wrap: wrap;
  }

  .level {
    flex: 1 1 30%;
    border-bottom: 1px solid var(--border-dim);
  }

  .spec-toc {
    grid-template-columns: 1fr;
  }

  .landing-nav {
    gap: 1rem;
  }
}

@media (max-width: 600px) {
  .landing-header {
    padding: 0 1rem;
  }

  .landing-nav .hide-mobile {
    display: none;
  }

  .hero {
    padding: calc(var(--header-h) + 2rem) 1rem 3rem;
  }

  .landing-section {
    padding: 3rem 1rem;
  }

  .principles {
    grid-template-columns: 1fr;
  }

  .levels {
    flex-direction: column;
  }

  .level {
    flex: none;
    border-right: none;
    text-align: left;
    display: flex;
    gap: 1rem;
    align-items: center;
  }
}

/* ==========================================================================
   Animations — Entrance
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  .hero-version,
  .hero h1,
  .hero-sub,
  .hero-actions {
    opacity: 0;
    transform: translateY(12px);
    animation: slideUp 0.6s var(--ease-out) forwards;
  }

  .hero-version { animation-delay: 0.1s; }
  .hero h1      { animation-delay: 0.2s; }
  .hero-sub     { animation-delay: 0.3s; }
  .hero-actions { animation-delay: 0.4s; }

  @keyframes slideUp {
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ==========================================================================
   Spec reader — Inline heading anchors
   ========================================================================== */

.spec-section h1,
.spec-section h2,
.spec-section h3 {
  position: relative;
}

.spec-section h1:hover .anchor,
.spec-section h2:hover .anchor,
.spec-section h3:hover .anchor {
  opacity: 1;
}

.anchor {
  position: absolute;
  left: -1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.2s ease;
  border: none;
}

.anchor:hover {
  color: var(--amber);
  border: none;
}

/* ==========================================================================
   Print styles
   ========================================================================== */

@media print {
  body::before { display: none; }
  .landing-header, .spec-header, .spec-sidebar, .sidebar-toggle { display: none; }
  .spec-layout { display: block; }
  .spec-content { padding: 0; max-width: none; }
  a { color: inherit; }
  pre { border: 1px solid #ccc; }
}
