* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Hide any glitch text that might appear */
*:not(script):not(style) {
    text-rendering: optimizeLegibility;
}

:root {
    --primary: #0d47a1;
    --primary-light: #1565c0;
    --primary-dark: #002171;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --bg: #fafbfc;
    --surface: #ffffff;
    --border: #e5e7eb;
    --shadow: 0 4px 20px rgba(13, 71, 161, 0.08);
    --radius: 12px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.7;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent horizontal scroll on mobile */
    overflow-x: hidden;
}

.app-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== Top navigation ========== */
.topnav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
}

.topnav-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #fff;
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.02em;
    transition: opacity var(--transition);
}

.topnav-logo:hover {
    opacity: 0.9;
}

.topnav-logo-img {
    width: 36px;
    height: auto;
}

.topnav-menu {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-item {
    padding: 10px 16px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px;
    transition: background var(--transition), color var(--transition);
    position: relative;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.2);
    display: inline-block;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 16px;
    right: 16px;
    height: 2px;
    background: #fff;
    border-radius: 1px;
}

.topnav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #fff;
    /* Better touch target */
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.topnav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: var(--transition);
}

/* ========== Main content ========== */
.main-content {
    flex: 1;
    padding: 48px 48px 80px;
    max-width: 920px;
    margin: 0 auto;
    width: 100%;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.page {
    display: none;
    animation: fadeIn 0.4s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== Page header (above image) ========== */
.page-header {
    margin-bottom: 20px;
}

.page-header h1 {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 2.35rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.03em;
    margin-bottom: 6px;
}

.page-header .author {
    font-size: 1rem;
    color: var(--text-muted);
    font-style: italic;
    font-weight: 400;
}

.page-header .author + .page-hero,
.page-hero {
    margin-top: 0;
}

/* ========== Hero image ========== */
.page-hero {
    margin-bottom: 32px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.hero-image {
    display: block;
    width: 100%;
    max-height: 400px;
    object-fit: cover;
    object-position: center;
    /* Prevent image dragging on mobile */
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

/* ========== Content sections ========== */
.content-section {
    margin-bottom: 48px;
}

.content-section h2 {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 48px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--primary);
    letter-spacing: -0.02em;
}

.content-section:first-of-type h2 {
    margin-top: 0;
}

.content-section h3 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-top: 32px;
    margin-bottom: 14px;
}

.content-section p {
    margin-bottom: 16px;
    font-size: 1.05rem;
    line-height: 1.85;
    color: var(--text);
}

.content-section ul {
    margin-left: 24px;
    margin-bottom: 22px;
}

.content-section li {
    margin-bottom: 10px;
    font-size: 1.05rem;
    line-height: 1.85;
}

.content-section strong {
    color: var(--primary-dark);
    font-weight: 600;
}

.highlight {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    text-align: center;
    padding: 24px;
    background: linear-gradient(135deg, rgba(13, 71, 161, 0.08) 0%, rgba(21, 101, 192, 0.12) 100%);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    margin: 32px 0;
    letter-spacing: 0.08em;
}

/* ========== Speech examples & boxes ========== */
.speech-example {
    background: #f8fafc;
    border-left: 4px solid var(--primary);
    padding: 24px;
    margin: 28px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
    line-height: 1.85;
}

.speech-example p {
    margin-bottom: 14px;
}

.example-box {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 20px;
    margin: 20px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.95rem;
    line-height: 1.8;
    overflow-x: auto;
}

.example-box p {
    margin-bottom: 10px;
}

/* Operative clauses indentation */
.operative-example .op-indent-1 {
    margin-left: 24px;
    margin-bottom: 8px;
}

.operative-example .op-indent-2 {
    margin-left: 48px;
    margin-bottom: 8px;
}

.external-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition);
}

.external-link:hover {
    color: var(--primary-dark);
    border-bottom-color: var(--primary);
}

/* ========== Footer ========== */
.footer {
    margin-top: 56px;
    padding-top: 28px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer p {
    margin-bottom: 6px;
}

/* ========== Back to top ========== */
.back-to-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(13, 71, 161, 0.35);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity var(--transition), visibility var(--transition), transform var(--transition), background var(--transition);
    z-index: 50;
    -webkit-tap-highlight-color: transparent;
    /* Better touch target */
    min-width: 48px;
    min-height: 48px;
}

.back-to-top:hover {
    background: var(--primary-dark);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ========== Responsive ========== */

/* Tablet (iPad and similar) */
@media (max-width: 1024px) and (min-width: 768px) {
    .main-content {
        padding: 36px 32px 72px;
        max-width: 100%;
    }

    .page-header h1 {
        font-size: 2rem;
    }

    .content-section h2 {
        font-size: 1.6rem;
    }

    .hero-image {
        max-height: 350px;
    }

    .topnav {
        padding: 0 20px;
    }

    .nav-item {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
}

/* Mobile and small tablets */
@media (max-width: 900px) {
    .topnav {
        padding: 0 16px;
        height: 60px;
    }

    .topnav-logo {
        font-size: 1.1rem;
    }

    .topnav-logo-img {
        width: 32px;
    }

    .topnav-menu {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--primary-dark);
        flex-direction: column;
        padding: 12px 16px;
        gap: 2px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.2);
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
        transition: var(--transition);
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }

    .topnav-menu.open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    .topnav-menu .nav-item {
        width: 100%;
        text-align: left;
        padding: 16px;
        font-size: 1rem;
        border-radius: 8px;
        min-height: 48px; /* Better touch target */
        display: flex;
        align-items: center;
    }

    .topnav-toggle {
        display: flex;
    }

    .main-content {
        padding: 24px 16px 60px;
        max-width: 100%;
    }

    .page-header {
        margin-bottom: 16px;
    }

    .page-header h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }

    .page-header .author {
        font-size: 0.9rem;
    }

    .content-section {
        margin-bottom: 36px;
    }

    .content-section h2 {
        font-size: 1.4rem;
        margin-top: 36px;
        margin-bottom: 16px;
        padding-bottom: 8px;
    }

    .content-section h3 {
        font-size: 1.2rem;
        margin-top: 24px;
        margin-bottom: 12px;
    }

    .content-section p {
        font-size: 1rem;
        line-height: 1.75;
        margin-bottom: 14px;
    }

    .content-section ul {
        margin-left: 20px;
        margin-bottom: 18px;
    }

    .content-section li {
        font-size: 1rem;
        line-height: 1.75;
        margin-bottom: 8px;
    }

    .hero-image {
        max-height: 240px;
    }

    .speech-example,
    .example-box {
        padding: 18px;
        margin: 20px 0;
        font-size: 0.95rem;
    }

    .highlight {
        font-size: 1.1rem;
        padding: 20px 16px;
        margin: 24px 0;
    }

    .back-to-top {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
    }

    .footer {
        margin-top: 40px;
        padding-top: 24px;
        font-size: 0.85rem;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .topnav {
        padding: 0 12px;
        height: 56px;
    }

    .topnav-logo {
        font-size: 1rem;
        gap: 8px;
    }

    .topnav-logo-img {
        width: 28px;
    }

    .main-content {
        padding: 20px 12px 56px;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    .content-section h2 {
        font-size: 1.25rem;
    }

    .content-section h3 {
        font-size: 1.1rem;
    }

    .content-section p,
    .content-section li {
        font-size: 0.95rem;
    }

    .hero-image {
        max-height: 200px;
    }

    .speech-example,
    .example-box {
        padding: 14px;
        font-size: 0.9rem;
    }

    .highlight {
        font-size: 1rem;
        padding: 16px 12px;
    }

    .back-to-top {
        width: 44px;
        height: 44px;
        bottom: 12px;
        right: 12px;
    }

    /* Improve touch targets for links */
    .external-link {
        padding: 2px 0;
        min-height: 44px;
        display: inline-block;
    }

    .nav-item {
        min-height: 48px;
    }
}

/* Landscape phones */
@media (max-width: 900px) and (orientation: landscape) {
    .topnav {
        height: 56px;
    }

    .topnav-menu {
        top: 56px;
        max-height: calc(100vh - 56px);
    }

    .hero-image {
        max-height: 200px;
    }
}
