/* Font Face Declarations */
@font-face {
    font-family: 'Cormorant Garamond';
    src: url('fonts/CormorantGaramond-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Cormorant Garamond';
    src: url('fonts/CormorantGaramond-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Cormorant Garamond';
    src: url('fonts/CormorantGaramond-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Cutive Mono';
    src: url('fonts/CutiveMono-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

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

body {
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 400;
    background-color: #f8f9fa;
    color: rgb(51, 51, 51);
    line-height: 1.6;
    user-select: none;
    -moz-user-select: none;
    -khtml-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
    margin: 0;
    padding: 0;
    height: 100vh;
    max-height: 100vh;
    /* Allow pull-to-refresh on mobile while preventing unwanted scrolling */
    overscroll-behavior-y: auto;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: #fff;
    /* Prevent internal scrolling but allow pull-to-refresh on body */
    overscroll-behavior-y: contain;
height: 100vh;
    max-height: 100vh; /* Prevent overflow on mobile */
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    display: flex;
    gap: 2rem;
    justify-content: flex-start;
    align-items: center;
    padding: 1rem 0;
    z-index: 100;
    width: 56em;
    align-self: center;
    flex-wrap: wrap;
    padding-right: 40px;
}

/* Menu Toggle Button */
.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
    position: absolute;
    right: 0;
    top: 18px;
}

.menu-toggle span {
    width: 100%;
    height: 3px;
    background-color: #000;
    border-radius: 3px;
    transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.app-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #000;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.document-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.document-selector {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 400;
    background-color: #fff;
    width: 72px;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid #000;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 39px;
    background-color: #fff;
}

.btn-primary {
    background-color: #1a73e8;
    color: #fff;
}

.btn-primary:hover {
    background-color: #1557b0;
}

.btn-secondary {
    color: rgb(51, 51, 51);
    border: 1px solid #ddd;
}


.btn-tool {
    color: rgb(51, 51, 51);
    padding: 0.5rem;
    width: 39px;
    transition: all 0.2s ease;
}

.btn-tool:hover {
    background-color: #fbbddf;
}

.btn-tool:disabled {
    background-color: #f8f9fa;
    color: #999;
    border-color: #ddd;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-tool:disabled:hover {
    transform: none;
}

.btn-tool:disabled .strikethrough-icon {
    text-decoration-color: #999;
}

.btn-tool:disabled .tool-icon {
    color: #999;
}

.btn-tool.active {
    color: #000;
}



.tool-icon {
    font-weight: 600;
}

.strikethrough-icon {
    text-decoration: line-through;
    text-decoration-thickness: 1px;
    text-decoration-color: currentColor;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.override-input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    width: 200px;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 400;
}

.override-input:focus {
    outline: none;
    border-color: #fbbddf;
    box-shadow: 0 0 0 2px rgba(251, 189, 223, 0.3);
}

.override-input:disabled {
    background-color: #f8f9fa;
    color: rgb(51, 51, 51);
    cursor: not-allowed;
}

.override-input.active {
    border-color: #fbbddf;
    box-shadow: 0 0 0 2px rgba(251, 189, 223, 0.3);
}

/* Editor Container */
.editor-container {
    flex: 1;    
    padding: 2rem;
    min-height: 0; /* Allow flexbox to properly constrain height */
    display: flex;
    overflow: hidden;
    flex-direction: column;
}

.editor-wrapper {
    max-width: 56em;
    min-width: 56em;

    margin: 0 auto;
    background-color: #fff;
    background-image: none; /* Ensure no background on editor */
    /* border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */
    min-height: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%; /* Prevent overflow */
}

.editor {
    width: 100%;
    min-height: 100%;
    border: none;    
    padding: 1rem 2rem;
    outline: none;
    font-size: 16px;
    line-height: 1.8;
    color: rgb(51, 51, 51);
    background-color: #fff;
    background-image: none; /* Ensure no background on editor */
    overflow-y: auto;
    font-family: 'Cutive Mono', 'Courier New', 'Courier', monospace;
    cursor: text;
    white-space: pre-wrap;
    word-wrap: break-word;
    user-select: all;
    -moz-user-select: all;
    -khtml-user-select: all;
    -webkit-user-select: all;
    -o-user-select: all;
box-shadow: 0px 0px .4em 4px #fbbddf;
}

.editor:empty::before {
    content: attr(data-placeholder);
    color: #999;
    font-style: italic;
    pointer-events: none;
}

.editor.focused:empty::before,
.editor:focus:empty::before {
    display: none;
}

.editor:focus {
    outline: none;
}

/* Caret indicator */
.editor::after {
    content: '|';
    margin-left: -3px;
    color: #000;
    font-weight: 300;
    animation: blink 1s infinite;
    display: none;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Show caret when focused */
.editor.focused::after {
    display: inline !important;
}

/* Text Formatting */
.strikethrough {
    text-decoration: line-through;
    color: rgb(51, 51, 51);
}

.text-highlight {
    background-color: #fbbddf;
    border-radius: 0;
    padding: 0;
    box-shadow: 0 0 0 0px rgba(251, 189, 223, 0.3);
    animation: highlightPulse 2s ease-in-out infinite alternate;
}

@keyframes highlightPulse {
    0% { background-color: #fbbddf; }
    100% { background-color: #f9a8d4; }
}

::selection {
    box-shadow: 0 0 0 0px rgba(251, 189, 223, 0.3);
    background-color: #fbbddf;
    color: rgb(51, 51, 51);
}

/* Character spans - base style */
.char {
    display: inline;
    position: relative;
}

/* Character spans with overlay text */
.char.overlay-text {
    position: relative;
    display: inline;
}

.char.overlay-text .overlay-char::selection {
  background-color: transparent;
}

/* Overlay characters - positioned absolutely over original character */
.char.overlay-text .overlay-char {
    position: absolute;
    background-color: red;
    top: 0;
    left: 0;
    color: rgb(51, 51, 51);
    z-index: 10;
    pointer-events: none;  /* Allow clicks to pass through to original text */
    background-color: transparent;
}

/* When overlay text is struck through, apply strikethrough to overlay character too */
.strikethrough.overlay-text .overlay-char {
    text-decoration: line-through;
    text-decoration-color: rgb(51, 51, 51);
    text-decoration-thickness: 1.5px;
}
   


@media (max-width: 768px) {

    .app-header {
        width: 91%;
    }
.editor-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 100%;
}
.editor {
    width: 100%;
}
}
@media (max-width: 768px) {
    /* Use dvh (dynamic viewport height) for mobile to account for browser UI */
    /* Fallback to vh for browsers that don't support dvh */
    .app-container {
        min-height: 100vh; /* Fallback */
    }

    body {
        height: 100vh; /* Fallback */
        max-height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        /* Allow pull-to-refresh on mobile */
        overscroll-behavior-y: auto;
    }

    .override-input {
        width: 100%;
        margin-left: 0;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    .editor-container {
        min-height: 0; /* Ensure flexbox constraint on mobile */
        flex: 1 1 auto; /* Allow shrinking if needed */
    }

    .editor {
        font-size: 18px; /* Increased for better mobile readability */
    }

    .modal-content {
        width: 95%;
        margin: 1rem;
    }
}

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

    .editor {
        padding: 0.75rem;
        font-size: 20px; /* Increased for better mobile readability on small screens */
    }

    .modal-actions {
        flex-direction: column;
    }
}

.overlay-text {
    position: relative;
    vertical-align: baseline;
    line-height: inherit;
    /* Styles are now applied directly via JavaScript to match original text exactly */
}

/* Mobile-specific styles */
@media (max-width: 768px) {
    /* Prevent text transformation on mobile */
    .editor, .editor * {
        text-transform: none !important;
        font-variant: normal !important;
    }
    
    /* Ensure proper text casing on mobile */
    .editor {
        text-transform: none !important;
        font-variant: normal !important;
    }
}

/* Sliding Menu */
.sliding-menu {
    position: fixed;
    top: 0;
    right: -300px;
    width: 300px;
    height: 100vh;
    background-color: #fff;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
}

.sliding-menu.open {
    right: 0;
}

.menu-content {
    padding: 4rem 1.5rem 2rem;
    position: relative;
}

.menu-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 2rem;
    line-height: 1;
    color: rgb(51, 51, 51);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.menu-close:hover {
    background-color: #f8f9fa;
    color: #000;
}

.menu-close:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.menu-link {
    display: block;
    padding: 1rem;
    color: rgb(51, 51, 51);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: background-color 0.2s ease;
    border-radius: 4px;
}

.menu-link:hover {
    background-color: #f8f9fa;
}

.menu-divider {
    height: 1px;
    background-color: #e1e5e9;
    margin: 1rem 0;
}

.menu-section {
    margin-top: 1rem;
}

.menu-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 0.75rem;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.document-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.document-item {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-family: 'Cormorant Garamond', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.95rem;
    color: rgb(51, 51, 51);
}

.document-item:hover {
    background-color: #f8f9fa;
}

.document-item.active {
    background-color: #e3f2fd;
    color: #1a73e8;
    font-weight: 500;
}

.document-item-name {
    display: block;
    margin-bottom: 0.25rem;
}

.document-item-date {
    font-size: 0.8rem;
    color: #999;
}

.document-item.active .document-item-date {
    color: #1a73e8;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 999;
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Document Name Modal */
.document-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.document-modal.active {
    display: flex;
    opacity: 1;
}

.document-modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 400px;
    width: 90%;
    animation: modalSlideIn 0.3s ease;
}

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

.document-modal-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: rgb(51, 51, 51);
}

.document-modal-description {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.95rem;
    color: #666;
    margin-bottom: 1.25rem;
}

.document-name-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
    color: rgb(51, 51, 51);
    margin-bottom: 1.5rem;
    transition: border-color 0.2s ease;
}

.document-name-input:focus {
    outline: none;
    border-color: #fbbddf;
    box-shadow: 0 0 0 2px rgba(251, 189, 223, 0.3);
}

.document-modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.document-modal-actions .btn {
    min-width: 80px;
}

.btn-primary {
    background-color: #1a73e8;
    color: white;
    border: none;
}

.btn-primary:hover {
    background-color: #1557b0;
}

.btn-secondary {
    color: rgb(51, 51, 51);
    border: none;
}

.btn:hover {
    background-color: #fbbddf;
}

/* Responsive adjustments for menu */
@media (max-width: 768px) {
    .sliding-menu {
        width: 280px;
        right: -280px;
    }
    
    .menu-toggle {
        width: 28px;
        height: 28px;
    }
    
    .menu-content {
        padding: 3.5rem 1.25rem 2rem;
    }
}

/* Print styles - only show editor */
@media print {
    /* Hide everything except the editor */
    .app-header,
    .sliding-menu,
    .menu-overlay {
        display: none !important;
    }
body {

        background-color: #fff !important;
}


    /* Show only the editor container */
    .app-container {
        display: block !important;
        height: auto !important;
        background-color: #fff !important;
    }

    .editor-container {
        padding: 0 !important;
        overflow: visible !important;
    }

    .editor-wrapper {
        max-width: 100% !important;
        min-width: 100% !important;
        margin: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        height: auto !important;
    }

    .editor {
        padding: 1rem !important;
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
        page-break-inside: avoid !important;
    }

}
