/* General Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Lato', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100vh;
    background-color: #f8f9fa;
    color: #333;
}

/* Sidebar Styling */
#sidebar {
    min-width: 250px;
    max-width: 250px;
    background: #2c3e50;
    color: #fff;
    transition: all 0.3s;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
}

#sidebar .sidebar-header {
    padding: 20px;
    background: #1a252f;
}

#sidebar .sidebar-header h3 {
    margin: 0;
    font-size: 1.3em;
    color: #fff;
}

#sidebar .sidebar-header p {
    margin: 5px 0 0 0;
    font-size: 0.9em;
    color: #bdc3c7;
}

#sidebar ul.components {
    padding: 20px 0;
    list-style: none;
    margin: 0;
}

#sidebar ul li {
    margin: 0;
}

#sidebar ul li a {
    padding: 10px 20px;
    font-size: 1em;
    display: block;
    color: #ecf0f1;
    text-decoration: none;
    transition: 0.2s;
}

#sidebar ul li a:hover, #sidebar ul li a.active {
    background: #34495e;
    border-left: 4px solid #18bc9c;
}

/* Language Toggle Button */
.lang-switch-container {
    padding: 20px;
    text-align: center;
}

#lang-toggle {
    background: #18bc9c;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9em;
    width: calc(100% - 40px);
}

#lang-toggle:hover {
    background: #128f76;
}

/* Mobile Menu Toggle Button */
#mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    background: #2c3e50;
    color: white;
    border: none;
    padding: 12px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2em;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#mobile-menu-toggle:hover {
    background: #34495e;
}

/* Content Area */
#content {
    margin-left: 250px;
    padding: 40px;
    width: 100%;
    max-width: 100%;
    line-height: 1.8;
    flex: 1;
}

/* Typography */
header {
    margin-bottom: 50px;
    border-bottom: 2px solid #ddd;
    padding-bottom: 20px;
}

h1 {
    font-family: 'Merriweather', serif;
    font-size: 2.5em;
    color: #2c3e50;
    margin: 0 0 10px 0;
    line-height: 1.2;
}

.author {
    font-size: 1.2em;
    color: #7f8c8d;
    font-style: italic;
}

h2 {
    font-family: 'Merriweather', serif;
    color: #2c3e50;
    border-bottom: 1px solid #ccc;
    padding-bottom: 10px;
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 2em;
}

h3 {
    font-family: 'Merriweather', serif;
    color: #18bc9c;
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 1.5em;
}

h4 {
    font-family: 'Merriweather', serif;
    color: #2c3e50;
    margin-top: 25px;
    margin-bottom: 12px;
    font-size: 1.25em;
}

/* Subsection and Section Headings */
.subsection-heading {
    color: #34495e;
    border-bottom: 1px dotted #bdc3c7;
    padding-bottom: 5px;
}

h3.section-heading {
    color: #18bc9c;
    border-bottom: 2px solid #18bc9c;
    padding-bottom: 8px;
    margin-top: 40px;
}

/* Footnotes Section */
.footnotes-section {
    margin: 20px 0 30px 0;
    padding: 20px;
    background: #f8f9fa;
    border-left: 3px solid #7f8c8d;
    border-radius: 0 5px 5px 0;
}

.footnote {
    font-size: 0.95em;
    margin-bottom: 12px;
    padding-left: 30px;
    text-indent: -30px;
    line-height: 1.6;
}

.footnote sup {
    color: #18bc9c;
    font-weight: bold;
    margin-right: 5px;
}

/* Superscript footnote links in text */
sup a.sdfootnoteanc,
a.sdfootnoteanc {
    color: #18bc9c;
    text-decoration: none;
    font-weight: bold;
}

sup a.sdfootnoteanc:hover {
    color: #128f76;
    text-decoration: underline;
}

/* References Section */
.references-section {
    margin: 20px 0 30px 0;
    padding: 20px;
    background: #eef2f5;
    border-left: 3px solid #3498db;
    border-radius: 0 5px 5px 0;
}

.reference {
    font-size: 0.95em;
    margin-bottom: 12px;
    padding-left: 30px;
    text-indent: -30px;
    line-height: 1.6;
}

.reference em {
    font-style: italic;
}

p {
    font-family: 'Merriweather', serif;
    font-size: 1.1em;
    margin-bottom: 1em;
}

li {
    font-family: 'Merriweather', serif;
    font-size: 1.1em;
}

blockquote {
    border-left: 4px solid #18bc9c;
    margin: 20px 0;
    padding: 15px;
    padding-left: 20px;
    font-style: italic;
    background: #eef2f5;
}

.biblio-list {
    list-style: none;
    padding-left: 0;
}

.biblio-list li {
    margin-bottom: 15px;
    padding-left: 20px;
    text-indent: -20px;
}

/* Chapter Display Logic */
.chapter {
    display: none;
    animation: fadeIn 0.5s;
}

.chapter.active-section {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Language Display Logic */
body.cy .lang-en {
    display: none !important;
}

body.cy .lang-cy {
    display: block !important;
}

body:not(.cy) .lang-cy {
    display: none !important;
}

/* Text Content Wrapper */
.text-content {
    max-width: 900px;
}

/* ================================================
   RESPONSIVE DESIGN - TABLET (768px - 1024px)
   ================================================ */

@media screen and (max-width: 1024px) {
    #content {
        padding: 30px 25px;
    }

    h1 {
        font-size: 2em;
    }

    h2 {
        font-size: 1.7em;
    }

    h3 {
        font-size: 1.3em;
    }

    p, li {
        font-size: 1em;
    }
}

/* ================================================
   RESPONSIVE DESIGN - MOBILE (max-width: 768px)
   ================================================ */

@media screen and (max-width: 768px) {
    body {
        flex-direction: column;
    }

    /* Hide sidebar by default on mobile */
    #sidebar {
        position: fixed;
        left: -250px;
        width: 250px;
        height: 100vh;
        transition: left 0.3s ease;
    }

    /* Show sidebar when active */
    #sidebar.active {
        left: 0;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }

    /* Show mobile menu button */
    #mobile-menu-toggle {
        display: block;
    }

    /* Adjust content area */
    #content {
        margin-left: 0;
        padding: 70px 20px 20px 20px;
        width: 100%;
    }

    /* Typography adjustments */
    h1 {
        font-size: 1.6em;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.4em;
    }

    h3 {
        font-size: 1.2em;
        margin-top: 20px;
    }

    p, li {
        font-size: 0.95em;
        line-height: 1.6;
    }

    header {
        margin-bottom: 30px;
        padding-bottom: 15px;
    }

    .author {
        font-size: 1em;
    }

    blockquote {
        padding: 10px;
        padding-left: 15px;
        margin: 15px 0;
        font-size: 0.9em;
    }

    /* Sidebar adjustments */
    #sidebar ul li a {
        font-size: 0.95em;
        padding: 12px 20px;
    }

    #sidebar .sidebar-header h3 {
        font-size: 1.2em;
    }

    #sidebar .sidebar-header p {
        font-size: 0.85em;
    }

    #lang-toggle {
        font-size: 0.85em;
        padding: 10px 15px;
    }
}

/* ================================================
   RESPONSIVE DESIGN - SMALL MOBILE (max-width: 480px)
   ================================================ */

@media screen and (max-width: 480px) {
    #content {
        padding: 60px 15px 15px 15px;
    }

    h1 {
        font-size: 1.4em;
    }

    h2 {
        font-size: 1.3em;
    }

    h3 {
        font-size: 1.1em;
    }

    p, li {
        font-size: 0.9em;
    }

    #mobile-menu-toggle {
        top: 10px;
        left: 10px;
        padding: 10px 12px;
        font-size: 1.1em;
    }

    #sidebar {
        width: 220px;
        left: -220px;
    }

    #sidebar.active {
        left: 0;
    }

    blockquote {
        font-size: 0.85em;
        padding: 8px;
        padding-left: 12px;
    }
}

/* ================================================
   PRINT STYLES
   ================================================ */

@media print {
    #sidebar {
        display: none;
    }

    #mobile-menu-toggle {
        display: none;
    }

    #content {
        margin-left: 0;
        padding: 0;
    }

    body {
        background: white;
    }

    .chapter {
        display: block !important;
        page-break-after: always;
    }

    /* Show both languages when printing */
    .lang-en, .lang-cy {
        display: block !important;
    }

    /* Add separator between languages */
    .lang-cy::before {
        content: "";
        display: block;
        border-top: 2px solid #ccc;
        margin: 40px 0 20px 0;
    }
}

/* ================================================
   ACCESSIBILITY IMPROVEMENTS
   ================================================ */

/* Focus styles for keyboard navigation */
a:focus, button:focus {
    outline: 2px solid #18bc9c;
    outline-offset: 2px;
}

/* Skip to content link for screen readers */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #18bc9c;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-content:focus {
    top: 0;
}

/* Improve contrast for better readability */
::selection {
    background: #18bc9c;
    color: white;
}

/* Reference Links */
a.internal-ref {
    color: #18bc9c;
    text-decoration: none;
    border-bottom: 1px dotted #18bc9c;
    transition: all 0.2s;
    cursor: pointer;
}

a.internal-ref:hover {
    color: #128f76;
    border-bottom: 1px solid #128f76;
    background: rgba(24, 188, 156, 0.1);
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 3px;
}

a.external-ref {
    color: #3498db;
    text-decoration: none;
    border-bottom: 1px dotted #3498db;
    word-break: break-all;
    transition: all 0.2s;
}

a.external-ref:hover {
    color: #2980b9;
    border-bottom: 1px solid #2980b9;
    background: rgba(52, 152, 219, 0.1);
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 3px;
}

/* External link icon */
a.external-ref::after {
    content: " ↗";
    font-size: 0.75em;
    vertical-align: super;
    opacity: 0.7;
}

/* Poetry table styling */
.poetry-table {
    width: 100%;
    max-width: 900px;
    margin: 2em 0 2em 3em;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
}

.poetry-table tr {
    border: none;
}

.poetry-table td {
    padding: 0.5em 1.5em;
    vertical-align: top;
    line-height: 1.6;
    border: none;
}

.poetry-table td.welsh-poetry {
    font-style: italic;
    color: #2c3e50;
    border-right: 2px solid #e0e0e0;
    width: 50%;
    padding-right: 2em;
    text-align: left;
}

.poetry-table td.welsh-poetry em {
    font-style: italic;
    display: block;
    margin-bottom: 0;
}

.poetry-table td.translation {
    color: #555;
    width: 50%;
    padding-left: 2em;
    text-align: left;
    font-style: normal;
}

/* For single-column poetry tables (Welsh only) */
.poetry-table td.welsh-poetry:only-child {
    border-right: none;
    width: 100%;
    text-align: left;
    padding-left: 2em;
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    #content {
        background-color: #1a1a1a;
    }

    h1, h2 {
        color: #e0e0e0;
    }

    blockquote {
        background: #2a2a2a;
        border-left-color: #18bc9c;
    }

    header {
        border-bottom-color: #444;
    }

    .poetry-table {
        background: #2a2a2a;
    }

    .poetry-table td.welsh-poetry {
        color: #e0e0e0;
    }

    .poetry-table td.translation {
        color: #b0b0b0;
    }

    .poetry-table tr {
        border-bottom-color: #444;
    }
}
