/* ============================================
   CSS Variables - Color Palette
   ============================================ */
:root {
    --color-primary: #2563eb;
    --color-secondary: #059669;
    --color-accent: #dc2626;
    --color-bg: #ffffff;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-border: #e5e7eb;
    --color-shadow: rgba(0, 0, 0, 0.1);
    --color-shadow-lg: rgba(0, 0, 0, 0.15);
}

/* ============================================
   Global Reset and Base Styles
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    font-size: clamp(16px, 2vw, 18px);
    line-height: 1.7;
    color: var(--color-text);
    background: var(--color-bg);
    overflow: hidden;
}

/* ============================================
   Page Container and Navigation
   ============================================ */
.page-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.page-container::-webkit-scrollbar {
    display: none;
}

.page {
    min-width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-content {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
    /* Add safe area padding for iOS devices (iPad/iPhone Safari) */
    padding-top: max(2rem, env(safe-area-inset-top));
}

.page-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    /* Extra top padding for iOS Safari to prevent header going under tab bar */
    padding-top: max(3rem, calc(env(safe-area-inset-top) + 1rem));
}

/* ============================================
   Typography
   ============================================ */
h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 1.5rem;
    color: var(--color-primary);
}

h2 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--color-text);
}

h3 {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    font-weight: 600;
    line-height: 1.4;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--color-text);
}

p {
    margin-bottom: 1rem;
}

ul, ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

li {
    margin-bottom: 0.5rem;
    line-height: 1.7;
}

strong {
    font-weight: 600;
    color: var(--color-primary);
}

em {
    font-style: italic;
    color: var(--color-text-light);
}

/* ============================================
   Illustrations
   ============================================ */
.illustration {
    margin: 2rem 0;
    text-align: center;
}

.illustration img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--color-shadow);
}

figcaption {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--color-text-light);
    font-style: italic;
}

/* ============================================
   Navigation Arrows
   ============================================ */
.nav-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--color-shadow);
}

.nav-arrow:hover {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

.nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-arrow:disabled:hover {
    background: var(--color-bg);
    color: var(--color-text);
    transform: translateY(-50%);
}

.nav-arrow-left {
    left: 1rem;
}

.nav-arrow-right {
    right: 1rem;
}

/* ============================================
   Page Indicators
   ============================================ */
.page-indicators {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.75rem 1rem;
    border-radius: 25px;
    box-shadow: 0 2px 8px var(--color-shadow);
}

.page-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.page-dot:hover {
    background: var(--color-text-light);
    transform: scale(1.2);
}

.page-dot.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    width: 30px;
    border-radius: 5px;
}

/* ============================================
   Page Number Display
   ============================================ */
.page-number {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    box-shadow: 0 2px 8px var(--color-shadow);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    pointer-events: none;
}

.page-number span {
    color: var(--color-primary);
}

/* ============================================
   Version Number Display
   ============================================ */
.version-number {
    position: fixed;
    bottom: 0.5rem;
    right: 0.5rem;
    z-index: 50;
    font-size: 0.7rem;
    color: var(--color-text-light);
    opacity: 0.5;
    font-family: monospace;
    pointer-events: none;
    user-select: none;
}

/* ============================================
   Chat Button
   ============================================ */
.chat-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 200;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--color-shadow-lg);
    transition: all 0.3s ease;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px var(--color-shadow-lg);
}

/* ============================================
   Chat Panel
   ============================================ */
.chat-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 16px var(--color-shadow-lg);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.chat-panel.open {
    right: 0;
}

.chat-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--color-primary);
}

.chat-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-close:hover {
    background: var(--color-border);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.chat-message.user {
    align-self: flex-end;
}

.chat-message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
}

.chat-message.user .message-content {
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .message-content {
    background: var(--color-border);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}

.chat-input-container {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 24px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--color-primary);
}

.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-send:hover {
    transform: scale(1.1);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-footer {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--color-border);
    text-align: center;
    color: var(--color-text-light);
}

/* Loading indicator */
.chat-loading {
    display: flex;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
}

.chat-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-light);
    animation: bounce 1.4s infinite ease-in-out both;
}

.chat-loading span:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-loading span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ============================================
   Responsive Design - Mobile
   ============================================ */
@media (max-width: 768px) {
    .page-inner {
        padding: 1rem 0.5rem;
        padding-top: max(2rem, calc(env(safe-area-inset-top) + 0.5rem));
    }

    .nav-arrow {
        width: 40px;
        height: 40px;
        top: 50vh; /* Use viewport height instead of percentage */
        transform: translateY(-50%);
    }

    .nav-arrow-left {
        left: 0.5rem;
    }

    .nav-arrow-right {
        right: 0.5rem;
    }

    /* Ensure hover doesn't break alignment on mobile */
    .nav-arrow:hover {
        transform: translateY(-50%) scale(1.1);
    }

    .page-indicators {
        bottom: 1rem;
        padding: 0.5rem 0.75rem;
    }

    .page-number {
        bottom: 3.5rem;
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }

    .page-dot {
        width: 8px;
        height: 8px;
    }

    .page-dot.active {
        width: 24px;
    }

    .chat-button {
        width: 50px;
        height: 50px;
        bottom: 1rem;
        right: 1rem;
    }

    .chat-panel {
        width: 100%;
        right: -100%;
    }

    .chat-panel.open {
        right: 0;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    h3 {
        font-size: 1.15rem;
    }

    .page-content {
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .chat-header {
        padding: 1rem;
    }

    .chat-messages {
        padding: 1rem;
    }
}

/* ============================================
   Article and Content Styling
   ============================================ */
.page-article {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

section {
    margin-bottom: 2rem;
}

/* Checkmarks and X marks */
.check {
    color: var(--color-secondary);
    font-weight: bold;
}

.cross {
    color: var(--color-accent);
    font-weight: bold;
}

/* ============================================
   Page Navigation Buttons
   ============================================ */
.page-navigation {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid var(--color-border);
}

.page-nav-btn {
    flex: 1;
    max-width: 200px;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    background: white;
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.page-nav-btn:hover:not(:disabled) {
    background: var(--color-primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--color-shadow-lg);
}

.page-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: var(--color-border);
    color: var(--color-text-light);
}

.page-nav-btn.prev-btn {
    margin-right: auto;
}

.page-nav-btn.next-btn {
    margin-left: auto;
}

/* Mobile optimization */
@media (max-width: 480px) {
    .page-navigation {
        flex-direction: column;
        gap: 0.75rem;
    }

    .page-nav-btn {
        max-width: 100%;
    }
}

/* ============================================
   Frontpage Styling
   ============================================ */
.frontpage {
    text-align: center;
}

.frontpage-content {
    max-width: 900px;
    margin: 0 auto;
}

.frontpage-header {
    margin-bottom: 3rem;
    padding: 2rem 0;
}

.frontpage-title {
    font-size: clamp(2.5rem, 6vw, 4rem);
    color: var(--color-primary);
    margin-bottom: 1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.frontpage-subtitle {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
    color: var(--color-text-light);
    font-weight: 400;
    font-style: italic;
}

.frontpage-intro {
    margin-bottom: 3rem;
    padding: 2rem;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--color-shadow);
}

.frontpage-text {
    font-size: clamp(1rem, 2vw, 1.15rem);
    line-height: 1.8;
    margin-bottom: 1.5rem;
    text-align: left;
}

.frontpage-list {
    text-align: left;
    font-size: clamp(1rem, 2vw, 1.15rem);
    line-height: 1.8;
    margin-left: 2rem;
    margin-bottom: 1.5rem;
}

.frontpage-list li {
    margin-bottom: 0.75rem;
}

.frontpage-welcome {
    margin-bottom: 3rem;
}

.frontpage-welcome h2 {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    color: var(--color-primary);
    margin-bottom: 1.5rem;
}

.frontpage-pillars {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.pillar {
    padding: 1.5rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--color-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.pillar:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px var(--color-shadow-lg);
}

.pillar-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.pillar h3 {
    font-size: 1.25rem;
    color: var(--color-primary);
    margin: 0.5rem 0;
}

.pillar p {
    font-size: 0.95rem;
    color: var(--color-text-light);
    margin: 0;
}

.frontpage-preparation {
    margin-bottom: 3rem;
    text-align: left;
}

.frontpage-preparation h2 {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    color: var(--color-primary);
    text-align: center;
    margin-bottom: 1.5rem;
}

.frontpage-promise {
    margin: 3rem 0;
}

.promise-box {
    padding: 2rem;
    background: linear-gradient(135deg, #dcfce7 0%, #d1fae5 100%);
    border-left: 4px solid var(--color-secondary);
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--color-shadow);
}

.promise-text {
    font-size: clamp(1.15rem, 2.5vw, 1.35rem);
    line-height: 1.7;
    color: var(--color-text);
    margin: 0;
    font-weight: 500;
}

.frontpage-start {
    margin-bottom: 2rem;
    text-align: left;
}

.frontpage-start h2 {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    color: var(--color-primary);
    text-align: center;
    margin-bottom: 1.5rem;
}

.next-btn-start {
    background: var(--color-primary);
    color: white;
    font-size: 1.1rem;
    padding: 1rem 2rem;
    max-width: 250px;
}

.next-btn-start:hover {
    background: #1e40af;
    transform: translateY(-2px) scale(1.05);
}

/* Frontpage responsive */
@media (max-width: 768px) {
    .frontpage-pillars {
        grid-template-columns: 1fr;
    }

    .frontpage-header {
        padding: 1rem 0;
    }

    .frontpage-intro {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .frontpage-title {
        font-size: 2rem;
    }

    .frontpage-subtitle {
        font-size: 1.1rem;
    }

    .pillar-icon {
        font-size: 2rem;
    }
}
