*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    /* Define CSS variables for consistent colors */
    --color-primary-dark: #1e293b; /* Slate 900 */
    --color-text-body: #334155; /* Slate 700 */
    --color-text-light: #475569; /* Slate 600 */
    --color-background-light: #f8fafc; /* Slate 50 */
    --color-background-white: #ffffff;
    --color-border-light: #cbd5e1; /* Slate 300 */
    --color-line: #94a3b8; /* Slate 400 */
    --color-link: #3b82f6; /* Blue 500 */

    /* Component specific lightened colors, derived from README mermaid diagram */
    --color-frontend: #ffe0ff; /* Lightened #f9f */
    --color-api-gateway: #e0e0ff; /* Lightened #bbf */
    --color-backend: #ffe0ff; /* Lightened #fbf */
    --color-cdn: #e0ffe0; /* Lightened #afa */
    --color-load-balancer: #e0ffe0; /* Lightened #afa */
    --color-queue-system: #ffe0ff; /* Lightened #f9f */
    --color-tool-engine: #e0e0ff; /* Lightened #bbf */
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -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; /* Slightly increased for better readability */
    background-color: var(--color-background-light);
    color: var(--color-text-body);
    padding: 20px;
    -webkit-font-smoothing: antialiased; /* Smoother fonts */
    -moz-osx-font-smoothing: grayscale; /* Smoother fonts */
}

h1 {
    font-size: 2.5rem; /* Slightly larger */
    line-height: 1.1;
    margin-top: 0;
    margin-bottom: 0.75em;
    color: var(--color-primary-dark);
    text-align: center;
    letter-spacing: -0.025em; /* Slightly tighter for headings */
}

h2 {
    font-size: 1.875rem; /* Slightly larger */
    line-height: 1.25;
    margin-top: 2.5em; /* Increased margin */
    margin-bottom: 1em;
    color: var(--color-primary-dark);
    letter-spacing: -0.025em;
}

h3 {
    font-size: 1.5rem; /* Slightly larger */
    line-height: 1.3;
    margin-top: 1.75em; /* Increased margin */
    margin-bottom: 0.75em;
    color: var(--color-primary-dark);
}

p {
    margin-top: 0;
    margin-bottom: 1.25em; /* Slightly increased margin */
}

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

a:hover {
    text-decoration: underline;
}

ul {
    list-style: disc;
    margin-left: 20px;
    padding-left: 0;
    margin-bottom: 1.5em;
}

li {
    margin-bottom: 0.75em;
}

li strong {
    color: var(--color-primary-dark);
}

section {
    max-width: 1000px;
    margin: 60px auto; /* Vertical spacing between sections */
    padding: 0 20px; /* Horizontal padding for sections */
}

/* Adjust h2/h3 margins within sections to prevent double spacing at the top */
section h2:first-child,
section h3:first-child {
    margin-top: 0;
}

.project-overview-text {
    max-width: 800px;
    margin: 20px auto 40px auto;
    text-align: center;
    font-size: 1.25rem; /* Slightly larger */
    line-height: 1.8; /* Increased for better readability */
    color: var(--color-text-light);
}

/* Architecture Diagram Styles */
.architecture-diagram {
    display: flex;
    flex-direction: column;
    gap: 80px; /* Space between rows for vertical connections */
    max-width: 1200px;
    margin: 40px auto;
    padding: 20px;
    border-radius: 12px;
    background-color: var(--color-background-white);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.diagram-row {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 120px; /* Space between components in a row for horizontal connections */
    position: relative;
}

.component-box {
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    background-color: var(--color-background-white);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    width: 280px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 2;
    cursor: pointer;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; /* Base transition */
}

/* Focus state for accessibility */
.component-box:focus-visible {
    outline: 2px solid var(--color-link); /* Blue outline */
    outline-offset: 4px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.5); /* Blue shadow */
}

.component-box h3 {
    font-size: 1.25rem;
    margin-top: 0;
    margin-bottom: 0.5em;
    color: var(--color-primary-dark);
}

.component-box p {
    font-size: 0.9rem;
    margin-top: 0;
    margin-bottom: 0.25em;
    color: var(--color-text-light);
}

/* Specific Box Colors matching README mermaid diagram */
.component-box.frontend { background-color: var(--color-frontend); }
.component-box.api-gateway { background-color: var(--color-api-gateway); }
.component-box.backend { background-color: var(--color-backend); }
.component-box.cdn { background-color: var(--color-cdn); }
.component-box.load-balancer { background-color: var(--color-load-balancer); }
.component-box.queue-system { background-color: var(--color-queue-system); }
.component-box.tool-engine { background-color: var(--color-tool-engine); }

/* Connection Lines using pseudo-elements */
.component-box::before,
.component-box::after {
    content: '';
    position: absolute;
    background-color: var(--color-line);
    z-index: 1;
}

/* Horizontal connection (to the right) - uses ::after */
.component-box.has-right-connection::after {
    width: 120px; /* Matches the gap between boxes */
    height: 2px;
    top: 50%;
    right: -120px; /* Extends from the right edge into the gap */
    transform: translateY(-50%);
}

/* Vertical connection (downwards) - uses ::before */
.component-box.has-down-connection::before {
    width: 2px;
    height: 80px; /* Matches the gap between rows */
    bottom: -80px; /* Extends from the bottom edge into the gap */
    left: 50%;
    transform: translateX(-50%);
}

/*
    The 'has-left-connection' class is present in index.html for api-gateway and backend.
    However, the visual line from left is implicitly drawn by the 'has-right-connection'
    of the preceding component (e.g., Frontend's 'has-right-connection' draws to API Gateway).
    The previous CSS rule for 'has-left-connection' drawing a line was problematic as it
    would not apply if 'has-right-connection' was also present on the same element,
    and attempting to draw a line 'from' the box to the left duplicates the preceding box's 'to the right' line.
    Therefore, the explicit CSS rule for 'has-left-connection' drawing a line is removed.
    The semantic meaning of 'has-left-connection' is still valid in HTML for clarity.
*/


/* Responsive Adjustments */
@media (max-width: 1024px) {
    body {
        padding: 15px;
    }

    h1 {
        font-size: 2.25rem;
    }

    h2 {
        font-size: 1.625rem;
    }

    h3 {
        font-size: 1.3rem;
    }

    section {
        margin: 50px auto;
        padding: 0 15px;
    }

    .project-overview-text {
        font-size: 1.125rem;
        margin: 15px auto 30px auto;
    }

    .architecture-diagram {
        max-width: 900px;
        padding: 15px;
        gap: 60px; /* Reduced vertical gap */
    }

    .diagram-row {
        gap: 80px; /* Reduced horizontal gap */
    }

    .component-box {
        width: 240px;
        min-height: 110px;
        padding: 18px;
    }

    .component-box.has-right-connection::after {
        width: 80px; /* Matches new horizontal gap */
        right: -80px;
    }

    .component-box.has-down-connection::before {
        height: 60px; /* Matches new vertical gap */
        bottom: -60px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    section {
        margin: 40px auto;
        padding: 0 10px;
    }

    .project-overview-text {
        font-size: 1rem;
        margin: 10px auto 25px auto;
    }

    .architecture-diagram {
        max-width: 100%; /* Full width */
        padding: 10px;
        gap: 40px; /* Further reduced vertical gap */
        border-radius: 8px;
    }

    .diagram-row {
        flex-direction: column; /* Stack components vertically */
        align-items: center;
        gap: 40px; /* Vertical gap between stacked components in a row */
    }

    .component-box {
        width: 90%; /* Take more width */
        max-width: 300px; /* Max width for larger screens */
        min-height: 90px;
        padding: 15px;
    }

    .component-box h3 {
        font-size: 1.1rem;
    }

    .component-box p {
        font-size: 0.85rem;
    }

    /* Hide horizontal lines when components are stacked vertically */
    .component-box.has-right-connection::after {
        display: none;
    }

    /* Adjust vertical lines for stacked layout */
    .component-box.has-down-connection::before {
        height: 40px; /* Matches new vertical gap */
        bottom: -40px;
        left: 50%;
        transform: translateX(-50%);
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    h3 {
        font-size: 1.1rem;
    }

    body {
        padding: 8px;
    }

    section {
        margin: 30px auto;
        padding: 0 8px;
    }

    .project-overview-text {
        font-size: 0.95rem;
        margin: 8px auto 20px auto;
    }

    .architecture-diagram {
        padding: 8px;
        gap: 30px;
    }

    .diagram-row {
        gap: 30px;
    }

    .component-box {
        padding: 12px;
        min-height: 80px;
    }

    .component-box h3 {
        font-size: 1rem;
    }

    .component-box p {
        font-size: 0.8rem;
    }

    .component-box.has-down-connection::before {
        height: 30px;
        bottom: -30px;
    }
}