body {
  color: var(--text);
  font-family: var(--main-font);
  line-height: 1.5;
  margin: 0;
  background-color: var(--background);
  background-image: var(--background-image);
}

header {
  top: 0;
  margin: 0;
  position: sticky;
  width: 100%;
  padding: .75rem 0;
  box-sizing: border-box;
  border-bottom: 1px solid var(--borders);
  background-color: var(--background); /* Change from hardcoded white */
  -webkit-backdrop-filter: saturate(110%) blur(5px);
  backdrop-filter: saturate(110%) blur(5px);
}

/* Container to match main content width */
/* Header layout update */
.header-container {
  max-width: 765px;
  margin: 0 auto;
  padding: 0 1em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1em;
}

/* Dark mode toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--borders);
  border-radius: 4px;
  padding: 0.5em;
  cursor: pointer;
  color: var(--text);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  background-color: var(--primary);
  color: white;
}

/* Show/hide icons based on theme */
[data-theme="dark"] .sun-icon,
.moon-icon {
  display: none;
}

[data-theme="dark"] .moon-icon,
.sun-icon {
  display: block;
}

[data-theme="dark"] img[src*="/img/classes/"],
[data-theme="dark"] img[src*="/img/races/"] {
  filter: invert(1) brightness(0.9);
}

/* Transitions for smooth theme switching */
html.theme-transitioning * {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

/* Home icon styling */
header .home-icon {
  display: flex;
  align-items: center;
}

header .home-icon a {
  color: var(--text);
  text-decoration: none;
  font-size: 1.2em;
  font-weight: bold;
}

/* Menu on the right */
header nav {
  margin-left: auto;
}

header ul {
  padding: 0;
  margin: 0;
  display: flex;
  list-style: none;
}

header li {
  margin-left: 1em; /* Space between menu items */
}

header a {
  color: var(--text);
  text-decoration: none;
}

header a:hover {
  color: var(--primary);
}

header .home-icon {
  display: flex;
  align-items: center;
}

header .home-icon a {
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: color 0.3s ease;
}

header .home-icon a:hover {
  color: var(--primary);
}

header .home-icon svg {
  transition: transform 0.2s ease;
}

header .home-icon a:hover svg {
  transform: scale(1.1);
}

.toc {
  position: fixed;
  right: 2em;
  top: 7em;
  padding: 1em;
  border: 1px solid var(--borders);
  background-color: var(--table-bg);
  font-size: smaller;
  width: 150px; /* Add a specific width instead of relying on content */
  max-height: 70vh; /* Prevent it from getting too tall */
  overflow-y: auto; /* Add scrolling if content is too long */
}

.toc ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
  white-space: normal; /* Change from nowrap to normal */
  overflow: visible; /* Change from hidden */
  text-overflow: clip; /* Change from ellipsis */
}

.toc ul ul {
  padding-left: 1em;
}

.toc li {
  width: auto; /* Remove the fixed width constraint */
  text-overflow: clip; /* Remove ellipsis */
  margin-bottom: 0.25em; /* Add some spacing between items */
  line-height: 1.3; /* Improve readability */
}

.toc a {
  display: block; /* Make links fill the available space */
  word-wrap: break-word; /* Allow long words to wrap */
}

main {
  max-width: 765px;
  margin: auto;
  padding: 1em;
}

/* content images */
main img {
  max-width: 85%;
  margin: auto;
  display: block;
}

h1 {
  margin-bottom: 0;
  font-weight: normal;
}

h2,
h3,
h4 {
  border-bottom: 1px solid var(--accent);
  font-weight: normal;
  scroll-margin-top: 3em;
}

time {
  margin: 0;
  font-size: small;
}

a {
  color: var(--links);
  text-decoration: none;
}

/* tables */
table {
  border-collapse: collapse;
  background-color: var(--table-bg);
  width: 100%;
}

td,
th {
  border: 1px solid var(--borders);
  padding: 0.25em .75em;
}

th {
  background-color: var(--table-head-bg);
  border-bottom: #bbb solid;
}

blockquote {
  border: 1px solid #ddd;
  margin: 0;
  padding: 0 1em;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: .5em;
}

.badge {
  border-radius: 1.5em;
  padding: .25em 1em;
  font-size: small;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--borders);
  white-space: nowrap;
}

.badge:hover {
  background-color: var(--primary);
  color: white;
}

.badge img {
  fill: white;
}

.badgeimg {
  display: inline;
  height: 1em;
  margin: -.25em 0em;
}

.container {
  display: flex;
  gap: 1em;
  flex-wrap: wrap;
}

.profile {
  width: 96px;
  border-radius: 5px;
  border: 1px solid var(--borders);
  padding: .5em 1em;
  text-decoration: none;
  color: var(--text);
  text-align: center;
  background-color: var(--table-bg);
  line-height: normal;
  font-size: small;
}

.profileimg {
  margin: auto;
  margin-bottom: 0.5em;
  width: 75px;
  height: 75px;
  max-width: 100%;
  object-fit: cover;
}

.profile:hover {
  box-shadow: 2px 2px 10px var(--borders);
}

@media (max-width: 1100px) {
  main {
    margin-left: 0;
  }

  .toc {
    right: 0;
  }
}

@media (max-width: 950px) {
  main {
    max-width: 100%;
  }

  .toc {
    display: none;
  }
}

/* Character Sheet Styling */
.character-sheet {
  max-width: 100%;
}

.character-header {
  display: flex;
  gap: 2em;
  margin-bottom: 2em;
  align-items: flex-start;
}

.character-portrait {
  flex-shrink: 0;
}

.character-portrait img {
  width: 150px;
  height: 150px;
  max-width: none;  /* Override the 50% max-width */
  margin: 0;        /* Override the auto margin */
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--borders);
}

.character-info {
  flex-grow: 1;
}

.character-badges {
  margin-top: 1em;
}

/* Stats Grid */
.character-stats {
  margin-bottom: 2em;
  padding: 1em;
  background-color: var(--table-bg);
  border: 1px solid var(--borders);
  border-radius: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1em;
}

.stat-block {
  display: flex;
  flex-direction: column;
  text-align: center;
  padding: 0.5em;
  border: 1px solid var(--borders);
  border-radius: 4px;
  background-color: var(--table-bg);
}

.stat-block strong {
  font-size: 0.8em;
  color: var(--accent);
  margin-bottom: 0.25em;
}

.stat-block span {
  font-size: 1.2em;
  font-weight: bold;
}

/* Ability Scores */
.ability-scores {
  margin-bottom: 2em;
}

.abilities-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1em;
}

.ability-score {
  text-align: center;
  padding: 1em;
  border: 2px solid var(--borders);
  border-radius: 8px;
  background-color: var(--table-bg);
}

.ability-score strong {
  display: block;
  font-size: 0.8em;
  color: var(--accent);
  margin-bottom: 0.5em;
}

.ability-score .score {
  display: block;
  font-size: 1.5em;
  font-weight: bold;
  margin-bottom: 0.25em;
}

.ability-score .modifier {
  display: block;
  font-size: 0.9em;
  color: var(--text);
}

/* Features and Skills */
.character-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2em;
  margin-bottom: 2em;
}

.skills-list, .features-list {
  list-style: none;
  padding: 0;
}

.skills-list li, .features-list li {
  padding: 0.25em 0;
  border-bottom: 1px solid var(--borders);
}

/* Responsive design */
@media (max-width: 768px) {
  .character-header {
    flex-direction: column;
    text-align: center;
  }
  
  .abilities-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .character-features {
    grid-template-columns: 1fr;
  }
}

/* Campaign Cards */
.campaigns-grid {
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 2em;
}

.campaign-card {
  width: 45%;
  max-width: none;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  background-color: var(--table-bg);
  border: 2px solid var(--borders);
  transition: all 0.3s ease;
  text-align: left;
  line-height: 1.4;
}

.campaign-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  transform: translateY(-2px);
}

.campaign-img {
  width: 400px;
  height: 200px;
  margin: 0;
  border-radius: 0;
  border: none;
}

.campaign-card .card-content {
  padding: 1.5em;
}

.campaign-card h3 {
  margin: 0 0 1em 0;
  font-size: 1.3em;
  color: var(--text);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.5em;
}

.campaign-modes {
  margin-bottom: 1em;
}

.campaign-modes .badge {
  margin-right: 0.5em;
  font-size: 0.8em;
}

.campaign-summary {
  color: var(--text);
  font-size: 0.9em;
  line-height: 1.4;
  margin-bottom: 1em;
}

.session-count {
  font-size: 0.8em;
  color: var(--accent);
  font-style: italic;
  margin: 0;
  text-align: right;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .campaigns-grid {
    grid-template-columns: 1fr;
  }
}

/* Campaign page list styling */
.session-list, .character-list, .spell-list {
  list-style: none;
  padding-left: 0;
  margin-bottom: 2em;
}

.session-list li, .character-list li, .spell-list li {
  padding: 0.5em 0;
  border-bottom: 1px solid var(--borders);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-list li:last-child, 
.character-list li:last-child, 
.spell-list li:last-child {
  border-bottom: none;
}

.session-list a, .character-list a, .spell-list a {
  color: var(--links);
  text-decoration: none;
  font-weight: 500;
}

.session-list a:hover, .character-list a:hover, .spell-list a:hover {
  color: var(--primary);
}

/* Session Cards */
.sessions-grid {
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5em;
}

.session-card {
  width: 40%;
  max-width: none;
  padding: 1.5em;
  border-radius: 8px;
  background-color: var(--table-bg);
  border: 2px solid var(--borders);
  transition: all 0.3s ease;
  text-align: left;
  line-height: 1.4;
  /* min-height: 200px; */
  display: flex;
  flex-direction: column;
}

.session-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  transform: translateY(-2px);
}

.session-card .card-content {
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.session-card h3 {
  margin: 0 0 1em 0;
  font-size: 1.3em;
  color: var(--text);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.5em;
}

.session-date {
  font-size: 0.9em;
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 1em;
  display: block;
}

.session-campaigns {
  margin-bottom: 1em;
}

.session-campaigns .badge {
  margin-right: 0.5em;
  font-size: 0.8em;
}

.session-summary {
  color: var(--text);
  font-size: 0.9em;
  line-height: 1.4;
  margin: 0;
  flex: 1;
}

/* Mobile responsive for sessions */
@media (max-width: 768px) {
  .sessions-grid {
    grid-template-columns: 1fr;
  }
  
  .session-card {
    min-height: 150px;
  }
}