:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c222b;
  --surface-3: #242b35;
  --border: #2a313c;
  --border-strong: #3a424f;
  --fg: #e6edf3;
  --fg-muted: #9aa4b2;
  --fg-faint: #6e7681;
  --accent: #fb6a3a;
  --accent-soft: #fb6a3a22;
  --accent-hover: #ff7d50;
  --user-bubble: #2b3340;
  --link: #79c0ff;
  --sidebar-w: 280px;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
button { font-family: inherit; }

/* App shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}
.sidebar-collapsed .app { grid-template-columns: 1fr; }

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem 0.6rem 1rem;
  display: flex;
  flex-direction: column;
}
.sidebar-collapsed .sidebar { display: none; }

/* Floating hamburger — always reachable, even when sidebar is hidden. */
.sidebar-toggle-floating {
  position: fixed;
  top: 0.7rem;
  left: calc(var(--sidebar-w) - 2.5rem);
  width: 34px;
  height: 34px;
  z-index: 50;
  background: var(--surface-2);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: left 0.18s ease, color 0.15s, border-color 0.15s;
}
.sidebar-toggle-floating:hover { color: var(--fg); border-color: var(--border-strong); }
.sidebar-collapsed .sidebar-toggle-floating { left: 0.7rem; }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.4rem 0.5rem 0.9rem;
  padding-right: 2.8rem; /* leave room for the floating toggle */
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--fg);
  font-weight: 700;
  font-size: 1.15rem;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 0.92rem;
  font-weight: 500;
  margin: 0 0.1rem;
}
.sidebar-link:hover { background: var(--surface-2); text-decoration: none; }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-link.minor {
  font-weight: 400;
  color: var(--fg-muted);
  font-size: 0.88rem;
  padding: 0.35rem 0.75rem;
}
.sidebar-link.minor:hover { color: var(--fg); }
.sidebar-icon { font-size: 1rem; }

.sidebar-section {
  margin-top: 1.1rem;
  padding: 0 0.1rem;
}
.sidebar-label {
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--fg-faint);
  padding: 0 0.75rem 0.4rem;
}
.sidebar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 0.88rem;
}
.sidebar-row:hover { background: var(--surface-2); text-decoration: none; }
.sidebar-row-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.sidebar-row-meta {
  font-size: 0.72rem;
  color: var(--fg-faint);
  background: var(--surface-3);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 0.75rem 0;
  color: var(--fg-faint);
  font-size: 0.78rem;
}

/* Content area */
.content {
  overflow-y: auto;
  height: 100vh;
}

/* Chat home */
.chat-home {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.chat-home-empty { justify-content: center; }
.chat-home-active { justify-content: flex-end; }

.chat-welcome {
  text-align: center;
  padding: 2rem 0;
  flex: 0 0 auto;
}
.chat-welcome-title {
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0 0 0.6rem;
  background: linear-gradient(135deg, var(--fg) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.chat-welcome-sub {
  color: var(--fg-muted);
  font-size: 1rem;
  margin: 0 0 2.2rem;
  max-width: 580px;
  margin-left: auto;
  margin-right: auto;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem;
  max-width: 720px;
  margin: 0 auto;
}
.prompt-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.prompt-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-1px);
}
.prompt-icon { font-size: 1.1rem; }
.prompt-label { flex: 1; }

/* Chat thread */
.chat-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 2rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.chat-turn { display: flex; flex-direction: column; gap: 0.3rem; }
.chat-turn-role {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.chat-turn-content {
  font-size: 0.97rem;
  line-height: 1.65;
  white-space: pre-wrap;
}
.chat-turn-user .chat-turn-content {
  background: var(--user-bubble);
  padding: 0.85rem 1.1rem;
  border-radius: 18px 18px 4px 18px;
  align-self: flex-end;
  max-width: 80%;
}
.chat-turn-user { align-items: flex-end; }
.chat-turn-assistant .chat-turn-content { color: var(--fg); }
.chat-rendered { line-height: 1.7; }
.chat-rendered p { margin: 0.5rem 0; }
.chat-rendered p:first-child { margin-top: 0; }
.chat-rendered p:last-child { margin-bottom: 0; }
.chat-rendered ul, .chat-rendered ol {
  margin: 0.6rem 0;
  padding-left: 1.4rem;
}
.chat-rendered li { margin: 0.35rem 0; }
.chat-rendered strong { color: var(--fg); font-weight: 600; }
.chat-rendered em { color: var(--fg-muted); font-style: italic; }
.chat-rendered code {
  background: var(--surface-2);
  color: var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88em;
}
.chat-rendered a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.1s;
}
.chat-rendered a:hover { border-bottom-color: var(--link); }
.chat-rendered h1, .chat-rendered h2, .chat-rendered h3 {
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
  color: var(--fg);
}
.chat-rendered blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.1rem 0.8rem;
  margin: 0.6rem 0;
  color: var(--fg-muted);
}

.chat-steps {
  font-size: 0.82rem;
  color: var(--fg-muted);
  margin: 0.15rem 0 0.45rem;
}
.chat-steps summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg-muted);
}
.chat-steps summary::before {
  content: "✓";
  color: var(--accent);
  font-size: 0.85rem;
}
.chat-steps[open] summary { color: var(--fg); }
.chat-steps ul {
  list-style: none;
  padding: 0.45rem 0 0 1rem;
  margin: 0;
}
.chat-steps li {
  padding: 0.18rem 0;
  color: var(--fg-muted);
}

.chat-live-steps {
  list-style: none;
  padding: 0;
  margin: 0.15rem 0 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.chat-live-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
  padding: 0.3rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  animation: stepFadeIn 0.25s ease-out;
}
@keyframes stepFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.step-spinner {
  color: var(--accent);
  animation: stepPulse 1.4s ease-in-out infinite;
  font-size: 0.7rem;
}
@keyframes stepPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.chat-typing { display: inline-flex; gap: 4px; padding: 0.6rem 0.2rem; }
.chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--fg-muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Composer */
.composer-wrap {
  padding: 1rem 0 1.5rem;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer {
  position: relative;
  display: flex;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  padding: 0.4rem 0.4rem 0.4rem 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 0.97rem;
  font-family: inherit;
  resize: none;
  outline: none;
  padding: 0.7rem 0;
  line-height: 1.5;
  max-height: 200px;
}
.composer textarea::placeholder { color: var(--fg-faint); }
.composer-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  margin-bottom: 0.05rem;
}
.composer-send:hover:not(:disabled) { background: var(--accent-hover); }
.composer-send:disabled { background: var(--surface-3); color: var(--fg-faint); cursor: not-allowed; }
.composer-foot {
  text-align: center;
  font-size: 0.75rem;
  color: var(--fg-faint);
  margin-top: 0.55rem;
}

/* Page wrapper for non-chat pages */
.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}
.page-header { margin-bottom: 2rem; }
.page-header h1 { margin: 0 0 0.5rem; font-size: 2rem; }
.page-sub { color: var(--fg-muted); margin: 0; }
.page-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.6rem; align-items: center; }

/* Player + team hero blocks */
.player-hero, .team-hero {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.player-hero-text, .team-hero-text { flex: 1; min-width: 0; }
.player-hero h1, .team-hero h1 { margin: 0 0 0.5rem; font-size: 2rem; }
.player-headshot {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
}
.team-logo-hero {
  width: 110px;
  height: 110px;
  object-fit: contain;
  flex-shrink: 0;
}
.player-team-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.team-chip-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

/* Sidebar avatars (small) */
.sidebar-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-3);
  flex-shrink: 0;
}
.sidebar-avatar-logo {
  border-radius: 4px;
  object-fit: contain;
  background: transparent;
}
.sidebar-row {
  gap: 0.55rem;
}
.page-section { margin: 2.5rem 0; }
.page-section-title {
  font-size: 1.15rem;
  margin: 0 0 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}

/* Chips */
.chip {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.chip-muted {
  background: var(--surface-3);
  color: var(--fg-muted);
}
.chip-accent {
  background: var(--accent);
  color: white;
}

/* Entity grid (used on listing pages) */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.7rem;
}
.entity-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  color: var(--fg);
  transition: all 0.15s;
}
.entity-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
  text-decoration: none;
  transform: translateY(-1px);
}
.entity-card-name {
  font-weight: 600;
  font-size: 0.97rem;
}
.entity-card-meta {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.entity-card-rank {
  margin-top: auto;
  font-size: 0.78rem;
  color: var(--fg-faint);
}

/* Wiki rendered content */
.wiki-content {
  font-size: 0.97rem;
  line-height: 1.7;
}
.wiki-content h1,
.wiki-content h2,
.wiki-content h3 { color: var(--fg); margin-top: 1.8em; }
.wiki-content h1:first-child,
.wiki-content h2:first-child { margin-top: 0; }
.wiki-content h2 {
  font-size: 1.25rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.wiki-content h3 { font-size: 1.05rem; color: var(--fg-muted); }
.wiki-content ul, .wiki-content ol { padding-left: 1.4rem; }
.wiki-content li { margin: 0.3rem 0; }
.wiki-content p { margin: 0.7rem 0; }
.wiki-content code {
  background: var(--surface-2);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88em;
}
.wiki-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.8rem 0;
  padding: 0.2rem 1rem;
  color: var(--fg-muted);
}
.wiki-content a { color: var(--link); }
.wiki-content a:hover { text-decoration: underline; }
.dead-wikilink {
  color: var(--fg-muted);
  border-bottom: 1px dotted var(--border-strong);
  cursor: help;
}

/* Mobile */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 100;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
  }
  /* On mobile, default to collapsed (hidden) — script in layout adds class on small screens */
  .sidebar-toggle-floating { left: 0.7rem; }
  .chat-welcome-title { font-size: 1.7rem; }
  .prompt-grid { grid-template-columns: 1fr; }
  .page { padding: 1.5rem 1rem 3rem; }
}
