/* ===== BB Playbook SPA Styles ===== */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-body: "Bitter", Georgia, serif;
  --font-mono: "Fira Mono", monospace;
  --header-height: 56px;
  --tabs-height: 40px;
  --sidebar-width: 280px;
  --toc-width: 220px;
  --max-width: 90rem;
}

/* --- Light theme --- */
[data-theme="light"] {
  --bg: #fff;
  --bg-alt: #f5f5f5;
  --bg-sidebar: #fafafa;
  --text: #333;
  --text-muted: #666;
  --border: #e0e0e0;
  --primary: #8b1a1a;
  --primary-light: #a63333;
  --primary-dark: #5c1010;
  --accent: #d4443b;
  --header-bg: linear-gradient(135deg, #5c1010 0%, #8b1a1a 60%, #a63333 100%);
  --tabs-bg: #4a0e0e;
  --table-header-bg: #8b1a1a;
  --table-hover: rgba(139, 26, 26, 0.04);
  --table-border: rgba(139, 26, 26, 0.25);
  --table-cell-border: rgba(139, 26, 26, 0.12);
  --shadow: rgba(0, 0, 0, 0.15);
  --code-bg: #f0f0f0;
  --link: #8b1a1a;
  --link-hover: #d4443b;
  --search-bg: rgba(255, 255, 255, 0.95);
  --overlay-bg: rgba(0, 0, 0, 0.5);
  --footer-bg: #2a2a2a;
  --footer-text: #888;
}

/* --- Dark theme (default) --- */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-alt: #242424;
  --bg-sidebar: #1e1e1e;
  --text: #e0e0e0;
  --text-muted: #999;
  --border: #333;
  --primary: #8b1a1a;
  --primary-light: #a63333;
  --primary-dark: #5c1010;
  --accent: #e85d54;
  --header-bg: linear-gradient(135deg, #5c1010 0%, #8b1a1a 60%, #a63333 100%);
  --tabs-bg: #4a0e0e;
  --table-header-bg: #8b1a1a;
  --table-hover: rgba(232, 93, 84, 0.06);
  --table-border: rgba(139, 26, 26, 0.4);
  --table-cell-border: rgba(139, 26, 26, 0.2);
  --shadow: rgba(0, 0, 0, 0.4);
  --code-bg: #2e2e2e;
  --link: #e85d54;
  --link-hover: #ff7b73;
  --search-bg: rgba(30, 30, 30, 0.97);
  --overlay-bg: rgba(0, 0, 0, 0.7);
  --footer-bg: #111;
  --footer-text: #777;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }

img { max-width: 100%; height: auto; }
code { font-family: var(--font-mono); font-size: 0.88em; background: var(--code-bg); padding: 0.15em 0.4em; border-radius: 3px; }
pre { background: var(--code-bg); padding: 1em; border-radius: 4px; overflow-x: auto; }
pre code { background: none; padding: 0; }

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  color: #fff;
  box-shadow: 0 2px 8px var(--shadow);
  height: var(--header-height);
}

.header__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
}

.header__logo img { border-radius: 4px; }

.header__spacer { flex: 1; }

.header__btn, .header__menu-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 0.2s;
}

.header__btn:hover, .header__menu-btn:hover { opacity: 1; }

.header__menu-btn { display: none; }

/* Theme toggle icons */
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: block; }

/* --- Loading bar --- */
.loading-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: 0;
  height: 3px;
  background: var(--accent);
  z-index: 101;
  transition: none;
  opacity: 0;
}

.loading-bar--active {
  opacity: 1;
  width: 70%;
  transition: width 0.8s cubic-bezier(0.1, 0.5, 0.3, 1);
}

.loading-bar--done {
  width: 100%;
  transition: width 0.15s ease, opacity 0.3s ease 0.15s;
  opacity: 0;
}

/* --- Tabs --- */
.tabs {
  background: var(--tabs-bg);
  color: #fff;
  height: var(--tabs-height);
  position: sticky;
  top: var(--header-height);
  z-index: 90;
}

.tabs__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tabs__link {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  padding: 0 1.25rem;
  height: 100%;
  display: flex;
  align-items: center;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tabs__link:hover { color: #fff; }

.tabs__link--active {
  color: #fff;
  border-bottom-color: var(--accent);
}

/* --- Main layout --- */
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
  min-height: calc(100vh - var(--header-height) - var(--tabs-height) - 50px);
}

/* --- Sidebar --- */
.sidebar {
  position: sticky;
  top: calc(var(--header-height) + var(--tabs-height));
  height: calc(100vh - var(--header-height) - var(--tabs-height));
  overflow-y: auto;
  padding: 1.25rem 1rem 2rem 1.25rem;
  border-right: 1px solid var(--border);
  background: var(--bg-sidebar);
  scrollbar-width: thin;
}

.sidebar__section { margin-bottom: 0.25rem; }

.sidebar__section-header {
  display: flex;
  align-items: center;
  gap: 0;
}

.sidebar__section-title {
  flex: 1;
  display: block;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.5rem 0.6rem;
  border-radius: 4px;
  transition: color 0.15s;
}

.sidebar__section-title:hover { color: var(--accent); }
.sidebar__section-title.sidebar__link--active { color: var(--accent); }

.sidebar__toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, color 0.15s;
  transform: rotate(-90deg);
  flex-shrink: 0;
}

.sidebar__toggle:hover { color: var(--accent); }

.sidebar__section--expanded > .sidebar__section-header .sidebar__toggle {
  transform: rotate(0deg);
}

/* Collapsed by default - hidden list */
.sidebar__list {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.sidebar__list-inner {
  overflow: hidden;
  list-style: none;
  margin: 0;
  padding: 0 0 0 0.6rem;
}

/* Expanded state */
.sidebar__section--expanded > .sidebar__list {
  grid-template-rows: 1fr;
}

.sidebar__link {
  display: block;
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
  color: var(--text);
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1.4;
}

.sidebar__link:hover {
  color: var(--accent);
  background: rgba(139, 26, 26, 0.06);
}

.sidebar__link--active {
  color: var(--accent) !important;
  font-weight: 600;
  background: rgba(139, 26, 26, 0.08);
}

/* --- Content --- */
.content {
  padding: 2rem 3rem 4rem;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: break-word;
}

.content__inner {
  max-width: 52rem;
  margin: 0 auto;
  overflow: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease;
  opacity: 1;
  transform: translateY(0);
}

/* Page transition */
.content--leaving {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.content--entering {
  opacity: 0;
  transform: translateY(4px);
}

.loading {
  text-align: center;
  padding: 4rem 0;
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* --- Typography in content --- */
.content h1 {
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 0.3em;
  margin-bottom: 1.25rem;
}

.content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(139, 26, 26, 0.2);
  padding-bottom: 0.2em;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.content h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 0.6rem;
}

.content h4, .content h5, .content h6 {
  font-weight: 700;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.content p {
  margin-bottom: 0.85rem;
  line-height: 1.7;
}

.content ul, .content ol {
  margin-bottom: 0.85rem;
  padding-left: 1.75rem;
}

.content li {
  margin-bottom: 0.35em;
  line-height: 1.6;
}

.content blockquote {
  border-left: 3px solid var(--primary);
  padding: 0.75em 1.25em;
  margin: 1.25em 0;
  color: var(--text-muted);
  background: var(--bg-alt);
  border-radius: 0 4px 4px 0;
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* Hero/lead images - cap height */
.content > img:first-child,
.content > p:first-of-type img,
.content > p:nth-of-type(2) img,
.content h1 + p img,
.content h1 + p + p img {
  max-height: 400px;
  width: auto;
  object-fit: contain;
  border-radius: 6px;
}

/* --- Tables --- */
.content .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.25rem 0;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--table-border);
  border-radius: 4px;
  font-size: 0.85rem;
  margin: 1.25rem 0;
}

.content th {
  background: var(--table-header-bg);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 0.65em 0.9em;
  white-space: nowrap;
}

.content td {
  padding: 0.55em 0.9em;
  border-top: 1px solid var(--table-cell-border);
  vertical-align: top;
}

.content tr:hover td { background: var(--table-hover); }

/* --- Team tier badge --- */
.team-tier-badge {
  display: inline-block;
  font-size: 0.55em;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  padding: 0.15em 0.6em;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 0.75rem;
  letter-spacing: 0.04em;
  position: relative;
  top: -0.1em;
}

/* --- Team positional table: skills sub-row --- */
.team-skills-row td {
  background: var(--bg-alt) !important;
  border-top: none;
  padding: 0.3em 0.9em 0.5em;
  font-size: 0.8rem;
}

.team-skills-label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-right: 0.3em;
}

.team-skill-tag {
  color: var(--link);
}

.team-skill-tag a {
  color: var(--link);
}

.team-skill-tag a:hover {
  color: var(--link-hover);
}

.team-skill-sep {
  color: var(--text-muted);
  margin: 0 0.1em;
}

/* --- Star player skills (inline) --- */
.sp-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.sp-skill-tag {
  display: inline-block;
  font-size: 0.82rem;
  padding: 0.2em 0.6em;
  border-radius: 4px;
  border: 1px solid var(--table-cell-border);
  background: var(--bg-alt);
  line-height: 1.4;
}

.sp-skill-tag a {
  color: var(--link);
}

.sp-skill-tag a:hover {
  color: var(--link-hover);
}

.sp-skill-tag--special {
  font-weight: 700;
  color: var(--text);
  border-color: var(--accent);
  background: rgba(139, 26, 26, 0.1);
}

/* --- Table of Contents --- */
.toc {
  position: sticky;
  top: calc(var(--header-height) + var(--tabs-height));
  height: calc(100vh - var(--header-height) - var(--tabs-height));
  overflow-y: auto;
  padding: 1.25rem 1rem 2rem 0.75rem;
  border-left: 1px solid var(--border);
  scrollbar-width: thin;
}

.toc--hidden { display: none; }

.toc__title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.toc__list { list-style: none; }

.toc__item { margin-bottom: 0.2rem; }

.toc__item--nested { padding-left: 0.85rem; }

.toc__link {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  padding: 0.2rem 0.4rem;
  line-height: 1.4;
  transition: color 0.15s, border-color 0.15s;
  border-left: 2px solid transparent;
  border-radius: 0;
}

.toc__link:hover { color: var(--accent); }

.toc__link--active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* --- Search overlay --- */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--overlay-bg);
  display: none;
  justify-content: center;
  padding-top: 12vh;
}

.search-overlay--open { display: flex; }

.search-box {
  background: var(--search-bg);
  border-radius: 10px;
  width: min(92vw, 560px);
  box-shadow: 0 8px 32px var(--shadow);
  position: relative;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
}

.search-box input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1.1rem;
  padding: 1rem 3rem 1rem 1.25rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  outline: none;
  border-radius: 10px 10px 0 0;
}

.search-box__close {
  position: absolute;
  top: 0.7rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.search-results {
  overflow-y: auto;
  max-height: calc(72vh - 56px);
}

.search-status {
  padding: 0.5rem 1.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.search-results__empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

.search-results__item {
  display: block;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: background 0.15s;
}

.search-results__item:hover,
.search-results__item--focused { background: var(--bg-alt); }

.search-results__title {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}

.search-results__route {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.search-results__snippet {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.search-highlight {
  background: rgba(212, 68, 59, 0.25);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 0.1em;
}

/* --- Sidebar overlay (mobile) --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 49;
  background: var(--overlay-bg);
}

.sidebar-overlay--visible { display: block; }

/* --- Back to top --- */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 80;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px var(--shadow);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.back-to-top--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover { background: var(--primary-light); }

/* --- Prev / Next page nav --- */
.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.page-nav__link {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}

.page-nav__link:hover {
  background: var(--bg-alt);
}

.page-nav__link--next {
  text-align: right;
}

.page-nav__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.page-nav__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}


/* --- Footer --- */
.footer {
  margin-top: auto;
  background: var(--footer-bg);
  color: var(--footer-text);
  text-align: center;
  padding: 1.25rem;
  font-size: 0.82rem;
}

/* --- Toast notification --- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--primary);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  box-shadow: 0 4px 16px var(--shadow);
  pointer-events: none;
  max-width: min(90vw, 480px);
  text-align: center;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ===== Responsive ===== */

/* Large desktop */
@media (min-width: 1600px) {
  :root {
    --sidebar-width: 300px;
    --toc-width: 240px;
  }

  .content { padding: 2.5rem 4rem 4rem; }
}

/* Medium screens: hide TOC */
@media (max-width: 1200px) {
  .main { grid-template-columns: var(--sidebar-width) 1fr; }
  .toc { display: none; }
  .content { padding: 1.75rem 2.5rem 3rem; }
}

/* Tablet: collapsible sidebar */
@media (max-width: 960px) {
  .header__menu-btn { display: flex; }

  .main { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: calc(var(--header-height) + 1rem);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 16px var(--shadow);
  }

  .sidebar--open { transform: translateX(0); }

  .toc { display: none; }

  .content { padding: 1.5rem 2rem 3rem; }
  .content__inner { max-width: 100%; }

  .content h1 { font-size: 1.6rem; }
  .content h2 { font-size: 1.3rem; }

  .tabs__inner { padding: 0 0.75rem; }
  .tabs__link { font-size: 0.8rem; padding: 0 0.75rem; }
}

/* Mobile */
@media (max-width: 600px) {
  .content { padding: 1rem; }

  .content h1 { font-size: 1.4rem; }
  .content h2 { font-size: 1.15rem; }
  .content h3 { font-size: 1.05rem; }
  .content p { line-height: 1.6; }

  .content table { font-size: 0.75rem; }
  .content th, .content td { padding: 0.4em 0.5em; }

  .content > p:first-of-type img,
  .content h1 + p img {
    max-height: 250px;
  }

  .header__title { font-size: 0.9rem; }
  .header__inner { padding: 0 0.75rem; }

  .tabs__link { font-size: 0.75rem; padding: 0 0.5rem; }

  .sidebar { width: 260px; }
}
