* {
    box-sizing: border-box;
}

body {
    background: #f0f2f5;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 24px 20px;
    color: #1e293b;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* карточки */
.card {
    background: white;
    border-radius: 24px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.05);
    padding: 1.5rem;
    margin-bottom: 2rem;
    transition: all 0.2s;
}

.card-header {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
    border-left: 5px solid #3b82f6;
    padding-left: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: space-between;
}

/* панель управления */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    background: #f8fafc;
    padding: 1rem;
    border-radius: 20px;
}

/* Секция сохранённых текстов */
.saved-texts-section {
    background: #fefce8;
    border-radius: 16px;
    padding: 1rem;
    margin-top: 1rem;
    border: 1px solid #00ebff;
}

.saved-texts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.saved-texts-header label {
    font-weight: 600;
    color: #854d0e;
    font-size: 0.9rem;
}

.saved-texts-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.saved-texts-controls input {
    border-color: #fde047;
    min-width: 200px;
}

.saved-texts-selector {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.saved-texts-selector select {
    flex: 1;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
    background: white;
    font-family: inherit;
    cursor: pointer;
}

.saved-texts-selector select:hover {
    border-color: #3b82f6;
}

button.success {
    background: #10b981;
}

button.success:hover {
    background: #059669;
}

button.danger {
    background: #ef4444;
}

button.danger:hover {
    background: #dc2626;
}

button.primary {
    background: #3b82f6;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
}

input, textarea, button, select {
    border-radius: 14px;
    border: 1px solid #cbd5e1;
    padding: 8px 14px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: 0.2s;
}

button {
    background: #3b82f6;
    color: white;
    border: none;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 18px;
}

button:hover {
    background: #2563eb;
    transform: scale(0.97);
}

button.secondary {
    background: #64748b;
}
button.secondary:hover {
    background: #475569;
}

textarea {
    width: 100%;
    min-height: 100px;
    font-family: monospace;
    resize: vertical;
}

/* Стили для блоков */
.blocks-container {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin: 20px 0;
    padding: 20px;
    background: #f8fafc;
    border-radius: 20px;
    border: 2px solid #e2e8f0;
    justify-content: center;
}

.block-wrapper {
    background: white;
    border-radius: 16px;
    border: 2px solid #cbd5e1;
    overflow: hidden;
    min-width: 80px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: all 0.2s;
}

.block-wrapper:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.block-header {
    background: #e2e8f0;
    padding: 6px 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    color: #475569;
    border-bottom: 1px solid #cbd5e1;
}

.block-content {
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    background: white;
}

.char-highlight {
    display: inline-block;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 4px 6px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    font-weight: 500;
    min-width: 28px;
    text-align: center;
    user-select: none;
}

.char-highlight:hover {
    background-color: #dbeafe;
    transform: scale(1.1);
}

.char-highlight.selected-start {
    background-color: #3b82f6;
    color: white;
    box-shadow: 0 0 0 2px #3b82f6;
    transform: scale(1.05);
}

.char-highlight.selected-end {
    background-color: #10b981;
    color: white;
    box-shadow: 0 0 0 2px #10b981;
    transform: scale(1.05);
}

.char-highlight.in-range {
    background-color: #fef08a;
    border-radius: 6px;
}


.char-highlight.has-comment:hover::after {
    content: "💬";
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: #f59e0b;
    color: white;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 12px;
    white-space: nowrap;
    pointer-events: none;
}

/* панель комментирования подстроки */
.substring-panel {
    background: #f1f5f9;
    border-radius: 20px;
    padding: 1rem;
    margin: 20px 0;
    border-left: 4px solid #f97316;
}

.comment-item {
    background: #ffffffdd;
    border-radius: 16px;
    padding: 12px;
    margin-top: 12px;
    border: 1px solid #cbd5e1;
    transition: all 0.2s;
}

.comment-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.comment-md {
    background: #f9f9ff;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 0.9rem;
}
.comment-md a {
    color: #2563eb;
    text-decoration: underline;
}

.badge {
    font-size: 0.7rem;
    background: #e2e8f0;
    padding: 2px 8px;
    border-radius: 20px;
}

@media (max-width: 768px) {
    .char-highlight {
        font-size: 0.9rem;
        padding: 3px 4px;
        min-width: 24px;
    }

    .block-content {
        padding: 8px;
        gap: 2px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .saved-texts-header {
        flex-direction: column;
        align-items: stretch;
    }

    .saved-texts-controls {
        flex-direction: column;
    }
}

/* Стили для маленьких кнопок редактирования */
.small-edit {
    font-size: 0.7rem !important;
    padding: 4px 12px !important;
    background: #3b82f6;
}

.small-edit:hover {
    background: #2563eb;
}

#selectionInfo {
    margin-top: 8px;
    padding: 8px;
    background: #f1f5f9;
    border-radius: 12px;
    font-family: monospace;
}