:root {
    /* Color Palette - Premium Light Theme */
    --primary: #4F46E5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;

    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-secondary: #f1f5f9;
    --bg-tertiary: #e2e8f0;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;

    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;

    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Space Grotesk', sans-serif;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
    display: flex;
    flex-direction: column;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Layout */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header (Mandatory Layout) */
.header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 50;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 24px;
}

/* Branding Area */
.branding-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    /* Indigo Gradient */
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.app-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.2;
}

.app-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-name {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.75rem;
    color: #6366f1;
    /* Primaryish Color */
    letter-spacing: -0.5px;
}

.beta-badge {
    font-size: 0.65rem;
    background: #4f46e5;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.ai-badge {
    font-size: 0.65rem;
    background: #312e81;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.app-subtitle {
    font-size: 0.65rem;
    color: #64748b;
    /* Slate 500 */
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    text-decoration: none;
    margin-top: 2px;
    transition: color 0.2s;
}

.app-subtitle:hover {
    color: var(--primary);
}

.creator-credit strong {
    margin-left: 4px;
    font-weight: 700;
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.social-link {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: 50%;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-size: 1.1rem;
}

.social-link:hover {
    background: var(--text-primary);
    color: white;
    transform: translateY(-2px);
}

.donate-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(236, 72, 153, 0.2);
}

.donate-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(236, 72, 153, 0.3);
}

.lang-toggle {
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 6px;
}

.lang-toggle:hover {
    background: var(--bg-secondary);
    color: var(--primary);
}

/* Main Workspace */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--bg-tertiary);
}

/* Sidebar (Content Input) */
.sidebar {
    width: 350px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 1px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.content-input-area {
    flex: 1;
    border: none;
    resize: none;
    padding: 16px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-body);
    outline: none;
    line-height: 1.6;
}

.content-input-area:focus {
    background: white;
}

.action-bar {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    background: var(--bg-surface);
}

.primary-btn {
    flex: 1;
    background: var(--primary);
    color: white;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.secondary-btn {
    padding: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    cursor: pointer;
}



.secondary-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.icon-btn {
    flex: 1;
    padding: 6px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.icon-btn.active {
    background: var(--primary);
    color: white;
}

/* Canvas Area (Preview) */
.canvas-area {
    flex: 1;
    background: #e5e7eb;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    gap: 40px;
    scroll-behavior: smooth;
    position: relative;
}

/* Typeset Page */
.page-wrapper {
    position: relative;
    box-shadow: var(--shadow-lg);
    transition: transform 0.2s;
    margin-bottom: 50px;
    /* Space for outside marks */
}

/* CMYK Simulation Filter */
.cmyk-mode .page-container {
    filter: sepia(0.1) contrast(0.95) brightness(0.95) saturate(0.9);
    /* Approximation of ink absorption */
}

/* Crop Marks */
.crop-marks::before,
.crop-marks::after {
    content: '';
    position: absolute;
    background: #000;
    pointer-events: none;
    z-index: 5;
}

/* Vertical Marks */
/* Crop Marks (Professional Style) */
.crop-marks::before,
.crop-marks::after,
.crop-mark-tl-v,
.crop-mark-tl-h,
.crop-mark-tr-v,
.crop-mark-tr-h,
.crop-mark-bl-v,
.crop-mark-bl-h,
.crop-mark-br-v,
.crop-mark-br-h {
    content: '';
    position: absolute;
    background: #000;
    z-index: 10;
}

/* Vertical Crop Marks (Top/Bottom) */
.crop-mark-tl-v,
.crop-mark-tr-v {
    top: -15mm;
    height: 10mm;
    width: 0.25pt;
}

.crop-mark-bl-v,
.crop-mark-br-v {
    bottom: -15mm;
    height: 10mm;
    width: 0.25pt;
}

/* Horizontal Crop Marks (Left/Right) */
.crop-mark-tl-h,
.crop-mark-bl-h {
    left: -15mm;
    width: 10mm;
    height: 0.25pt;
}

.crop-mark-tr-h,
.crop-mark-br-h {
    right: -15mm;
    width: 10mm;
    height: 0.25pt;
}

/* Positioning Relative to Corners */
.crop-mark-tl-v {
    left: 0;
}

.crop-mark-tr-v {
    right: 0;
}

.crop-mark-bl-v {
    left: 0;
}

.crop-mark-br-v {
    right: 0;
}

.crop-mark-tl-h {
    top: 0;
}

.crop-mark-bl-h {
    bottom: 0;
}

.crop-mark-tr-h {
    top: 0;
}

.crop-mark-br-h {
    bottom: 0;
}

/* Bleed Guide */
.bleed-guide {
    position: absolute;
    top: calc(var(--bleed) * -1mm);
    left: calc(var(--bleed) * -1mm);
    right: calc(var(--bleed) * -1mm);
    bottom: calc(var(--bleed) * -1mm);
    border: 0.5pt solid cyan;
    /* Standard Bleed Color */
    z-index: 2;
    pointer-events: none;
}

.crop-mark-br-v {
    position: absolute;
    bottom: -10mm;
    right: 0;
    width: 1px;
    height: 7mm;
    background: #000;
}

.crop-mark-br-h {
    position: absolute;
    bottom: 0;
    right: -10mm;
    width: 7mm;
    height: 1px;
    background: #000;
}

/* Bleed Guide */
.bleed-guide {
    position: absolute;
    top: calc(var(--bleed) * -1mm);
    left: calc(var(--bleed) * -1mm);
    right: calc(var(--bleed) * -1mm);
    bottom: calc(var(--bleed) * -1mm);
    border: 1px dashed var(--danger);
    pointer-events: none;
    z-index: 4;
}

.bleed-label {
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 8px;
    color: var(--danger);
    text-transform: uppercase;
    white-space: nowrap;
}

.page-container {
    background: white;
    width: 210mm;
    /* A4 */
    height: 297mm;
    position: relative;
    overflow: visible;
    --bleed: 0;
}

.page-container-inner {
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding: 2.54cm;
    position: relative;
}

/* Content Typography */
.page-container-inner p {
    text-align: justify;
    text-justify: inter-word;
    margin-bottom: 1em;
}

.page-container-inner h1,
.page-container-inner h2,
.page-container-inner h3 {
    margin-bottom: 0.5em;
    margin-top: 1em;
    font-weight: 700;
    line-height: 1.2;
}



.page-container h1,
.page-container h2,
.page-container h3 {
    margin-bottom: 0.5em;
    margin-top: 1em;
    font-weight: 700;
    line-height: 1.2;
}

/* Page Number Positioning */
.page-number {
    position: absolute;
    font-size: 10pt;
    color: var(--text-tertiary);
    pointer-events: none;
    z-index: 10;
}

.page-number.pos-center {
    bottom: 10mm;
    left: 0;
    width: 100%;
    text-align: center;
}

.page-number.pos-left {
    bottom: 10mm;
    left: 10mm;
    text-align: left;
}

.page-number.pos-right {
    bottom: 10mm;
    right: 10mm;
    text-align: right;
}

.page-number.pos-top_left {
    top: 10mm;
    left: 10mm;
    text-align: left;
}

.page-number.pos-top_right {
    top: 10mm;
    right: 10mm;
    text-align: right;
}

/* Rulers */
.ruler-h,
.ruler-v {
    position: absolute;
    background: rgba(0, 0, 0, 0.05);
    /* Very subtle */
    z-index: 20;
    pointer-events: none;
    display: none;
}

.show-rulers .ruler-h {
    display: block;
}

.show-rulers .ruler-v {
    display: block;
}

/* Rulers (Classic Word Style) */
.ruler-h {
    top: -25px;
    left: 0;
    right: 0;
    height: 25px;
    background: #fff;
    border-bottom: 1px solid #aaa;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);

    /* Ticks: cm (tall), 5mm (medium), mm (short) */
    background-image:
        linear-gradient(90deg, #333 1px, transparent 1px),
        /* 1cm */
        linear-gradient(90deg, #999 1px, transparent 1px),
        /* 0.5cm */
        linear-gradient(90deg, #ccc 1px, transparent 1px);
    /* 1mm */

    background-size:
        10mm 100%,
        /* 1cm tick every 10mm */
        5mm 50%,
        /* 0.5cm tick every 5mm */
        1mm 25%;
    /* 1mm tick every 1mm */

    background-position:
        0 0,
        /* cm full height */
        0 bottom,
        /* 5mm at bottom */
        0 bottom;
    /* 1mm at bottom */

    background-repeat: repeat-x;
}

.ruler-v {
    top: 0;
    bottom: 0;
    left: -25px;
    width: 25px;
    background: #fff;
    border-right: 1px solid #aaa;
    box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);

    /* Vertical Ticks */
    background-image:
        linear-gradient(#333 1px, transparent 1px),
        /* 1cm */
        linear-gradient(#999 1px, transparent 1px),
        /* 0.5cm */
        linear-gradient(#ccc 1px, transparent 1px);
    /* 1mm */

    background-size:
        100% 10mm,
        50% 5mm,
        25% 1mm;

    background-position:
        0 0,
        right 0,
        right 0;

    background-repeat: repeat-y;
}

/* Registration Marks */
.reg-mark {
    position: absolute;
    width: 6mm;
    height: 6mm;
    border-radius: 50%;
    border: 0.5px solid #000;
    z-index: 5;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reg-mark::before,
.reg-mark::after {
    content: '';
    position: absolute;
    background: #000;
}

.reg-mark::before {
    width: 100%;
    height: 0.5px;
}

.reg-mark::after {
    width: 0.5px;
    height: 100%;
}

.reg-mark-top {
    top: 2mm;
    left: 50%;
    transform: translateX(-50%);
}

.reg-mark-bottom {
    bottom: 2mm;
    left: 50%;
    transform: translateX(-50%);
}

.reg-mark-left {
    top: 50%;
    left: 2mm;
    transform: translateY(-50%);
}

.reg-mark-right {
    top: 50%;
    right: 2mm;
    transform: translateY(-50%);
}

/* Color Bars */
.color-bar {
    position: absolute;
    top: 2mm;
    /* Top Slugs */
    right: 15mm;
    display: flex;
    gap: 0;
    z-index: 5;
    pointer-events: none;
}

.color-swatch {
    width: 4mm;
    height: 4mm;
    border: 0.5px solid rgba(0, 0, 0, 0.1);
}

/* Page Info (Slug) */
.page-info-slug {
    position: absolute;
    bottom: 2mm;
    left: 20mm;
    font-size: 6pt;
    font-family: monospace;
    color: #444;
    z-index: 50;
    white-space: nowrap;
    pointer-events: none;
}


/* Properties Panel */
.properties-panel {
    width: 300px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

/* Property Tabs */
.prop-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-body);
}

.prop-tab {
    flex: 1;
    padding: 12px 8px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    text-transform: uppercase;
}

.prop-tab:hover {
    color: var(--primary);
    background: var(--bg-surface);
}

.prop-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--bg-surface);
}

.prop-content {
    flex: 1;
    overflow-y: auto;
}

.prop-tab-content {
    display: none;
}

.prop-tab-content.active {
    display: block;
}

.prop-group {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.prop-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.prop-slider {
    flex: 1;
    accent-color: var(--primary);
}

.slider-value {
    font-size: 0.85rem;
    font-weight: 600;
    width: 40px;
    text-align: right;
    color: var(--text-primary);
}

.prop-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 8px;
}

.prop-select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    font-family: inherit;
    color: var(--text-primary);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    color: var(--primary);
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.loading-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Bottom Nav (Mobile Only) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    /* Desktop hidden */
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 8px 0;
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    color: var(--text-tertiary);
}

.bottom-nav-item i {
    font-size: 1.4rem;
}

.bottom-nav-item.active {
    color: var(--primary);
}

/* Donate Modal */
.donate-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.donate-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.donate-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
}

.donate-modal-content {
    position: relative;
    background: var(--bg-surface);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    overflow-y: auto;
}

.donate-modal.visible .donate-modal-content {
    transform: translateY(0);
}

.donate-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.donate-modal-close:hover {
    background: var(--danger);
    color: white;
}

.donate-section {
    margin: 20px 0;
    padding: 16px;
    background: var(--bg-body);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.crypto-address,
.wise-value {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    margin-top: 8px;
}

.crypto-address code,
.wise-value code {
    flex: 1;
    font-family: 'Monaco', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    word-break: break-all;
}

.copy-btn {
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
    color: var(--text-secondary);
}

.copy-btn:hover {
    background: var(--primary);
    color: white;
}

/* Utilities */
.hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .header {
        padding: 0 16px;
    }

    .header-content {
        gap: 12px;
    }

    .sidebar,
    .properties-panel {
        display: none;
    }

    /* Mobile simplified view */
    .bottom-nav {
        display: flex;
    }

    .header-actions .social-link {
        display: none;
    }

    /* Hide socials on mobile header if crowded */
    .creator-credit {
        display: none;
    }

    .canvas-area {
        padding: 20px;
    }

    .page-container {
        transform: scale(0.5);
        transform-origin: top center;
        margin-bottom: 0;
    }
}