/* =========================================================
   Frontend Performance Guide — Main Styles
   ========================================================= */

@view-transition { navigation: auto; }

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

:root {
  --color-bg:         #ffffff;
  --color-surface:    #f8f9fa;
  --color-border:     #e2e8f0;
  --color-text:       #1a202c;
  --color-text-muted: #718096;
  --color-primary:    #2b6cb0;
  --color-primary-dk: #2c5282;
  --color-accent:     #ed8936;
  --color-success:    #38a169;
  --color-warn:       #d69e2e;
  --color-danger:     #e53e3e;

  --font-sans: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', "Fira Code", "Cascadia Code", "SF Mono", Consolas, monospace;

  --radius: 6px;
  --sidebar-width: 240px;
  --content-max: 800px;
  --site-max: 1200px;
}

html { font-size: 16px; scroll-behavior: smooth; height: 100%; }
body {
  font-family: var(--font-sans); color: var(--color-text); background: var(--color-bg); line-height: 1.7;
  height: 100%; display: flex; flex-direction: column;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Skip Link ------------------------------------------- */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--color-primary); color: #fff; padding: 8px 16px;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* --- Site Header ----------------------------------------- */
.site-header {
  background: var(--color-primary);
  color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.header-inner {
  padding: 0 1.5rem;
  display: flex; align-items: center; gap: 1.5rem; height: 56px;
}
.site-logo { color: #fff; font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }
.header-github {
  margin-left: auto;
  color: rgba(255,255,255,.85); font-size: .8rem;
  padding: 4px 10px; border-radius: var(--radius);
  transition: background .15s;
}
.header-github:hover { background: rgba(255,255,255,.18); color: #fff; text-decoration: none; }
.nav-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; margin-left: 0; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: #fff; margin: 5px 0; border-radius: 2px; }

/* --- Site Body (sidebar + main) -------------------------- */
.site-body { display: flex; flex: 1; min-height: 0; }

/* --- Left Nav (desktop) ---------------------------------- */
.site-nav {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  position: sticky; top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 1rem 0;
}
.site-nav ul { list-style: none; }
.site-nav a {
  display: grid;
  grid-template-columns: 2ch 1fr;
  gap: 0 .4em;
  padding: 5px 1rem;
  font-size: .8rem;
  color: var(--color-text-muted);
  border-radius: 0;
  transition: background .15s, color .15s;
}
.nav-num { text-align: right; color: var(--color-text-muted); opacity: .6; }
.site-nav a:hover {
  background: var(--color-border);
  color: var(--color-text);
  text-decoration: none;
}
.site-nav a[aria-current="page"] {
  color: var(--color-primary);
  font-weight: 600;
  background: #fff;
  border-right: 3px solid var(--color-primary);
}

#main { flex: 1; min-width: 0; overflow: auto; }

/* --- Topic Layout ---------------------------------------- */
.topic-layout {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 2rem;
  padding: 2rem 1.5rem;
  align-items: start;
}

.topic-sidebar {
  position: sticky; top: 72px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  order: 1;
}

.toc { margin-top: 2rem; border-top: 1px solid var(--color-border); padding-top: 1.5rem; }
.toc-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-muted); margin-bottom: .75rem; }
.toc ol, .toc ul { list-style: none; padding-left: .75rem; }
.toc a { font-size: .8rem; color: var(--color-text-muted); }
.toc a:hover { color: var(--color-primary); }

/* --- Topic Content --------------------------------------- */
.topic-content { max-width: var(--content-max); }
.topic-header { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--color-border); }
.topic-header h1 { font-size: 2rem; font-weight: 800; line-height: 1.2; margin-bottom: .5rem; }
.topic-description { font-size: 1.125rem; color: var(--color-text-muted); }
.reading-time { font-size: .8rem; color: var(--color-text-muted); margin-top: .5rem; }

/* Prose */
.topic-content h2 { font-size: 1.5rem; margin: 2.5rem 0 1rem; padding-top: 1rem; border-top: 1px solid var(--color-border); }
.topic-content h3 { font-size: 1.2rem; margin: 2rem 0 .75rem; }
.topic-content h4 { font-size: 1rem; margin: 1.5rem 0 .5rem; font-weight: 700; }
.topic-content p { margin-bottom: 1rem; }
.topic-content ul, .topic-content ol { margin: 1rem 0 1rem 1.5rem; }
.topic-content li { margin-bottom: .4rem; }
.topic-content blockquote { border-left: 4px solid var(--color-primary); padding: .75rem 1rem; background: var(--color-surface); margin: 1.5rem 0; color: var(--color-text-muted); }
.topic-content table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: .9rem; }
.topic-content th, .topic-content td { border: 1px solid var(--color-border); padding: .5rem .75rem; text-align: left; }
.topic-content th { background: var(--color-surface); font-weight: 600; }
.topic-content code { font-family: var(--font-mono); font-size: .85em; background: var(--color-surface); padding: .15em .35em; border-radius: 3px; }
.topic-content pre { margin: 1.5rem 0; }
.topic-content pre code { background: none; padding: 0; font-size: .875rem; }

/* Tip / Warning callouts */
.tip, .warning {
  padding: 1rem 1.25rem; border-radius: var(--radius); margin: 1.5rem 0;
  border-left: 4px solid;
}
.tip    { background: #ebf8ff; border-color: #4299e1; }
.warning { background: #fffbeb; border-color: var(--color-warn); }
.tip > p:first-child::before    { content: "💡 "; }
.warning > p:first-child::before { content: "⚠️ "; }

/* --- Pagination ------------------------------------------ */
.topic-pagination {
  display: flex; gap: 1rem; margin-top: 3rem; padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}
.pagination-prev, .pagination-next {
  flex: 1; display: flex; flex-direction: column;
  padding: 1rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); transition: border-color .15s;
}
.pagination-prev:hover, .pagination-next:hover { border-color: var(--color-primary); text-decoration: none; }
.pagination-next { text-align: right; margin-left: auto; }
.pagination-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-muted); }
.pagination-title { font-weight: 600; color: var(--color-primary); }

/* --- Demo Embed ------------------------------------------ */
.demo-embed { margin: 2rem 0; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.demo-embed iframe { display: block; width: 100%; border: none; }
.demo-open-link {
  display: block; padding: .5rem 1rem; background: var(--color-surface);
  font-size: .8rem; text-align: right; border-top: 1px solid var(--color-border);
}

/* --- Checklist ------------------------------------------- */
.checklist-layout { padding: 2rem 1.5rem; }
.checklist-header { margin-bottom: 2rem; }
.checklist-controls { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; align-items: center; }
.checklist-item {
  display: grid;
  grid-template-columns: 2rem 1fr auto auto;
  gap: .75rem; align-items: start;
  padding: .75rem 0; border-bottom: 1px solid var(--color-border);
}
.checklist-item input[type="checkbox"] { margin-top: .25rem; width: 1.1rem; height: 1.1rem; }
.priority-badge, .effort-badge {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  padding: .2em .5em; border-radius: 3px;
}
.priority-high   { background: #fed7d7; color: #c53030; }
.priority-medium { background: #fefcbf; color: #b7791f; }
.priority-low    { background: #c6f6d5; color: #276749; }

/* --- Homepage -------------------------------------------- */
.home-hero {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dk) 100%);
  color: #fff; padding: 4rem 1.5rem; text-align: center;
}
.home-hero h1 { font-size: 2.5rem; font-weight: 900; margin-bottom: 1rem; }
.home-hero p  { font-size: 1.25rem; opacity: .9; max-width: 600px; margin: 0 auto 2rem; }
.btn { display: inline-block; padding: .75rem 1.75rem; border-radius: var(--radius); font-weight: 600; transition: background .15s; }
.btn-white { background: #fff; color: var(--color-primary); }
.btn-white:hover { background: rgba(255,255,255,.9); text-decoration: none; }

.topics-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem;
  max-width: var(--site-max); margin: 3rem auto; padding: 0 1.5rem;
}
.topic-card {
  display: flex; flex-direction: column;
  padding: 1.25rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); transition: box-shadow .15s, transform .15s;
}
.topic-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); transform: translateY(-2px); text-decoration: none; }
.topic-card-title { font-weight: 700; color: var(--color-text); margin-bottom: .5rem; }
.topic-card-desc  { font-size: .875rem; color: var(--color-text-muted); flex: 1; }


/* --- Responsive ------------------------------------------ */
@media (max-width: 768px) {
  .site-body { display: block; }

  .site-nav {
    display: none;
    position: fixed; top: 56px; left: 0; bottom: 0;
    width: 280px; z-index: 40;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    box-shadow: 4px 0 16px rgba(0,0,0,.1);
    height: auto;
  }
  .site-nav.is-open { display: block; }

  .nav-toggle { display: block; }

  .topic-layout { grid-template-columns: 1fr; }
  .topic-sidebar { position: static; max-height: none; }
}
