* {
    box-sizing: border-box;
}

:root {
    --caliper-line-width: 1px;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Source Sans Pro', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    user-select: none;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    /* Prevent pull-to-refresh and overscroll effects on mobile */
    overscroll-behavior-y: contain;
}

.header {
    background: linear-gradient(135deg, #8C1515 0%, #B83A3A 70%, #FFFFFF 100%);
    color: #FFFFFF;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    z-index: 2000;
    position: relative;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #FFFFFF;
}

.header-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: nowrap; /* Should ideally not wrap, adjust button sizes/text if it does */
    overflow-x: auto; /* Allow horizontal scrolling on small screens if controls overflow */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.btn {
    background: #53565A;
    color: #FFFFFF;
    border: 1px solid #4D4F53;
    padding: 7px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease-in-out;
    white-space: nowrap;
    flex-shrink: 0; /* Prevent buttons from shrinking excessively */
}
.btn:disabled {
    background: #BDBDBD;
    color: #757575;
    cursor: not-allowed;
    border-color: #9E9E9E;
}
.btn:hover:not(:disabled) {
    background: #4D4F53;
    border-color: #36383A;
}

.btn.action-red {
    background: #8C1515;
    border-color: #7A1212;
    color: #FFFFFF;
}
.btn.action-red:hover:not(:disabled) {
    background: #7A1212;
}

.btn.clear { background: #E0E0E0; color: #333333; border-color: #BDBDBD; }
.btn.clear:hover:not(:disabled) { background: #D4D4D4; }


.color-selector { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.color-option {
    width: 20px; height: 20px;
    border-radius: 50%; cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.3s, transform 0.2s;
}
.color-option:hover { transform: scale(1.1); }
.color-option.selected { border-color: #FFFFFF; }

.reference-controls { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
#referenceLabel { font-size: 12px; color: #FFFFFF; font-weight: 500; }
.reference-selector select {
    padding: 4px 6px;
    border-radius: 4px; border: 1px solid #BDBDBD;
    background: #FFFFFF; color: #333; font-size: 12px;
}
.reference-selector select:disabled { background: #F5F5F5; color: #9E9E9E; cursor: not-allowed; }
.reference-selector select option { background: #fff; color: #333; }

.info-button {
    background: #53565A; border: 1px solid #4D4F53; color: #FFFFFF;
    width: 26px; height: 26px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: bold; cursor: pointer; font-size: 14px;
    transition: background 0.2s ease-in-out;
    flex-shrink: 0;
}
.info-button:hover { background: #4D4F53; }

.workspace { position: relative; flex-grow: 1; overflow: hidden; background: #fff; }
.drop-zone {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 3px dashed #ddd; margin: 20px; border-radius: 12px; background: #fafafa;
    transition: all 0.3s;
}
.drop-zone.drag-over { border-color: #8C1515; background: #FFF0F0; }
.drop-zone.has-content { display: none; }
.drop-zone-content { text-align: center; }
.drop-zone h3 { margin: 0 0 15px 0; font-size: 24px; color: #333; }
.drop-zone p { margin: 5px 0; font-size: 16px; }
.paste-btn {
    background: #A94343; color: white; border: none; padding: 12px 24px;
    border-radius: 8px; cursor: pointer; font-size: 16px; margin-top: 20px;
    transition: background 0.3s;
}
.paste-btn:hover { background: #8C1515; }
.browse-files-btn { background: #53565A; color: white; border: none; margin-top: 10px; }
.browse-files-btn:hover { background: #4D4F53; }

.content-area { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: auto; padding: 20px; display: none; }
.content-area.has-content { display: block; }
.pasted-image { max-width: 100%; height: auto; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
.pasted-text { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.1); white-space: pre-wrap; font-family: monospace; line-height: 1.6; }
.clear-content {
    position: absolute; top: 10px; right: 10px; background: rgba(200, 0, 0, 0.7);
    color: white; border: none; padding: 6px 10px; border-radius: 4px;
    cursor: pointer; font-size: 12px; z-index: 1500; transition: background 0.3s;
}
.clear-content:hover { background: rgba(200, 0, 0, 1); }
.file-input { display: none; }

.caliper { position: absolute; pointer-events: none; z-index: 1000; touch-action: none; /* Prevent browser default touch actions on the caliper itself */}
.caliper-line {
    position: absolute; background: var(--caliper-color, black); pointer-events: auto;
    touch-action: none; /* Prevent browser default touch actions */
}
.caliper.is-reference-caliper .caliper-line.caliper-vertical {
    background-image: repeating-linear-gradient(transparent 0, transparent 4px, var(--caliper-color, black) 4px, var(--caliper-color, black) 8px);
    background-color: transparent !important;
}
.caliper.is-reference-caliper .caliper-line.caliper-horizontal {
    background-image: repeating-linear-gradient(to right, transparent 0, transparent 4px, var(--caliper-color, black) 4px, var(--caliper-color, black) 8px);
    background-color: transparent !important;
}
.caliper-vertical { width: var(--caliper-line-width); cursor: ew-resize; }
.caliper-horizontal { height: var(--caliper-line-width); cursor: move; }

.rhythm-extension-line { position: absolute; height: var(--caliper-line-width); background: var(--caliper-color, black); pointer-events: none; }
.rhythm-tick-mark { position: absolute; width: var(--caliper-line-width); background: var(--caliper-color, black); pointer-events: none; }
.caliper.is-reference-caliper .rhythm-extension-line,
.caliper.is-reference-caliper .rhythm-tick-mark {
     background-image: repeating-linear-gradient(to right, transparent 0, transparent 4px, var(--caliper-color, black) 4px, var(--caliper-color, black) 8px);
    background-color: transparent !important;
}

.caliper-handle {
    position: absolute; width: 12px; height: 12px; background: var(--caliper-color, black);
    cursor: grab; border-radius: 2px; transform: translate(-50%, -50%); pointer-events: auto;
    touch-action: none; /* Prevent browser default touch actions */
}
.caliper-handle:active { cursor: grabbing; }
.caliper-label {
    position: absolute; background: rgba(0, 0, 0, 0.85); color: white;
    padding: 3px 6px; border-radius: 4px; font-size: 11px; font-weight: bold;
    pointer-events: auto; white-space: pre; line-height: 1.3;
}

/* Modal Base */
.modal-overlay {
    display: none; position: fixed; z-index: 3000;
    left: 0; top: 0; width: 100%; height: 100%;
    overflow: auto; background-color: rgba(0,0,0,0.7);
    align-items: center; justify-content: center;
}
.modal-content-wrapper {
    background-color: #ffffff; margin: auto; padding: 20px 30px;
    border: none; width: 90%; max-width: 650px;
    border-radius: 8px; box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    position: relative; max-height: 90vh; overflow-y: auto;
}
.modal-close-button {
    color: #757575; position: absolute; top: 12px; right: 15px;
    font-size: 30px; font-weight: bold; cursor: pointer; line-height: 1;
}
.modal-close-button:hover, .modal-close-button:focus { color: #000000; text-decoration: none; }
.modal-title { margin-top: 0; font-size: 22px; margin-bottom: 15px;}
.modal-text-content p, .modal-text-content li { font-size: 14px; line-height: 1.6; color: #333; margin-bottom: 8px;}
.modal-text-content ul { padding-left: 20px; margin-bottom: 15px;}
.modal-text-content strong { font-weight: 600;}

/* Specific Modal Styles */
#instructionsModal .modal-title { color: #8C1515; }
#instructionsModal strong { color: #8C1515; }

.footer {
    background-color: #f0f0f0;
    color: #777777;
    text-align: center;
    padding: 8px 0;
    font-size: 0.8em;
    border-top: 1px solid #dddddd;
    width: 100%;
    flex-shrink: 0; /* Prevent footer from shrinking */
}
.footer a {
    color: #53565A;
    text-decoration: none;
}
.footer a:hover {
    text-decoration: underline;
    color: #8C1515;
}

.pdf-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 1600;
}

#pageIndicator {
    font-size: 14px;
    font-weight: bold;
    color: #333;
}
