/* Collapse Terminal — fixed layout */
:root{
  --footer-h: 64px;
  --header-h: 64px;
  --border: #262626;
  --bg: #0b0b0b;
  --bg-elevated: #111111;
  --text: #e6e6e6;
  --muted: #9a9a9a;
  --accent: #00d26a; /* terminal green */
  --focus: #3a3a3a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.6 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  display: grid;
  grid-template-rows: var(--header-h) 1fr auto;
  min-height: 100svh;
}
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* Header */

.site-header{
  height: var(--header-h);
  display:flex;
  align-items:center;
  gap:12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.brand{
  display:flex;
  align-items:center;
  gap:10px;
}
.brand .wordmark{
  font-weight: 650;
  font-size: 16px;
  letter-spacing: .3px;
  color: var(--text);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  line-height: 1;
  white-space: nowrap;
}
@media (min-width: 720px){
  .brand .wordmark{ font-size: 17px; letter-spacing: .35px; }
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight:700;
  letter-spacing: .2px;
}
.accent{ color: var(--accent); }


/* Two-column shell */
.layout{
  grid-row: 2;

  display:grid;
  grid-template-columns: 300px 1fr;
  min-height: 0;

  min-height: calc(100svh - var(--header-h));
}
@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; }
  #sidebar{
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    order: -1;
  }
  #reader{
    border-left: none;
    padding: 12px;
    padding-bottom: 56px; /* extra room above footer on phones */
  }
  .site-header{
    position: sticky;
    top: 0;
    z-index: 10;
  }
}
  #sidebar{
  position: sticky;
  top: var(--header-h);
  align-self: start;
  max-height: calc(100svh - var(--header-h) - 24px);
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 0;
}
  #reader{
  min-height: calc(100svh - var(--header-h));
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow: auto;
  padding: 16px;
  padding-bottom: 48px; /* space above footer */
}
  .site-header{
    position: sticky;
    top: 0;
    z-index: 10;
  }
}
}

/* Sidebar: always visible */
#sidebar{
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100svh - var(--header-h));
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 0;
}
.cats{
  display:block;
  padding: 0 8px;
}
.cat{
  border-bottom: 1px solid var(--border);
}
.cat > summary{
  cursor: pointer;
  user-select: none;
  padding: 10px 8px;
  outline: none;
}
.cat > summary::-webkit-details-marker{ display:none; }
.cat > summary:before{
  content: "▸";
  display:inline-block;
  margin-right:8px;
  transform: translateY(-1px);
  transition: transform .15s ease;
}
.cat[open] > summary:before{ transform: rotate(90deg) translateX(-1px); }
.cat ul{
  list-style: none;
  margin: 0;
  padding: 0 0 10px 24px;
}
.cat a{
  display:block;
  padding: 6px 4px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
}
.cat a:focus, .cat a:hover{
  background: var(--focus);
}

/* Reader */
#reader{
  min-height: calc(100svh - var(--header-h));
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow: auto;
  padding: 16px;
}
#reader h1, #reader h2, #reader h3{
  margin: 0 0 12px;
}

/* Footer separated visually */
.site-footer{
  grid-row: 3;
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 12px 16px;
  box-shadow: 0 -1px 0 var(--border), 0 -8px 16px rgba(0,0,0,.35) inset;
  z-index: 5;
}
.site-footer p{ margin: 0; color: var(--muted); }
.site-footer p{ margin: 0; color: var(--muted); }

/* Content styling */
article{
  max-width: 90ch;
  margin: 0 auto;
}
pre, code{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
pre{
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 8px;
  overflow:auto;
  background: #0f0f0f;
}
kbd{
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-bottom-color: #202020;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}



/* Mobile-hardening */
img, svg, video { max-width: 100%; height: auto; }
pre, code { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
a { word-break: break-word; }


/* Fix: ensure main content never hides behind footer */
#reader{ padding-bottom: var(--footer-h); background: var(--bg); }

/* Fix: footer contrast and safe stacking */
.site-footer{
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 7;
}
.site-footer p{ margin:0; color: var(--muted); }

/* Fix: sidebar background and height to footer */
#sidebar{ background: var(--bg); }
@media (min-width: 900px){
  #sidebar{ 
    height: calc(100svh - var(--header-h)); 
    overflow:auto; 
  }
}

@media (min-width: 1280px){ article{ max-width: 110ch; } }

/* Mobile: compact category bar that doesn't block reading */
@media (max-width: 900px){
  #sidebar{
    position: sticky;
    top: var(--header-h);
    z-index: 8;
    background: var(--bg);
    padding: 0;
    border-bottom: 1px solid var(--border);
  }
  #sidebar .cats{ margin:0; }
  #sidebar details.cat > summary{
    padding: 12px;
    list-style: none;
    cursor: pointer;
  }
  #sidebar details.cat[open] > ul{
    max-height: 50vh;
    overflow: auto;
    padding: 8px 12px 12px;
    margin: 0;
  }
}


/* ===== Mobile Compact Pass (≤900px) ===== */
@media (max-width: 900px){
  :root{ --mspace: 10px; }

  /* tighter header */
  .site-header{ padding: 10px 14px; }

  /* sidebar shell */
  #sidebar{
    font-size: 14px;
    line-height: 1.25;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    box-shadow: 0 1px 0 var(--border);
  }

  /* compact category rows */
  #sidebar details.cat{ border-top: 1px solid var(--border); }
  #sidebar details.cat > summary{
    padding: 10px 12px;
    font-weight: 600;
    letter-spacing: .2px;
    list-style: none;
  }
  #sidebar details.cat > summary::-webkit-details-marker{ display:none; }

  /* compact list inside an opened category */
  #sidebar details.cat[open] > ul{
    margin: 0;
    padding: 6px 8px 10px;
    max-height: 48vh; /* never swallows the page */
    overflow: auto;
    border-top: 1px dashed var(--border);
  }
  #sidebar .cats li{
    margin: 0;
    padding: 6px 6px;
    list-style: none;
    border-radius: 6px;
  }
  #sidebar .cats li + li{ margin-top: 2px; }
  #sidebar .cats li a{ display: inline-block; padding: 2px 4px; }

  /* reader text gets slightly larger and airier for legibility */
  #reader article{
    font-size: 17px;
    line-height: 1.55;
  }
}


/* ===== Mobile/Tablet list-first view ===== */
@media (max-width: 1024px){
  /* single column layout on small screens */
  .layout{ grid-template-columns: 1fr; }

  /* View states driven by [data-view] on <body> */
  body[data-view="list"] #reader{ display: none !important; }
  body[data-view="list"] #sidebar{ display: block !important; }

  body[data-view="reader"] #sidebar{ display: none !important; }
  body[data-view="reader"] #reader{ display: block !important; }

  /* make the brand tappable without visual clutter */
  .brand{ cursor: pointer; }
}

.cat > summary{ cursor:pointer; }

#sidebar .cats li{ cursor:pointer; }
#sidebar .cats li a{ text-decoration: underline; }


/* --- CT Fixes v2 --- */

/* Grid layout: sidebar + reader */
.layout{
  display:grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  min-height: calc(100vh - var(--footer-h, 0px) - var(--header-h, 64px));
}
#sidebar{ overflow:auto; }
#reader{ overflow:auto; min-height: 60vh; }

/* Prevent centered/narrow content in reader */
#reader > * { max-width: none !important; margin: 0; }
#reader article, #reader section { padding: 16px; }

/* Mobile behavior */
@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; }
  /* default: list view shows only sidebar */
  body.view-list #sidebar{ display:block; }
  body.view-list #reader{ display:none; }

  /* reader view hides sidebar, shows reader full-screen */
  body.view-reader #sidebar{ display:none; }
  body.view-reader #reader{ display:block; }
}

/* Make case-file anchors obviously clickable */
#sidebar .cats a[href^="#/"]{
  cursor: pointer;
  text-decoration: underline;
}

/* details persistence visual (optional): keep smooth state */
#sidebar details.cat{ transition: all .15s ease; }


/* Persistent frame around reader content */
#reader .reader-frame{
  border: 1px solid var(--border, #444);
  border-radius: 8px;
  background: var(--bg, #111);
  padding: 20px;
  margin: 16px;
  max-width: 100ch;
  box-sizing: border-box;
}
#reader .reader-frame article{ margin: 0; padding: 0; }

/* Smooth swap without flash */
#reader.fade-in { animation: ctFadeIn .15s ease-in; }
@keyframes ctFadeIn { from { opacity: .6; } to { opacity: 1; } }


/* Remove focus ring/outline inside reader (prevents white border on reload) */
#reader *:focus,
#reader *:focus-visible {
  outline: none !important;
}
/* Firefox specific focus ring */
#reader *:-moz-focusring {
  outline: none !important;
}


/* === Global link styling (pro-clean) === */
a {
  color: #00FF66;
  text-decoration: underline;
  text-underline-offset: 2px;
}
a:hover,
a:focus-visible {
  text-decoration-thickness: 2px;
  filter: brightness(1.08);
}
a:visited {
  color: #00e65c;
}

/* === Brand underscore (slow blink) === */
.brand .wordmark { color: #e8e8e8; }
.brand .wordmark .underscore {
  color: #00FF66;
  animation: ct-caret-blink 1.6s steps(2, start) infinite;
}
@keyframes ct-caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.25; }
}
