/* ============================================================
   BASE RESET & BODY
   ============================================================ */
body {
    margin: 0;
    font-family: 'Raleway', sans-serif;
    background-color: #121212;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
}

/* Prevent horizontal overflow globally */
* {
    max-width: 100%;
}

img, video, iframe, canvas {
    max-width: 100%;
    height: auto;
}

/* Ensure long words wrap */
p, li, span, div {
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

/* ============================================================
   CONTAINERS
   ============================================================ */
.header-container,
.chapter,
.content,
.footer,
header {
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

.header-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0 15px;
}

.header-container h1 {
    margin: 0;
    font-size: 2em;
    font-family: 'Playfair Display', serif;
    color: #42a5f5;
    word-wrap: break-word;
}

.header-container p {
    font-size: 1em;
    margin-top: 10px;
    color: #e0e0e0;
    word-wrap: break-word;
}

/* ============================================================
   CHAPTER LAYOUT
   ============================================================ */
.chapter {
    margin: 0 auto;
    padding: 20px;
    max-width: 1000px;
    background-color: #1a1a1a;
    border: 1px solid #444444;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    width: 100%;
    box-sizing: border-box;
}

.chapter-intro {
    text-align: justify;
    margin-bottom: 20px;
    color: #e0e0e0;
    padding: 0 15px;
    word-wrap: break-word;
}

.content {
    margin-bottom: 40px;
    text-align: justify;
    color: #e0e0e0;
    padding: 0 15px;
    word-wrap: break-word;
}

/* ============================================================
   IMAGES
   ============================================================ */
.chapter-dessert-image {
    display: block;
    margin: 0 auto;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 8px rgba(66, 165, 245, 0.3);
    margin-bottom: 10px;
    max-width: 100%;
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
h2, h3 {
    color: #42a5f5;
    margin-top: 20px;
    font-size: 1.4em;
    word-wrap: break-word;
}

/* ============================================================
   CODE BLOCKS
   ============================================================ */
pre {
    background-color: #2e2e2e;
    color: #42a5f5;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    margin-top: 10px;
    margin-bottom: 10px;
    max-width: 100%;
    word-wrap: break-word;
    white-space: pre-wrap;
}

code {
    font-family: 'Courier New', monospace;
    background-color: #2e2e2e;
    color: #42a5f5;
    padding: 2px 4px;
    border-radius: 3px;
    word-wrap: break-word;
    white-space: normal;
}

/* ============================================================
   FOOTER & HEADER
   ============================================================ */
.footer,
header {
    background-color: #1f1f1f;
    color: #e0e0e0;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    padding: 15px;
}

/* ============================================================
   SOCIAL MEDIA
   ============================================================ */
.social-media {
    margin-top: 10px;
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.social-icon {
    color: #42a5f5;
    font-size: 20px;
    margin: 0 10px;
    transition: transform 0.3s, color 0.3s;
    text-decoration: none;
}

.social-icon:hover {
    transform: scale(1.2);
    color: #1e88e5;
}

/* ============================================================
   BACK-TO-TOP BUTTON — text version "Top"
   ============================================================ */
#backToTop {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 14px 22px;
    background: #42a5f5;
    color: #121212;
    border: none;
    border-radius: 50px;               /* pill shape suits text */
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    font-family: 'Orbitron', 'Segoe UI', sans-serif;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 1px;
    box-shadow:
        0 0 10px rgba(66, 165, 245, 0.6),
        0 0 18px rgba(26, 133, 255, 0.4);
    pointer-events: none;              /* don't block clicks when hidden */
}

#backToTop.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#backToTop:hover {
    background: #1e88e5;
    box-shadow:
        0 0 12px rgba(30, 136, 229, 0.7),
        0 0 22px rgba(66, 165, 245, 0.6);
    transform: scale(1.08);
}

#backToTop:active {
    background: #10396a;
    color: #ffffff;
    transform: scale(0.92);
}

/* ============================================================
   TABLES
   ============================================================ */
table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    display: block;
    margin: 0 auto;
}

/* ============================================================
   RESPONSIVE — tablets & below (max 768px)
   ============================================================ */
@media (max-width: 768px) {
    body {
        align-items: center;
        justify-content: center;
    }

    .chapter {
        padding: 20px 15px;
        max-width: 95%;
        margin: 0 auto;
        border: 1px solid #444444;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .header-container {
        text-align: center;
        align-items: center;
    }

    .chapter-intro {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
        max-width: 100%;
    }

    .content {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    h2, h3 {
        font-size: 1.2em;
        text-align: center;
        width: 100%;
    }

    .header-container h1 {
        font-size: 1.5em;
        text-align: center;
    }

    .header-container p {
        font-size: 0.9em;
        text-align: center;
        max-width: 100%;
    }

    .chapter-dessert-image {
        width: 120px;
        height: 120px;
        margin: 0 auto 15px auto;
    }

    pre, code {
        font-size: 0.9em;
        text-align: left;
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    pre {
        text-align: left;
        width: calc(100% - 30px);
    }

    .social-icon {
        font-size: 18px;
        margin: 0 8px;
    }

    p, ul, ol {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
        width: 100%;
        max-width: 100%;
    }

    ul, ol {
        padding-left: 0;
        list-style-position: inside;
        display: inline-block;
        text-align: left;
    }

    li {
        text-align: left;
        margin-bottom: 5px;
    }
}

/* ============================================================
   RESPONSIVE — small phones (max 480px)
   ============================================================ */
@media (max-width: 480px) {
    .header-container h1 {
        font-size: 1.3em;
        text-align: center;
    }

    .header-container p {
        font-size: 0.85em;
        text-align: center;
    }

    .chapter-intro,
    .content {
        font-size: 0.95em;
        text-align: center;
        width: 100%;
    }

    .content p {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
    }

    h2, h3 {
        font-size: 1.1em;
        text-align: center;
    }

    .chapter-dessert-image {
        width: 100px;
        height: 100px;
        margin: 0 auto 10px auto;
    }

    .social-media {
        gap: 10px;
        justify-content: center;
    }

    .social-icon {
        font-size: 16px;
        margin: 0 5px;
    }

    .chapter > * {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
    }

    pre {
        text-align: left;
        margin: 10px auto;
        width: calc(100% - 20px);
    }

    #backToTop {
        bottom: 18px;
        right: 18px;
        padding: 12px 18px;
        font-size: 14px;
    }
}

/* ============================================================
   TOUCH DEVICES — larger tap target
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
    #backToTop {
        padding: 16px 24px;
        font-size: 16px;
    }
}

/* ============================================================
   DESKTOP — restore left-aligned reading layout (min 769px)
   ============================================================ */
@media (min-width: 769px) {
    .chapter-intro,
    .content {
        text-align: justify;
    }

    .content p,
    .chapter-intro p {
        text-align: justify;
    }

    h2, h3 {
        text-align: left;
    }

    ul, ol {
        text-align: left;
        list-style-position: outside;
        padding-left: 20px;
    }

    li {
        text-align: left;
    }
}