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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
}

.screen {
    display: none;
    height: 100vh;
    height: 100dvh; /* برای موبایل */
    flex-direction: column;
    overflow: hidden;
}

.screen.active {
    display: flex;
}

/* صفحه بارگذاری */
#loading {
    justify-content: center;
    align-items: center;
    background: #fff;
}

.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* صفحه اصلی (آدرس بدون پارامتر) */
#home {
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #2c3e50 0%, #3498db 100%);
    color: #fff;
}
.home-content {
    text-align: center;
    padding: 2rem;
    max-width: 320px;
}
.home-content h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}
.home-content p {
    margin-bottom: 0.75rem;
    line-height: 1.6;
}
.home-content .home-hint {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* هدر */
.header {
    background: #2c3e50;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 100;
}

.header h2 {
    font-size: 16px;
    font-weight: 500;
    flex: 1;
    text-align: center;
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    gap: 5px;
    align-items: center;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.1);
}

#rotateBtn {
    transition: transform 0.3s ease;
}

#rotateBtn:hover {
    transform: rotate(90deg);
}

/* کانتینر کتاب */
.book-container {
    flex: 1;
    overflow: auto;
    background: #e8e8e8;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px;
    position: relative;
    touch-action: pan-x pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
}

.page-wrapper {
    position: relative;
    max-width: 100%;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    margin: auto;
    overflow: visible;
    touch-action: none;
}

#annotations {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#pageImage {
    max-width: 100%;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.1s;
    touch-action: none;
    transform-origin: center center;
}

/* کنترل‌ها */
.controls {
    background: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
    z-index: 100;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0; /* اجازه فشرده شدن */
}

.btn-control {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-control:hover {
    background: #2980b9;
}

.btn-control:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.page-info-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0; /* اجازه فشرده شدن */
    overflow: hidden;
}

.page-info {
    font-size: 16px;
    font-weight: 500;
    color: #2c3e50;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background 0.2s;
    white-space: nowrap;
}

.page-info:hover {
    background: #ecf0f1;
}

.tool-checkbox {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    border-radius: 8px;
    background: #ecf0f1;
    border: 2px solid #bdc3c7;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    flex-shrink: 0;
}

.tool-checkbox:hover {
    background: #d5dbdb;
    border-color: #95a5a6;
}

.tool-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.tool-checkbox span {
    font-size: 20px;
    color: #7f8c8d;
    transition: all 0.2s;
}

.tool-checkbox input[type="checkbox"]:checked + span {
    color: #27ae60;
    font-weight: bold;
}

.tool-checkbox:has(input[type="checkbox"]:checked) {
    background: #d5f4e6;
    border-color: #27ae60;
}

.toolbar-inline {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.toolbar-inline::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.toolbar-inline .tool-btn {
    width: 35px;
    height: 35px;
    font-size: 18px;
    flex-shrink: 0;
}

/* نوار ابزار */
.toolbar {
    background: white;
    padding: 10px;
    display: flex;
    justify-content: center;
    gap: 15px;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
    flex-shrink: 0; /* جلوگیری از کوچک شدن در rotate */
}

.tool-btn {
    background: #ecf0f1;
    border: none;
    font-size: 24px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #bdc3c7;
    transform: scale(1.1);
}

.tool-btn.active {
    background: #3498db;
    color: white;
}

/* منوی کناری */
.sidebar {
    position: fixed;
    right: -300px;
    top: 0;
    width: 300px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
    transition: right 0.3s;
    z-index: 1000;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    background: #2c3e50;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-content {
    padding: 20px;
}

.sidebar-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background: #ecf0f1;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: right;
    font-size: 14px;
    transition: background 0.2s;
}

.sidebar-btn:hover {
    background: #bdc3c7;
}

/* مودال */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: auto;
}

.modal-header {
    padding: 15px;
    border-bottom: 1px solid #ecf0f1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
}

.close-modal {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #7f8c8d;
}

#noteText {
    width: 100%;
    min-height: 150px;
    padding: 15px;
    border: none;
    border-bottom: 1px solid #ecf0f1;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

.modal-actions {
    padding: 15px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn-danger {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-primary {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

/* لیست نوت‌ها */
.notes-list {
    padding: 15px;
    max-height: 400px;
    overflow-y: auto;
}

.note-item {
    padding: 12px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border-right: 3px solid #3498db;
}

.note-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.note-page {
    font-size: 12px;
    color: #7f8c8d;
}

.note-delete {
    background: transparent;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 16px;
}

.note-text {
    font-size: 14px;
    color: #2c3e50;
}

/* نوت روی صفحه */
.page-note {
    position: absolute;
    background: rgba(255, 255, 0, 0.9);
    padding: 5px 8px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    max-width: 150px;
    word-wrap: break-word;
    pointer-events: auto;
    z-index: 10;
}

/* هایلایت */
.highlight-line {
    position: absolute;
    background: rgba(255, 255, 0, 0.25);
    border: none;
    pointer-events: none;
    z-index: 5;
}

/* منوی انتخاب صفحه */
.page-selector-container {
    padding: 20px;
}

.page-selector-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.page-selector-item {
    background: #ecf0f1;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.page-selector-item:hover {
    background: #3498db;
    color: white;
    border-color: #2980b9;
    transform: scale(1.05);
}

.page-selector-item.current {
    background: #2ecc71;
    color: white;
    border-color: #27ae60;
}

.page-selector-item.read {
    border: 3px solid #27ae60 !important;
    border-radius: 8px;
}

.page-selector-item.read.current {
    border: 3px solid #27ae60 !important;
    background: #2ecc71;
    color: white;
}

.page-selector-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

/* Media Queries برای گوشی‌های کوچک */
@media (max-width: 480px) {
    .controls {
        padding: 10px 8px;
        gap: 5px;
    }
    
    .btn-control {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .page-info {
        font-size: 14px;
        padding: 4px 8px;
    }
    
    .page-info-container {
        gap: 5px;
    }
    
    .toolbar-inline {
        gap: 5px;
    }
    
    .toolbar-inline .tool-btn,
    .tool-checkbox {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
    
    .tool-checkbox span {
        font-size: 16px;
    }
}

/* Media Queries برای گوشی‌های خیلی کوچک */
@media (max-width: 360px) {
    .controls {
        padding: 8px 5px;
        gap: 4px;
    }
    
    .btn-control {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    .page-info {
        font-size: 12px;
        padding: 3px 6px;
    }
    
    .toolbar-inline {
        gap: 4px;
    }
    
    .toolbar-inline .tool-btn,
    .tool-checkbox {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .tool-checkbox span {
        font-size: 14px;
    }
}

/* Media Queries برای گوشی‌های با عرض خیلی کم (مثل iPhone SE) */
@media (max-width: 320px) {
    .btn-control {
        padding: 6px 8px;
        font-size: 10px;
    }
    
    .page-info {
        font-size: 11px;
    }
    
    .toolbar-inline .tool-btn,
    .tool-checkbox {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }
}


