/* ===================================================
   Jepia Webdoc — Shared Stylesheet
   =================================================== */

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

/* ---- Design Tokens ---- */
:root {
  --bg-deep:     #1a151c;
  --bg-base:     #2a1f2d;
  --bg-elevated: #2f2532;
  --bg-surface:  #3a2f3d;
  --border:      #4a3a4d;
  --text:        #ffc49b;
  --accent:      #ff9e6d;
  --code-text:   #c8f7c5;
  --link:        #6dcaff;
  --muted:       #888;
  --font-sans:   "Averia Sans Libre", sans-serif;
  --font-mono:   "IBM Plex Mono", monospace;
  --nav-h:       52px;
  --sidebar-w:   270px;
  --max-w:       1200px;
  --pad-x:       28px;
}

/* ---- Base ---- */
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-mono);
  background-color: var(--bg-base);
  color: var(--text);
  line-height: 1.7;
  margin: 0;
  padding: 0;
  font-size: 1rem;
}

/* ---- Top Navigation Bar ---- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 200;
  background-color: var(--bg-deep);
  border-bottom: 2px solid var(--border);
  height: var(--nav-h);
}

.topnav-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--pad-x);
  height: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  flex-shrink: 0;
}
.topnav-brand:hover { text-decoration: none; }
.topnav-brand img { height: 28px; width: auto; }

.topnav-links {
  display: flex;
  gap: 2px;
  margin-left: auto;
  align-items: center;
}

.topnav-links a {
  color: var(--text);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 0.88rem;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.topnav-links a:hover,
.topnav-links a.active {
  background-color: var(--bg-surface);
  color: var(--accent);
  text-decoration: none;
}

/* Hamburger button */
.topnav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 8px 9px;
  margin-left: auto;
}
.topnav-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background-color: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.topnav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topnav-hamburger.open span:nth-child(2) { opacity: 0; }
.topnav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---- Page Wrapper ---- */
.page-wrapper {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 36px var(--pad-x) 72px;
}

/* ---- Page Header ---- */
.page-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}
.page-header img { height: 72px; width: auto; }
.page-header h1 { margin: 0; border-bottom: none; padding-bottom: 0; }

/* ---- Typography ---- */
h1, h2, h3 {
  font-family: var(--font-sans);
  color: var(--accent);
  margin-top: 2rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
}
h1 {
  font-size: clamp(1.7rem, 4.5vw, 2.8rem);
  border-bottom: 4px solid var(--accent);
}
h2 { font-size: clamp(1.35rem, 3.5vw, 2rem); }
h3 { font-size: clamp(1.05rem, 2.5vw, 1.5rem); }

/* ---- Inline Code ---- */
code:not([class*="language-"]) {
  background-color: var(--bg-deep);
  color: var(--code-text);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

pre {
  background-color: var(--bg-deep);
  padding: 16px;
  overflow-x: auto;
  border-left: 4px solid var(--accent);
  border-radius: 0 4px 4px 0;
  margin: 1rem 0;
  -webkit-overflow-scrolling: touch;
}

pre:not([class*="language-"]) {
  color: var(--code-text);
}

/* ---- Links ---- */
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Tables ---- */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}
th, td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
th {
  background-color: var(--bg-surface);
  color: var(--text);
}
tr:nth-child(even) { background-color: var(--bg-elevated); }

/* ---- Blockquote ---- */
blockquote {
  border-left: 4px solid var(--link);
  padding-left: 1rem;
  margin-left: 0;
  color: #ccc;
}

/* ---- Card / Note Boxes ---- */
.card {
  background-color: var(--bg-deep);
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
  border-left: 6px solid var(--accent);
}
.card h3 { margin-top: 0; }

.note-box {
  background-color: var(--bg-surface);
  border-left: 6px solid var(--accent);
  padding: 12px 18px;
  margin: 20px 0;
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.note-box > img.box-icon { width: 48px; height: 48px; flex-shrink: 0; margin-top: 2px; }
.note-box > div { flex: 1; }

.tip-box {
  background-color: #2f3a2d;
  border-left: 6px solid var(--code-text);
  padding: 12px 18px;
  margin: 20px 0;
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.tip-box > img.box-icon { width: 48px; height: 48px; flex-shrink: 0; margin-top: 2px; }
.tip-box > div { flex: 1; }

.output-block {
  background-color: var(--bg-deep);
  color: #aaa;
  padding: 16px;
  border-left: 4px solid var(--border);
  border-radius: 4px;
  margin: 1rem 0;
  font-size: 0.9rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---- Index Page Grid ---- */
.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 30px;
}

.grid-item {
  background-color: var(--bg-elevated);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.2s, transform 0.15s;
}
.grid-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.grid-item h3 { margin-top: 0; }

/* ---- Two-Column Layout (sidebar + content) ---- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 32px;
  align-items: start;
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  max-height: calc(100dvh - var(--nav-h) - 32px);
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--bg-deep);
  padding: 18px;
  border-radius: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: 2px; }

.sidebar h3 {
  margin-top: 0;
  font-size: 0.95rem;
  border-bottom-color: var(--border);
}

.sidebar ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.sidebar li { margin-bottom: 2px; }

.sidebar a {
  display: block;
  padding: 5px 10px;
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
  transition: background-color 0.1s, color 0.1s;
}
.sidebar a:hover,
.sidebar a.active {
  background-color: var(--bg-elevated);
  color: var(--accent);
  text-decoration: none;
}

.sidebar .section-group {
  margin-top: 4px;
  margin-bottom: 4px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}
.sidebar .section-group li { margin-bottom: 1px; }

/* ---- Sidebar Search ---- */
.sidebar-search {
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.sidebar-search::placeholder { color: var(--muted); }
.sidebar-search:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

/* ---- Collapsible Sidebar Categories ---- */
.sidebar .category-toggle {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}
.sidebar .category-toggle::before { content: '\25BE '; font-size: 0.7em; }
.sidebar .category-toggle.collapsed::before { content: '\25B8 '; }
.sidebar .section-group.collapsed { display: none; }

/* ---- Component Entry ---- */
.comp-entry { margin-bottom: 2.5rem; }
.comp-entry h3 { font-size: 1.1rem; }

/* ---- Badges ---- */
.badge-experimental {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 3px;
  background-color: #3a3520;
  color: #f0c040;
  border: 1px solid #6a6030;
  vertical-align: middle;
  margin-left: 6px;
}
.badge-deprecated {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 3px;
  background-color: #3a2020;
  color: #f06060;
  border: 1px solid #6a3030;
  vertical-align: middle;
  margin-left: 6px;
}

/* Mobile sidebar toggle button */
.sidebar-toggle {
  display: none;
}

/* ---- Content area ---- */
.content { min-width: 0; }

/* ---- Texture preview (Examples page) ---- */
.texture-preview {
  display: inline-block;
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  border: 2px solid var(--border);
  border-radius: 4px;
  margin: 4px 8px 4px 0;
  vertical-align: middle;
  background-color: var(--bg-deep);
}

.texture-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

/* ---- Footer ---- */
footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Medium — compact nav links */
@media (max-width: 960px) {
  :root { --pad-x: 20px; }
  .topnav-links a { padding: 5px 9px; font-size: 0.84rem; }
}

/* Tablet — sidebar collapses */
@media (max-width: 820px) {
  :root { --sidebar-w: 230px; }
}

/* Mobile — full single-column, collapsible sidebar */
@media (max-width: 680px) {
  :root { --pad-x: 16px; }

  /* Hamburger nav */
  .topnav-hamburger { display: flex; }
  .topnav-links {
    display: none;
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    flex-direction: column;
    background-color: var(--bg-deep);
    border-bottom: 2px solid var(--border);
    padding: 12px 20px 16px;
    gap: 2px;
    z-index: 199;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  }
  .topnav-links.open { display: flex; }
  .topnav-links a { font-size: 0.95rem; padding: 9px 12px; }

  /* Single column layout */
  .layout { grid-template-columns: 1fr; }

  /* Sidebar toggle button */
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background-color: var(--bg-deep);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    cursor: pointer;
    margin-bottom: 0;
    transition: background-color 0.15s;
  }
  .sidebar-toggle:hover { background-color: var(--bg-elevated); }
  .sidebar-toggle .toggle-arrow { transition: transform 0.2s; }
  .sidebar-toggle.open .toggle-arrow { transform: rotate(180deg); }

  /* Sidebar hidden by default, shown when .open */
  .sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
    display: none;
    margin-bottom: 16px;
    border-radius: 0 0 8px 8px;
  }
  .sidebar.open { display: block; }

  /* Sidebar toggle wraps both button + sidebar */
  .sidebar-wrap { margin-bottom: 20px; }

  /* Tables scroll horizontally */
  .content table,
  .page-wrapper table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .content table th,
  .content table td,
  .page-wrapper table th,
  .page-wrapper table td {
    white-space: normal;
    min-width: 120px;
  }

  /* Page header */
  .page-header { flex-direction: column; gap: 12px; text-align: center; }
  .page-header img { height: 56px; }
}
