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

/* Only media should be capped; don't blanket-cap every element */
img, video, iframe, canvas {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Long words wrap, but don't force it on layout containers */
p, li, span, code, h1, h2, h3 {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

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

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

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

.header-container h1 {
    margin: 0;
    padding-top: 40px;
    font-size: 1.8em;
    font-family: 'Playfair Display', serif;
    color: #ff4d4d;
    text-align: center;
    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);
}

.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-meal-image {
    display: block;
    margin: 0 auto 10px auto;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 8px rgba(255, 0, 0, 0.3);
    max-width: 100%;
}

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

/* ============================================================
   CODE BLOCKS — never overflow, always readable
   ============================================================ */
pre {
    background-color: #333333;
    color: #ff4d4d;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-family: 'Courier New', monospace;
    margin: 10px 0;
    max-width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

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

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

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

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

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

/* ============================================================
   BACK-TO-TOP BUTTON (text version)
   ============================================================ */
#backToTop {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 18px;
    background: #ff4d4d;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, background 0.2s ease;
    z-index: 1000;
    display: none;
}

#backToTop.show {
    display: block;
}

#backToTop:hover {
    background: #b30000;
    transform: translateY(-2px);
}

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

/* ============================================================
   RESPONSIVE — tablets & below (max 768px)
   ============================================================ */
@media (max-width: 768px) {
    .chapter {
        padding: 16px;
        max-width: 100%;
        margin: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    .header-container {
        text-align: center;
        padding: 15px;
    }

    .header-container h1 {
        font-size: 1.5em;
        padding-top: 20px;
    }

    .header-container p {
        font-size: 1em;
    }

    /* Keep reading text left/justified — centering hurts readability */
    .chapter-intro,
    .content {
        text-align: left;
        padding: 0;
        margin-bottom: 24px;
    }

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

    h2, h3 {
        font-size: 1.2em;
        text-align: left;
    }

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

    pre {
        font-size: 0.85em;
        width: 100%;
        margin: 12px 0;
        padding: 10px;
    }

    pre code {
        font-size: inherit;
    }

    ul, ol {
        padding-left: 24px;
        text-align: left;
    }

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

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

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

    .header-container p {
        font-size: 0.9em;
    }

    .chapter {
        padding: 12px;
    }

    .chapter-intro,
    .content {
        font-size: 0.95em;
    }

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

    .chapter-meal-image {
        width: 100px;
        height: 100px;
    }

    pre {
        font-size: 0.8em;
        padding: 8px;
    }

    .social-media {
        gap: 10px;
    }

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

    #backToTop {
        bottom: max(15px, env(safe-area-inset-bottom));
        right: max(15px, env(safe-area-inset-right));
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* ============================================================
   TOUCH DEVICES — larger, comfortable button with safe area
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
    #backToTop {
        padding: 14px 22px;
        font-size: 16px;
        bottom: max(20px, env(safe-area-inset-bottom));
        right: max(20px, env(safe-area-inset-right));
    }
}

/* ============================================================
   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;
    }
}