/* Root variables for color scheme */
:root {
    --primary-color: #003366; /* Navy blue */
    --secondary-color: #4A6FA5; /* Lighter blue */
    --primary-darker: #00264D; /* Darker navy */
    --white-color: #F0F4F8; /* Off-white */
    --black-color: #1A1A1A; /* Soft black */
    --light-blue: #7AA1D2; /* Light blue */
    --medium-blue: #C0D8F0; /* Medium light blue */
    --dark-blue: #1E3A5F; /* Dark blue */
}

/* Dark mode colors */
.dark {
    --primary-color: #4A6FA5; /* Lighter blue for dark mode */
    --secondary-color: #7AA1D2; /* Even lighter blue for dark mode */
    --primary-darker: #003366; /* Navy blue for dark mode */
    --white-color: #1A1A1A; /* Soft black for dark mode background */
    --black-color: #F0F4F8; /* Off-white for dark mode text */
    --light-blue: #003366; /* Navy blue for dark mode accents */
    --medium-blue: #1E3A5F; /* Dark blue for dark mode medium accents */
    --dark-blue: #C0D8F0; /* Medium light blue for dark mode dark accents */
}

/* Importing Lust font from Adobe Typekit */
@import url('https://use.typekit.net/frc3znr.css');

/* Global styles */
html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--white-color);
    color: var(--black-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

.container {
    width: 100%;
    margin: 0 auto;
    max-width: 1140px;
    padding: 0 10px;
}

/* Typography */
h1, h4, h5, h6, a {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    padding-left: 4px;
    padding-right: 4px;
}

h2, h3 {
    font-family: 'lust', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    margin-top: 0.7em;
    margin-bottom: 0.5em;
}

h2 {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--primary-color);
}

h3 {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--secondary-color);
}

p {
    margin-bottom: 1rem;
}

a {
    color: var(--primary-color);
    text-decoration: underline;
    font-weight: bold;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--secondary-color);
}

/* Header styles */
header {
    background: linear-gradient(to top, var(--secondary-color) -100%, var(--primary-color) 50%, var(--primary-darker) 150%);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    color: var(--white-color);
    transition: 0.3s;
    width: 100vw;
    max-width: 100vw;
    margin: 0;
    padding-left: 10%;
    padding-right: 10%;
    box-sizing: border-box;
    overflow-x: hidden;
}

#header-logo {
    max-height: 60px;
    width: 100%;
    object-fit: contain;
}

#book-title {
    font-family: 'lust', serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--white-color);
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
    line-height: 1.2;
}

header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--white-color);
}

header h2 {
    font-size: 1.25rem;
    color: var(--medium-blue);
    margin-top: 0.5rem;
}

header p {
    font-size: 0.875rem;
    color: var(--white-color);
    margin-top: 0.5rem;
}

/* Navigation styles */
.navbar {
    padding: 10px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.navbar img {
    margin-right: auto;
    max-width: 80%;
}

.navbar a {
    color: var(--white-color);
    text-decoration: none;
    text-transform: none;
    transition: color 0.3s ease;
    font-size: calc(0.6em + 1vw);
}

.navbar a:hover,
.navbar a.active {
    color: var(--light-blue);
}

/* Chapter list styles */
#chapter-list {
    list-style-type: none;
    padding: 0;
}

#chapter-list li {
    margin-bottom: 0.5rem;
}

#chapter-list a {
    display: block;
    padding: 0.3rem;
    color: var(--primary-color);
    text-decoration: none;
    border-radius: 0.25rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#chapter-list a:hover,
#chapter-list a.active {
    background-color: var(--primary-color);
    color: var(--white-color);
}

#chapter-list a.active {
    font-weight: bold;
}

#chapter-list h3 {
    border-bottom: 1px solid var(--medium-blue);
    padding-bottom: 0.5rem;
    margin-top: 1.5rem;
}

#chapter-list li {
    margin-left: 1rem;
}

/* Button styles */
button {
    font-family: 'lust', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    background-color: var(--primary-color);
    color: var(--white-color);
    border: none;
    padding: 10px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    transition-duration: 0.4s;
    cursor: pointer;
}

button:hover {
    background-color: var(--secondary-color);
    color: var(--white-color);
}

/* Form styles */
#search-input {
    width: 90%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--medium-blue);
    border-radius: 0.375rem;
    background: var(--white-color);
    color: var(--black-color);
}

#search-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-color);
}

input[type="text"],
input[type="email"],
input[type="tel"] {
    background: var(--white-color);
    border: 1px solid var(--medium-blue);
    padding: 10px;
    margin: 5px 0;
    color: var(--black-color);
    border-radius: 0.375rem;
}

input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--medium-blue);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    position: relative;
    vertical-align: middle;
    margin-right: 8px;
}

input[type="checkbox"]:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::before {
    content: '\2714';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--white-color);
    font-size: 14px;
}

input[type="checkbox"]:focus {
    box-shadow: 0 0 0 2px rgba(0, 51, 102, 0.3);
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 1em;
}

/* List styles */
ul, ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

ul li, ol li {
    margin-bottom: 10px;
}

ul.no-bullets {
    list-style-type: none;
    padding-right: 10px;
    margin: 0;
}

/* Section styles */
section {
    padding: 60px 0;
}

/* Markdown content styles */
.markdown-content {
    font-size: 1rem;
    line-height: 1.5;
    max-width: none;
    color: var(--black-color);
}

#markdown-content h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

#markdown-content h2 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--primary-color);
}

#markdown-content h3 {
    font-size: 1.6rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--secondary-color);
}

#markdown-content h4 {
    font-size: 1.4rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--secondary-color);
}

#markdown-content h5 {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

#markdown-content h6 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

#markdown-content p {
    font-size: 1rem;
    margin-bottom: 1rem;
}

#markdown-content a {
    color: var(--primary-color);
}

#markdown-content ul, #markdown-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
    list-style-type: disc;
    padding-left: 1rem;
}

#markdown-content li {
    margin-bottom: 0.5rem;
}

#markdown-content pre {
    padding: 1rem;
    border-radius: 0.375rem;
    overflow-x: auto;
    margin-bottom: 1rem;
    background-color: var(--medium-blue);
}

#markdown-content code {
    background-color: var(--medium-blue);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    color: var(--primary-darker);
}

/* Footer styles */
footer {
    background: var(--primary-darker);
    color: var(--white-color);
    padding: 20px 0;
}

.footer a {
    color: var(--light-blue);
    padding: 0 20px;
    text-decoration: none;
    text-transform: none;
    transition: color 0.3s ease;
    font-size: 1rem;
}

.footer a:hover,
.footer a.active {
    color: var(--white-color);
}

.footer li:after {
    content: " •";
    padding-right: 10px;
}

/* Table of Contents sidebar */
#toc-sidebar {
    font-size: 1rem;
}

#toc-sidebar h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding-top: 0.25rem;
    color: var(--primary-color);
}

#toc-sidebar ul {
    list-style-type: none;
    padding: 0;
}

#toc-sidebar li {
    margin-bottom: 0.25rem;
}

#toc-sidebar a {
    color: var(--secondary-color);
}

#toc-sidebar a:hover {
    color: var(--primary-darker);
    text-decoration: underline;
}

#toc-sidebar .toc-level-2 {
    margin-left: 0;
}

#toc-sidebar .toc-level-3 {
    margin-left: 1rem;
}

#toc-sidebar .active {
    font-weight: 700;
    color: var(--primary-darker);
}

/* Back to top button */
.back-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--primary-color);
    color: var(--white-color);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 24px;
    cursor: pointer;
    transition: opacity 0.3s, background-color 0.3s;
    opacity: 1;
}

.back-to-top:hover {
    background-color: var(--secondary-color);
}

.back-to-top.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Custom scrollbar styles */
::-webkit-scrollbar {
    width: 0.5rem;
}

::-webkit-scrollbar-track {
    background-color: var(--medium-blue);
}

::-webkit-scrollbar-thumb {
    background-color: var(--secondary-color);
    border-radius: 0.25rem;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--primary-color);
}

/* Responsive design */
@media (min-width: 600px) {
    .navbar {
        justify-content: flex-start;
    }
    .navbar a {
        padding-right: 1em;
    }
}

@media (max-width: 640px) {
    header {
      padding: 1rem;
    }
  
    #book-title {
      font-size: 1.8rem;
      line-height: 1.2;
    }
  
    #header-logo {
      max-height: 40px;
    }
  }
  

@media (min-width: 640px) {
    .markdown-content {
        font-size: 1.125rem;
    }
}

@media (min-width: 1024px) {
    .markdown-content {
        font-size: 1.25rem;
    }
}

@media (max-width: 1023px) {
    #chapter-toggle, .toc-toggle {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
        box-sizing: border-box;
    }
}

@media (max-width: 1023px) {
    .container {
        flex-direction: column;
    }

    #left-sidebar, #right-sidebar {
        width: 100%;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 1rem;
    }
    
    #markdown-content {
        width: 100%;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 1rem;
    }
}

@media (min-width: 1280px) {
    .markdown-content {
        font-size: 1.5rem;
    }
}

@media (max-width: 640px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    button, input[type="text"], input[type="email"], input[type="tel"] {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    #chapter-list a, #toc-sidebar a, button {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
    }

    input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }
}
  

  @media (max-width: 800px) {
    .container {
      flex-direction: column;
    }
  
    #left-sidebar, #right-sidebar {
      width: 80%;
      margin-left: auto;
      margin-right: auto;
      margin-bottom: 1rem;
    }
    
    #markdown-content {
      width: 80%;
      margin-left: auto;
      margin-right: auto;
      margin-bottom: 1rem;
    }
  }
    

/* Print styles */
@media print {
    .no-print {
        display: none;
    }
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

#chapter-toggle, .toc-toggle {
    display: none;
}

@media (max-width: 1023px) {
    #chapter-toggle, .toc-toggle {
        display: block;
    }
}

#chapter-sidebar, #toc-sidebar {
    transition: all 0.3s ease-in-out;
}

/* Light/Dark mode toggle */
.dark .dot {
    transform: translateX(100%);
}

.dark body {
    background-color: var(--white-color);
    color: var(--black-color);
}

.dark header {
    background: linear-gradient(to top, var(--secondary-color) -100%, var(--primary-color) 50%, var(--primary-darker) 150%);
}

.dark #markdown-content {
    background-color: var(--white-color);
    color: var(--black-color);
}

.dark #toc-sidebar, .dark #chapter-sidebar, .dark #right-sidebar {
    background-color: var(--white-color);
    color: var(--black-color);
}

.dark input[type="text"], .dark input[type="email"], .dark input[type="tel"] {
    background-color: var(--medium-blue);
    color: var(--black-color);
    border-color: var(--secondary-color);
}

.dark button {
    background-color: var(--primary-color);
    color: var(--white-color);
}

.dark button:hover {
    background-color: var(--secondary-color);
}

.dark a {
    color: var(--primary-color);
}

.dark a:hover {
    color: var(--secondary-color);
}

.dark a:active {
    color: var(--secondary-color);
}

/* Transition for smooth theme switching */
body, header, #markdown-content, #toc-sidebar, #chapter-sidebar, input, button, a {
    transition: background-color 0.3s ease, color 0.3s ease;
    border: none;
}

@media (max-width: 1023px) {
    .order-first {
        order: -1;
    }
    .lg\:order-last {
        order: 1;
    }
}
