/**
 * UYI Write - Base Styles
 * Reset, variables, and base typography
 */

:root {
    /* Brand palette (light + dark) */
    --color-core: #7c5cfa;
    --color-supporting-a: #e57373;
    --color-supporting-b: #4f7df3;
    --color-pop: #e53935;
    --brand-gradient: linear-gradient(90deg, #4f7df3 0%, #7c5cfa 48%, #e53935 100%);

    /* Color Palette – Dark theme */
    --bg-primary: #1a1b1b;
    --bg-secondary: #222324;
    --bg-tertiary: #2a2b2e;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --accent: #7c5cfa;
    --accent-hover: #9170fc;
    --info: #4f7df3;
    --border-color: #343536;
    --error: #d32f2f;
    --success: #388e3c;
    --warning: #e8b84a;
    
    /* Typography – Greycliff (style guide) */
    --font-brand: 'Greycliff CF', 'Greycliff', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: 'Greycliff CF', 'Greycliff', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-ui: 'Greycliff CF', 'Greycliff', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Spacing */
    --spacing-xs: 0.125rem;
    --spacing-sm: 0.375rem;
    --spacing-md: 0.5rem;
    --spacing-lg: 0.75rem;
    --spacing-xl: 1rem;
    
    /* Preferences: highlight and text selection opacity (1 = full, 0.01–1 from sliders) */
    --pref-highlight-opacity: 1;
    --pref-text-selector-opacity: 1;
    /* UI typography (dashboard / public pages; not used for layout on write.php) */
    --pref-ui-font-size: 16px;
    --pref-ui-font-family: var(--font-ui);
    /* Write page editor body only (set inline on write.php + preferences.js) */
    --pref-editor-font-size: 16px;
    --pref-editor-font-family: var(--font-body);

    /* Layout */
    --header-height: 40px;
    --studio-nav-height: 4.15rem;
    --sidebar-width: 160px;
    --sidebar-left-width: 140px;
    --sidebar-ai-control-width: 300px;
    --sidebar-collapsed-width: 50px;
    --editor-stats-height: 42px;
}

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

html {
    /* Root font size drives rem across the app (book cards, headings, etc.) */
    font-size: var(--pref-ui-font-size, 16px);
}

html, body {
    min-height: 100vh;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

body {
    font-family: var(--pref-ui-font-family, var(--font-ui));
    overflow-x: hidden;
}

/* write.php: font size/family prefs target the chapter editor only, not chrome (rem stays 16px on html) */
body.page-write {
    font-family: var(--font-ui);
}

a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--text-primary);
}

img {
    max-width: 100%;
    height: auto;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input, textarea, select {
    font-family: inherit;
    color: var(--text-primary);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Text Selection */
::selection {
    background-color: #000;
    color: #7c5cfa;
}

::-moz-selection {
    background-color: #000;
    color: #7c5cfa;
}

/* Light theme: softer selection (avoid harsh black-on-white) */
body.theme-light ::selection {
    background-color: rgba(124, 92, 250, 0.28);
    color: #303030;
}

body.theme-light ::-moz-selection {
    background-color: rgba(124, 92, 250, 0.28);
    color: #303030;
}

/* Light theme: invert logo (white-on-transparent → black-on-transparent for visibility) */
body.theme-light .uyi-logo {
    filter: invert(1) brightness(0.95);
}

/* Light theme (bg #ffffff, text #303030) */
body.theme-light {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #eeeeee;
    --text-primary: #303030;
    --text-secondary: #555555;
    --accent: #7c5cfa;
    --accent-hover: #6547e8;
    --info: #4f7df3;
    --border-color: #d0d0d0;
}
body.theme-light .ql-editor {
    background-color: #ffffff;
    color: #303030;
}
body.theme-light .ql-container.ql-snow {
    border-color: var(--border-color);
}
body.theme-light .ql-toolbar.ql-snow {
    border-color: var(--border-color);
    background: var(--bg-tertiary);
}

/* Theme toggle: smooth crossfade (View Transitions) or color interpolation (fallback) */
@media (prefers-reduced-motion: no-preference) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 0.55s;
        animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }
}

@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 0.001ms !important;
    }
}

/* Browsers without View Transitions API: interpolate common theme surfaces */
@media (prefers-reduced-motion: no-preference) {
    html.theme-color-transition,
    html.theme-color-transition body {
        transition: background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }

    html.theme-color-transition .header,
    html.theme-color-transition .main-content,
    html.theme-color-transition .modal-content {
        transition: background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Match layout.css: .sidebar-left / .sidebar-right override .sidebar transition */
    html.theme-color-transition .sidebar.sidebar-left {
        transition: transform 0.3s ease, left 0.3s ease, background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }

    html.theme-color-transition .sidebar.sidebar-right {
        transition: transform 0.3s ease, background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }

    html.theme-color-transition .sidebar:not(.sidebar-left):not(.sidebar-right) {
        transition: width 0.3s ease, left 0.3s ease, background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }

    html.theme-color-transition body.pref-hide-ui-while-typing .main-content {
        transition: margin 0.25s ease, min-height 0.25s ease, max-height 0.25s ease, background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }

    html.theme-color-transition .ProseMirror,
    html.theme-color-transition .ql-editor,
    html.theme-color-transition .ql-toolbar.ql-snow,
    html.theme-color-transition .ql-container.ql-snow {
        transition: background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1), color 0.45s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

